-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
57 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
30 changes: 30 additions & 0 deletions
30
android/local/src/main/java/poke/rogue/helper/local/datastore/VersionDataStore.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
package poke.rogue.helper.local.datastore | ||
|
||
import android.content.Context | ||
import androidx.datastore.core.DataStore | ||
import androidx.datastore.preferences.core.Preferences | ||
import androidx.datastore.preferences.core.edit | ||
import androidx.datastore.preferences.core.intPreferencesKey | ||
import androidx.datastore.preferences.preferencesDataStore | ||
import kotlinx.coroutines.flow.Flow | ||
import kotlinx.coroutines.flow.map | ||
|
||
class VersionDataStore(private val context: Context) { | ||
private val Context.dataStore: DataStore<Preferences> by preferencesDataStore(name = DATA_BASE_NAME) | ||
|
||
fun databaseVersion(): Flow<Int?> = | ||
context.dataStore.data.map { preferences -> | ||
preferences[DATABASE_VERSION_KEY] | ||
} | ||
|
||
suspend fun saveDatabaseVersion(version: Int) { | ||
context.dataStore.edit { preferences -> | ||
preferences[DATABASE_VERSION_KEY] = version | ||
} | ||
} | ||
|
||
companion object { | ||
private const val DATA_BASE_NAME = "datastore_version" | ||
private val DATABASE_VERSION_KEY = intPreferencesKey("database_version") | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters