mirror of
https://github.com/AllanWang/Frost-for-Facebook.git
synced 2024-11-08 20:12:39 +01:00
Migrate showcase prefs to pref section
This commit is contained in:
parent
5eb18e7464
commit
daf8f74ecf
@ -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<Prefs>().reset()
|
||||
get<Showcase>().reset()
|
||||
|
||||
base.evaluate()
|
||||
}
|
||||
@ -72,7 +70,6 @@ class FrostTestApp : Application() {
|
||||
FrostDatabase.module(),
|
||||
prefFactoryModule(),
|
||||
Prefs.module(),
|
||||
Showcase.module(),
|
||||
FbCookie.module()
|
||||
)
|
||||
)
|
||||
|
@ -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) {
|
||||
|
@ -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)
|
||||
|
@ -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() }
|
||||
|
@ -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()
|
||||
}
|
||||
}
|
||||
|
@ -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 */
|
||||
)
|
||||
|
||||
}
|
||||
|
@ -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
|
||||
|
@ -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
|
||||
|
@ -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
|
||||
|
@ -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) {
|
||||
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
|
||||
val firstWebOverlay: Boolean by kprefSingle("first_web_overlay")
|
||||
override val firstWebOverlay: Boolean by kprefSingle("first_web_overlay")
|
||||
|
||||
val intro: Boolean by kprefSingle("intro_pages")
|
||||
|
||||
companion object {
|
||||
fun module() = module {
|
||||
single { Showcase(get()) }
|
||||
}
|
||||
}
|
||||
override val intro: Boolean by kprefSingle("intro_pages")
|
||||
}
|
@ -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
|
||||
|
Loading…
Reference in New Issue
Block a user