forked from Ashinch/ReadYou
-
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.
feat(settings): support export and import json for preferences (Ashin…
- Loading branch information
Showing
72 changed files
with
803 additions
and
793 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
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
11 changes: 8 additions & 3 deletions
11
app/src/main/java/me/ash/reader/infrastructure/preference/CustomPrimaryColorPreference.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,23 +1,28 @@ | ||
package me.ash.reader.infrastructure.preference | ||
|
||
import android.content.Context | ||
import androidx.compose.runtime.compositionLocalOf | ||
import androidx.datastore.preferences.core.Preferences | ||
import kotlinx.coroutines.CoroutineScope | ||
import kotlinx.coroutines.launch | ||
import me.ash.reader.ui.ext.DataStoreKeys | ||
import me.ash.reader.ui.ext.DataStoreKey | ||
import me.ash.reader.ui.ext.DataStoreKey.Companion.customPrimaryColor | ||
import me.ash.reader.ui.ext.dataStore | ||
import me.ash.reader.ui.ext.put | ||
|
||
val LocalCustomPrimaryColor = | ||
compositionLocalOf { CustomPrimaryColorPreference.default } | ||
|
||
object CustomPrimaryColorPreference { | ||
|
||
const val default = "" | ||
|
||
fun put(context: Context, scope: CoroutineScope, value: String) { | ||
scope.launch { | ||
context.dataStore.put(DataStoreKeys.CustomPrimaryColor, value) | ||
context.dataStore.put(DataStoreKey.customPrimaryColor, value) | ||
} | ||
} | ||
|
||
fun fromPreferences(preferences: Preferences) = | ||
preferences[DataStoreKeys.CustomPrimaryColor.key] ?: default | ||
preferences[DataStoreKey.keys[customPrimaryColor]?.key as Preferences.Key<String>] ?: default | ||
} |
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
11 changes: 8 additions & 3 deletions
11
app/src/main/java/me/ash/reader/infrastructure/preference/FeedsFilterBarPaddingPreference.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,23 +1,28 @@ | ||
package me.ash.reader.infrastructure.preference | ||
|
||
import android.content.Context | ||
import androidx.compose.runtime.compositionLocalOf | ||
import androidx.datastore.preferences.core.Preferences | ||
import kotlinx.coroutines.CoroutineScope | ||
import kotlinx.coroutines.launch | ||
import me.ash.reader.ui.ext.DataStoreKeys | ||
import me.ash.reader.ui.ext.DataStoreKey | ||
import me.ash.reader.ui.ext.DataStoreKey.Companion.feedsFilterBarPadding | ||
import me.ash.reader.ui.ext.dataStore | ||
import me.ash.reader.ui.ext.put | ||
|
||
val LocalFeedsFilterBarPadding = | ||
compositionLocalOf { FeedsFilterBarPaddingPreference.default } | ||
|
||
object FeedsFilterBarPaddingPreference { | ||
|
||
const val default = 60 | ||
|
||
fun put(context: Context, scope: CoroutineScope, value: Int) { | ||
scope.launch { | ||
context.dataStore.put(DataStoreKeys.FeedsFilterBarPadding, value) | ||
context.dataStore.put(DataStoreKey.feedsFilterBarPadding, value) | ||
} | ||
} | ||
|
||
fun fromPreferences(preferences: Preferences) = | ||
preferences[DataStoreKeys.FeedsFilterBarPadding.key] ?: default | ||
preferences[DataStoreKey.keys[feedsFilterBarPadding]?.key as Preferences.Key<Int>] ?: default | ||
} |
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
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
Oops, something went wrong.