Make disk source rVal nullable

This commit is contained in:
Patrick Honkonen 2024-11-19 13:35:43 -05:00
parent 3325026708
commit 3c22e2dd2d
No known key found for this signature in database
GPG key ID: B63AF42A5531C877
5 changed files with 17 additions and 14 deletions

View file

@ -324,7 +324,7 @@ interface SettingsDiskSource {
* Gets whether or not the given [userId] has registered for export via the credential exchange
* protocol.
*/
fun getVaultRegisteredForExport(userId: String): Boolean
fun getVaultRegisteredForExport(userId: String): Boolean?
/**
* Stores the given value for whether or not the given [userId] has registered for export via
@ -335,5 +335,5 @@ interface SettingsDiskSource {
/**
* Emits updates that track [getVaultRegisteredForExport] for the given [userId].
*/
fun getVaultRegisteredForExportFlow(userId: String): Flow<Boolean>
fun getVaultRegisteredForExportFlow(userId: String): Flow<Boolean?>
}

View file

@ -82,7 +82,7 @@ class SettingsDiskSourceImpl(
mutableMapOf<String, MutableSharedFlow<Boolean?>>()
private val mutableVaultRegisteredForExportFlow =
mutableMapOf<String, MutableSharedFlow<Boolean>>()
mutableMapOf<String, MutableSharedFlow<Boolean?>>()
override var appLanguage: AppLanguage?
get() = getString(key = APP_LANGUAGE_KEY)
@ -447,15 +447,15 @@ class SettingsDiskSourceImpl(
getMutableShowImportLoginsSettingBadgeFlow(userId)
.onSubscription { emit(getShowImportLoginsSettingBadge(userId)) }
override fun getVaultRegisteredForExport(userId: String): Boolean =
getBoolean(IS_VAULT_REGISTERED_FOR_EXPORT.appendIdentifier(userId)) == true
override fun getVaultRegisteredForExport(userId: String): Boolean? =
getBoolean(IS_VAULT_REGISTERED_FOR_EXPORT.appendIdentifier(userId))
override fun storeVaultRegisteredForExport(userId: String, isRegistered: Boolean) {
putBoolean(IS_VAULT_REGISTERED_FOR_EXPORT.appendIdentifier(userId), isRegistered)
getMutableVaultRegisteredForExportFlow(userId).tryEmit(isRegistered)
}
override fun getVaultRegisteredForExportFlow(userId: String): Flow<Boolean> =
override fun getVaultRegisteredForExportFlow(userId: String): Flow<Boolean?> =
getMutableVaultRegisteredForExportFlow(userId)
.onSubscription { emit(getVaultRegisteredForExport(userId)) }
@ -512,7 +512,7 @@ class SettingsDiskSourceImpl(
private fun getMutableVaultRegisteredForExportFlow(
userId: String,
): MutableSharedFlow<Boolean> = mutableVaultRegisteredForExportFlow.getOrPut(userId) {
): MutableSharedFlow<Boolean?> = mutableVaultRegisteredForExportFlow.getOrPut(userId) {
bufferedMutableSharedFlow(replay = 1)
}
}

View file

@ -557,7 +557,7 @@ class SettingsRepositoryImpl(
}
override fun isVaultRegisteredForExport(userId: String): Boolean {
return settingsDiskSource.getVaultRegisteredForExport(userId)
return settingsDiskSource.getVaultRegisteredForExport(userId) == true
}
override fun storeVaultRegisteredForExport(userId: String, isRegistered: Boolean) {
@ -567,10 +567,13 @@ class SettingsRepositoryImpl(
override fun getVaultRegisteredForExportFlow(userId: String): StateFlow<Boolean> {
return settingsDiskSource
.getVaultRegisteredForExportFlow(userId)
.map { it ?: false }
.stateIn(
scope = unconfinedScope,
started = SharingStarted.Eagerly,
initialValue = settingsDiskSource.getVaultRegisteredForExport(userId),
initialValue = settingsDiskSource
.getVaultRegisteredForExport(userId)
?: false,
)
}

View file

@ -1217,7 +1217,7 @@ class SettingsDiskSourceTest {
fakeSharedPreferences.edit {
putBoolean(vaultRegisteredForExportKey, true)
}
assertTrue(settingsDiskSource.getVaultRegisteredForExport(userId = mockUserId))
assertTrue(settingsDiskSource.getVaultRegisteredForExport(userId = mockUserId)!!)
}
@Test
@ -1234,12 +1234,12 @@ class SettingsDiskSourceTest {
val mockUserId = "mockUserId"
settingsDiskSource.getVaultRegisteredForExportFlow(mockUserId).test {
// The initial values of the Flow are in sync
assertFalse(awaitItem())
assertFalse(awaitItem() ?: false)
settingsDiskSource.storeVaultRegisteredForExport(mockUserId, true)
assertTrue(awaitItem())
assertTrue(awaitItem() ?: false)
// Update the value to false
settingsDiskSource.storeVaultRegisteredForExport(mockUserId, false)
assertFalse(awaitItem())
assertFalse(awaitItem() ?: true)
}
}
}

View file

@ -362,7 +362,7 @@ class FakeSettingsDiskSource : SettingsDiskSource {
getMutableVaultRegisteredForExportFlow(userId = userId).tryEmit(registered)
}
override fun getVaultRegisteredForExportFlow(userId: String): Flow<Boolean> =
override fun getVaultRegisteredForExportFlow(userId: String): Flow<Boolean?> =
getMutableVaultRegisteredForExportFlow(userId = userId).onSubscription {
emit(getVaultRegisteredForExport(userId = userId))
}