diff options
author | Allan Wang <me@allanwang.ca> | 2020-07-18 20:25:35 -0700 |
---|---|---|
committer | Allan Wang <me@allanwang.ca> | 2020-07-18 20:25:35 -0700 |
commit | daf8f74ecf4953ffa99b75c2ac35a4b8711f8b10 (patch) | |
tree | 1b3802f6536f1c114e95b2ef267686cec0841310 /app/src/main/kotlin/com/pitchedapps/frost/prefs | |
parent | 5eb18e7464ceb5b7029912498ab02cf9b2556903 (diff) | |
download | frost-daf8f74ecf4953ffa99b75c2ac35a4b8711f8b10.tar.gz frost-daf8f74ecf4953ffa99b75c2ac35a4b8711f8b10.tar.bz2 frost-daf8f74ecf4953ffa99b75c2ac35a4b8711f8b10.zip |
Migrate showcase prefs to pref section
Diffstat (limited to 'app/src/main/kotlin/com/pitchedapps/frost/prefs')
7 files changed, 105 insertions, 13 deletions
diff --git a/app/src/main/kotlin/com/pitchedapps/frost/prefs/Prefs.kt b/app/src/main/kotlin/com/pitchedapps/frost/prefs/Prefs.kt index ec0a9cad..2714b930 100644 --- a/app/src/main/kotlin/com/pitchedapps/frost/prefs/Prefs.kt +++ b/app/src/main/kotlin/com/pitchedapps/frost/prefs/Prefs.kt @@ -24,12 +24,29 @@ import com.pitchedapps.frost.prefs.sections.FeedPrefs import com.pitchedapps.frost.prefs.sections.FeedPrefsImpl import com.pitchedapps.frost.prefs.sections.NotifPrefs import com.pitchedapps.frost.prefs.sections.NotifPrefsImpl +import com.pitchedapps.frost.prefs.sections.ShowcasePrefs +import com.pitchedapps.frost.prefs.sections.ShowcasePrefsImpl import com.pitchedapps.frost.prefs.sections.ThemePrefs import com.pitchedapps.frost.prefs.sections.ThemePrefsImpl import org.koin.core.context.KoinContextHandler import org.koin.dsl.module -interface Prefs : BehaviourPrefs, CorePrefs, FeedPrefs, NotifPrefs, ThemePrefs { +/** + * [Prefs] is no longer an actual pref, but we will expose the reset function as it is used elsewhere + */ +interface PrefsBase { + fun reset() + fun deleteKeys(vararg keys: String) +} + +interface Prefs : + BehaviourPrefs, + CorePrefs, + FeedPrefs, + NotifPrefs, + ThemePrefs, + ShowcasePrefs, + PrefsBase { companion object { fun get(): Prefs = KoinContextHandler.get().get() @@ -39,13 +56,15 @@ interface Prefs : BehaviourPrefs, CorePrefs, FeedPrefs, NotifPrefs, ThemePrefs { single<FeedPrefs> { FeedPrefsImpl(factory = get()) } single<NotifPrefs> { NotifPrefsImpl(factory = get()) } single<ThemePrefs> { ThemePrefsImpl(factory = get()) } + single<ShowcasePrefs> { ShowcasePrefsImpl(factory = get()) } single<Prefs> { PrefsImpl( behaviourPrefs = get(), corePrefs = get(), feedPrefs = get(), notifPrefs = get(), - themePrefs = get() + themePrefs = get(), + showcasePrefs = get() ) } // Needed for migration @@ -55,14 +74,35 @@ interface Prefs : BehaviourPrefs, CorePrefs, FeedPrefs, NotifPrefs, ThemePrefs { } class PrefsImpl( - behaviourPrefs: BehaviourPrefs, - corePrefs: CorePrefs, - feedPrefs: FeedPrefs, - notifPrefs: NotifPrefs, - themePrefs: ThemePrefs + private val behaviourPrefs: BehaviourPrefs, + private val corePrefs: CorePrefs, + private val feedPrefs: FeedPrefs, + private val notifPrefs: NotifPrefs, + private val themePrefs: ThemePrefs, + private val showcasePrefs: ShowcasePrefs ) : Prefs, BehaviourPrefs by behaviourPrefs, CorePrefs by corePrefs, FeedPrefs by feedPrefs, NotifPrefs by notifPrefs, - ThemePrefs by themePrefs + ThemePrefs by themePrefs, + ShowcasePrefs by showcasePrefs { + + override fun reset() { + behaviourPrefs.reset() + corePrefs.reset() + feedPrefs.reset() + notifPrefs.reset() + themePrefs.reset() + showcasePrefs.reset() + } + + override fun deleteKeys(vararg keys: String) { + behaviourPrefs.deleteKeys() + corePrefs.deleteKeys() + feedPrefs.deleteKeys() + notifPrefs.deleteKeys() + themePrefs.deleteKeys() + showcasePrefs.deleteKeys() + } +} diff --git a/app/src/main/kotlin/com/pitchedapps/frost/prefs/sections/BehaviourPrefs.kt b/app/src/main/kotlin/com/pitchedapps/frost/prefs/sections/BehaviourPrefs.kt index ea55f7e3..ace444fe 100644 --- a/app/src/main/kotlin/com/pitchedapps/frost/prefs/sections/BehaviourPrefs.kt +++ b/app/src/main/kotlin/com/pitchedapps/frost/prefs/sections/BehaviourPrefs.kt @@ -20,10 +20,11 @@ import ca.allanwang.kau.kpref.KPref import ca.allanwang.kau.kpref.KPrefFactory import com.pitchedapps.frost.BuildConfig import com.pitchedapps.frost.prefs.OldPrefs +import com.pitchedapps.frost.prefs.PrefsBase import org.koin.core.KoinComponent import org.koin.core.inject -interface BehaviourPrefs { +interface BehaviourPrefs : PrefsBase { var biometricsEnabled: Boolean var overlayEnabled: Boolean @@ -105,4 +106,5 @@ class BehaviourPrefsImpl( "full_size_image", oldPrefs.fullSizeImage /* false */ ) + } diff --git a/app/src/main/kotlin/com/pitchedapps/frost/prefs/sections/CorePrefs.kt b/app/src/main/kotlin/com/pitchedapps/frost/prefs/sections/CorePrefs.kt index f5cab25e..2927d10c 100644 --- a/app/src/main/kotlin/com/pitchedapps/frost/prefs/sections/CorePrefs.kt +++ b/app/src/main/kotlin/com/pitchedapps/frost/prefs/sections/CorePrefs.kt @@ -20,10 +20,11 @@ import ca.allanwang.kau.kpref.KPref import ca.allanwang.kau.kpref.KPrefFactory import com.pitchedapps.frost.BuildConfig import com.pitchedapps.frost.prefs.OldPrefs +import com.pitchedapps.frost.prefs.PrefsBase import org.koin.core.KoinComponent import org.koin.core.inject -interface CorePrefs { +interface CorePrefs : PrefsBase { var lastLaunch: Long var userId: Long diff --git a/app/src/main/kotlin/com/pitchedapps/frost/prefs/sections/FeedPrefs.kt b/app/src/main/kotlin/com/pitchedapps/frost/prefs/sections/FeedPrefs.kt index e99bce75..0060f9ad 100644 --- a/app/src/main/kotlin/com/pitchedapps/frost/prefs/sections/FeedPrefs.kt +++ b/app/src/main/kotlin/com/pitchedapps/frost/prefs/sections/FeedPrefs.kt @@ -21,10 +21,11 @@ import ca.allanwang.kau.kpref.KPrefFactory import com.pitchedapps.frost.BuildConfig import com.pitchedapps.frost.enums.MainActivityLayout import com.pitchedapps.frost.prefs.OldPrefs +import com.pitchedapps.frost.prefs.PrefsBase import org.koin.core.KoinComponent import org.koin.core.inject -interface FeedPrefs { +interface FeedPrefs : PrefsBase { var webTextScaling: Int var feedSort: Int diff --git a/app/src/main/kotlin/com/pitchedapps/frost/prefs/sections/NotifPrefs.kt b/app/src/main/kotlin/com/pitchedapps/frost/prefs/sections/NotifPrefs.kt index 45d12453..e3e95516 100644 --- a/app/src/main/kotlin/com/pitchedapps/frost/prefs/sections/NotifPrefs.kt +++ b/app/src/main/kotlin/com/pitchedapps/frost/prefs/sections/NotifPrefs.kt @@ -20,10 +20,11 @@ import ca.allanwang.kau.kpref.KPref import ca.allanwang.kau.kpref.KPrefFactory import com.pitchedapps.frost.BuildConfig import com.pitchedapps.frost.prefs.OldPrefs +import com.pitchedapps.frost.prefs.PrefsBase import org.koin.core.KoinComponent import org.koin.core.inject -interface NotifPrefs { +interface NotifPrefs : PrefsBase { var notificationKeywords: Set<String> var notificationsGeneral: Boolean diff --git a/app/src/main/kotlin/com/pitchedapps/frost/prefs/sections/ShowcasePrefs.kt b/app/src/main/kotlin/com/pitchedapps/frost/prefs/sections/ShowcasePrefs.kt new file mode 100644 index 00000000..516a14c5 --- /dev/null +++ b/app/src/main/kotlin/com/pitchedapps/frost/prefs/sections/ShowcasePrefs.kt @@ -0,0 +1,46 @@ +/* + * Copyright 2018 Allan Wang + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see <http://www.gnu.org/licenses/>. + */ +package com.pitchedapps.frost.prefs.sections + +import ca.allanwang.kau.kpref.KPref +import ca.allanwang.kau.kpref.KPrefFactory +import com.pitchedapps.frost.BuildConfig +import com.pitchedapps.frost.prefs.PrefsBase + +interface ShowcasePrefs : PrefsBase { + /** + * Check if this is the first time launching the web overlay; show snackbar if true + */ + val firstWebOverlay: Boolean + + val intro: Boolean +} + +/** + * Created by Allan Wang on 2017-07-03. + * + * Showcase prefs that offer one time helpers to guide new users + */ +class ShowcasePrefsImpl( + factory: KPrefFactory +) : KPref("${BuildConfig.APPLICATION_ID}.showcase", factory), + ShowcasePrefs { + + override val firstWebOverlay: Boolean by kprefSingle("first_web_overlay") + + override val intro: Boolean by kprefSingle("intro_pages") +} diff --git a/app/src/main/kotlin/com/pitchedapps/frost/prefs/sections/ThemePrefs.kt b/app/src/main/kotlin/com/pitchedapps/frost/prefs/sections/ThemePrefs.kt index c5ecb68b..cd35103b 100644 --- a/app/src/main/kotlin/com/pitchedapps/frost/prefs/sections/ThemePrefs.kt +++ b/app/src/main/kotlin/com/pitchedapps/frost/prefs/sections/ThemePrefs.kt @@ -28,10 +28,11 @@ import com.pitchedapps.frost.enums.FACEBOOK_BLUE import com.pitchedapps.frost.enums.Theme import com.pitchedapps.frost.injectors.InjectorContract import com.pitchedapps.frost.prefs.OldPrefs +import com.pitchedapps.frost.prefs.PrefsBase import org.koin.core.KoinComponent import org.koin.core.inject -interface ThemePrefs { +interface ThemePrefs : PrefsBase { var theme: Int var customTextColor: Int |