From c8b54fd10a08ed53eb7d21578a4fe990fe14e3bc Mon Sep 17 00:00:00 2001 From: Allan Wang Date: Sun, 23 Feb 2020 16:06:45 -0800 Subject: Move prefs to service locator --- .../com/pitchedapps/frost/settings/Appearance.kt | 42 ++++++++--------- .../com/pitchedapps/frost/settings/Behaviour.kt | 28 ++++++------ .../com/pitchedapps/frost/settings/Experimental.kt | 4 +- .../kotlin/com/pitchedapps/frost/settings/Feed.kt | 30 ++++++------ .../com/pitchedapps/frost/settings/Network.kt | 5 +- .../pitchedapps/frost/settings/Notifications.kt | 53 +++++++++++----------- .../com/pitchedapps/frost/settings/Security.kt | 4 +- 7 files changed, 83 insertions(+), 83 deletions(-) (limited to 'app/src/main/kotlin/com/pitchedapps/frost/settings') diff --git a/app/src/main/kotlin/com/pitchedapps/frost/settings/Appearance.kt b/app/src/main/kotlin/com/pitchedapps/frost/settings/Appearance.kt index 4391b3ca..361ac457 100644 --- a/app/src/main/kotlin/com/pitchedapps/frost/settings/Appearance.kt +++ b/app/src/main/kotlin/com/pitchedapps/frost/settings/Appearance.kt @@ -45,7 +45,7 @@ fun SettingsActivity.getAppearancePrefs(): KPrefAdapterBuilder.() -> Unit = { header(R.string.theme_customization) - text(R.string.theme, Prefs::theme, { Prefs.theme = it }) { + text(R.string.theme, prefs::theme, { prefs.theme = it }) { onClick = { materialDialog { title(R.string.theme) @@ -71,7 +71,7 @@ fun SettingsActivity.getAppearancePrefs(): KPrefAdapterBuilder.() -> Unit = { } fun KPrefColorPicker.KPrefColorContract.dependsOnCustom() { - enabler = Prefs::isCustomTheme + enabler = prefs::isCustomTheme onDisabledClick = { frostSnackbar(R.string.requires_custom_theme) } allowCustom = true } @@ -80,8 +80,8 @@ fun SettingsActivity.getAppearancePrefs(): KPrefAdapterBuilder.() -> Unit = { CssAssets.CUSTOM.reset() } - colorPicker(R.string.text_color, Prefs::customTextColor, { - Prefs.customTextColor = it + colorPicker(R.string.text_color, prefs::customTextColor, { + prefs.customTextColor = it reload() invalidateCustomTheme() shouldRestartMain() @@ -90,8 +90,8 @@ fun SettingsActivity.getAppearancePrefs(): KPrefAdapterBuilder.() -> Unit = { allowCustomAlpha = false } - colorPicker(R.string.accent_color, Prefs::customAccentColor, { - Prefs.customAccentColor = it + colorPicker(R.string.accent_color, prefs::customAccentColor, { + prefs.customAccentColor = it reload() invalidateCustomTheme() shouldRestartMain() @@ -100,8 +100,8 @@ fun SettingsActivity.getAppearancePrefs(): KPrefAdapterBuilder.() -> Unit = { allowCustomAlpha = false } - colorPicker(R.string.background_color, Prefs::customBackgroundColor, { - Prefs.customBackgroundColor = it + colorPicker(R.string.background_color, prefs::customBackgroundColor, { + prefs.customBackgroundColor = it bgCanvas.ripple(it, duration = 500L) invalidateCustomTheme() setFrostTheme(true) @@ -111,8 +111,8 @@ fun SettingsActivity.getAppearancePrefs(): KPrefAdapterBuilder.() -> Unit = { allowCustomAlpha = true } - colorPicker(R.string.header_color, Prefs::customHeaderColor, { - Prefs.customHeaderColor = it + colorPicker(R.string.header_color, prefs::customHeaderColor, { + prefs.customHeaderColor = it frostNavigationBar() toolbarCanvas.ripple(it, RippleCanvas.MIDDLE, RippleCanvas.END, duration = 500L) reload() @@ -122,8 +122,8 @@ fun SettingsActivity.getAppearancePrefs(): KPrefAdapterBuilder.() -> Unit = { allowCustomAlpha = true } - colorPicker(R.string.icon_color, Prefs::customIconColor, { - Prefs.customIconColor = it + colorPicker(R.string.icon_color, prefs::customIconColor, { + prefs.customIconColor = it invalidateOptionsMenu() shouldRestartMain() }) { @@ -135,9 +135,9 @@ fun SettingsActivity.getAppearancePrefs(): KPrefAdapterBuilder.() -> Unit = { text( R.string.main_activity_layout, - Prefs::mainActivityLayoutType, - { Prefs.mainActivityLayoutType = it }) { - textGetter = { string(Prefs.mainActivityLayout.titleRes) } + prefs::mainActivityLayoutType, + { prefs.mainActivityLayoutType = it }) { + textGetter = { string(prefs.mainActivityLayout.titleRes) } onClick = { materialDialog { title(R.string.main_activity_layout_desc) @@ -160,8 +160,8 @@ fun SettingsActivity.getAppearancePrefs(): KPrefAdapterBuilder.() -> Unit = { onClick = { launchTabCustomizerActivity() } } - checkbox(R.string.tint_nav, Prefs::tintNavBar, { - Prefs.tintNavBar = it + checkbox(R.string.tint_nav, prefs::tintNavBar, { + prefs.tintNavBar = it frostNavigationBar() setFrostResult(REQUEST_NAV) }) { @@ -172,15 +172,15 @@ fun SettingsActivity.getAppearancePrefs(): KPrefAdapterBuilder.() -> Unit = { KPrefTextSeekbar( KPrefSeekbar.KPrefSeekbarBuilder( globalOptions, - R.string.web_text_scaling, Prefs::webTextScaling + R.string.web_text_scaling, prefs::webTextScaling ) { - Prefs.webTextScaling = it + prefs.webTextScaling = it setFrostResult(REQUEST_TEXT_ZOOM) }) ) - checkbox(R.string.enforce_black_media_bg, Prefs::blackMediaBg, { - Prefs.blackMediaBg = it + checkbox(R.string.enforce_black_media_bg, prefs::blackMediaBg, { + prefs.blackMediaBg = it }) { descRes = R.string.enforce_black_media_bg_desc } diff --git a/app/src/main/kotlin/com/pitchedapps/frost/settings/Behaviour.kt b/app/src/main/kotlin/com/pitchedapps/frost/settings/Behaviour.kt index 8f57b539..eb83de74 100644 --- a/app/src/main/kotlin/com/pitchedapps/frost/settings/Behaviour.kt +++ b/app/src/main/kotlin/com/pitchedapps/frost/settings/Behaviour.kt @@ -26,47 +26,47 @@ import com.pitchedapps.frost.utils.Prefs */ fun SettingsActivity.getBehaviourPrefs(): KPrefAdapterBuilder.() -> Unit = { - checkbox(R.string.auto_refresh_feed, Prefs::autoRefreshFeed, { Prefs.autoRefreshFeed = it }) { + checkbox(R.string.auto_refresh_feed, prefs::autoRefreshFeed, { prefs.autoRefreshFeed = it }) { descRes = R.string.auto_refresh_feed_desc } - checkbox(R.string.fancy_animations, Prefs::animate, { Prefs.animate = it; animate = it }) { + checkbox(R.string.fancy_animations, prefs::animate, { prefs.animate = it; animate = it }) { descRes = R.string.fancy_animations_desc } checkbox( R.string.overlay_swipe, - Prefs::overlayEnabled, - { Prefs.overlayEnabled = it; shouldRefreshMain() }) { + prefs::overlayEnabled, + { prefs.overlayEnabled = it; shouldRefreshMain() }) { descRes = R.string.overlay_swipe_desc } checkbox( R.string.overlay_full_screen_swipe, - Prefs::overlayFullScreenSwipe, - { Prefs.overlayFullScreenSwipe = it }) { + prefs::overlayFullScreenSwipe, + { prefs.overlayFullScreenSwipe = it }) { descRes = R.string.overlay_full_screen_swipe_desc } checkbox( R.string.open_links_in_default, - Prefs::linksInDefaultApp, - { Prefs.linksInDefaultApp = it }) { + prefs::linksInDefaultApp, + { prefs.linksInDefaultApp = it }) { descRes = R.string.open_links_in_default_desc } - checkbox(R.string.viewpager_swipe, Prefs::viewpagerSwipe, { Prefs.viewpagerSwipe = it }) { + checkbox(R.string.viewpager_swipe, prefs::viewpagerSwipe, { prefs.viewpagerSwipe = it }) { descRes = R.string.viewpager_swipe_desc } checkbox( R.string.force_message_bottom, - Prefs::messageScrollToBottom, - { Prefs.messageScrollToBottom = it }) { + prefs::messageScrollToBottom, + { prefs.messageScrollToBottom = it }) { descRes = R.string.force_message_bottom_desc } - checkbox(R.string.enable_pip, Prefs::enablePip, { Prefs.enablePip = it }) { + checkbox(R.string.enable_pip, prefs::enablePip, { prefs.enablePip = it }) { descRes = R.string.enable_pip_desc } @@ -78,11 +78,11 @@ fun SettingsActivity.getBehaviourPrefs(): KPrefAdapterBuilder.() -> Unit = { // } // } - checkbox(R.string.exit_confirmation, Prefs::exitConfirmation, { Prefs.exitConfirmation = it }) { + checkbox(R.string.exit_confirmation, prefs::exitConfirmation, { prefs.exitConfirmation = it }) { descRes = R.string.exit_confirmation_desc } - checkbox(R.string.analytics, Prefs::analytics, { Prefs.analytics = it }) { + checkbox(R.string.analytics, prefs::analytics, { prefs.analytics = it }) { descRes = R.string.analytics_desc } } diff --git a/app/src/main/kotlin/com/pitchedapps/frost/settings/Experimental.kt b/app/src/main/kotlin/com/pitchedapps/frost/settings/Experimental.kt index 9814fd76..45b7ea86 100644 --- a/app/src/main/kotlin/com/pitchedapps/frost/settings/Experimental.kt +++ b/app/src/main/kotlin/com/pitchedapps/frost/settings/Experimental.kt @@ -37,8 +37,8 @@ fun SettingsActivity.getExperimentalPrefs(): KPrefAdapterBuilder.() -> Unit = { // Experimental content ends here -------------------- - checkbox(R.string.verbose_logging, Prefs::verboseLogging, { - Prefs.verboseLogging = it + checkbox(R.string.verbose_logging, prefs::verboseLogging, { + prefs.verboseLogging = it KL.shouldLog = { it != Log.VERBOSE } }) { descRes = R.string.verbose_logging_desc diff --git a/app/src/main/kotlin/com/pitchedapps/frost/settings/Feed.kt b/app/src/main/kotlin/com/pitchedapps/frost/settings/Feed.kt index d1350df5..87fce560 100644 --- a/app/src/main/kotlin/com/pitchedapps/frost/settings/Feed.kt +++ b/app/src/main/kotlin/com/pitchedapps/frost/settings/Feed.kt @@ -31,7 +31,7 @@ import com.pitchedapps.frost.utils.REQUEST_FAB */ fun SettingsActivity.getFeedPrefs(): KPrefAdapterBuilder.() -> Unit = { - text(R.string.newsfeed_sort, Prefs::feedSort, { Prefs.feedSort = it }) { + text(R.string.newsfeed_sort, prefs::feedSort, { prefs.feedSort = it }) { descRes = R.string.newsfeed_sort_desc onClick = { materialDialog { @@ -50,50 +50,50 @@ fun SettingsActivity.getFeedPrefs(): KPrefAdapterBuilder.() -> Unit = { textGetter = { string(FeedSort(it).textRes) } } - checkbox(R.string.aggressive_recents, Prefs::aggressiveRecents, { - Prefs.aggressiveRecents = it + checkbox(R.string.aggressive_recents, prefs::aggressiveRecents, { + prefs.aggressiveRecents = it shouldRefreshMain() }) { descRes = R.string.aggressive_recents_desc } - checkbox(R.string.composer, Prefs::showComposer, { - Prefs.showComposer = it + checkbox(R.string.composer, prefs::showComposer, { + prefs.showComposer = it shouldRefreshMain() }) { descRes = R.string.composer_desc } - checkbox(R.string.create_fab, Prefs::showCreateFab, { - Prefs.showCreateFab = it + checkbox(R.string.create_fab, prefs::showCreateFab, { + prefs.showCreateFab = it setFrostResult(REQUEST_FAB) }) { descRes = R.string.create_fab_desc } - checkbox(R.string.suggested_friends, Prefs::showSuggestedFriends, { - Prefs.showSuggestedFriends = it + checkbox(R.string.suggested_friends, prefs::showSuggestedFriends, { + prefs.showSuggestedFriends = it shouldRefreshMain() }) { descRes = R.string.suggested_friends_desc } - checkbox(R.string.suggested_groups, Prefs::showSuggestedGroups, { - Prefs.showSuggestedGroups = it + checkbox(R.string.suggested_groups, prefs::showSuggestedGroups, { + prefs.showSuggestedGroups = it shouldRefreshMain() }) { descRes = R.string.suggested_groups_desc } - checkbox(R.string.show_stories, Prefs::showStories, { - Prefs.showStories = it + checkbox(R.string.show_stories, prefs::showStories, { + prefs.showStories = it shouldRefreshMain() }) { descRes = R.string.show_stories_desc } - checkbox(R.string.facebook_ads, Prefs::showFacebookAds, { - Prefs.showFacebookAds = it + checkbox(R.string.facebook_ads, prefs::showFacebookAds, { + prefs.showFacebookAds = it shouldRefreshMain() }) { descRes = R.string.facebook_ads_desc diff --git a/app/src/main/kotlin/com/pitchedapps/frost/settings/Network.kt b/app/src/main/kotlin/com/pitchedapps/frost/settings/Network.kt index a1ec33e6..c275227f 100644 --- a/app/src/main/kotlin/com/pitchedapps/frost/settings/Network.kt +++ b/app/src/main/kotlin/com/pitchedapps/frost/settings/Network.kt @@ -19,7 +19,6 @@ package com.pitchedapps.frost.settings import ca.allanwang.kau.kpref.activity.KPrefAdapterBuilder import com.pitchedapps.frost.R import com.pitchedapps.frost.activities.SettingsActivity -import com.pitchedapps.frost.utils.Prefs /** * Created by Allan Wang on 2017-08-08. @@ -28,8 +27,8 @@ fun SettingsActivity.getNetworkPrefs(): KPrefAdapterBuilder.() -> Unit = { checkbox( R.string.network_media_on_metered, - { !Prefs.loadMediaOnMeteredNetwork }, - { Prefs.loadMediaOnMeteredNetwork = !it }) { + { !prefs.loadMediaOnMeteredNetwork }, + { prefs.loadMediaOnMeteredNetwork = !it }) { descRes = R.string.network_media_on_metered_desc } } diff --git a/app/src/main/kotlin/com/pitchedapps/frost/settings/Notifications.kt b/app/src/main/kotlin/com/pitchedapps/frost/settings/Notifications.kt index b8a80e8d..06159ba5 100644 --- a/app/src/main/kotlin/com/pitchedapps/frost/settings/Notifications.kt +++ b/app/src/main/kotlin/com/pitchedapps/frost/settings/Notifications.kt @@ -41,6 +41,7 @@ import com.pitchedapps.frost.utils.frostSnackbar import com.pitchedapps.frost.utils.frostUri import com.pitchedapps.frost.views.Keywords import kotlinx.coroutines.launch +import org.koin.android.ext.android.get /** * Created by Allan Wang on 2017-06-29. @@ -54,8 +55,8 @@ fun SettingsActivity.getNotificationPrefs(): KPrefAdapterBuilder.() -> Unit = { text( R.string.notification_frequency, - Prefs::notificationFreq, - { Prefs.notificationFreq = it }) { + prefs::notificationFreq, + { prefs.notificationFreq = it }) { val options = longArrayOf(15, 30, 60, 120, 180, 300, 1440, 2880) val texts = options.map { if (it <= 0) string(R.string.no_notifications) else minuteToText(it) } @@ -71,7 +72,7 @@ fun SettingsActivity.getNotificationPrefs(): KPrefAdapterBuilder.() -> Unit = { } } } - enabler = { Prefs.hasNotifications } + enabler = { prefs.hasNotifications } textGetter = { minuteToText(it) } } @@ -88,36 +89,36 @@ fun SettingsActivity.getNotificationPrefs(): KPrefAdapterBuilder.() -> Unit = { } } - checkbox(R.string.notification_general, Prefs::notificationsGeneral, + checkbox(R.string.notification_general, prefs::notificationsGeneral, { - Prefs.notificationsGeneral = it + prefs.notificationsGeneral = it reloadByTitle(R.string.notification_general_all_accounts) - if (!Prefs.notificationsInstantMessages) + if (!prefs.notificationsInstantMessages) reloadByTitle(R.string.notification_frequency) }) { descRes = R.string.notification_general_desc } - checkbox(R.string.notification_general_all_accounts, Prefs::notificationAllAccounts, - { Prefs.notificationAllAccounts = it }) { + checkbox(R.string.notification_general_all_accounts, prefs::notificationAllAccounts, + { prefs.notificationAllAccounts = it }) { descRes = R.string.notification_general_all_accounts_desc - enabler = { Prefs.notificationsGeneral } + enabler = { prefs.notificationsGeneral } } - checkbox(R.string.notification_messages, Prefs::notificationsInstantMessages, + checkbox(R.string.notification_messages, prefs::notificationsInstantMessages, { - Prefs.notificationsInstantMessages = it + prefs.notificationsInstantMessages = it reloadByTitle(R.string.notification_messages_all_accounts) - if (!Prefs.notificationsGeneral) + if (!prefs.notificationsGeneral) reloadByTitle(R.string.notification_frequency) }) { descRes = R.string.notification_messages_desc } - checkbox(R.string.notification_messages_all_accounts, Prefs::notificationsImAllAccounts, - { Prefs.notificationsImAllAccounts = it }) { + checkbox(R.string.notification_messages_all_accounts, prefs::notificationsImAllAccounts, + { prefs.notificationsImAllAccounts = it }) { descRes = R.string.notification_messages_all_accounts_desc - enabler = { Prefs.notificationsInstantMessages } + enabler = { prefs.notificationsInstantMessages } } if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) { @@ -130,8 +131,8 @@ fun SettingsActivity.getNotificationPrefs(): KPrefAdapterBuilder.() -> Unit = { } } } else { - checkbox(R.string.notification_sound, Prefs::notificationSound, { - Prefs.notificationSound = it + checkbox(R.string.notification_sound, prefs::notificationSound, { + prefs.notificationSound = it reloadByTitle( R.string.notification_ringtone, R.string.message_ringtone @@ -139,7 +140,7 @@ fun SettingsActivity.getNotificationPrefs(): KPrefAdapterBuilder.() -> Unit = { }) fun KPrefText.KPrefTextContract.ringtone(code: Int) { - enabler = Prefs::notificationSound + enabler = prefs::notificationSound textGetter = { if (it.isBlank()) string(R.string.kau_default) else RingtoneManager.getRingtone(this@getNotificationPrefs, frostUri(it)) @@ -163,21 +164,21 @@ fun SettingsActivity.getNotificationPrefs(): KPrefAdapterBuilder.() -> Unit = { } } - text(R.string.notification_ringtone, Prefs::notificationRingtone, - { Prefs.notificationRingtone = it }) { + text(R.string.notification_ringtone, prefs::notificationRingtone, + { prefs.notificationRingtone = it }) { ringtone(SettingsActivity.REQUEST_NOTIFICATION_RINGTONE) } - text(R.string.message_ringtone, Prefs::messageRingtone, - { Prefs.messageRingtone = it }) { + text(R.string.message_ringtone, prefs::messageRingtone, + { prefs.messageRingtone = it }) { ringtone(SettingsActivity.REQUEST_MESSAGE_RINGTONE) } - checkbox(R.string.notification_vibrate, Prefs::notificationVibrate, - { Prefs.notificationVibrate = it }) + checkbox(R.string.notification_vibrate, prefs::notificationVibrate, + { prefs.notificationVibrate = it }) - checkbox(R.string.notification_lights, Prefs::notificationLights, - { Prefs.notificationLights = it }) + checkbox(R.string.notification_lights, prefs::notificationLights, + { prefs.notificationLights = it }) } if (BuildConfig.DEBUG) { diff --git a/app/src/main/kotlin/com/pitchedapps/frost/settings/Security.kt b/app/src/main/kotlin/com/pitchedapps/frost/settings/Security.kt index 754e19de..e966272d 100644 --- a/app/src/main/kotlin/com/pitchedapps/frost/settings/Security.kt +++ b/app/src/main/kotlin/com/pitchedapps/frost/settings/Security.kt @@ -32,7 +32,7 @@ fun SettingsActivity.getSecurityPrefs(): KPrefAdapterBuilder.() -> Unit = { descRes = R.string.security_disclaimer_info } - checkbox(R.string.enable_biometrics, Prefs::biometricsEnabled, { + checkbox(R.string.enable_biometrics, prefs::biometricsEnabled, { launch { /* * For security, we should request authentication when: @@ -40,7 +40,7 @@ fun SettingsActivity.getSecurityPrefs(): KPrefAdapterBuilder.() -> Unit = { * - disabling to ensure that it is permitted */ BiometricUtils.authenticate(this@getSecurityPrefs, force = true).await() - Prefs.biometricsEnabled = it + prefs.biometricsEnabled = it reloadByTitle(R.string.enable_biometrics) } }) { -- cgit v1.2.3