diff options
Diffstat (limited to 'app/src/main/kotlin/com/pitchedapps/frost/settings/Notifications.kt')
-rw-r--r-- | app/src/main/kotlin/com/pitchedapps/frost/settings/Notifications.kt | 72 |
1 files changed, 44 insertions, 28 deletions
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 1f9411e4..0200f109 100644 --- a/app/src/main/kotlin/com/pitchedapps/frost/settings/Notifications.kt +++ b/app/src/main/kotlin/com/pitchedapps/frost/settings/Notifications.kt @@ -1,3 +1,19 @@ +/* + * Copyright 2018 Allan Wang + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see <http://www.gnu.org/licenses/>. + */ package com.pitchedapps.frost.settings import android.annotation.SuppressLint @@ -22,7 +38,6 @@ import com.pitchedapps.frost.utils.frostSnackbar import com.pitchedapps.frost.utils.materialDialogThemed import com.pitchedapps.frost.views.Keywords - /** * Created by Allan Wang on 2017-06-29. */ @@ -66,33 +81,33 @@ fun SettingsActivity.getNotificationPrefs(): KPrefAdapterBuilder.() -> Unit = { } 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) - }) { + { + 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 }) { + { Prefs.notificationAllAccounts = it }) { descRes = R.string.notification_general_all_accounts_desc enabler = Prefs::notificationsGeneral } 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) - }) { + { + 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 }) { + { Prefs.notificationsImAllAccounts = it }) { descRes = R.string.notification_messages_all_accounts_desc enabler = Prefs::notificationsInstantMessages } @@ -102,15 +117,17 @@ fun SettingsActivity.getNotificationPrefs(): KPrefAdapterBuilder.() -> Unit = { descRes = R.string.notification_channel_desc onClick = { val intent = Intent(Settings.ACTION_APP_NOTIFICATION_SETTINGS) - .putExtra(Settings.EXTRA_APP_PACKAGE, packageName) + .putExtra(Settings.EXTRA_APP_PACKAGE, packageName) startActivity(intent) } } } else { checkbox(R.string.notification_sound, Prefs::notificationSound, { Prefs.notificationSound = it - reloadByTitle(R.string.notification_ringtone, - R.string.message_ringtone) + reloadByTitle( + R.string.notification_ringtone, + R.string.message_ringtone + ) }) fun KPrefText.KPrefTextContract<String>.ringtone(code: Int) { @@ -118,8 +135,8 @@ fun SettingsActivity.getNotificationPrefs(): KPrefAdapterBuilder.() -> Unit = { textGetter = { if (it.isBlank()) string(R.string.kau_default) else RingtoneManager.getRingtone(this@getNotificationPrefs, Uri.parse(it)) - ?.getTitle(this@getNotificationPrefs) - ?: "---" //todo figure out why this happens + ?.getTitle(this@getNotificationPrefs) + ?: "---" //todo figure out why this happens } onClick = { val intent = Intent(RingtoneManager.ACTION_RINGTONE_PICKER).apply { @@ -135,20 +152,20 @@ fun SettingsActivity.getNotificationPrefs(): KPrefAdapterBuilder.() -> Unit = { } text(R.string.notification_ringtone, Prefs::notificationRingtone, - { Prefs.notificationRingtone = it }) { + { Prefs.notificationRingtone = it }) { ringtone(SettingsActivity.REQUEST_NOTIFICATION_RINGTONE) } text(R.string.message_ringtone, Prefs::messageRingtone, - { Prefs.messageRingtone = it }) { + { Prefs.messageRingtone = it }) { ringtone(SettingsActivity.REQUEST_MESSAGE_RINGTONE) } checkbox(R.string.notification_vibrate, Prefs::notificationVibrate, - { Prefs.notificationVibrate = it }) + { Prefs.notificationVibrate = it }) checkbox(R.string.notification_lights, Prefs::notificationLights, - { Prefs.notificationLights = it }) + { Prefs.notificationLights = it }) } if (BuildConfig.DEBUG) { @@ -165,10 +182,9 @@ fun SettingsActivity.getNotificationPrefs(): KPrefAdapterBuilder.() -> Unit = { descRes = R.string.notification_fetch_now_desc onClick = { val text = - if (fetchNotifications()) R.string.notification_fetch_success - else R.string.notification_fetch_fail + if (fetchNotifications()) R.string.notification_fetch_success + else R.string.notification_fetch_fail frostSnackbar(text) } } - -}
\ No newline at end of file +} |