mirror of
https://github.com/signalapp/Signal-Android.git
synced 2026-04-21 17:29:32 +01:00
Observe service outages in a lifecycle-aware fashion.
This commit is contained in:
committed by
mtang-signal
parent
fd31bc60b2
commit
4002dea05d
@@ -9,15 +9,18 @@ import android.content.Context
|
||||
import androidx.compose.runtime.Composable
|
||||
import androidx.compose.ui.res.stringResource
|
||||
import kotlinx.coroutines.flow.Flow
|
||||
import kotlinx.coroutines.flow.map
|
||||
import org.thoughtcrime.securesms.R
|
||||
import org.thoughtcrime.securesms.banner.Banner
|
||||
import org.thoughtcrime.securesms.banner.ui.compose.DefaultBanner
|
||||
import org.thoughtcrime.securesms.banner.ui.compose.Importance
|
||||
import org.thoughtcrime.securesms.util.TextSecurePreferences
|
||||
|
||||
class ServiceOutageBanner(context: Context) : Banner() {
|
||||
class ServiceOutageBanner(outageInProgress: Boolean) : Banner() {
|
||||
|
||||
override val enabled = TextSecurePreferences.getServiceOutage(context)
|
||||
constructor(context: Context) : this(TextSecurePreferences.getServiceOutage(context))
|
||||
|
||||
override val enabled = outageInProgress
|
||||
|
||||
@Composable
|
||||
override fun DisplayBanner() {
|
||||
@@ -31,8 +34,14 @@ class ServiceOutageBanner(context: Context) : Banner() {
|
||||
companion object {
|
||||
|
||||
@JvmStatic
|
||||
fun createFlow(context: Context): Flow<ServiceOutageBanner> = createAndEmit {
|
||||
fun createOneShotFlow(context: Context): Flow<ServiceOutageBanner> = createAndEmit {
|
||||
ServiceOutageBanner(context)
|
||||
}
|
||||
|
||||
/**
|
||||
* Take a [Flow] of [Boolean] values representing the service status and map it into a [Flow] of [ServiceOutageBanner]
|
||||
*/
|
||||
@JvmStatic
|
||||
fun fromFlow(statusFlow: Flow<Boolean>): Flow<ServiceOutageBanner> = statusFlow.map { ServiceOutageBanner(it) }
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user