Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 8f56daff authored by Santiago Etchebehere's avatar Santiago Etchebehere
Browse files

Fix fragment getting stuck when resuming

Make sure the isAvailable flow for ThemedIcons emits correctly

Fixes: 417135083
Flag: com.android.systemui.shared.new_customization_picker_ui
Test: see video
Test: existing unit tests
Change-Id: Ia0bf21afd6874fea55e6c3c6cdff36b408708fa4
parent 72feedb9
Loading
Loading
Loading
Loading
+4 −9
Original line number Diff line number Diff line
@@ -39,8 +39,7 @@ import kotlinx.coroutines.flow.Flow
import kotlinx.coroutines.flow.MutableStateFlow
import kotlinx.coroutines.flow.SharingStarted
import kotlinx.coroutines.flow.callbackFlow
import kotlinx.coroutines.flow.map
import kotlinx.coroutines.flow.shareIn
import kotlinx.coroutines.flow.filterNotNull
import kotlinx.coroutines.flow.stateIn
import kotlinx.coroutines.launch

@@ -54,6 +53,7 @@ constructor(
    @BackgroundDispatcher private val backgroundScope: CoroutineScope,
) : ThemedIconRepository {
    private val uri: MutableStateFlow<Uri?> = MutableStateFlow(null)
    private val _isAvailable: MutableStateFlow<Boolean?> = MutableStateFlow(null)
    private var getUriJob: Job =
        backgroundScope.launch {
            val homeIntent = Intent(Intent.ACTION_MAIN).addCategory(Intent.CATEGORY_HOME)
@@ -92,15 +92,10 @@ constructor(
                        .appendPath(ICON_THEMED)
                        .build()
                }
            _isAvailable.value = uri.value != null
        }

    override val isAvailable: Flow<Boolean> =
        uri.map { it != null }
            .shareIn(
                scope = backgroundScope,
                started = SharingStarted.WhileSubscribed(),
                replay = 1,
            )
    override val isAvailable: Flow<Boolean> = _isAvailable.filterNotNull()

    override val isActivated: Flow<Boolean> =
        callbackFlow {