From cc8311e116819cd1eb2b41502d7ad7ace3edc739 Mon Sep 17 00:00:00 2001 From: tarsin Date: Wed, 7 Jun 2023 15:18:58 +0800 Subject: [PATCH] Opt-in DataStorePreferencesPreview --- app/build.gradle.kts | 1 + app/src/main/java/com/hippo/ehviewer/Settings.kt | 11 ++++------- .../java/com/hippo/ehviewer/ui/CommonOperations.kt | 2 +- 3 files changed, 6 insertions(+), 8 deletions(-) diff --git a/app/build.gradle.kts b/app/build.gradle.kts index a1a01e3ae..3fedcbc01 100644 --- a/app/build.gradle.kts +++ b/app/build.gradle.kts @@ -116,6 +116,7 @@ android { "-opt-in=kotlinx.coroutines.FlowPreview", "-opt-in=kotlinx.serialization.ExperimentalSerializationApi", "-opt-in=splitties.experimental.ExperimentalSplittiesApi", + "-opt-in=splitties.preferences.DataStorePreferencesPreview", ) } diff --git a/app/src/main/java/com/hippo/ehviewer/Settings.kt b/app/src/main/java/com/hippo/ehviewer/Settings.kt index 1bee388b3..71d719001 100755 --- a/app/src/main/java/com/hippo/ehviewer/Settings.kt +++ b/app/src/main/java/com/hippo/ehviewer/Settings.kt @@ -6,17 +6,14 @@ import com.hippo.ehviewer.client.data.FavListUrlBuilder import kotlinx.coroutines.flow.Flow import kotlinx.coroutines.flow.flow import splitties.preferences.DataStorePreferences -import splitties.preferences.DataStorePreferencesPreview import splitties.preferences.edit import java.util.Locale import kotlin.reflect.KProperty -@OptIn(DataStorePreferencesPreview::class) object Settings : DataStorePreferences(null) { - const val KEY_SHOW_TAG_TRANSLATIONS = "show_tag_translations" - const val INVALID_DEFAULT_FAV_SLOT = -2 - const val KEY_BUILT_IN_HOSTS = "built_in_hosts_2" - const val KEY_DOMAIN_FRONTING = "domain_fronting" + private const val KEY_SHOW_TAG_TRANSLATIONS = "show_tag_translations" + private const val KEY_BUILT_IN_HOSTS = "built_in_hosts_2" + private const val KEY_DOMAIN_FRONTING = "domain_fronting" var downloadScheme by stringOrNullPref("image_scheme", null) var downloadAuthority by stringOrNullPref("image_authority", null) @@ -63,7 +60,7 @@ object Settings : DataStorePreferences(null) { var favLocalCount by intPref("fav_local", 0) var favCloudCount by intPref("fav_cloud", 0) var recentFavCat by intPref("recent_fav_cat", FavListUrlBuilder.FAV_CAT_ALL) - var defaultFavSlot by intPref("default_favorite_2", INVALID_DEFAULT_FAV_SLOT) // -1 for local, 0 - 9 for cloud favorite, other for no default fav slot + var defaultFavSlot by intPref("default_favorite_2", -2) // -1 for local, 0 - 9 for cloud favorite, other for no default fav slot var securityDelay by intPref("require_unlock_delay", 0) var clipboardTextHashCode by intPref("clipboard_text_hash_code", 0) var listThumbSize by intPref("list_tile_size", 40) diff --git a/app/src/main/java/com/hippo/ehviewer/ui/CommonOperations.kt b/app/src/main/java/com/hippo/ehviewer/ui/CommonOperations.kt index 6ba2bf542..98fdb6e5c 100644 --- a/app/src/main/java/com/hippo/ehviewer/ui/CommonOperations.kt +++ b/app/src/main/java/com/hippo/ehviewer/ui/CommonOperations.kt @@ -235,7 +235,7 @@ suspend fun Context.addToFavorites(galleryInfo: GalleryInfo, select: Boolean = f if (checked) { Settings.defaultFavSlot = slot1 } else { - Settings.defaultFavSlot = Settings.INVALID_DEFAULT_FAV_SLOT + Settings.defaultFavSlot = -2 } } }