fix: Display a correct current region when Re-logging into an account

This commit is contained in:
Artem Chepurnoy 2024-01-28 09:27:33 +02:00
parent 97ff7e84ad
commit c22595537e
No known key found for this signature in database
GPG Key ID: FAC37D0CF674043E
2 changed files with 33 additions and 15 deletions

View File

@ -455,8 +455,9 @@ private fun LoginItemDropdown(
ExpandedIfNotEmpty(field.text) { text -> ExpandedIfNotEmpty(field.text) { text ->
Text( Text(
text = text, text = text,
style = MaterialTheme.typography.bodySmall, style = MaterialTheme.typography.labelMedium,
color = MaterialTheme.colorScheme.primary, color = MaterialTheme.colorScheme.primary
.combineAlpha(LocalContentColor.current.alpha),
) )
} }
} }

View File

@ -36,6 +36,7 @@ import com.artemchep.keyguard.provider.bitwarden.usecase.internal.AddAccount
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.icons.icon import com.artemchep.keyguard.ui.icons.icon
import kotlinx.collections.immutable.persistentListOf
import kotlinx.collections.immutable.toPersistentList import kotlinx.collections.immutable.toPersistentList
import kotlinx.collections.immutable.toPersistentMap import kotlinx.collections.immutable.toPersistentMap
import kotlinx.coroutines.CoroutineScope import kotlinx.coroutines.CoroutineScope
@ -173,7 +174,19 @@ fun produceLoginScreenState(
// region // region
val regionDefault = LoginRegion.default val regionDefault = if (
args.env.baseUrl.isNotBlank() ||
args.env.webVaultUrl.isNotBlank() ||
args.env.apiUrl.isNotBlank() ||
args.env.identityUrl.isNotBlank() ||
args.env.iconsUrl.isNotBlank() ||
args.env.notificationsUrl.isNotBlank() ||
args.env.headers.isNotEmpty()
) {
LoginRegion.Custom
} else {
LoginRegion.Predefined(args.env.region)
}
val regionSink = mutablePersistedFlow(KEY_REGION) { regionDefault.key } val regionSink = mutablePersistedFlow(KEY_REGION) { regionDefault.key }
val regionFlow = regionSink val regionFlow = regionSink
.map { regionName -> .map { regionName ->
@ -181,18 +194,22 @@ fun produceLoginScreenState(
?: regionDefault ?: regionDefault
} }
val regionItems = LoginRegion.values val regionItems = if (args.envEditable) {
.asSequence() LoginRegion.values
.map { region -> .asSequence()
FlatItemAction( .map { region ->
id = region.key, FlatItemAction(
title = translate(region.title), id = region.key,
onClick = { title = translate(region.title),
regionSink.value = region.key onClick = {
}, regionSink.value = region.key
) },
} )
.toPersistentList() }
.toPersistentList()
} else {
persistentListOf()
}
// //
// //