@@ -28,7 +28,6 @@ import androidx.datastore.preferences.core.stringPreferencesKey
2828import androidx.datastore.preferences.preferencesDataStore
2929import com.wire.android.BuildConfig
3030import com.wire.android.feature.AppLockSource
31- import com.wire.android.migration.failure.UserMigrationStatus
3231import com.wire.android.ui.theme.ThemeOption
3332import com.wire.android.util.sha256
3433import dagger.hilt.android.qualifiers.ApplicationContext
@@ -50,7 +49,6 @@ class GlobalDataStore @Inject constructor(@ApplicationContext private val contex
5049 // keys
5150 private val SHOW_CALLING_DOUBLE_TAP_TOAST =
5251 booleanPreferencesKey(" show_calling_double_tap_toast_" )
53- private val MIGRATION_COMPLETED = booleanPreferencesKey(" migration_completed" )
5452 private val WELCOME_SCREEN_PRESENTED = booleanPreferencesKey(" welcome_screen_presented" )
5553 private val IS_LOGGING_ENABLED = booleanPreferencesKey(" is_logging_enabled" )
5654 private val APP_LOCK_PASSCODE = stringPreferencesKey(" app_lock_passcode" )
@@ -63,14 +61,8 @@ class GlobalDataStore @Inject constructor(@ApplicationContext private val contex
6361
6462 private val Context .dataStore: DataStore <Preferences > by preferencesDataStore(name = PREFERENCES_NAME )
6563
66- private fun userMigrationStatusKey (userId : String ): Preferences .Key <Int > =
67- intPreferencesKey(" user_migration_status_$userId " )
68-
6964 private fun userDoubleTapToastStatusKey (userId : String ): Preferences .Key <Boolean > =
7065 booleanPreferencesKey(" $SHOW_CALLING_DOUBLE_TAP_TOAST$userId " )
71-
72- private fun userLastMigrationAppVersion (userId : String ): Preferences .Key <Int > =
73- intPreferencesKey(" migration_app_version_$userId " )
7466 }
7567
7668 suspend fun clear () {
@@ -86,10 +78,6 @@ class GlobalDataStore @Inject constructor(@ApplicationContext private val contex
8678 ): Flow <String > =
8779 context.dataStore.data.map { it[key] ? : defaultValue }
8880
89- fun isMigrationCompletedFlow (): Flow <Boolean > = getBooleanPreference(MIGRATION_COMPLETED , false )
90-
91- suspend fun isMigrationCompleted (): Boolean = isMigrationCompletedFlow().firstOrNull() ? : false
92-
9381 fun isLoggingEnabled (): Flow <Boolean > =
9482 getBooleanPreference(IS_LOGGING_ENABLED , BuildConfig .LOGGING_ENABLED )
9583
@@ -104,59 +92,9 @@ class GlobalDataStore @Inject constructor(@ApplicationContext private val contex
10492 context.dataStore.edit { it[RECORD_AUDIO_EFFECTS_CHECKBOX ] = enabled }
10593 }
10694
107- suspend fun setMigrationCompleted () {
108- context.dataStore.edit { it[MIGRATION_COMPLETED ] = true }
109- }
110-
11195 suspend fun isWelcomeScreenPresented (): Boolean =
11296 getBooleanPreference(WELCOME_SCREEN_PRESENTED , false ).firstOrNull() ? : false
11397
114- suspend fun setWelcomeScreenPresented () {
115- context.dataStore.edit { it[WELCOME_SCREEN_PRESENTED ] = true }
116- }
117-
118- suspend fun setWelcomeScreenNotPresented () {
119- context.dataStore.edit { it[WELCOME_SCREEN_PRESENTED ] = false }
120- }
121-
122- suspend fun setUserMigrationStatus (userId : String , status : UserMigrationStatus ) {
123- context.dataStore.edit { it[userMigrationStatusKey(userId)] = status.value }
124- when (status) {
125- UserMigrationStatus .Completed ,
126- UserMigrationStatus .CompletedWithErrors ,
127- UserMigrationStatus .Successfully -> setUserMigrationAppVersion(
128- userId,
129- BuildConfig .VERSION_CODE
130- )
131-
132- UserMigrationStatus .NoNeed ,
133- UserMigrationStatus .NotStarted -> {
134- /* no-op */
135- }
136- }
137- }
138-
139- /* *
140- * Returns the migration status of the user with the given [userId].
141- * If there is no status stored, the status will be [UserMigrationStatus.NoNeed]
142- * meaning that the user does not need to be migrated.
143- */
144- fun getUserMigrationStatus (userId : String ): Flow <UserMigrationStatus ?> =
145- context.dataStore.data.map {
146- it[userMigrationStatusKey(userId)]?.let { status ->
147- UserMigrationStatus .fromInt(
148- status
149- )
150- }
151- }
152-
153- suspend fun setUserMigrationAppVersion (userId : String , version : Int ) {
154- context.dataStore.edit { it[userLastMigrationAppVersion(userId)] = version }
155- }
156-
157- suspend fun getUserMigrationAppVersion (userId : String ): Int? =
158- context.dataStore.data.map { it[userLastMigrationAppVersion(userId)] }.firstOrNull()
159-
16098 suspend fun setShouldShowDoubleTapToastStatus (userId : String , shouldShow : Boolean ) {
16199 context.dataStore.edit { it[userDoubleTapToastStatusKey(userId)] = shouldShow }
162100 }
0 commit comments