mirror of
https://github.com/bitwarden/android.git
synced 2024-10-31 15:15:34 +03:00
Simplify BaseDiskSource usage (#261)
This commit is contained in:
parent
0a09facde0
commit
ef35477083
4 changed files with 5 additions and 33 deletions
|
@ -39,6 +39,7 @@ class AuthDiskSourceImpl(
|
||||||
key = STATE_KEY,
|
key = STATE_KEY,
|
||||||
value = value?.let { json.encodeToString(value) },
|
value = value?.let { json.encodeToString(value) },
|
||||||
)
|
)
|
||||||
|
mutableUserStateFlow.tryEmit(value)
|
||||||
}
|
}
|
||||||
|
|
||||||
override val userStateFlow: Flow<UserStateJson?>
|
override val userStateFlow: Flow<UserStateJson?>
|
||||||
|
@ -50,15 +51,6 @@ class AuthDiskSourceImpl(
|
||||||
extraBufferCapacity = Int.MAX_VALUE,
|
extraBufferCapacity = Int.MAX_VALUE,
|
||||||
)
|
)
|
||||||
|
|
||||||
override fun onSharedPreferenceChanged(
|
|
||||||
sharedPreferences: SharedPreferences?,
|
|
||||||
key: String?,
|
|
||||||
) {
|
|
||||||
when (key) {
|
|
||||||
STATE_KEY -> mutableUserStateFlow.tryEmit(userState)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
override fun getUserKey(userId: String): String? =
|
override fun getUserKey(userId: String): String? =
|
||||||
getString(key = "${MASTER_KEY_ENCRYPTION_USER_KEY}_$userId")
|
getString(key = "${MASTER_KEY_ENCRYPTION_USER_KEY}_$userId")
|
||||||
|
|
||||||
|
|
|
@ -1,22 +1,15 @@
|
||||||
package com.x8bit.bitwarden.data.platform.datasource.disk
|
package com.x8bit.bitwarden.data.platform.datasource.disk
|
||||||
|
|
||||||
import android.content.SharedPreferences
|
import android.content.SharedPreferences
|
||||||
import android.content.SharedPreferences.OnSharedPreferenceChangeListener
|
|
||||||
import androidx.core.content.edit
|
import androidx.core.content.edit
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Base class for simplifying interactions with [SharedPreferences].
|
* Base class for simplifying interactions with [SharedPreferences].
|
||||||
*/
|
*/
|
||||||
|
@Suppress("UnnecessaryAbstractClass")
|
||||||
abstract class BaseDiskSource(
|
abstract class BaseDiskSource(
|
||||||
private val sharedPreferences: SharedPreferences,
|
private val sharedPreferences: SharedPreferences,
|
||||||
) : OnSharedPreferenceChangeListener {
|
) {
|
||||||
|
|
||||||
init {
|
|
||||||
@Suppress("LeakingThis")
|
|
||||||
sharedPreferences
|
|
||||||
.registerOnSharedPreferenceChangeListener(this)
|
|
||||||
}
|
|
||||||
|
|
||||||
protected fun getString(
|
protected fun getString(
|
||||||
key: String,
|
key: String,
|
||||||
default: String? = null,
|
default: String? = null,
|
||||||
|
|
|
@ -26,6 +26,7 @@ class EnvironmentDiskSourceImpl(
|
||||||
key = PRE_AUTH_URLS_KEY,
|
key = PRE_AUTH_URLS_KEY,
|
||||||
value = value?.let { json.encodeToString(value) },
|
value = value?.let { json.encodeToString(value) },
|
||||||
)
|
)
|
||||||
|
mutableEnvironmentUrlDataFlow.tryEmit(value)
|
||||||
}
|
}
|
||||||
|
|
||||||
override val preAuthEnvironmentUrlDataFlow: Flow<EnvironmentUrlDataJson?>
|
override val preAuthEnvironmentUrlDataFlow: Flow<EnvironmentUrlDataJson?>
|
||||||
|
@ -36,13 +37,4 @@ class EnvironmentDiskSourceImpl(
|
||||||
replay = 1,
|
replay = 1,
|
||||||
extraBufferCapacity = Int.MAX_VALUE,
|
extraBufferCapacity = Int.MAX_VALUE,
|
||||||
)
|
)
|
||||||
|
|
||||||
override fun onSharedPreferenceChanged(
|
|
||||||
sharedPreferences: SharedPreferences?,
|
|
||||||
key: String?,
|
|
||||||
) {
|
|
||||||
when (key) {
|
|
||||||
PRE_AUTH_URLS_KEY -> mutableEnvironmentUrlDataFlow.tryEmit(preAuthEnvironmentUrlData)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,8 +1,8 @@
|
||||||
package com.x8bit.bitwarden.data.tools.generator.datasource.disk
|
package com.x8bit.bitwarden.data.tools.generator.datasource.disk
|
||||||
|
|
||||||
import android.content.SharedPreferences
|
import android.content.SharedPreferences
|
||||||
import com.x8bit.bitwarden.data.tools.generator.repository.model.PasswordGenerationOptions
|
|
||||||
import com.x8bit.bitwarden.data.platform.datasource.disk.BaseDiskSource
|
import com.x8bit.bitwarden.data.platform.datasource.disk.BaseDiskSource
|
||||||
|
import com.x8bit.bitwarden.data.tools.generator.repository.model.PasswordGenerationOptions
|
||||||
import kotlinx.serialization.encodeToString
|
import kotlinx.serialization.encodeToString
|
||||||
import kotlinx.serialization.json.Json
|
import kotlinx.serialization.json.Json
|
||||||
|
|
||||||
|
@ -33,11 +33,6 @@ class GeneratorDiskSourceImpl(
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun onSharedPreferenceChanged(
|
|
||||||
sharedPreferences: SharedPreferences?,
|
|
||||||
key: String?,
|
|
||||||
) = Unit
|
|
||||||
|
|
||||||
private fun getPasswordGenerationOptionsKey(userId: String): String =
|
private fun getPasswordGenerationOptionsKey(userId: String): String =
|
||||||
"${BASE_KEY}_${PASSWORD_GENERATION_OPTIONS_KEY}_$userId"
|
"${BASE_KEY}_${PASSWORD_GENERATION_OPTIONS_KEY}_$userId"
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue