aboutsummaryrefslogtreecommitdiff
path: root/app/src/main/kotlin/com/pitchedapps/frost/settings
diff options
context:
space:
mode:
Diffstat (limited to 'app/src/main/kotlin/com/pitchedapps/frost/settings')
-rw-r--r--app/src/main/kotlin/com/pitchedapps/frost/settings/Notifications.kt38
1 files changed, 36 insertions, 2 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 8fcb3594..429b74fb 100644
--- a/app/src/main/kotlin/com/pitchedapps/frost/settings/Notifications.kt
+++ b/app/src/main/kotlin/com/pitchedapps/frost/settings/Notifications.kt
@@ -1,7 +1,12 @@
package com.pitchedapps.frost.settings
+import android.content.Intent
+import android.media.RingtoneManager
+import android.net.Uri
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.R
import com.pitchedapps.frost.activities.SettingsActivity
import com.pitchedapps.frost.services.fetchNotifications
@@ -11,6 +16,7 @@ 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.
*/
@@ -59,7 +65,36 @@ fun SettingsActivity.getNotificationPrefs(): KPrefAdapterBuilder.() -> Unit = {
descRes = R.string.notification_messages_desc
}
- checkbox(R.string.notification_sound, { Prefs.notificationSound }, { Prefs.notificationSound = it })
+ 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)
+ }
+ onClick = {
+ _, _, item ->
+ 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)
+ true
+ }
+ }
+
+ 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)
+ }
checkbox(R.string.notification_vibrate, { Prefs.notificationVibrate }, { Prefs.notificationVibrate = it })
@@ -75,5 +110,4 @@ fun SettingsActivity.getNotificationPrefs(): KPrefAdapterBuilder.() -> Unit = {
}
}
-
} \ No newline at end of file