Move flow.concurrentMap to ktx

This commit is contained in:
LoveSy 2021-11-13 03:49:41 +08:00 committed by John Wu
parent b6affe06a5
commit be9b0c2e8f
2 changed files with 15 additions and 8 deletions

View File

@ -0,0 +1,13 @@
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)) }
}
}

View File

@ -9,6 +9,7 @@ import com.topjohnwu.magisk.arch.Queryable
import com.topjohnwu.magisk.databinding.filterableListOf
import com.topjohnwu.magisk.databinding.itemBindingOf
import com.topjohnwu.magisk.di.AppContext
import com.topjohnwu.magisk.ktx.concurrentMap
import com.topjohnwu.magisk.utils.Utils
import com.topjohnwu.superuser.Shell
import kotlinx.coroutines.*
@ -16,6 +17,7 @@ import kotlinx.coroutines.flow.*
import java.util.*
import kotlin.collections.ArrayList
@FlowPreview
class DenyListViewModel : BaseViewModel(), Queryable {
override val queryDelay = 0L
@ -46,14 +48,6 @@ class DenyListViewModel : BaseViewModel(), Queryable {
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")
override fun refresh() = viewModelScope.launch {
if (!Utils.showSuperUser()) {