aboutsummaryrefslogtreecommitdiff
path: root/app/src/main/kotlin/com/pitchedapps/frost/settings/Notifications.kt
diff options
context:
space:
mode:
authorAllan Wang <me@allanwang.ca>2018-03-11 15:47:35 -0400
committerGitHub <noreply@github.com>2018-03-11 15:47:35 -0400
commit67988a25d83fc10b187fcc821c3ceacfad0195d5 (patch)
tree58d6622f3eccf0275d55ee7f6ef2ba76845211ab /app/src/main/kotlin/com/pitchedapps/frost/settings/Notifications.kt
parent7f74e08270e34eb66a824ac18519293d4a42278c (diff)
downloadfrost-67988a25d83fc10b187fcc821c3ceacfad0195d5.tar.gz
frost-67988a25d83fc10b187fcc821c3ceacfad0195d5.tar.bz2
frost-67988a25d83fc10b187fcc821c3ceacfad0195d5.zip
Fix/notification sound (#763)
* Update dependencies * Update theme * Fix bad css merge * Add notification feedback for fetching now * Hide notif settings that no longer work with channels * Wip android o channels * Revert back to old group method * Update dependencies * Update rxnetwork version
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.kt97
1 files changed, 63 insertions, 34 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 2ee086c0..962e60ae 100644
--- a/app/src/main/kotlin/com/pitchedapps/frost/settings/Notifications.kt
+++ b/app/src/main/kotlin/com/pitchedapps/frost/settings/Notifications.kt
@@ -1,14 +1,20 @@
package com.pitchedapps.frost.settings
+import android.annotation.SuppressLint
import android.content.Intent
import android.media.RingtoneManager
import android.net.Uri
+import android.os.Build
+import android.provider.Settings
import ca.allanwang.kau.kpref.activity.KPrefAdapterBuilder
import ca.allanwang.kau.kpref.activity.items.KPrefText
import ca.allanwang.kau.utils.minuteToText
import ca.allanwang.kau.utils.string
+import com.pitchedapps.frost.BuildConfig
import com.pitchedapps.frost.R
import com.pitchedapps.frost.activities.SettingsActivity
+import com.pitchedapps.frost.dbflow.NotificationModel
+import com.pitchedapps.frost.dbflow.loadFbCookiesAsync
import com.pitchedapps.frost.services.fetchNotifications
import com.pitchedapps.frost.services.scheduleNotifications
import com.pitchedapps.frost.utils.Prefs
@@ -20,6 +26,7 @@ import com.pitchedapps.frost.views.Keywords
/**
* Created by Allan Wang on 2017-06-29.
*/
+@SuppressLint("InlinedApi")
fun SettingsActivity.getNotificationPrefs(): KPrefAdapterBuilder.() -> Unit = {
text(R.string.notification_frequency, Prefs::notificationFreq, { Prefs.notificationFreq = it }) {
@@ -90,47 +97,69 @@ fun SettingsActivity.getNotificationPrefs(): KPrefAdapterBuilder.() -> Unit = {
enabler = Prefs::notificationsInstantMessages
}
- checkbox(R.string.notification_sound, Prefs::notificationSound, {
- Prefs.notificationSound = it
- reloadByTitle(R.string.notification_ringtone,
- R.string.message_ringtone)
- })
-
- fun KPrefText.KPrefTextContract<String>.ringtone(code: Int) {
- enabler = Prefs::notificationSound
- 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
+ if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
+ plainText(R.string.notification_channel) {
+ descRes = R.string.notification_channel_desc
+ onClick = {
+ val intent = Intent(Settings.ACTION_APP_NOTIFICATION_SETTINGS)
+ .putExtra(Settings.EXTRA_APP_PACKAGE, packageName)
+ startActivity(intent)
+ }
}
- onClick = {
- val intent = Intent(RingtoneManager.ACTION_RINGTONE_PICKER).apply {
- putExtra(RingtoneManager.EXTRA_RINGTONE_TITLE, string(R.string.select_ringtone))
- putExtra(RingtoneManager.EXTRA_RINGTONE_SHOW_SILENT, false)
- putExtra(RingtoneManager.EXTRA_RINGTONE_SHOW_DEFAULT, true)
- putExtra(RingtoneManager.EXTRA_RINGTONE_TYPE, RingtoneManager.TYPE_NOTIFICATION)
- if (item.pref.isNotBlank())
- putExtra(RingtoneManager.EXTRA_RINGTONE_EXISTING_URI, Uri.parse(item.pref))
+ } else {
+ checkbox(R.string.notification_sound, Prefs::notificationSound, {
+ Prefs.notificationSound = it
+ reloadByTitle(R.string.notification_ringtone,
+ R.string.message_ringtone)
+ })
+
+ fun KPrefText.KPrefTextContract<String>.ringtone(code: Int) {
+ enabler = Prefs::notificationSound
+ 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
+ }
+ onClick = {
+ val intent = Intent(RingtoneManager.ACTION_RINGTONE_PICKER).apply {
+ putExtra(RingtoneManager.EXTRA_RINGTONE_TITLE, string(R.string.select_ringtone))
+ putExtra(RingtoneManager.EXTRA_RINGTONE_SHOW_SILENT, false)
+ putExtra(RingtoneManager.EXTRA_RINGTONE_SHOW_DEFAULT, true)
+ putExtra(RingtoneManager.EXTRA_RINGTONE_TYPE, RingtoneManager.TYPE_NOTIFICATION)
+ if (item.pref.isNotBlank())
+ putExtra(RingtoneManager.EXTRA_RINGTONE_EXISTING_URI, Uri.parse(item.pref))
+ }
+ startActivityForResult(intent, code)
}
- startActivityForResult(intent, code)
}
- }
- text(R.string.notification_ringtone, Prefs::notificationRingtone,
- { Prefs.notificationRingtone = it }) {
- ringtone(SettingsActivity.REQUEST_NOTIFICATION_RINGTONE)
- }
+ 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 }) {
- ringtone(SettingsActivity.REQUEST_MESSAGE_RINGTONE)
- }
+ 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) {
+ plainText(R.string.reset_notif_epoch) {
+ onClick = {
+ loadFbCookiesAsync {
+ it.map { NotificationModel(it.id) }.forEach { it.save() }
+ }
+ }
+ }
+ }
plainText(R.string.notification_fetch_now) {
descRes = R.string.notification_fetch_now_desc