forked from embedded-dev-research/openvino-notes
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathAppSessionPreferences.kt
More file actions
33 lines (28 loc) · 1.01 KB
/
Copy pathAppSessionPreferences.kt
File metadata and controls
33 lines (28 loc) · 1.01 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
package com.itlab.notes.auth
import android.content.Context
import androidx.datastore.core.DataStore
import androidx.datastore.preferences.core.Preferences
import androidx.datastore.preferences.core.booleanPreferencesKey
import androidx.datastore.preferences.core.edit
import androidx.datastore.preferences.preferencesDataStore
import kotlinx.coroutines.flow.Flow
import kotlinx.coroutines.flow.map
internal val Context.appSessionDataStore: DataStore<Preferences> by preferencesDataStore(
name = "app_session_preferences",
)
class AppSessionPreferences(
private val context: Context,
) {
val continueOffline: Flow<Boolean> =
context.appSessionDataStore.data.map { prefs ->
prefs[CONTINUE_OFFLINE] ?: false
}
suspend fun setContinueOffline(enabled: Boolean) {
context.appSessionDataStore.edit { prefs ->
prefs[CONTINUE_OFFLINE] = enabled
}
}
private companion object {
val CONTINUE_OFFLINE = booleanPreferencesKey("continue_offline")
}
}