-
Notifications
You must be signed in to change notification settings - Fork 27
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
5 changed files
with
32 additions
and
13 deletions.
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
28 changes: 22 additions & 6 deletions
28
wearApp/src/main/java/fr/paug/androidmakers/wear/data/LocalPreferencesRepository.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 |
---|---|---|
@@ -1,11 +1,27 @@ | ||
package fr.paug.androidmakers.wear.data | ||
|
||
import android.content.Context | ||
import kotlinx.coroutines.flow.MutableStateFlow | ||
import org.jraf.android.kprefs.Prefs | ||
import androidx.datastore.core.DataStore | ||
import androidx.datastore.preferences.core.Preferences | ||
import androidx.datastore.preferences.core.booleanPreferencesKey | ||
import androidx.datastore.preferences.core.edit | ||
import kotlinx.coroutines.flow.Flow | ||
import kotlinx.coroutines.flow.map | ||
|
||
class LocalPreferencesRepository(applicationContext: Context) { | ||
private val localPrefs = Prefs(applicationContext) | ||
class LocalPreferencesRepository( | ||
private val dataStore: DataStore<Preferences> | ||
) { | ||
|
||
val showOnlyBookmarkedSessions: MutableStateFlow<Boolean> by localPrefs.BooleanFlow(false) | ||
companion object { | ||
private const val PREF_SHOW_ONLY_BOOKMARK_SESSIONS = "show_only_bookmark_sessions" | ||
} | ||
|
||
val showOnlyBookmarkedSessions: Flow<Boolean> = dataStore.data.map { prefs -> | ||
prefs[booleanPreferencesKey(PREF_SHOW_ONLY_BOOKMARK_SESSIONS)] ?: false | ||
} | ||
|
||
suspend fun setShowOnlyBookmarkedSessions(showOnlyBookmarkedSessions: Boolean) { | ||
dataStore.edit { prefs -> | ||
prefs[booleanPreferencesKey(PREF_SHOW_ONLY_BOOKMARK_SESSIONS)] = showOnlyBookmarkedSessions | ||
} | ||
} | ||
} |
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