From daf8f74ecf4953ffa99b75c2ac35a4b8711f8b10 Mon Sep 17 00:00:00 2001 From: Allan Wang Date: Sat, 18 Jul 2020 20:25:35 -0700 Subject: Migrate showcase prefs to pref section --- .../kotlin/com/pitchedapps/frost/FrostTestApp.kt | 3 -- .../main/kotlin/com/pitchedapps/frost/FrostApp.kt | 9 +--- .../pitchedapps/frost/activities/LoginActivity.kt | 8 ++-- .../frost/activities/WebOverlayActivity.kt | 6 +-- .../kotlin/com/pitchedapps/frost/prefs/Prefs.kt | 56 ++++++++++++++++++---- .../frost/prefs/sections/BehaviourPrefs.kt | 4 +- .../pitchedapps/frost/prefs/sections/CorePrefs.kt | 3 +- .../pitchedapps/frost/prefs/sections/FeedPrefs.kt | 3 +- .../pitchedapps/frost/prefs/sections/NotifPrefs.kt | 3 +- .../frost/prefs/sections/ShowcasePrefs.kt | 46 ++++++++++++++++++ .../pitchedapps/frost/prefs/sections/ThemePrefs.kt | 3 +- .../kotlin/com/pitchedapps/frost/utils/Showcase.kt | 41 ---------------- 12 files changed, 111 insertions(+), 74 deletions(-) create mode 100644 app/src/main/kotlin/com/pitchedapps/frost/prefs/sections/ShowcasePrefs.kt delete mode 100644 app/src/main/kotlin/com/pitchedapps/frost/utils/Showcase.kt diff --git a/app/src/androidTest/kotlin/com/pitchedapps/frost/FrostTestApp.kt b/app/src/androidTest/kotlin/com/pitchedapps/frost/FrostTestApp.kt index e8007a62..b52b3335 100644 --- a/app/src/androidTest/kotlin/com/pitchedapps/frost/FrostTestApp.kt +++ b/app/src/androidTest/kotlin/com/pitchedapps/frost/FrostTestApp.kt @@ -24,7 +24,6 @@ import ca.allanwang.kau.kpref.KPrefFactoryInMemory import com.pitchedapps.frost.db.FrostDatabase import com.pitchedapps.frost.facebook.FbCookie import com.pitchedapps.frost.prefs.Prefs -import com.pitchedapps.frost.utils.Showcase import org.junit.rules.TestRule import org.junit.runner.Description import org.junit.runners.model.Statement @@ -53,7 +52,6 @@ class FrostTestRule : TestRule { // Reset prefs get().reset() - get().reset() base.evaluate() } @@ -72,7 +70,6 @@ class FrostTestApp : Application() { FrostDatabase.module(), prefFactoryModule(), Prefs.module(), - Showcase.module(), FbCookie.module() ) ) diff --git a/app/src/main/kotlin/com/pitchedapps/frost/FrostApp.kt b/app/src/main/kotlin/com/pitchedapps/frost/FrostApp.kt index aaaaf605..278a4e3c 100644 --- a/app/src/main/kotlin/com/pitchedapps/frost/FrostApp.kt +++ b/app/src/main/kotlin/com/pitchedapps/frost/FrostApp.kt @@ -34,8 +34,6 @@ import com.pitchedapps.frost.services.setupNotificationChannels import com.pitchedapps.frost.utils.BuildUtils import com.pitchedapps.frost.utils.FrostPglAdBlock import com.pitchedapps.frost.utils.L -import com.pitchedapps.frost.utils.Showcase -import java.util.Random import org.koin.android.ext.koin.androidContext import org.koin.android.ext.koin.androidLogger import org.koin.core.KoinComponent @@ -43,13 +41,13 @@ import org.koin.core.context.startKoin import org.koin.core.get import org.koin.core.module.Module import org.koin.dsl.module +import java.util.Random /** * Created by Allan Wang on 2017-05-28. */ class FrostApp : Application(), KoinComponent { - private lateinit var showcasePrefs: Showcase private lateinit var prefs: Prefs override fun onCreate() { @@ -63,7 +61,6 @@ class FrostApp : Application(), KoinComponent { FrostDatabase.module(), prefFactoryModule(), Prefs.module(), - Showcase.module(), FbCookie.module() ) ) @@ -73,7 +70,6 @@ class FrostApp : Application(), KoinComponent { return } prefs = get() - showcasePrefs = get() initPrefs() // initBugsnag() @@ -108,8 +104,7 @@ class FrostApp : Application(), KoinComponent { } private fun initPrefs() { - prefs.deleteKeys("search_bar") - showcasePrefs.deleteKeys("shown_release", "experimental_by_default") + prefs.deleteKeys("search_bar", "shown_release", "experimental_by_default") KL.shouldLog = { BuildConfig.DEBUG } L.shouldLog = { when (it) { diff --git a/app/src/main/kotlin/com/pitchedapps/frost/activities/LoginActivity.kt b/app/src/main/kotlin/com/pitchedapps/frost/activities/LoginActivity.kt index 25a97ae2..eaf6453e 100644 --- a/app/src/main/kotlin/com/pitchedapps/frost/activities/LoginActivity.kt +++ b/app/src/main/kotlin/com/pitchedapps/frost/activities/LoginActivity.kt @@ -41,7 +41,6 @@ import com.pitchedapps.frost.facebook.profilePictureUrl import com.pitchedapps.frost.glide.FrostGlide import com.pitchedapps.frost.glide.GlideApp import com.pitchedapps.frost.utils.L -import com.pitchedapps.frost.utils.Showcase import com.pitchedapps.frost.utils.frostEvent import com.pitchedapps.frost.utils.frostJsoup import com.pitchedapps.frost.utils.launchNewTask @@ -49,8 +48,6 @@ import com.pitchedapps.frost.utils.logFrostEvent import com.pitchedapps.frost.utils.setFrostColors import com.pitchedapps.frost.utils.uniqueOnly import com.pitchedapps.frost.web.LoginWebView -import java.net.UnknownHostException -import kotlin.coroutines.resume import kotlinx.coroutines.Dispatchers import kotlinx.coroutines.async import kotlinx.coroutines.channels.Channel @@ -60,6 +57,8 @@ import kotlinx.coroutines.suspendCancellableCoroutine import kotlinx.coroutines.withContext import kotlinx.coroutines.withTimeout import org.koin.android.ext.android.inject +import java.net.UnknownHostException +import kotlin.coroutines.resume /** * Created by Allan Wang on 2017-06-01. @@ -72,7 +71,6 @@ class LoginActivity : BaseActivity() { private val textview: AppCompatTextView by bindView(R.id.textview) private val profile: ImageView by bindView(R.id.profile) private val cookieDao: CookieDao by inject() - private val showcasePrefs: Showcase by inject() private lateinit var profileLoader: RequestManager private val refreshChannel = Channel(10) @@ -138,7 +136,7 @@ class LoginActivity : BaseActivity() { */ val cookies = ArrayList(cookieDao.selectAll()) delay(1000) - if (showcasePrefs.intro) + if (prefs.intro) launchNewTask(cookies, true) else launchNewTask(cookies, true) diff --git a/app/src/main/kotlin/com/pitchedapps/frost/activities/WebOverlayActivity.kt b/app/src/main/kotlin/com/pitchedapps/frost/activities/WebOverlayActivity.kt index 01fad8fa..abc07d57 100644 --- a/app/src/main/kotlin/com/pitchedapps/frost/activities/WebOverlayActivity.kt +++ b/app/src/main/kotlin/com/pitchedapps/frost/activities/WebOverlayActivity.kt @@ -66,7 +66,6 @@ import com.pitchedapps.frost.utils.ARG_URL import com.pitchedapps.frost.utils.ARG_USER_ID import com.pitchedapps.frost.utils.BiometricUtils import com.pitchedapps.frost.utils.L -import com.pitchedapps.frost.utils.Showcase import com.pitchedapps.frost.utils.frostSnackbar import com.pitchedapps.frost.utils.setFrostColors import com.pitchedapps.frost.views.FrostContentWeb @@ -76,7 +75,6 @@ import kotlinx.coroutines.Dispatchers import kotlinx.coroutines.ExperimentalCoroutinesApi import kotlinx.coroutines.launch import okhttp3.HttpUrl.Companion.toHttpUrlOrNull -import org.koin.android.ext.android.inject /** * Created by Allan Wang on 2017-06-01. @@ -169,8 +167,6 @@ abstract class WebOverlayActivityBase(private val userAgent: String = USER_AGENT get() = content.coreView private val coordinator: CoordinatorLayout by bindView(R.id.overlay_main_content) - private val showcasePrefs: Showcase by inject() - private inline val urlTest: String? get() = intent.getStringExtra(ARG_URL) ?: intent.dataString @@ -231,7 +227,7 @@ abstract class WebOverlayActivityBase(private val userAgent: String = USER_AGENT } authDefer.await() reloadBase(true) - if (showcasePrefs.firstWebOverlay) { + if (prefs.firstWebOverlay) { coordinator.frostSnackbar(R.string.web_overlay_swipe_hint) { duration = BaseTransientBottomBar.LENGTH_INDEFINITE setAction(R.string.kau_got_it) { dismiss() } 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 { FeedPrefsImpl(factory = get()) } single { NotifPrefsImpl(factory = get()) } single { ThemePrefsImpl(factory = get()) } + single { ShowcasePrefsImpl(factory = get()) } single { 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 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 . + */ +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 diff --git a/app/src/main/kotlin/com/pitchedapps/frost/utils/Showcase.kt b/app/src/main/kotlin/com/pitchedapps/frost/utils/Showcase.kt deleted file mode 100644 index 423eda97..00000000 --- a/app/src/main/kotlin/com/pitchedapps/frost/utils/Showcase.kt +++ /dev/null @@ -1,41 +0,0 @@ -/* - * 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 . - */ -package com.pitchedapps.frost.utils - -import ca.allanwang.kau.kpref.KPref -import ca.allanwang.kau.kpref.KPrefFactory -import com.pitchedapps.frost.BuildConfig -import org.koin.dsl.module - -/** - * Created by Allan Wang on 2017-07-03. - * - * Showcase prefs that offer one time helpers to guide new users - */ -class Showcase(factory: KPrefFactory) : KPref("${BuildConfig.APPLICATION_ID}.showcase", factory) { - - // check if this is the first time launching the web overlay; show snackbar if true - val firstWebOverlay: Boolean by kprefSingle("first_web_overlay") - - val intro: Boolean by kprefSingle("intro_pages") - - companion object { - fun module() = module { - single { Showcase(get()) } - } - } -} -- cgit v1.2.3