From d96d1d06a7c1581b97c042f2a74e7cd5b1c2546e Mon Sep 17 00:00:00 2001 From: Allan Wang Date: Sat, 17 Apr 2021 17:49:18 -0700 Subject: Update theme providers and readd koin modules --- .../com/pitchedapps/frost/settings/Appearance.kt | 107 +++++++++++++-------- .../com/pitchedapps/frost/settings/Behaviour.kt | 15 ++- .../kotlin/com/pitchedapps/frost/settings/Debug.kt | 2 +- .../com/pitchedapps/frost/settings/Experimental.kt | 11 ++- .../kotlin/com/pitchedapps/frost/settings/Feed.kt | 99 ++++++++++++------- .../com/pitchedapps/frost/settings/Network.kt | 3 +- .../pitchedapps/frost/settings/Notifications.kt | 68 ++++++++----- .../com/pitchedapps/frost/settings/Security.kt | 15 +-- 8 files changed, 201 insertions(+), 119 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 64d9dba2..bfa59a4f 100644 --- a/app/src/main/kotlin/com/pitchedapps/frost/settings/Appearance.kt +++ b/app/src/main/kotlin/com/pitchedapps/frost/settings/Appearance.kt @@ -43,7 +43,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, { themeProvider.setTheme(it) }) { onClick = { materialDialog { title(R.string.theme) @@ -78,53 +78,68 @@ fun SettingsActivity.getAppearancePrefs(): KPrefAdapterBuilder.() -> Unit = { themeProvider.reset() } - colorPicker(R.string.text_color, prefs::customTextColor, { - prefs.customTextColor = it - reload() - invalidateCustomTheme() - shouldRestartMain() - }) { + colorPicker( + R.string.text_color, prefs::customTextColor, + { + prefs.customTextColor = it + reload() + invalidateCustomTheme() + shouldRestartMain() + } + ) { dependsOnCustom() allowCustomAlpha = false } - colorPicker(R.string.accent_color, prefs::customAccentColor, { - prefs.customAccentColor = it - reload() - invalidateCustomTheme() - shouldRestartMain() - }) { + colorPicker( + R.string.accent_color, prefs::customAccentColor, + { + prefs.customAccentColor = it + reload() + invalidateCustomTheme() + shouldRestartMain() + } + ) { dependsOnCustom() allowCustomAlpha = false } - colorPicker(R.string.background_color, prefs::customBackgroundColor, { - prefs.customBackgroundColor = it - bgCanvas.ripple(it, duration = 500L) - invalidateCustomTheme() - setFrostTheme(themeProvider, true) - shouldRestartMain() - }) { + colorPicker( + R.string.background_color, prefs::customBackgroundColor, + { + prefs.customBackgroundColor = it + bgCanvas.ripple(it, duration = 500L) + invalidateCustomTheme() + setFrostTheme(themeProvider, true) + shouldRestartMain() + } + ) { dependsOnCustom() allowCustomAlpha = true } - colorPicker(R.string.header_color, prefs::customHeaderColor, { - prefs.customHeaderColor = it - frostNavigationBar(prefs, themeProvider) - toolbarCanvas.ripple(it, RippleCanvas.MIDDLE, RippleCanvas.END, duration = 500L) - reload() - shouldRestartMain() - }) { + colorPicker( + R.string.header_color, prefs::customHeaderColor, + { + prefs.customHeaderColor = it + frostNavigationBar(prefs, themeProvider) + toolbarCanvas.ripple(it, RippleCanvas.MIDDLE, RippleCanvas.END, duration = 500L) + reload() + shouldRestartMain() + } + ) { dependsOnCustom() allowCustomAlpha = true } - colorPicker(R.string.icon_color, prefs::customIconColor, { - prefs.customIconColor = it - invalidateOptionsMenu() - shouldRestartMain() - }) { + colorPicker( + R.string.icon_color, prefs::customIconColor, + { + prefs.customIconColor = it + invalidateOptionsMenu() + shouldRestartMain() + } + ) { dependsOnCustom() allowCustomAlpha = false } @@ -134,7 +149,8 @@ fun SettingsActivity.getAppearancePrefs(): KPrefAdapterBuilder.() -> Unit = { text( R.string.main_activity_layout, prefs::mainActivityLayoutType, - { prefs.mainActivityLayoutType = it }) { + { prefs.mainActivityLayoutType = it } + ) { textGetter = { string(prefs.mainActivityLayout.titleRes) } onClick = { materialDialog { @@ -158,11 +174,14 @@ fun SettingsActivity.getAppearancePrefs(): KPrefAdapterBuilder.() -> Unit = { onClick = { launchTabCustomizerActivity() } } - checkbox(R.string.tint_nav, prefs::tintNavBar, { - prefs.tintNavBar = it - frostNavigationBar(prefs, themeProvider) - setFrostResult(REQUEST_NAV) - }) { + checkbox( + R.string.tint_nav, prefs::tintNavBar, + { + prefs.tintNavBar = it + frostNavigationBar(prefs, themeProvider) + setFrostResult(REQUEST_NAV) + } + ) { descRes = R.string.tint_nav_desc } @@ -174,12 +193,16 @@ fun SettingsActivity.getAppearancePrefs(): KPrefAdapterBuilder.() -> Unit = { ) { 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 551b3ff1..a9d99763 100644 --- a/app/src/main/kotlin/com/pitchedapps/frost/settings/Behaviour.kt +++ b/app/src/main/kotlin/com/pitchedapps/frost/settings/Behaviour.kt @@ -36,21 +36,24 @@ fun SettingsActivity.getBehaviourPrefs(): KPrefAdapterBuilder.() -> Unit = { checkbox( R.string.overlay_swipe, prefs::overlayEnabled, - { prefs.overlayEnabled = it; shouldRefreshMain() }) { + { prefs.overlayEnabled = it; shouldRefreshMain() } + ) { descRes = R.string.overlay_swipe_desc } checkbox( R.string.overlay_full_screen_swipe, prefs::overlayFullScreenSwipe, - { prefs.overlayFullScreenSwipe = it }) { + { 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 = it } + ) { descRes = R.string.open_links_in_default_desc } @@ -61,14 +64,16 @@ fun SettingsActivity.getBehaviourPrefs(): KPrefAdapterBuilder.() -> Unit = { checkbox( R.string.force_message_bottom, prefs::messageScrollToBottom, - { prefs.messageScrollToBottom = it }) { + { prefs.messageScrollToBottom = it } + ) { descRes = R.string.force_message_bottom_desc } checkbox( R.string.auto_expand_text_box, prefs::autoExpandTextBox, - { prefs.autoExpandTextBox = it; shouldRefreshMain() }) { + { prefs.autoExpandTextBox = it; shouldRefreshMain() } + ) { descRes = R.string.auto_expand_text_box_desc } diff --git a/app/src/main/kotlin/com/pitchedapps/frost/settings/Debug.kt b/app/src/main/kotlin/com/pitchedapps/frost/settings/Debug.kt index 9a4751b8..65348e71 100644 --- a/app/src/main/kotlin/com/pitchedapps/frost/settings/Debug.kt +++ b/app/src/main/kotlin/com/pitchedapps/frost/settings/Debug.kt @@ -39,11 +39,11 @@ import com.pitchedapps.frost.facebook.parsers.SearchParser import com.pitchedapps.frost.utils.L import com.pitchedapps.frost.utils.frostUriFromFile import com.pitchedapps.frost.utils.sendFrostEmail -import java.io.File import kotlinx.coroutines.Dispatchers import kotlinx.coroutines.Job import kotlinx.coroutines.channels.Channel import kotlinx.coroutines.launch +import java.io.File /** * Created by Allan Wang on 2017-06-30. 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 30b16f81..995500f0 100644 --- a/app/src/main/kotlin/com/pitchedapps/frost/settings/Experimental.kt +++ b/app/src/main/kotlin/com/pitchedapps/frost/settings/Experimental.kt @@ -36,10 +36,13 @@ fun SettingsActivity.getExperimentalPrefs(): KPrefAdapterBuilder.() -> Unit = { // Experimental content ends here -------------------- - checkbox(R.string.verbose_logging, prefs::verboseLogging, { - prefs.verboseLogging = it - KL.shouldLog = { it != Log.VERBOSE } - }) { + 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 f8d10437..914874a2 100644 --- a/app/src/main/kotlin/com/pitchedapps/frost/settings/Feed.kt +++ b/app/src/main/kotlin/com/pitchedapps/frost/settings/Feed.kt @@ -49,66 +49,93 @@ fun SettingsActivity.getFeedPrefs(): KPrefAdapterBuilder.() -> Unit = { textGetter = { string(FeedSort(it).textRes) } } - checkbox(R.string.aggressive_recents, prefs::aggressiveRecents, { - prefs.aggressiveRecents = it - shouldRefreshMain() - }) { + 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 - shouldRefreshMain() - }) { + 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 - setFrostResult(REQUEST_FAB) - }) { + 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 - shouldRefreshMain() - }) { + 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 - shouldRefreshMain() - }) { + 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 - shouldRefreshMain() - }) { + checkbox( + R.string.show_stories, prefs::showStories, + { + prefs.showStories = it + shouldRefreshMain() + } + ) { descRes = R.string.show_stories_desc } - checkbox(R.string.show_post_actions, prefs::showPostActions, { - prefs.showPostActions = it - shouldRefreshMain() - }) { + checkbox( + R.string.show_post_actions, prefs::showPostActions, + { + prefs.showPostActions = it + shouldRefreshMain() + } + ) { descRes = R.string.show_post_actions_desc } - checkbox(R.string.show_post_reactions, prefs::showPostReactions, { - prefs.showPostReactions = it - shouldRefreshMain() - }) { + checkbox( + R.string.show_post_reactions, prefs::showPostReactions, + { + prefs.showPostReactions = it + shouldRefreshMain() + } + ) { descRes = R.string.show_post_reactions_desc } - checkbox(R.string.full_size_image, prefs::fullSizeImage, { - prefs.fullSizeImage = it - shouldRefreshMain() - }) { + checkbox( + R.string.full_size_image, prefs::fullSizeImage, + { + prefs.fullSizeImage = it + shouldRefreshMain() + } + ) { descRes = R.string.full_size_image_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 c275227f..9df8bf86 100644 --- a/app/src/main/kotlin/com/pitchedapps/frost/settings/Network.kt +++ b/app/src/main/kotlin/com/pitchedapps/frost/settings/Network.kt @@ -28,7 +28,8 @@ fun SettingsActivity.getNetworkPrefs(): KPrefAdapterBuilder.() -> Unit = { checkbox( R.string.network_media_on_metered, { !prefs.loadMediaOnMeteredNetwork }, - { prefs.loadMediaOnMeteredNetwork = !it }) { + { 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 397825f6..96429f1c 100644 --- a/app/src/main/kotlin/com/pitchedapps/frost/settings/Notifications.kt +++ b/app/src/main/kotlin/com/pitchedapps/frost/settings/Notifications.kt @@ -54,7 +54,8 @@ fun SettingsActivity.getNotificationPrefs(): KPrefAdapterBuilder.() -> Unit = { text( R.string.notification_frequency, prefs::notificationFreq, - { prefs.notificationFreq = it }) { + { 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) } @@ -87,34 +88,42 @@ fun SettingsActivity.getNotificationPrefs(): KPrefAdapterBuilder.() -> Unit = { } } - checkbox(R.string.notification_general, prefs::notificationsGeneral, + checkbox( + R.string.notification_general, prefs::notificationsGeneral, { prefs.notificationsGeneral = it reloadByTitle(R.string.notification_general_all_accounts) 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 } } - checkbox(R.string.notification_messages, prefs::notificationsInstantMessages, + checkbox( + R.string.notification_messages, prefs::notificationsInstantMessages, { prefs.notificationsInstantMessages = it reloadByTitle(R.string.notification_messages_all_accounts) 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 } } @@ -129,13 +138,16 @@ fun SettingsActivity.getNotificationPrefs(): KPrefAdapterBuilder.() -> Unit = { } } } else { - checkbox(R.string.notification_sound, prefs::notificationSound, { - prefs.notificationSound = it - reloadByTitle( - R.string.notification_ringtone, - R.string.message_ringtone - ) - }) + checkbox( + R.string.notification_sound, prefs::notificationSound, + { + prefs.notificationSound = it + reloadByTitle( + R.string.notification_ringtone, + R.string.message_ringtone + ) + } + ) fun KPrefText.KPrefTextContract.ringtone(code: Int) { enabler = prefs::notificationSound @@ -162,21 +174,29 @@ 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 aa38fffd..61c69f10 100644 --- a/app/src/main/kotlin/com/pitchedapps/frost/settings/Security.kt +++ b/app/src/main/kotlin/com/pitchedapps/frost/settings/Security.kt @@ -31,18 +31,21 @@ fun SettingsActivity.getSecurityPrefs(): KPrefAdapterBuilder.() -> Unit = { descRes = R.string.security_disclaimer_info } - checkbox(R.string.enable_biometrics, prefs::biometricsEnabled, { - launch { + checkbox( + R.string.enable_biometrics, prefs::biometricsEnabled, + { + launch { /* * For security, we should request authentication when: * - enabling to ensure that it is supported * - disabling to ensure that it is permitted */ - BiometricUtils.authenticate(this@getSecurityPrefs, prefs, force = true).await() - prefs.biometricsEnabled = it - reloadByTitle(R.string.enable_biometrics) + BiometricUtils.authenticate(this@getSecurityPrefs, prefs, force = true).await() + prefs.biometricsEnabled = it + reloadByTitle(R.string.enable_biometrics) + } } - }) { + ) { descRes = R.string.enable_biometrics_desc enabler = { BiometricUtils.isSupported(this@getSecurityPrefs) } } -- cgit v1.2.3