diff options
author | Allan Wang <me@allanwang.ca> | 2019-08-06 21:38:39 -0700 |
---|---|---|
committer | Allan Wang <me@allanwang.ca> | 2019-08-06 21:38:39 -0700 |
commit | ae6709598ced6fd2eb1e423ff133154258efdcca (patch) | |
tree | 5f3415d03a7c882967e6aa2cb8a8c31e7ca273f7 /app/src/main | |
parent | d500d1dd6e05c6128dcb15fe8e15acb2aaf979cd (diff) | |
download | frost-ae6709598ced6fd2eb1e423ff133154258efdcca.tar.gz frost-ae6709598ced6fd2eb1e423ff133154258efdcca.tar.bz2 frost-ae6709598ced6fd2eb1e423ff133154258efdcca.zip |
Restrict notification service
Diffstat (limited to 'app/src/main')
4 files changed, 48 insertions, 4 deletions
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 ba5b839b..c4fa4c4d 100644 --- a/app/src/main/kotlin/com/pitchedapps/frost/settings/Behaviour.kt +++ b/app/src/main/kotlin/com/pitchedapps/frost/settings/Behaviour.kt @@ -83,6 +83,10 @@ fun SettingsActivity.getBehaviourPrefs(): KPrefAdapterBuilder.() -> Unit = { descRes = R.string.exit_confirmation_desc } + checkbox(R.string.web_only, Prefs::webOnly, { Prefs.webOnly = it }) { + descRes = R.string.web_only_desc + } + 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/Notifications.kt b/app/src/main/kotlin/com/pitchedapps/frost/settings/Notifications.kt index 4ef76b3b..40b9428d 100644 --- a/app/src/main/kotlin/com/pitchedapps/frost/settings/Notifications.kt +++ b/app/src/main/kotlin/com/pitchedapps/frost/settings/Notifications.kt @@ -22,6 +22,7 @@ import android.media.RingtoneManager import android.os.Build import android.provider.Settings import ca.allanwang.kau.kpref.activity.KPrefAdapterBuilder +import ca.allanwang.kau.kpref.activity.KPrefItemActions import ca.allanwang.kau.kpref.activity.items.KPrefText import ca.allanwang.kau.utils.materialDialog import ca.allanwang.kau.utils.minuteToText @@ -48,6 +49,20 @@ import kotlinx.coroutines.launch @SuppressLint("InlinedApi") fun SettingsActivity.getNotificationPrefs(): KPrefAdapterBuilder.() -> Unit = { + fun KPrefItemActions.leaveWebOnlyDialog() { + if (Prefs.webOnly) { + materialDialog { + title(R.string.leave_web_only_title) + message(R.string.leave_web_only_desc) + positiveButton(R.string.kau_yes) { + Prefs.webOnly = false + reloadSelf() + } + negativeButton(R.string.kau_no) + } + } + } + text( R.string.notification_frequency, Prefs::notificationFreq, @@ -67,10 +82,15 @@ fun SettingsActivity.getNotificationPrefs(): KPrefAdapterBuilder.() -> Unit = { } } } + onDisabledClick = { + leaveWebOnlyDialog() + } enabler = { - val enabled = Prefs.notificationsGeneral || Prefs.notificationsInstantMessages - if (!enabled) + val enabled = + !Prefs.webOnly && (Prefs.notificationsGeneral || Prefs.notificationsInstantMessages) + if (!enabled) { scheduleNotifications(-1) + } enabled } textGetter = { minuteToText(it) } @@ -97,12 +117,19 @@ fun SettingsActivity.getNotificationPrefs(): KPrefAdapterBuilder.() -> Unit = { reloadByTitle(R.string.notification_frequency) }) { descRes = R.string.notification_general_desc + enabler = { !Prefs.webOnly } + onDisabledClick = { + leaveWebOnlyDialog() + } } 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.webOnly && Prefs.notificationsGeneral } + onDisabledClick = { + leaveWebOnlyDialog() + } } checkbox(R.string.notification_messages, Prefs::notificationsInstantMessages, @@ -113,12 +140,19 @@ fun SettingsActivity.getNotificationPrefs(): KPrefAdapterBuilder.() -> Unit = { reloadByTitle(R.string.notification_frequency) }) { descRes = R.string.notification_messages_desc + enabler = { !Prefs.webOnly } + onDisabledClick = { + leaveWebOnlyDialog() + } } 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.webOnly && Prefs.notificationsInstantMessages } + onDisabledClick = { + leaveWebOnlyDialog() + } } if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) { diff --git a/app/src/main/kotlin/com/pitchedapps/frost/utils/Prefs.kt b/app/src/main/kotlin/com/pitchedapps/frost/utils/Prefs.kt index eb8e4b35..f17645d0 100644 --- a/app/src/main/kotlin/com/pitchedapps/frost/utils/Prefs.kt +++ b/app/src/main/kotlin/com/pitchedapps/frost/utils/Prefs.kt @@ -191,6 +191,8 @@ object Prefs : KPref() { var showCreateFab: Boolean by kpref("show_create_fab", true) + var webOnly: Boolean by kpref("web_only", false) + inline val mainActivityLayout: MainActivityLayout get() = MainActivityLayout(mainActivityLayoutType) diff --git a/app/src/main/res/values/strings_pref_behaviour.xml b/app/src/main/res/values/strings_pref_behaviour.xml index 32188698..890a7531 100644 --- a/app/src/main/res/values/strings_pref_behaviour.xml +++ b/app/src/main/res/values/strings_pref_behaviour.xml @@ -19,6 +19,10 @@ <string name="force_message_bottom_desc">When loading a message thread, trigger a scroll to the bottom of the page rather than loading the page as is.</string> <string name="enable_pip">Enable PIP</string> <string name="enable_pip_desc">Enable picture in picture videos</string> + <string name="web_only">Web Only</string> + <string name="web_only_desc">Having troubles? Enable to use web exclusive features. All parsing and background services will be disabled.</string> + <string name="leave_web_only_title">Leave web only mode</string> + <string name="leave_web_only_desc">Currently in web only mode. Would you like to disable it to continue?</string> <string name="autoplay_settings">Autoplay Settings</string> <string name="autoplay_settings_desc">Open Facebook\'s auto play settings. Note that it must be disabled for PIP to work.</string> <string name="exit_confirmation">Exit Confirmation</string> |