Skip to content

Commit

Permalink
coroutine like block code
Browse files Browse the repository at this point in the history
  • Loading branch information
Louis-XWB committed Sep 17, 2024
1 parent 44d8a13 commit 0e347ca
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 0 deletions.
4 changes: 4 additions & 0 deletions app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,10 @@
android:exported="true"
android:theme="@style/Theme.CourseCoroutines" />

<activity android:name="._1_basics.DeMagicActivity"
android:exported="true"
android:theme="@style/Theme.CourseCoroutines" />

</application>

</manifest>
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
package com.novar.supercorouutine._1_basics

import android.os.Bundle
import android.os.Handler
import android.os.HandlerThread
import android.os.Looper
import android.widget.TextView
import androidx.activity.ComponentActivity
import androidx.lifecycle.lifecycleScope
import com.novar.supercorouutine.R
import com.novar.supercorouutine.common.Contributor
import com.novar.supercorouutine.common.gitHub
import kotlinx.coroutines.launch
import kotlin.concurrent.thread

class DeMagicActivity : ComponentActivity() {
private lateinit var infoTextView: TextView

override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.layout_1)
infoTextView = findViewById(R.id.infoTextView)

lifecycleScope.launch {
// switchToBackground {
// gitHub.contributors("square", "retrofit")
// switchToMain {
// showContributors(contributors)
// }
// }
}
}

private fun coroutinesStyle() = lifecycleScope.launch {
val contributors = gitHub.contributors("square", "retrofit")
showContributors(contributors)
}

private fun showContributors(contributors: List<Contributor>) = contributors
.map { "${it.login} (${it.contributions})" }
.reduce { acc, s -> "$acc\n$s" }
.let { infoTextView.text = it }
}

0 comments on commit 0e347ca

Please sign in to comment.