From ae6709598ced6fd2eb1e423ff133154258efdcca Mon Sep 17 00:00:00 2001 From: Allan Wang Date: Tue, 6 Aug 2019 21:38:39 -0700 Subject: Restrict notification service --- .../com/pitchedapps/frost/settings/Behaviour.kt | 4 +++ .../pitchedapps/frost/settings/Notifications.kt | 42 +++++++++++++++++++--- .../kotlin/com/pitchedapps/frost/utils/Prefs.kt | 2 ++ app/src/main/res/values/strings_pref_behaviour.xml | 4 +++ 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 @@ When loading a message thread, trigger a scroll to the bottom of the page rather than loading the page as is. Enable PIP Enable picture in picture videos + Web Only + Having troubles? Enable to use web exclusive features. All parsing and background services will be disabled. + Leave web only mode + Currently in web only mode. Would you like to disable it to continue? Autoplay Settings Open Facebook\'s auto play settings. Note that it must be disabled for PIP to work. Exit Confirmation -- cgit v1.2.3