Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,8 @@ dependencies {
androidTestImplementation 'androidx.test.espresso:espresso-core:3.4.0'

// coroutines
implementation 'org.jetbrains.kotlinx:kotlinx-coroutines-core:1.5.2'
implementation 'org.jetbrains.kotlinx:kotlinx-coroutines-android:1.5.2'
implementation 'org.jetbrains.kotlinx:kotlinx-coroutines-core:1.6.0'
implementation 'org.jetbrains.kotlinx:kotlinx-coroutines-android:1.6.0'

// viewModelScope
implementation 'androidx.lifecycle:lifecycle-viewmodel-ktx:2.4.0'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,10 +74,9 @@ class MainActivity : AppCompatActivity() {
}

@CheckResult
@ExperimentalCoroutinesApi
fun View.clicks(): Flow<Unit> {
return callbackFlow {
setOnClickListener { offer(Unit) }
setOnClickListener { trySend(Unit) }
awaitClose { setOnClickListener(null) }
}
}
6 changes: 3 additions & 3 deletions app/src/main/java/com/hoc081098/stateflowsample/MainVM.kt
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ class MainVM : ViewModel() {
const val MAX_SECONDS = 10
}

private val actionChannel = BroadcastChannel<MainAction>(Channel.BUFFERED)
private val actionChannel = Channel<MainAction>(Channel.BUFFERED)

val stateFlow: StateFlow<MainState>

Expand All @@ -31,7 +31,7 @@ class MainVM : ViewModel() {
var resume = 0L

actionChannel
.asFlow()
.consumeAsFlow()
.onEach { action ->
when (action) {
MainAction.START -> Unit
Expand Down Expand Up @@ -70,7 +70,7 @@ class MainVM : ViewModel() {
}
.onEach { stateFlow.value = it }
.onEach { Log.d("###", "Main state: $it") }
.catch { }
.catch { Log.d("###", "Exception: $it") }
.launchIn(viewModelScope)
}
}
Binary file modified gradle/wrapper/gradle-wrapper.jar
Binary file not shown.
3 changes: 1 addition & 2 deletions gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
#Sat May 09 19:32:08 ICT 2020
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-7.3.3-all.zip
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-7.3.2-all.zip
Loading