Use trySend multiple times

Change-Id: Ie00c4180d07fc4bb9d457647f3b7ddadd5a3c032
pull/1187/head
Tomáš Mlynarič 11 months ago
parent 08bfc54832
commit 12a3a6edde

@ -89,7 +89,7 @@ class NiaAppState(
val windowSizeClass: WindowSizeClass,
networkMonitor: NetworkMonitor,
userNewsResourceRepository: UserNewsResourceRepository,
private val timeZoneMonitor: TimeZoneMonitor,
timeZoneMonitor: TimeZoneMonitor,
) {
val currentDestination: NavDestination?
@Composable get() = navController

@ -35,6 +35,7 @@ import kotlinx.coroutines.flow.SharedFlow
import kotlinx.coroutines.flow.SharingStarted
import kotlinx.coroutines.flow.callbackFlow
import kotlinx.coroutines.flow.conflate
import kotlinx.coroutines.flow.distinctUntilChanged
import kotlinx.coroutines.flow.flowOn
import kotlinx.coroutines.flow.shareIn
import kotlinx.datetime.TimeZone
@ -87,10 +88,16 @@ internal class TimeZoneBroadcastMonitor @Inject constructor(
context.registerReceiver(receiver, IntentFilter(Intent.ACTION_TIMEZONE_CHANGED))
}
// Send here again, because registering the Broadcast Receiver can take up to several milliseconds.
// This way, we can reduce the likelihood that a TZ change wouldn't be caught with the Broadcast Receiver.
trySend(TimeZone.currentSystemDefault())
awaitClose {
context.unregisterReceiver(receiver)
}
}
// We use to prevent multiple emissions of the same type, because we use trySend multiple times.
.distinctUntilChanged()
.conflate()
.flowOn(ioDispatcher)
// Sharing the callback to prevent multiple BroadcastReceivers being registered

Loading…
Cancel
Save