1
0
mirror of https://github.com/AllanWang/Frost-for-Facebook.git synced 2024-11-12 14:03:00 +01:00

Migrate showcase prefs to pref section

This commit is contained in:
Allan Wang 2020-07-18 20:25:35 -07:00
parent 5eb18e7464
commit daf8f74ecf
No known key found for this signature in database
GPG Key ID: C93E3F9C679D7A56
11 changed files with 82 additions and 45 deletions

View File

@ -24,7 +24,6 @@ import ca.allanwang.kau.kpref.KPrefFactoryInMemory
import com.pitchedapps.frost.db.FrostDatabase import com.pitchedapps.frost.db.FrostDatabase
import com.pitchedapps.frost.facebook.FbCookie import com.pitchedapps.frost.facebook.FbCookie
import com.pitchedapps.frost.prefs.Prefs import com.pitchedapps.frost.prefs.Prefs
import com.pitchedapps.frost.utils.Showcase
import org.junit.rules.TestRule import org.junit.rules.TestRule
import org.junit.runner.Description import org.junit.runner.Description
import org.junit.runners.model.Statement import org.junit.runners.model.Statement
@ -53,7 +52,6 @@ class FrostTestRule : TestRule {
// Reset prefs // Reset prefs
get<Prefs>().reset() get<Prefs>().reset()
get<Showcase>().reset()
base.evaluate() base.evaluate()
} }
@ -72,7 +70,6 @@ class FrostTestApp : Application() {
FrostDatabase.module(), FrostDatabase.module(),
prefFactoryModule(), prefFactoryModule(),
Prefs.module(), Prefs.module(),
Showcase.module(),
FbCookie.module() FbCookie.module()
) )
) )

View File

