mirror of
https://github.com/AllanWang/Frost-for-Facebook.git
synced 2024-11-09 20:42:34 +01:00
Create extension for converting emitters
This commit is contained in:
parent
30d6fd9d33
commit
0c97abd838
@ -24,9 +24,9 @@ import com.pitchedapps.frost.facebook.parsers.BadgeParser
|
||||
import com.pitchedapps.frost.utils.L
|
||||
import com.pitchedapps.frost.views.BadgedIcon
|
||||
import com.pitchedapps.frost.web.FrostEmitter
|
||||
import com.pitchedapps.frost.web.asFrostEmitter
|
||||
import kotlinx.coroutines.Dispatchers
|
||||
import kotlinx.coroutines.ExperimentalCoroutinesApi
|
||||
import kotlinx.coroutines.channels.BroadcastChannel
|
||||
import kotlinx.coroutines.channels.BufferOverflow
|
||||
import kotlinx.coroutines.flow.MutableSharedFlow
|
||||
import kotlinx.coroutines.flow.MutableStateFlow
|
||||
@ -41,14 +41,14 @@ import kotlinx.coroutines.flow.onEach
|
||||
|
||||
@UseExperimental(ExperimentalCoroutinesApi::class)
|
||||
class MainActivity : BaseMainActivity() {
|
||||
|
||||
|
||||
private val fragmentMutableFlow = MutableSharedFlow<Int>(extraBufferCapacity = 10, onBufferOverflow = BufferOverflow.DROP_OLDEST)
|
||||
override val fragmentFlow: SharedFlow<Int> = fragmentMutableFlow.asSharedFlow()
|
||||
override val fragmentEmit: FrostEmitter<Int> = FrostEmitter { fragmentMutableFlow.tryEmit(it) }
|
||||
override val fragmentEmit: FrostEmitter<Int> = fragmentMutableFlow.asFrostEmitter()
|
||||
|
||||
private val headerMutableFlow = MutableStateFlow("")
|
||||
override val headerFlow: SharedFlow<String> = headerMutableFlow.asSharedFlow()
|
||||
override val headerEmit: FrostEmitter<String> = FrostEmitter { headerMutableFlow.tryEmit(it) }
|
||||
override val headerEmit: FrostEmitter<String> = headerMutableFlow.asFrostEmitter()
|
||||
|
||||
override fun onNestedCreate(savedInstanceState: Bundle?) {
|
||||
with(contentBinding) {
|
||||
|
@ -20,7 +20,6 @@ import com.mikepenz.iconics.typeface.IIcon
|
||||
import com.pitchedapps.frost.fragments.BaseFragment
|
||||
import com.pitchedapps.frost.web.FrostEmitter
|
||||
import kotlinx.coroutines.ExperimentalCoroutinesApi
|
||||
import kotlinx.coroutines.channels.BroadcastChannel
|
||||
import kotlinx.coroutines.flow.SharedFlow
|
||||
|
||||
@UseExperimental(ExperimentalCoroutinesApi::class)
|
||||
|
@ -47,7 +47,6 @@ import kotlinx.coroutines.CoroutineScope
|
||||
import kotlinx.coroutines.ExperimentalCoroutinesApi
|
||||
import kotlinx.coroutines.Job
|
||||
import kotlinx.coroutines.SupervisorJob
|
||||
import kotlinx.coroutines.channels.ReceiveChannel
|
||||
import kotlinx.coroutines.flow.launchIn
|
||||
import kotlinx.coroutines.flow.onEach
|
||||
import kotlinx.coroutines.isActive
|
||||
|
@ -41,6 +41,7 @@ import com.pitchedapps.frost.injectors.ThemeProvider
|
||||
import com.pitchedapps.frost.prefs.Prefs
|
||||
import com.pitchedapps.frost.utils.L
|
||||
import com.pitchedapps.frost.web.FrostEmitter
|
||||
import com.pitchedapps.frost.web.asFrostEmitter
|
||||
import dagger.hilt.android.AndroidEntryPoint
|
||||
import kotlinx.coroutines.CoroutineScope
|
||||
import kotlinx.coroutines.ExperimentalCoroutinesApi
|
||||
@ -139,22 +140,19 @@ abstract class FrostContentViewBase(
|
||||
|
||||
override val refreshFlow: SharedFlow<Boolean> = refreshMutableFlow.asSharedFlow()
|
||||
|
||||
override val refreshEmit: FrostEmitter<Boolean> =
|
||||
FrostEmitter { refreshMutableFlow.tryEmit(it) }
|
||||
override val refreshEmit: FrostEmitter<Boolean> = refreshMutableFlow.asFrostEmitter()
|
||||
|
||||
private val progressMutableFlow = MutableStateFlow(0)
|
||||
|
||||
override val progressFlow: SharedFlow<Int> = progressMutableFlow.asSharedFlow()
|
||||
|
||||
override val progressEmit: FrostEmitter<Int> =
|
||||
FrostEmitter { progressMutableFlow.tryEmit(it) }
|
||||
override val progressEmit: FrostEmitter<Int> = progressMutableFlow.asFrostEmitter()
|
||||
|
||||
private val titleMutableFlow = MutableStateFlow("")
|
||||
|
||||
override val titleFlow: SharedFlow<String> = titleMutableFlow.asSharedFlow()
|
||||
|
||||
override val titleEmit: FrostEmitter<String> =
|
||||
FrostEmitter { titleMutableFlow.tryEmit(it) }
|
||||
override val titleEmit: FrostEmitter<String> = titleMutableFlow.asFrostEmitter()
|
||||
|
||||
override lateinit var scope: CoroutineScope
|
||||
|
||||
|
@ -25,6 +25,7 @@ import dagger.hilt.DefineComponent
|
||||
import dagger.hilt.EntryPoint
|
||||
import dagger.hilt.InstallIn
|
||||
import dagger.hilt.android.components.ViewComponent
|
||||
import kotlinx.coroutines.flow.MutableSharedFlow
|
||||
import kotlinx.coroutines.flow.SharedFlow
|
||||
import javax.inject.Qualifier
|
||||
import javax.inject.Scope
|
||||
@ -62,6 +63,8 @@ interface FrostWebEntryPoint {
|
||||
|
||||
fun interface FrostEmitter<T> : (T) -> Unit
|
||||
|
||||
fun <T> MutableSharedFlow<T>.asFrostEmitter(): FrostEmitter<T> = FrostEmitter { tryEmit(it) }
|
||||
|
||||
@Module
|
||||
@InstallIn(FrostWebComponent::class)
|
||||
object FrostWebFlowModule {
|
||||
|
Loading…
Reference in New Issue
Block a user