aboutsummaryrefslogtreecommitdiff
path: root/app
diff options
context:
space:
mode:
authorAllan Wang <me@allanwang.ca>2021-11-23 11:50:06 -0800
committerAllan Wang <me@allanwang.ca>2021-11-23 11:50:06 -0800
commit0c97abd838ee834ef17d1b2e746fa26ea9663bd5 (patch)
treef90e3f5110e6e4fe724b9c2fde125769cd0d36fd /app
parent30d6fd9d33e17110726a299749b058416ed77ecf (diff)
downloadfrost-0c97abd838ee834ef17d1b2e746fa26ea9663bd5.tar.gz
frost-0c97abd838ee834ef17d1b2e746fa26ea9663bd5.tar.bz2
frost-0c97abd838ee834ef17d1b2e746fa26ea9663bd5.zip
Create extension for converting emitters
Diffstat (limited to 'app')
-rw-r--r--app/src/main/kotlin/com/pitchedapps/frost/activities/MainActivity.kt8
-rw-r--r--app/src/main/kotlin/com/pitchedapps/frost/contracts/ActivityContract.kt1
-rw-r--r--app/src/main/kotlin/com/pitchedapps/frost/fragments/BaseFragment.kt1
-rw-r--r--app/src/main/kotlin/com/pitchedapps/frost/views/FrostContentView.kt10
-rw-r--r--app/src/main/kotlin/com/pitchedapps/frost/web/FrostWeb.kt3
5 files changed, 11 insertions, 12 deletions
diff --git a/app/src/main/kotlin/com/pitchedapps/frost/activities/MainActivity.kt b/app/src/main/kotlin/com/pitchedapps/frost/activities/MainActivity.kt
index 97067b21..2e44e5f9 100644
--- a/app/src/main/kotlin/com/pitchedapps/frost/activities/MainActivity.kt
+++ b/app/src/main/kotlin/com/pitchedapps/frost/activities/MainActivity.kt
@@ -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) {
diff --git a/app/src/main/kotlin/com/pitchedapps/frost/contracts/ActivityContract.kt b/app/src/main/kotlin/com/pitchedapps/frost/contracts/ActivityContract.kt
index 3c5d7412..721282aa 100644
--- a/app/src/main/kotlin/com/pitchedapps/frost/contracts/ActivityContract.kt
+++ b/app/src/main/kotlin/com/pitchedapps/frost/contracts/ActivityContract.kt
@@ -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)
diff --git a/app/src/main/kotlin/com/pitchedapps/frost/fragments/BaseFragment.kt b/app/src/main/kotlin/com/pitchedapps/frost/fragments/BaseFragment.kt
index 5c97de65..e10fd141 100644
--- a/app/src/main/kotlin/com/pitchedapps/frost/fragments/BaseFragment.kt
+++ b/app/src/main/kotlin/com/pitchedapps/frost/fragments/BaseFragment.kt
@@ -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
diff --git a/app/src/main/kotlin/com/pitchedapps/frost/views/FrostContentView.kt b/app/src/main/kotlin/com/pitchedapps/frost/views/FrostContentView.kt
index 75d1ffe4..f9d04ad1 100644
--- a/app/src/main/kotlin/com/pitchedapps/frost/views/FrostContentView.kt
+++ b/app/src/main/kotlin/com/pitchedapps/frost/views/FrostContentView.kt
@@ -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
diff --git a/app/src/main/kotlin/com/pitchedapps/frost/web/FrostWeb.kt b/app/src/main/kotlin/com/pitchedapps/frost/web/FrostWeb.kt
index 30845a79..ba05a2c4 100644
--- a/app/src/main/kotlin/com/pitchedapps/frost/web/FrostWeb.kt
+++ b/app/src/main/kotlin/com/pitchedapps/frost/web/FrostWeb.kt
@@ -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 {