@ -34,8 +34,6 @@ import com.pitchedapps.frost.services.setupNotificationChannels
import com.pitchedapps.frost.utils.BuildUtils import com.pitchedapps.frost.utils.BuildUtils
import com.pitchedapps.frost.utils.FrostPglAdBlock import com.pitchedapps.frost.utils.FrostPglAdBlock
import com.pitchedapps.frost.utils.L 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.androidContext
import org.koin.android.ext.koin.androidLogger import org.koin.android.ext.koin.androidLogger
import org.koin.core.KoinComponent import org.koin.core.KoinComponent
@ -43,13 +41,13 @@ import org.koin.core.context.startKoin
import org.koin.core.get import org.koin.core.get
import org.koin.core.module.Module import org.koin.core.module.Module
import org.koin.dsl.module import org.koin.dsl.module
import java.util.Random
/** /**
* Created by Allan Wang on 2017-05-28. * Created by Allan Wang on 2017-05-28.
*/ */
class FrostApp : Application(), KoinComponent { class FrostApp : Application(), KoinComponent {
private lateinit var showcasePrefs: Showcase
private lateinit var prefs: Prefs private lateinit var prefs: Prefs
override fun onCreate() { override fun onCreate() {
@ -63,7 +61,6 @@ class FrostApp : Application(), KoinComponent {
FrostDatabase.module(), FrostDatabase.module(),
prefFactoryModule(), prefFactoryModule(),
Prefs.module(), Prefs.module(),
Showcase.module(),
FbCookie.module() FbCookie.module()
) )
) )
@ -73,7 +70,6 @@ class FrostApp : Application(), KoinComponent {
return return
} }
prefs = get() prefs = get()
showcasePrefs = get()
initPrefs() initPrefs()
// initBugsnag() // initBugsnag()
@ -108,8 +104,7 @@ class FrostApp : Application(), KoinComponent {
} }
private fun initPrefs() { private fun initPrefs() {
prefs.deleteKeys("search_bar") prefs.deleteKeys("search_bar", "shown_release", "experimental_by_default")
showcasePrefs.deleteKeys("shown_release", "experimental_by_default")
KL.shouldLog = { BuildConfig.DEBUG } KL.shouldLog = { BuildConfig.DEBUG }
L.shouldLog = { L.shouldLog = {
when (it) { when (it) {

View File

@ -41,7 +41,6 @@ import com.pitchedapps.frost.facebook.profilePictureUrl
import com.pitchedapps.frost.glide.FrostGlide import com.pitchedapps.frost.glide.FrostGlide
import com.pitchedapps.frost.glide.GlideApp import com.pitchedapps.frost.glide.GlideApp
import com.pitchedapps.frost.utils.L import com.pitchedapps.frost.utils.L
import com.pitchedapps.frost.utils.Showcase
import com.pitchedapps.frost.utils.frostEvent import com.pitchedapps.frost.utils.frostEvent
import com.pitchedapps.frost.utils.frostJsoup import com.pitchedapps.frost.utils.frostJsoup
import com.pitchedapps.frost.utils.launchNewTask 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.setFrostColors
import com.pitchedapps.frost.utils.uniqueOnly import com.pitchedapps.frost.utils.uniqueOnly
import com.pitchedapps.frost.web.LoginWebView import com.pitchedapps.frost.web.LoginWebView
import java.net.UnknownHostException
import kotlin.coroutines.resume
import kotlinx.coroutines.Dispatchers import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.async import kotlinx.coroutines.async
import kotlinx.coroutines.channels.Channel import kotlinx.coroutines.channels.Channel
@ -60,6 +57,8 @@ import kotlinx.coroutines.suspendCancellableCoroutine
import kotlinx.coroutines.withContext import kotlinx.coroutines.withContext
import kotlinx.coroutines.withTimeout import kotlinx.coroutines.withTimeout
import org.koin.android.ext.android.inject import org.koin.android.ext.android.inject
import java.net.UnknownHostException
import kotlin.coroutines.resume
/** /**
* Created by Allan Wang on 2017-06-01. * 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 textview: AppCompatTextView by bindView(R.id.textview)
private val profile: ImageView by bindView(R.id.profile) private val profile: ImageView by bindView(R.id.profile)
private val cookieDao: CookieDao by inject() private val cookieDao: CookieDao by inject()
private val showcasePrefs: Showcase by inject()
private lateinit var profileLoader: RequestManager private lateinit var profileLoader: RequestManager
private val refreshChannel = Channel<Boolean>(10) private val refreshChannel = Channel<Boolean>(10)
@ -138,7 +136,7 @@ class LoginActivity : BaseActivity() {
*/ */
val cookies = ArrayList(cookieDao.selectAll()) val cookies = ArrayList(cookieDao.selectAll())
delay(1000) delay(1000)
if (showcasePrefs.intro) if (prefs.intro)
launchNewTask<IntroActivity>(cookies, true) launchNewTask<IntroActivity>(cookies, true)
else else
launchNewTask<MainActivity>(cookies, true) launchNewTask<MainActivity>(cookies, true)

View File

@ -66,7 +66,6 @@ import com.pitchedapps.frost.utils.ARG_URL
import com.pitchedapps.frost.utils.ARG_USER_ID import com.pitchedapps.frost.utils.ARG_USER_ID
import com.pitchedapps.frost.utils.BiometricUtils import com.pitchedapps.frost.utils.BiometricUtils
import com.pitchedapps.frost.utils.L import com.pitchedapps.frost.utils.L
import com.pitchedapps.frost.utils.Showcase
import com.pitchedapps.frost.utils.frostSnackbar import com.pitchedapps.frost.utils.frostSnackbar
import com.pitchedapps.frost.utils.setFrostColors import com.pitchedapps.frost.utils.setFrostColors
import com.pitchedapps.frost.views.FrostContentWeb import com.pitchedapps.frost.views.FrostContentWeb
@ -76,7 +75,6 @@ import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.ExperimentalCoroutinesApi import kotlinx.coroutines.ExperimentalCoroutinesApi
import kotlinx.coroutines.launch import kotlinx.coroutines.launch
import okhttp3.HttpUrl.Companion.toHttpUrlOrNull import okhttp3.HttpUrl.Companion.toHttpUrlOrNull
import org.koin.android.ext.android.inject
/** /**
* Created by Allan Wang on 2017-06-01. * Created by Allan Wang on 2017-06-01.
@ -169,8 +167,6 @@ abstract class WebOverlayActivityBase(private val userAgent: String = USER_AGENT
get() = content.coreView get() = content.coreView
private val coordinator: CoordinatorLayout by bindView(R.id.overlay_main_content) private val coordinator: CoordinatorLayout by bindView(R.id.overlay_main_content)
private val showcasePrefs: Showcase by inject()
private inline val urlTest: String? private inline val urlTest: String?
get() = intent.getStringExtra(ARG_URL) ?: intent.dataString get() = intent.getStringExtra(ARG_URL) ?: intent.dataString
@ -231,7 +227,7 @@ abstract class WebOverlayActivityBase(private val userAgent: String = USER_AGENT
} }
authDefer.await() authDefer.await()
reloadBase(true) reloadBase(true)
if (showcasePrefs.firstWebOverlay) { if (prefs.firstWebOverlay) {
coordinator.frostSnackbar(R.string.web_overlay_swipe_hint) { coordinator.frostSnackbar(R.string.web_overlay_swipe_hint) {
duration = BaseTransientBottomBar.LENGTH_INDEFINITE duration = BaseTransientBottomBar.LENGTH_INDEFINITE
setAction(R.string.kau_got_it) { dismiss() } setAction(R.string.kau_got_it) { dismiss() }

View File

@ -24,12 +24,29 @@ import com.pitchedapps.frost.prefs.sections.FeedPrefs
import com.pitchedapps.frost.prefs.sections.FeedPrefsImpl import com.pitchedapps.frost.prefs.sections.FeedPrefsImpl
import com.pitchedapps.frost.prefs.sections.NotifPrefs import com.pitchedapps.frost.prefs.sections.NotifPrefs
import com.pitchedapps.frost.prefs.sections.NotifPrefsImpl 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.ThemePrefs
import com.pitchedapps.frost.prefs.sections.ThemePrefsImpl import com.pitchedapps.frost.prefs.sections.ThemePrefsImpl
import org.koin.core.context.KoinContextHandler import org.koin.core.context.KoinContextHandler
import org.koin.dsl.module 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 { companion object {
fun get(): Prefs = KoinContextHandler.get().get() fun get(): Prefs = KoinContextHandler.get().get()
@ -39,13 +56,15 @@ interface Prefs : BehaviourPrefs, CorePrefs, FeedPrefs, NotifPrefs, ThemePrefs {
single<FeedPrefs> { FeedPrefsImpl(factory = get()) } single<FeedPrefs> { FeedPrefsImpl(factory = get()) }
single<NotifPrefs> { NotifPrefsImpl(factory = get()) } single<NotifPrefs> { NotifPrefsImpl(factory = get()) }
single<ThemePrefs> { ThemePrefsImpl(factory = get()) } single<ThemePrefs> { ThemePrefsImpl(factory = get()) }
single<ShowcasePrefs> { ShowcasePrefsImpl(factory = get()) }
single<Prefs> { single<Prefs> {
PrefsImpl( PrefsImpl(
behaviourPrefs = get(), behaviourPrefs = get(),
corePrefs = get(), corePrefs = get(),
feedPrefs = get(), feedPrefs = get(),
notifPrefs = get(), notifPrefs = get(),
themePrefs = get() themePrefs = get(),
showcasePrefs = get()
) )
} }
// Needed for migration // Needed for migration
@ -55,14 +74,35 @@ interface Prefs : BehaviourPrefs, CorePrefs, FeedPrefs, NotifPrefs, ThemePrefs {
} }
class PrefsImpl( class PrefsImpl(
behaviourPrefs: BehaviourPrefs, private val behaviourPrefs: BehaviourPrefs,
corePrefs: CorePrefs, private val corePrefs: CorePrefs,
feedPrefs: FeedPrefs, private val feedPrefs: FeedPrefs,
notifPrefs: NotifPrefs, private val notifPrefs: NotifPrefs,
themePrefs: ThemePrefs private val themePrefs: ThemePrefs,
private val showcasePrefs: ShowcasePrefs
) : Prefs, ) : Prefs,
BehaviourPrefs by behaviourPrefs, BehaviourPrefs by behaviourPrefs,
CorePrefs by corePrefs, CorePrefs by corePrefs,
FeedPrefs by feedPrefs, FeedPrefs by feedPrefs,
NotifPrefs by notifPrefs, 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()
}
}

View File

@ -20,10 +20,11 @@ import ca.allanwang.kau.kpref.KPref
import ca.allanwang.kau.kpref.KPrefFactory import ca.allanwang.kau.kpref.KPrefFactory
import com.pitchedapps.frost.BuildConfig import com.pitchedapps.frost.BuildConfig
import com.pitchedapps.frost.prefs.OldPrefs import com.pitchedapps.frost.prefs.OldPrefs
import com.pitchedapps.frost.prefs.PrefsBase
import org.koin.core.KoinComponent import org.koin.core.KoinComponent
import org.koin.core.inject import org.koin.core.inject
interface BehaviourPrefs { interface BehaviourPrefs : PrefsBase {
var biometricsEnabled: Boolean var biometricsEnabled: Boolean
var overlayEnabled: Boolean var overlayEnabled: Boolean
@ -105,4 +106,5 @@ class BehaviourPrefsImpl(
"full_size_image", "full_size_image",
oldPrefs.fullSizeImage /* false */ oldPrefs.fullSizeImage /* false */
) )
} }

View File

@ -20,10 +20,11 @@ import ca.allanwang.kau.kpref.KPref
import ca.allanwang.kau.kpref.KPrefFactory import ca.allanwang.kau.kpref.KPrefFactory
import com.pitchedapps.frost.BuildConfig import com.pitchedapps.frost.BuildConfig
import com.pitchedapps.frost.prefs.OldPrefs import com.pitchedapps.frost.prefs.OldPrefs
import com.pitchedapps.frost.prefs.PrefsBase
import org.koin.core.KoinComponent import org.koin.core.KoinComponent
import org.koin.core.inject import org.koin.core.inject
interface CorePrefs { interface CorePrefs : PrefsBase {
var lastLaunch: Long var lastLaunch: Long
var userId: Long var userId: Long

View File

@ -21,10 +21,11 @@ import ca.allanwang.kau.kpref.KPrefFactory
import com.pitchedapps.frost.BuildConfig import com.pitchedapps.frost.BuildConfig
import com.pitchedapps.frost.enums.MainActivityLayout import com.pitchedapps.frost.enums.MainActivityLayout
import com.pitchedapps.frost.prefs.OldPrefs import com.pitchedapps.frost.prefs.OldPrefs
import com.pitchedapps.frost.prefs.PrefsBase
import org.koin.core.KoinComponent import org.koin.core.KoinComponent
import org.koin.core.inject import org.koin.core.inject
interface FeedPrefs { interface FeedPrefs : PrefsBase {
var webTextScaling: Int var webTextScaling: Int
var feedSort: Int var feedSort: Int

View File

@ -20,10 +20,11 @@ import ca.allanwang.kau.kpref.KPref
import ca.allanwang.kau.kpref.KPrefFactory import ca.allanwang.kau.kpref.KPrefFactory
import com.pitchedapps.frost.BuildConfig import com.pitchedapps.frost.BuildConfig
import com.pitchedapps.frost.prefs.OldPrefs import com.pitchedapps.frost.prefs.OldPrefs
import com.pitchedapps.frost.prefs.PrefsBase
import org.koin.core.KoinComponent import org.koin.core.KoinComponent
import org.koin.core.inject import org.koin.core.inject
interface NotifPrefs { interface NotifPrefs : PrefsBase {
var notificationKeywords: Set<String> var notificationKeywords: Set<String>
var notificationsGeneral: Boolean var notificationsGeneral: Boolean

View File

@ -14,28 +14,33 @@
* You should have received a copy of the GNU General Public License * You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>. * 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.KPref
import ca.allanwang.kau.kpref.KPrefFactory import ca.allanwang.kau.kpref.KPrefFactory
import com.pitchedapps.frost.BuildConfig 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. * Created by Allan Wang on 2017-07-03.
* *
* Showcase prefs that offer one time helpers to guide new users * Showcase prefs that offer one time helpers to guide new users
*/ */
class Showcase(factory: KPrefFactory) : KPref("${BuildConfig.APPLICATION_ID}.showcase", factory) { class ShowcasePrefsImpl(
factory: KPrefFactory
) : KPref("${BuildConfig.APPLICATION_ID}.showcase", factory),
ShowcasePrefs {
// check if this is the first time launching the web overlay; show snackbar if true override val firstWebOverlay: Boolean by kprefSingle("first_web_overlay")
val firstWebOverlay: Boolean by kprefSingle("first_web_overlay")
val intro: Boolean by kprefSingle("intro_pages") override val intro: Boolean by kprefSingle("intro_pages")
companion object {
fun module() = module {
single { Showcase(get()) }
}
}
} }

View File

@ -28,10 +28,11 @@ import com.pitchedapps.frost.enums.FACEBOOK_BLUE
import com.pitchedapps.frost.enums.Theme import com.pitchedapps.frost.enums.Theme
import com.pitchedapps.frost.injectors.InjectorContract import com.pitchedapps.frost.injectors.InjectorContract
import com.pitchedapps.frost.prefs.OldPrefs import com.pitchedapps.frost.prefs.OldPrefs
import com.pitchedapps.frost.prefs.PrefsBase
import org.koin.core.KoinComponent import org.koin.core.KoinComponent
import org.koin.core.inject import org.koin.core.inject
interface ThemePrefs { interface ThemePrefs : PrefsBase {
var theme: Int var theme: Int
var customTextColor: Int var customTextColor: Int