Skip to content

Commit

Permalink
kotlinx-coroutines:1.6.0-RC
Browse files Browse the repository at this point in the history
  • Loading branch information
hoc081098 committed Nov 25, 2021
1 parent f07674c commit 1458539
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 13 deletions.
4 changes: 2 additions & 2 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,8 @@ dependencies {
implementation "androidx.lifecycle:lifecycle-runtime-ktx:2.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-RC"
implementation "org.jetbrains.kotlinx:kotlinx-coroutines-android:1.6.0-RC"

// Hilt
implementation "com.google.dagger:hilt-android:2.40.2"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,6 @@ import com.hoc081098.paginationmviflow.FlowTransformer
import com.hoc081098.paginationmviflow.pipe
import com.hoc081098.paginationmviflow.ui.main.MainContract.PartialStateChange
import dagger.hilt.android.lifecycle.HiltViewModel
import kotlinx.coroutines.ExperimentalCoroutinesApi
import kotlinx.coroutines.FlowPreview
import kotlinx.coroutines.channels.Channel
import kotlinx.coroutines.flow.Flow
import kotlinx.coroutines.flow.MutableSharedFlow
Expand All @@ -29,10 +27,6 @@ import com.hoc081098.paginationmviflow.ui.main.MainContract.SingleEvent as SE
import com.hoc081098.paginationmviflow.ui.main.MainContract.ViewIntent as VI
import com.hoc081098.paginationmviflow.ui.main.MainContract.ViewState as VS

@OptIn(
ExperimentalCoroutinesApi::class,
FlowPreview::class
)
@HiltViewModel
class MainVM @Inject constructor(
private val mainProcessors: MainProcessors,
Expand Down
9 changes: 4 additions & 5 deletions app/src/main/java/com/hoc081098/paginationmviflow/util.kt
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ import androidx.lifecycle.lifecycleScope
import androidx.lifecycle.repeatOnLifecycle
import androidx.recyclerview.widget.RecyclerView
import androidx.swiperefreshlayout.widget.SwipeRefreshLayout
import kotlinx.coroutines.ExperimentalCoroutinesApi
import kotlinx.coroutines.Job
import kotlinx.coroutines.channels.awaitClose
import kotlinx.coroutines.flow.Flow
Expand All @@ -22,9 +21,11 @@ import kotlinx.coroutines.flow.collect
import kotlinx.coroutines.launch

fun interface FlowTransformer<I, O> {
@CheckResult
fun transform(input: Flow<I>): Flow<O>
}

@CheckResult
@Suppress("NOTHING_TO_INLINE")
inline fun <I, O> Flow<I>.pipe(transformer: FlowTransformer<I, O>) =
transformer.transform(this)
Expand All @@ -35,7 +36,6 @@ fun Context.toast(text: CharSequence) = Toast.makeText(this, text, Toast.LENGTH_

fun Fragment.toast(text: CharSequence) = requireContext().toast(text)

@OptIn(ExperimentalCoroutinesApi::class)
@CheckResult
fun SwipeRefreshLayout.refreshes(): Flow<Unit> {
return callbackFlow {
Expand All @@ -44,7 +44,6 @@ fun SwipeRefreshLayout.refreshes(): Flow<Unit> {
}
}

@OptIn(ExperimentalCoroutinesApi::class)
@CheckResult
fun View.clicks(): Flow<View> {
return callbackFlow {
Expand All @@ -55,7 +54,7 @@ fun View.clicks(): Flow<View> {

data class RecyclerViewScrollEvent(val view: RecyclerView, val dx: Int, val dy: Int)

@OptIn(ExperimentalCoroutinesApi::class)
@CheckResult
fun RecyclerView.scrollEvents(): Flow<RecyclerViewScrollEvent> {
return callbackFlow {
val listener = object : RecyclerView.OnScrollListener() {
Expand All @@ -74,7 +73,7 @@ fun RecyclerView.scrollEvents(): Flow<RecyclerViewScrollEvent> {
}
}

@OptIn(ExperimentalCoroutinesApi::class)
@CheckResult
fun ViewGroup.detaches(): Flow<Unit> {
return callbackFlow {
val listener = object : View.OnAttachStateChangeListener {
Expand Down

0 comments on commit 1458539

Please sign in to comment.