diff options
Diffstat (limited to 'app/src/main/kotlin/com/pitchedapps/frost/prefs')
8 files changed, 890 insertions, 0 deletions
diff --git a/app/src/main/kotlin/com/pitchedapps/frost/prefs/OldPrefs.kt b/app/src/main/kotlin/com/pitchedapps/frost/prefs/OldPrefs.kt new file mode 100644 index 00000000..954c7f9a --- /dev/null +++ b/app/src/main/kotlin/com/pitchedapps/frost/prefs/OldPrefs.kt @@ -0,0 +1,149 @@ +/* + * 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 + +import ca.allanwang.kau.kpref.KPref +import ca.allanwang.kau.kpref.KPrefFactory +import com.pitchedapps.frost.BuildConfig +import com.pitchedapps.frost.enums.FeedSort + +/** + * Created by Allan Wang on 2017-05-28. + * + * Shared Preference object with lazy cached retrievals + * + * As of 2020-07-18, prefs have been split up into multiple folders + */ +@Deprecated(level = DeprecationLevel.WARNING, message = "Use pref segments") +class OldPrefs(factory: KPrefFactory) : KPref("${BuildConfig.APPLICATION_ID}.prefs", factory) { + + var lastLaunch: Long by kpref("last_launch", -1L) + + var userId: Long by kpref("user_id", -1L) + + var prevId: Long by kpref("prev_id", -1L) + + var theme: Int by kpref("theme", 0) + + var customTextColor: Int by kpref("color_text", 0xffeceff1.toInt()) + + var customAccentColor: Int by kpref("color_accent", 0xff0288d1.toInt()) + + var customBackgroundColor: Int by kpref("color_bg", 0xff212121.toInt()) + + var customHeaderColor: Int by kpref("color_header", 0xff01579b.toInt()) + + var customIconColor: Int by kpref("color_icons", 0xffeceff1.toInt()) + + var exitConfirmation: Boolean by kpref("exit_confirmation", true) + + var notificationFreq: Long by kpref("notification_freq", 15L) + + var versionCode: Int by kpref("version_code", -1) + + var prevVersionCode: Int by kpref("prev_version_code", -1) + + var installDate: Long by kpref("install_date", -1L) + + var identifier: Int by kpref("identifier", -1) + + var tintNavBar: Boolean by kpref("tint_nav_bar", true) + + var webTextScaling: Int by kpref("web_text_scaling", 100) + + var feedSort: Int by kpref("feed_sort", FeedSort.DEFAULT.ordinal) + + var aggressiveRecents: Boolean by kpref("aggressive_recents", false) + + var showComposer: Boolean by kpref("status_composer_feed", true) + + var showSuggestedFriends: Boolean by kpref("suggested_friends_feed", true) + + var showSuggestedGroups: Boolean by kpref("suggested_groups_feed", true) + + var showFacebookAds: Boolean by kpref("facebook_ads", false) + + var showStories: Boolean by kpref("show_stories", true) + + var animate: Boolean by kpref("fancy_animations", true) + + var notificationKeywords: Set<String> by kpref("notification_keywords", mutableSetOf()) + + var notificationsGeneral: Boolean by kpref("notification_general", true) + + var notificationAllAccounts: Boolean by kpref("notification_all_accounts", true) + + var notificationsInstantMessages: Boolean by kpref("notification_im", true) + + var notificationsImAllAccounts: Boolean by kpref("notification_im_all_accounts", false) + + var notificationVibrate: Boolean by kpref("notification_vibrate", true) + + var notificationSound: Boolean by kpref("notification_sound", true) + + var notificationRingtone: String by kpref("notification_ringtone", "") + + var messageRingtone: String by kpref("message_ringtone", "") + + var notificationLights: Boolean by kpref("notification_lights", true) + + var messageScrollToBottom: Boolean by kpref("message_scroll_to_bottom", false) + + var enablePip: Boolean by kpref("enable_pip", true) + + /** + * Despite the naming, this toggle currently only enables debug logging. + * Verbose is never logged in release builds. + */ + var verboseLogging: Boolean by kpref("verbose_logging", false) + + var analytics: Boolean by kpref("analytics", false) { +// if (!BuildConfig.DEBUG) { +// if (it) { +// Bugsnag.setAutoCaptureSessions(true) +// Bugsnag.enableExceptionHandler() +// } else { +// Bugsnag.setAutoCaptureSessions(false) +// Bugsnag.disableExceptionHandler() +// } +// } + } + + var biometricsEnabled: Boolean by kpref("biometrics_enabled", false) + + var overlayEnabled: Boolean by kpref("overlay_enabled", true) + + var overlayFullScreenSwipe: Boolean by kpref("overlay_full_screen_swipe", true) + + var viewpagerSwipe: Boolean by kpref("viewpager_swipe", true) + + var loadMediaOnMeteredNetwork: Boolean by kpref("media_on_metered_network", true) + + var debugSettings: Boolean by kpref("debug_settings", false) + + var linksInDefaultApp: Boolean by kpref("link_in_default_app", false) + + var mainActivityLayoutType: Int by kpref("main_activity_layout_type", 0) + + var blackMediaBg: Boolean by kpref("black_media_bg", false) + + var autoRefreshFeed: Boolean by kpref("auto_refresh_feed", false) + + var showCreateFab: Boolean by kpref("show_create_fab", true) + + var fullSizeImage: Boolean by kpref("full_size_image", false) +} diff --git a/app/src/main/kotlin/com/pitchedapps/frost/prefs/Prefs.kt b/app/src/main/kotlin/com/pitchedapps/frost/prefs/Prefs.kt new file mode 100644 index 00000000..2714b930 --- /dev/null +++ b/app/src/main/kotlin/com/pitchedapps/frost/prefs/Prefs.kt @@ -0,0 +1,108 @@ +/* + * Copyright 2020 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 + +import com.pitchedapps.frost.prefs.sections.BehaviourPrefs +import com.pitchedapps.frost.prefs.sections.BehaviourPrefsImpl +import com.pitchedapps.frost.prefs.sections.CorePrefs +import com.pitchedapps.frost.prefs.sections.CorePrefsImpl +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 + +/** + * [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() + + fun module() = module { + single<BehaviourPrefs> { BehaviourPrefsImpl(factory = get()) } + single<CorePrefs> { CorePrefsImpl(factory = get()) } + 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(), + showcasePrefs = get() + ) + } + // Needed for migration + single<OldPrefs> { OldPrefs(factory = get()) } + } + } +} + +class PrefsImpl( + 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, + 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 new file mode 100644 index 00000000..ad0cb6be --- /dev/null +++ b/app/src/main/kotlin/com/pitchedapps/frost/prefs/sections/BehaviourPrefs.kt @@ -0,0 +1,109 @@ +/* + * Copyright 2020 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.OldPrefs +import com.pitchedapps.frost.prefs.PrefsBase +import org.koin.core.KoinComponent +import org.koin.core.inject + +interface BehaviourPrefs : PrefsBase { + var biometricsEnabled: Boolean + + var overlayEnabled: Boolean + + var overlayFullScreenSwipe: Boolean + + var viewpagerSwipe: Boolean + + var loadMediaOnMeteredNetwork: Boolean + + var debugSettings: Boolean + + var linksInDefaultApp: Boolean + + var blackMediaBg: Boolean + + var autoRefreshFeed: Boolean + + var showCreateFab: Boolean + + var fullSizeImage: Boolean +} + +class BehaviourPrefsImpl( + factory: KPrefFactory +) : KPref("${BuildConfig.APPLICATION_ID}.prefs.behaviour", factory), + BehaviourPrefs, KoinComponent { + + private val oldPrefs: OldPrefs by inject() + + override var biometricsEnabled: Boolean by kpref( + "biometrics_enabled", + oldPrefs.biometricsEnabled /* false */ + ) + + override var overlayEnabled: Boolean by kpref( + "overlay_enabled", + oldPrefs.overlayEnabled /* true */ + ) + + override var overlayFullScreenSwipe: Boolean by kpref( + "overlay_full_screen_swipe", + oldPrefs.overlayFullScreenSwipe /* true */ + ) + + override var viewpagerSwipe: Boolean by kpref( + "viewpager_swipe", + oldPrefs.viewpagerSwipe /* true */ + ) + + override var loadMediaOnMeteredNetwork: Boolean by kpref( + "media_on_metered_network", + oldPrefs.loadMediaOnMeteredNetwork /* true */ + ) + + override var debugSettings: Boolean by kpref( + "debug_settings", + oldPrefs.debugSettings /* false */ + ) + + override var linksInDefaultApp: Boolean by kpref( + "link_in_default_app", + oldPrefs.linksInDefaultApp /* false */ + ) + + override var blackMediaBg: Boolean by kpref("black_media_bg", oldPrefs.blackMediaBg /* false */) + + override var autoRefreshFeed: Boolean by kpref( + "auto_refresh_feed", + oldPrefs.autoRefreshFeed /* false */ + ) + + override var showCreateFab: Boolean by kpref( + "show_create_fab", + oldPrefs.showCreateFab /* true */ + ) + + override var fullSizeImage: Boolean by kpref( + "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 new file mode 100644 index 00000000..d1609d73 --- /dev/null +++ b/app/src/main/kotlin/com/pitchedapps/frost/prefs/sections/CorePrefs.kt @@ -0,0 +1,121 @@ +/* + * Copyright 2020 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.OldPrefs +import com.pitchedapps.frost.prefs.PrefsBase +import org.koin.core.KoinComponent +import org.koin.core.inject + +interface CorePrefs : PrefsBase { + var lastLaunch: Long + + var userId: Long + + var prevId: Long + + val frostId: String + + var versionCode: Int + + var prevVersionCode: Int + + var installDate: Long + + var identifier: Int + + /** + * Despite the naming, this toggle currently only enables debug logging. + * Verbose is never logged in release builds. + */ + var verboseLogging: Boolean + + /** + * True to enable analytic reports (BugSnag) + */ + var analytics: Boolean + + var enablePip: Boolean + + var exitConfirmation: Boolean + + var animate: Boolean + + var messageScrollToBottom: Boolean +} + +class CorePrefsImpl( + factory: KPrefFactory +) : KPref("${BuildConfig.APPLICATION_ID}.prefs.core", factory), + CorePrefs, KoinComponent { + + private val oldPrefs: OldPrefs by inject() + + override var lastLaunch: Long by kpref("last_launch", oldPrefs.lastLaunch /* -1L */) + + override var userId: Long by kpref("user_id", oldPrefs.userId /* -1L */) + + override var prevId: Long by kpref("prev_id", oldPrefs.prevId /* -1L */) + + override val frostId: String + get() = "$installDate-$identifier" + + override var versionCode: Int by kpref("version_code", oldPrefs.versionCode /* -1 */) + + override var prevVersionCode: Int by kpref( + "prev_version_code", + oldPrefs.prevVersionCode /* -1 */ + ) + + override var installDate: Long by kpref("install_date", oldPrefs.installDate /* -1L */) + + override var identifier: Int by kpref("identifier", oldPrefs.identifier /* -1 */) + + override var verboseLogging: Boolean by kpref( + "verbose_logging", + oldPrefs.verboseLogging /* false */ + ) + + override var analytics: Boolean by kpref("analytics", oldPrefs.analytics /* false */) { +// if (!BuildConfig.DEBUG) { +// if (it) { +// Bugsnag.setAutoCaptureSessions(true) +// Bugsnag.enableExceptionHandler() +// } else { +// Bugsnag.setAutoCaptureSessions(false) +// Bugsnag.disableExceptionHandler() +// } +// } + } + + override var enablePip: Boolean by kpref("enable_pip", oldPrefs.enablePip /* true */) + + override var exitConfirmation: Boolean by kpref( + "exit_confirmation", + oldPrefs.exitConfirmation /* true */ + ) + + override var animate: Boolean by kpref("fancy_animations", oldPrefs.animate /* true */) + + override var messageScrollToBottom: Boolean by kpref( + "message_scroll_to_bottom", + oldPrefs.messageScrollToBottom /* false */ + ) +} 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 new file mode 100644 index 00000000..0060f9ad --- /dev/null +++ b/app/src/main/kotlin/com/pitchedapps/frost/prefs/sections/FeedPrefs.kt @@ -0,0 +1,98 @@ +/* + * Copyright 2020 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.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 : PrefsBase { + var webTextScaling: Int + + var feedSort: Int + + var aggressiveRecents: Boolean + + var showComposer: Boolean + + var showSuggestedFriends: Boolean + + var showSuggestedGroups: Boolean + + var showFacebookAds: Boolean + + var showStories: Boolean + + var mainActivityLayoutType: Int + + val mainActivityLayout: MainActivityLayout +} + +class FeedPrefsImpl( + factory: KPrefFactory +) : KPref("${BuildConfig.APPLICATION_ID}.prefs.feed", factory), + FeedPrefs, KoinComponent { + + private val oldPrefs: OldPrefs by inject() + + override var webTextScaling: Int by kpref("web_text_scaling", oldPrefs.webTextScaling /* 100 */) + + override var feedSort: Int by kpref( + "feed_sort", + oldPrefs.feedSort /* FeedSort.DEFAULT.ordinal */ + ) + + override var aggressiveRecents: Boolean by kpref( + "aggressive_recents", + oldPrefs.aggressiveRecents /* false */ + ) + + override var showComposer: Boolean by kpref( + "status_composer_feed", + oldPrefs.showComposer /* true */ + ) + + override var showSuggestedFriends: Boolean by kpref( + "suggested_friends_feed", + oldPrefs.showSuggestedFriends /* true */ + ) + + override var showSuggestedGroups: Boolean by kpref( + "suggested_groups_feed", + oldPrefs.showSuggestedGroups /* true */ + ) + + override var showFacebookAds: Boolean by kpref( + "facebook_ads", + oldPrefs.showFacebookAds /* false */ + ) + + override var showStories: Boolean by kpref("show_stories", oldPrefs.showStories /* true */) + + override var mainActivityLayoutType: Int by kpref( + "main_activity_layout_type", + oldPrefs.mainActivityLayoutType /* 0 */ + ) + + override val mainActivityLayout: MainActivityLayout + get() = MainActivityLayout(mainActivityLayoutType) +} 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 new file mode 100644 index 00000000..5b0ba83b --- /dev/null +++ b/app/src/main/kotlin/com/pitchedapps/frost/prefs/sections/NotifPrefs.kt @@ -0,0 +1,112 @@ +/* + * Copyright 2020 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.OldPrefs +import com.pitchedapps.frost.prefs.PrefsBase +import org.koin.core.KoinComponent +import org.koin.core.inject + +interface NotifPrefs : PrefsBase { + var notificationKeywords: Set<String> + + var notificationsGeneral: Boolean + + var notificationAllAccounts: Boolean + + var notificationsInstantMessages: Boolean + + var notificationsImAllAccounts: Boolean + + var notificationVibrate: Boolean + + var notificationSound: Boolean + + var notificationRingtone: String + + var messageRingtone: String + + var notificationLights: Boolean + + var notificationFreq: Long +} + +class NotifPrefsImpl( + factory: KPrefFactory +) : KPref("${BuildConfig.APPLICATION_ID}.prefs.notif", factory), + NotifPrefs, KoinComponent { + + private val oldPrefs: OldPrefs by inject() + + override var notificationKeywords: Set<String> by kpref( + "notification_keywords", + oldPrefs.notificationKeywords /* mutableSetOf() */ + ) + + override var notificationsGeneral: Boolean by kpref( + "notification_general", + oldPrefs.notificationsGeneral /* true */ + ) + + override var notificationAllAccounts: Boolean by kpref( + "notification_all_accounts", + oldPrefs.notificationAllAccounts /* true */ + ) + + override var notificationsInstantMessages: Boolean by kpref( + "notification_im", + oldPrefs.notificationsInstantMessages /* true */ + ) + + override var notificationsImAllAccounts: Boolean by kpref( + "notification_im_all_accounts", + oldPrefs.notificationsImAllAccounts /* false */ + ) + + override var notificationVibrate: Boolean by kpref( + "notification_vibrate", + oldPrefs.notificationVibrate /* true */ + ) + + override var notificationSound: Boolean by kpref( + "notification_sound", + oldPrefs.notificationSound /* true */ + ) + + override var notificationRingtone: String by kpref( + "notification_ringtone", + oldPrefs.notificationRingtone /* "" */ + ) + + override var messageRingtone: String by kpref( + "message_ringtone", + oldPrefs.messageRingtone /* "" */ + ) + + override var notificationLights: Boolean by kpref( + "notification_lights", + oldPrefs.notificationLights /* true */ + ) + + override var notificationFreq: Long by kpref( + "notification_freq", + oldPrefs.notificationFreq /* 15L */ + ) +} 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 new file mode 100644 index 00000000..487827de --- /dev/null +++ b/app/src/main/kotlin/com/pitchedapps/frost/prefs/sections/ThemePrefs.kt @@ -0,0 +1,147 @@ +/* + * Copyright 2020 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 android.graphics.Color +import ca.allanwang.kau.kotlin.lazyResettable +import ca.allanwang.kau.kpref.KPref +import ca.allanwang.kau.kpref.KPrefFactory +import ca.allanwang.kau.utils.colorToForeground +import ca.allanwang.kau.utils.isColorVisibleOn +import ca.allanwang.kau.utils.withAlpha +import com.pitchedapps.frost.BuildConfig +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 : PrefsBase { + var theme: Int + + var customTextColor: Int + + var customAccentColor: Int + + var customBackgroundColor: Int + + var customHeaderColor: Int + + var customIconColor: Int + + val textColor: Int + + val accentColor: Int + + val accentColorForWhite: Int + + val nativeBgColor: Int + + fun nativeBgColor(unread: Boolean): Int + + val bgColor: Int + + val headerColor: Int + + val iconColor: Int + + val themeInjector: InjectorContract + + val isCustomTheme: Boolean + + var tintNavBar: Boolean +} + +class ThemePrefsImpl( + factory: KPrefFactory +) : KPref("${BuildConfig.APPLICATION_ID}.prefs.theme", factory), + ThemePrefs, KoinComponent { + + private val oldPrefs: OldPrefs by inject() + + override var theme: Int by kpref("theme", oldPrefs.theme /* 0 */) { _: Int -> + loader.invalidate() + } + + override var customTextColor: Int by kpref( + "color_text", + oldPrefs.customTextColor /* 0xffeceff1.toInt() */ + ) + + override var customAccentColor: Int by kpref( + "color_accent", + oldPrefs.customAccentColor /* 0xff0288d1.toInt() */ + ) + + override var customBackgroundColor: Int by kpref( + "color_bg", + oldPrefs.customBackgroundColor /* 0xff212121.toInt() */ + ) + + override var customHeaderColor: Int by kpref( + "color_header", + oldPrefs.customHeaderColor /* 0xff01579b.toInt() */ + ) + + override var customIconColor: Int by kpref( + "color_icons", + oldPrefs.customIconColor /* 0xffeceff1.toInt() */ + ) + + private val loader = lazyResettable { Theme.values[theme] } + + private val t: Theme by loader + + override val textColor: Int + get() = t.textColorGetter(this) + + override val accentColor: Int + get() = t.accentColorGetter(this) + + override val accentColorForWhite: Int + get() = when { + accentColor.isColorVisibleOn(Color.WHITE) -> accentColor + textColor.isColorVisibleOn(Color.WHITE) -> textColor + else -> FACEBOOK_BLUE + } + + override val nativeBgColor: Int + get() = bgColor.withAlpha(30) + + override fun nativeBgColor(unread: Boolean) = bgColor + .colorToForeground(if (unread) 0.7f else 0.0f) + .withAlpha(30) + + override val bgColor: Int + get() = t.backgroundColorGetter(this) + + override val headerColor: Int + get() = t.headerColorGetter(this) + + override val iconColor: Int + get() = t.iconColorGetter(this) + + override val themeInjector: InjectorContract + get() = t.injector + + override val isCustomTheme: Boolean + get() = t == Theme.CUSTOM + + override var tintNavBar: Boolean by kpref("tint_nav_bar", oldPrefs.tintNavBar /* true */) +} |