aboutsummaryrefslogtreecommitdiff
path: root/app/src/main/kotlin/com/pitchedapps/frost/activities
diff options
context:
space:
mode:
Diffstat (limited to 'app/src/main/kotlin/com/pitchedapps/frost/activities')
-rw-r--r--app/src/main/kotlin/com/pitchedapps/frost/activities/BaseMainActivity.kt19
-rw-r--r--app/src/main/kotlin/com/pitchedapps/frost/activities/MainActivity.kt12
2 files changed, 18 insertions, 13 deletions
diff --git a/app/src/main/kotlin/com/pitchedapps/frost/activities/BaseMainActivity.kt b/app/src/main/kotlin/com/pitchedapps/frost/activities/BaseMainActivity.kt
index 84352cb4..8585f68b 100644
--- a/app/src/main/kotlin/com/pitchedapps/frost/activities/BaseMainActivity.kt
+++ b/app/src/main/kotlin/com/pitchedapps/frost/activities/BaseMainActivity.kt
@@ -498,7 +498,10 @@ abstract class BaseMainActivity :
)
positiveButton(R.string.kau_yes) {
this@BaseMainActivity.launch {
- fbCookie.logout(this@BaseMainActivity, deleteCookie = true)
+ fbCookie.logout(
+ this@BaseMainActivity,
+ deleteCookie = true
+ )
}
}
negativeButton(R.string.kau_no)
@@ -637,7 +640,7 @@ abstract class BaseMainActivity :
private fun refreshAll() {
L.d { "Refresh all" }
- fragmentChannel.offer(REQUEST_REFRESH)
+ fragmentEmit(REQUEST_REFRESH)
}
override fun onCreateOptionsMenu(menu: Menu): Boolean {
@@ -737,19 +740,19 @@ abstract class BaseMainActivity :
* These results can be stacked
*/
if (hasRequest(REQUEST_REFRESH)) {
- fragmentChannel.offer(REQUEST_REFRESH)
+ fragmentEmit(REQUEST_REFRESH)
}
if (hasRequest(REQUEST_NAV)) {
frostNavigationBar(prefs, themeProvider)
}
if (hasRequest(REQUEST_TEXT_ZOOM)) {
- fragmentChannel.offer(REQUEST_TEXT_ZOOM)
+ fragmentEmit(REQUEST_TEXT_ZOOM)
}
if (hasRequest(REQUEST_SEARCH)) {
invalidateOptionsMenu()
}
if (hasRequest(REQUEST_FAB)) {
- fragmentChannel.offer(lastPosition)
+ fragmentEmit(lastPosition)
}
if (hasRequest(REQUEST_NOTIFICATION)) {
scheduleNotificationsFromPrefs(prefs)
@@ -792,7 +795,6 @@ abstract class BaseMainActivity :
override fun onDestroy() {
controlWebview?.destroy()
super.onDestroy()
- fragmentChannel.close()
}
override fun collapseAppBar() {
@@ -864,10 +866,9 @@ abstract class BaseMainActivity :
lastPosition = 0
viewpager.setCurrentItem(0, false)
viewpager.offscreenPageLimit = pages.size
+ // todo check if post is necessary
viewpager.post {
- if (!fragmentChannel.isClosedForSend) {
- fragmentChannel.offer(0)
- }
+ fragmentEmit(0)
} // trigger hook so title is set
}
}
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 4b18088c..97067b21 100644
--- a/app/src/main/kotlin/com/pitchedapps/frost/activities/MainActivity.kt
+++ b/app/src/main/kotlin/com/pitchedapps/frost/activities/MainActivity.kt
@@ -27,6 +27,8 @@ import com.pitchedapps.frost.web.FrostEmitter
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
import kotlinx.coroutines.flow.SharedFlow
import kotlinx.coroutines.flow.asSharedFlow
@@ -39,8 +41,10 @@ import kotlinx.coroutines.flow.onEach
@UseExperimental(ExperimentalCoroutinesApi::class)
class MainActivity : BaseMainActivity() {
-
- override val fragmentChannel = BroadcastChannel<Int>(10)
+
+ 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) }
private val headerMutableFlow = MutableStateFlow("")
override val headerFlow: SharedFlow<String> = headerMutableFlow.asSharedFlow()
@@ -61,9 +65,9 @@ class MainActivity : BaseMainActivity() {
return
}
if (lastPosition != -1) {
- fragmentChannel.offer(-(lastPosition + 1))
+ fragmentEmit(-(lastPosition + 1))
}
- fragmentChannel.offer(position)
+ fragmentEmit(position)
lastPosition = position
}