aboutsummaryrefslogtreecommitdiff
path: root/app/src/main/kotlin/com/pitchedapps/frost/settings
diff options
context:
space:
mode:
authorAllan Wang <me@allanwang.ca>2019-08-06 21:38:39 -0700
committerAllan Wang <me@allanwang.ca>2019-08-06 21:38:39 -0700
commitae6709598ced6fd2eb1e423ff133154258efdcca (patch)
tree5f3415d03a7c882967e6aa2cb8a8c31e7ca273f7 /app/src/main/kotlin/com/pitchedapps/frost/settings
parentd500d1dd6e05c6128dcb15fe8e15acb2aaf979cd (diff)
downloadfrost-ae6709598ced6fd2eb1e423ff133154258efdcca.tar.gz
frost-ae6709598ced6fd2eb1e423ff133154258efdcca.tar.bz2
frost-ae6709598ced6fd2eb1e423ff133154258efdcca.zip
Restrict notification service
Diffstat (limited to 'app/src/main/kotlin/com/pitchedapps/frost/settings')
-rw-r--r--app/src/main/kotlin/com/pitchedapps/frost/settings/Behaviour.kt4
-rw-r--r--app/src/main/kotlin/com/pitchedapps/frost/settings/Notifications.kt42
2 files changed, 42 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) {