feat: Auto-close Cipher/Account/Wordlist screens when the model disappears
This commit is contained in:
parent
37e8f8430d
commit
7c2f73649d
@ -77,6 +77,7 @@ import com.artemchep.keyguard.feature.navigation.state.produceScreenState
|
|||||||
import com.artemchep.keyguard.provider.bitwarden.ServerEnv
|
import com.artemchep.keyguard.provider.bitwarden.ServerEnv
|
||||||
import com.artemchep.keyguard.res.Res
|
import com.artemchep.keyguard.res.Res
|
||||||
import com.artemchep.keyguard.ui.FlatItemAction
|
import com.artemchep.keyguard.ui.FlatItemAction
|
||||||
|
import com.artemchep.keyguard.ui.autoclose.launchAutoPopSelfHandler
|
||||||
import com.artemchep.keyguard.ui.buildContextItems
|
import com.artemchep.keyguard.ui.buildContextItems
|
||||||
import com.artemchep.keyguard.ui.icons.ChevronIcon
|
import com.artemchep.keyguard.ui.icons.ChevronIcon
|
||||||
import com.artemchep.keyguard.ui.icons.EmailIcon
|
import com.artemchep.keyguard.ui.icons.EmailIcon
|
||||||
@ -90,7 +91,6 @@ import com.artemchep.keyguard.ui.icons.icon
|
|||||||
import com.artemchep.keyguard.ui.icons.iconSmall
|
import com.artemchep.keyguard.ui.icons.iconSmall
|
||||||
import com.artemchep.keyguard.ui.theme.badgeContainer
|
import com.artemchep.keyguard.ui.theme.badgeContainer
|
||||||
import com.artemchep.keyguard.ui.theme.isDark
|
import com.artemchep.keyguard.ui.theme.isDark
|
||||||
import kotlinx.coroutines.DelicateCoroutinesApi
|
|
||||||
import kotlinx.coroutines.flow.Flow
|
import kotlinx.coroutines.flow.Flow
|
||||||
import kotlinx.coroutines.flow.FlowCollector
|
import kotlinx.coroutines.flow.FlowCollector
|
||||||
import kotlinx.coroutines.flow.combine
|
import kotlinx.coroutines.flow.combine
|
||||||
@ -205,6 +205,7 @@ fun accountState(
|
|||||||
|
|
||||||
val accountFlow = getAccounts()
|
val accountFlow = getAccounts()
|
||||||
.map { it.firstOrNull(accountId) }
|
.map { it.firstOrNull(accountId) }
|
||||||
|
launchAutoPopSelfHandler(accountFlow)
|
||||||
val metaFlow = getMetas()
|
val metaFlow = getMetas()
|
||||||
.map { it.firstOrNull(accountId) }
|
.map { it.firstOrNull(accountId) }
|
||||||
val profileFlow = getProfiles()
|
val profileFlow = getProfiles()
|
||||||
|
@ -14,7 +14,6 @@ import com.artemchep.keyguard.common.usecase.RemoveWordlistById
|
|||||||
import com.artemchep.keyguard.feature.crashlytics.crashlyticsAttempt
|
import com.artemchep.keyguard.feature.crashlytics.crashlyticsAttempt
|
||||||
import com.artemchep.keyguard.feature.generator.wordlist.util.WordlistUtil
|
import com.artemchep.keyguard.feature.generator.wordlist.util.WordlistUtil
|
||||||
import com.artemchep.keyguard.feature.home.vault.search.IndexedText
|
import com.artemchep.keyguard.feature.home.vault.search.IndexedText
|
||||||
import com.artemchep.keyguard.feature.navigation.state.navigatePopSelf
|
|
||||||
import com.artemchep.keyguard.feature.navigation.state.produceScreenState
|
import com.artemchep.keyguard.feature.navigation.state.produceScreenState
|
||||||
import com.artemchep.keyguard.feature.search.search.IndexedModel
|
import com.artemchep.keyguard.feature.search.search.IndexedModel
|
||||||
import com.artemchep.keyguard.feature.search.search.mapSearch
|
import com.artemchep.keyguard.feature.search.search.mapSearch
|
||||||
@ -22,12 +21,9 @@ import com.artemchep.keyguard.feature.search.search.searchFilter
|
|||||||
import com.artemchep.keyguard.feature.search.search.searchQueryHandle
|
import com.artemchep.keyguard.feature.search.search.searchQueryHandle
|
||||||
import com.artemchep.keyguard.res.Res
|
import com.artemchep.keyguard.res.Res
|
||||||
import com.artemchep.keyguard.ui.FlatItemAction
|
import com.artemchep.keyguard.ui.FlatItemAction
|
||||||
|
import com.artemchep.keyguard.ui.autoclose.launchAutoPopSelfHandler
|
||||||
import com.artemchep.keyguard.ui.buildContextItems
|
import com.artemchep.keyguard.ui.buildContextItems
|
||||||
import kotlinx.coroutines.flow.drop
|
|
||||||
import kotlinx.coroutines.flow.filter
|
|
||||||
import kotlinx.coroutines.flow.launchIn
|
|
||||||
import kotlinx.coroutines.flow.map
|
import kotlinx.coroutines.flow.map
|
||||||
import kotlinx.coroutines.flow.onEach
|
|
||||||
import kotlinx.coroutines.flow.stateIn
|
import kotlinx.coroutines.flow.stateIn
|
||||||
import org.kodein.di.compose.localDI
|
import org.kodein.di.compose.localDI
|
||||||
import org.kodein.di.direct
|
import org.kodein.di.direct
|
||||||
@ -110,17 +106,7 @@ fun produceWordlistViewState(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
.stateIn(screenScope)
|
.stateIn(screenScope)
|
||||||
// Auto-close the screen if a model
|
launchAutoPopSelfHandler(wordlistFlow)
|
||||||
// disappears
|
|
||||||
wordlistFlow
|
|
||||||
// We drop the first event, because we don't want to never let
|
|
||||||
// the user open the screen if the model doesn't exist, we want to
|
|
||||||
// close it if the model existed before and a user has seen it.
|
|
||||||
.drop(1)
|
|
||||||
.filter { it == null }
|
|
||||||
// Pop the screen.
|
|
||||||
.onEach { navigatePopSelf() }
|
|
||||||
.launchIn(screenScope)
|
|
||||||
|
|
||||||
fun onClick(model: String) {
|
fun onClick(model: String) {
|
||||||
}
|
}
|
||||||
|
@ -177,6 +177,7 @@ import com.artemchep.keyguard.res.Res
|
|||||||
import com.artemchep.keyguard.ui.ContextItem
|
import com.artemchep.keyguard.ui.ContextItem
|
||||||
import com.artemchep.keyguard.ui.FlatItemAction
|
import com.artemchep.keyguard.ui.FlatItemAction
|
||||||
import com.artemchep.keyguard.ui.MediumEmphasisAlpha
|
import com.artemchep.keyguard.ui.MediumEmphasisAlpha
|
||||||
|
import com.artemchep.keyguard.ui.autoclose.launchAutoPopSelfHandler
|
||||||
import com.artemchep.keyguard.ui.buildContextItems
|
import com.artemchep.keyguard.ui.buildContextItems
|
||||||
import com.artemchep.keyguard.ui.colorizePassword
|
import com.artemchep.keyguard.ui.colorizePassword
|
||||||
import com.artemchep.keyguard.ui.icons.ChevronIcon
|
import com.artemchep.keyguard.ui.icons.ChevronIcon
|
||||||
@ -398,6 +399,8 @@ fun vaultViewScreenState(
|
|||||||
.firstOrNull { it.id == itemId && it.accountId == accountId }
|
.firstOrNull { it.id == itemId && it.accountId == accountId }
|
||||||
}
|
}
|
||||||
.distinctUntilChanged()
|
.distinctUntilChanged()
|
||||||
|
launchAutoPopSelfHandler(secretFlow)
|
||||||
|
|
||||||
val ciphersFlow = getCiphers()
|
val ciphersFlow = getCiphers()
|
||||||
.map { secrets ->
|
.map { secrets ->
|
||||||
secrets
|
secrets
|
||||||
|
@ -0,0 +1,26 @@
|
|||||||
|
package com.artemchep.keyguard.ui.autoclose
|
||||||
|
|
||||||
|
import com.artemchep.keyguard.feature.navigation.state.RememberStateFlowScope
|
||||||
|
import com.artemchep.keyguard.feature.navigation.state.navigatePopSelf
|
||||||
|
import kotlinx.coroutines.flow.Flow
|
||||||
|
import kotlinx.coroutines.flow.drop
|
||||||
|
import kotlinx.coroutines.flow.filter
|
||||||
|
import kotlinx.coroutines.flow.launchIn
|
||||||
|
import kotlinx.coroutines.flow.onEach
|
||||||
|
|
||||||
|
fun <T : Any> RememberStateFlowScope.launchAutoPopSelfHandler(
|
||||||
|
contentFlow: Flow<T?>,
|
||||||
|
) {
|
||||||
|
// Auto-close the screen if a model disappears.
|
||||||
|
// This happens if a user deletes the
|
||||||
|
// cipher, for example.
|
||||||
|
contentFlow
|
||||||
|
// We drop the first event, because we don't want to never let
|
||||||
|
// the user open the screen if the model doesn't exist, we want to
|
||||||
|
// close it if the model existed before and a user has seen it.
|
||||||
|
.drop(1)
|
||||||
|
.filter { it == null }
|
||||||
|
// Pop the screen.
|
||||||
|
.onEach { navigatePopSelf() }
|
||||||
|
.launchIn(screenScope)
|
||||||
|
}
|
Loading…
x
Reference in New Issue
Block a user