Commit be9b0c2e authored by LoveSy's avatar LoveSy Committed by John Wu

Move flow.concurrentMap to ktx

parent b6affe06
package com.topjohnwu.magisk.ktx
import kotlinx.coroutines.FlowPreview
import kotlinx.coroutines.flow.Flow
import kotlinx.coroutines.flow.flatMapMerge
import kotlinx.coroutines.flow.flow
@FlowPreview
inline fun <T, R> Flow<T>.concurrentMap(crossinline transform: suspend (T) -> R): Flow<R> {
return flatMapMerge { value ->
flow { emit(transform(value)) }
}
}
...@@ -9,6 +9,7 @@ import com.topjohnwu.magisk.arch.Queryable ...@@ -9,6 +9,7 @@ import com.topjohnwu.magisk.arch.Queryable
import com.topjohnwu.magisk.databinding.filterableListOf import com.topjohnwu.magisk.databinding.filterableListOf
import com.topjohnwu.magisk.databinding.itemBindingOf import com.topjohnwu.magisk.databinding.itemBindingOf
import com.topjohnwu.magisk.di.AppContext import com.topjohnwu.magisk.di.AppContext
import com.topjohnwu.magisk.ktx.concurrentMap
import com.topjohnwu.magisk.utils.Utils import com.topjohnwu.magisk.utils.Utils
import com.topjohnwu.superuser.Shell import com.topjohnwu.superuser.Shell
import kotlinx.coroutines.* import kotlinx.coroutines.*
...@@ -16,6 +17,7 @@ import kotlinx.coroutines.flow.* ...@@ -16,6 +17,7 @@ import kotlinx.coroutines.flow.*
import java.util.* import java.util.*
import kotlin.collections.ArrayList import kotlin.collections.ArrayList
@FlowPreview
class DenyListViewModel : BaseViewModel(), Queryable { class DenyListViewModel : BaseViewModel(), Queryable {
override val queryDelay = 0L override val queryDelay = 0L
...@@ -46,14 +48,6 @@ class DenyListViewModel : BaseViewModel(), Queryable { ...@@ -46,14 +48,6 @@ class DenyListViewModel : BaseViewModel(), Queryable {
it.bindExtra(BR.viewModel, this) it.bindExtra(BR.viewModel, this)
} }
@FlowPreview
private inline fun <T, R> Flow<T>.concurrentMap(crossinline transform: suspend (T) -> R): Flow<R> {
return flatMapMerge { value ->
flow { emit(transform(value)) }
}
}
@FlowPreview
@SuppressLint("InlinedApi") @SuppressLint("InlinedApi")
override fun refresh() = viewModelScope.launch { override fun refresh() = viewModelScope.launch {
if (!Utils.showSuperUser()) { if (!Utils.showSuperUser()) {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment