diff options
Diffstat (limited to 'app/src/main')
-rw-r--r-- | app/src/main/kotlin/com/pitchedapps/frost/FrostApp.kt | 9 | ||||
-rw-r--r-- | app/src/main/kotlin/com/pitchedapps/frost/activities/LoginActivity.kt | 8 | ||||
-rw-r--r-- | app/src/main/kotlin/com/pitchedapps/frost/activities/WebOverlayActivity.kt | 6 | ||||
-rw-r--r-- | app/src/main/kotlin/com/pitchedapps/frost/prefs/Prefs.kt | 56 | ||||
-rw-r--r-- | app/src/main/kotlin/com/pitchedapps/frost/prefs/sections/BehaviourPrefs.kt | 4 | ||||
-rw-r--r-- | app/src/main/kotlin/com/pitchedapps/frost/prefs/sections/CorePrefs.kt | 3 | ||||
-rw-r--r-- | app/src/main/kotlin/com/pitchedapps/frost/prefs/sections/FeedPrefs.kt | 3 | ||||
-rw-r--r-- | app/src/main/kotlin/com/pitchedapps/frost/prefs/sections/NotifPrefs.kt | 3 | ||||
-rw-r--r-- | app/src/main/kotlin/com/pitchedapps/frost/prefs/sections/ShowcasePrefs.kt (renamed from app/src/main/kotlin/com/pitchedapps/frost/utils/Showcase.kt) | 29 | ||||
-rw-r--r-- | app/src/main/kotlin/com/pitchedapps/frost/prefs/sections/ThemePrefs.kt | 3 |
10 files changed, 82 insertions, 42 deletions
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<Boolean>(10) @@ -138,7 +136,7 @@ class LoginActivity : BaseActivity() { */ val cookies = ArrayList(cookieDao.selectAll()) delay(1000) - if (showcasePrefs.intro) + if (prefs.intro) launchNewTask<IntroActivity>(cookies, true) else launchNewTask<MainActivity>(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<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/utils/Showcase.kt b/app/src/main/kotlin/com/pitchedapps/frost/prefs/sections/ShowcasePrefs.kt index 423eda97..516a14c5 100644 --- a/app/src/main/kotlin/com/pitchedapps/frost/utils/Showcase.kt +++ b/app/src/main/kotlin/com/pitchedapps/frost/prefs/sections/ShowcasePrefs.kt @@ -14,28 +14,33 @@ * 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.utils +package com.pitchedapps.frost.prefs.sections import ca.allanwang.kau.kpref.KPref import ca.allanwang.kau.kpref.KPrefFactory import com.pitchedapps.frost.BuildConfig -import org.koin.dsl.module +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 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") +class ShowcasePrefsImpl( + factory: KPrefFactory +) : KPref("${BuildConfig.APPLICATION_ID}.showcase", factory), + ShowcasePrefs { - val intro: Boolean by kprefSingle("intro_pages") + override val firstWebOverlay: Boolean by kprefSingle("first_web_overlay") - companion object { - fun module() = module { - single { Showcase(get()) } - } - } + 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 |