aboutsummaryrefslogtreecommitdiff
path: root/app/src/main/kotlin/com/pitchedapps/frost/services
diff options
context:
space:
mode:
authorAllan Wang <me@allanwang.ca>2019-06-13 17:19:25 -0700
committerAllan Wang <me@allanwang.ca>2019-06-13 17:19:25 -0700
commit7ad2a898571db9c0db95caf09cda8632660ff6dd (patch)
treeb956e8354030f9be7bbf48fcb8ea8c7acc685481 /app/src/main/kotlin/com/pitchedapps/frost/services
parent682227c17b46ff7957f9399b7f610d52f06c1428 (diff)
downloadfrost-7ad2a898571db9c0db95caf09cda8632660ff6dd.tar.gz
frost-7ad2a898571db9c0db95caf09cda8632660ff6dd.tar.bz2
frost-7ad2a898571db9c0db95caf09cda8632660ff6dd.zip
Resolve file uri ourself for ringtones, resolves #1423
Diffstat (limited to 'app/src/main/kotlin/com/pitchedapps/frost/services')
-rw-r--r--app/src/main/kotlin/com/pitchedapps/frost/services/FrostNotifications.kt6
-rw-r--r--app/src/main/kotlin/com/pitchedapps/frost/services/NotificationService.kt2
-rw-r--r--app/src/main/kotlin/com/pitchedapps/frost/services/NotificationUtils.kt6
3 files changed, 7 insertions, 7 deletions
diff --git a/app/src/main/kotlin/com/pitchedapps/frost/services/FrostNotifications.kt b/app/src/main/kotlin/com/pitchedapps/frost/services/FrostNotifications.kt
index 4b0e1a82..0b1deb4e 100644
--- a/app/src/main/kotlin/com/pitchedapps/frost/services/FrostNotifications.kt
+++ b/app/src/main/kotlin/com/pitchedapps/frost/services/FrostNotifications.kt
@@ -170,7 +170,7 @@ enum class NotificationType(
val ringtone = ringtone()
notifs.forEachIndexed { i, notif ->
// Ring at most twice
- notif.withAlert(i < 2, ringtone).notify(context)
+ notif.withAlert(context, i < 2, ringtone).notify(context)
}
return notifs.size
}
@@ -302,8 +302,8 @@ data class FrostNotification(
val notif: NotificationCompat.Builder
) {
- fun withAlert(enable: Boolean, ringtone: String): FrostNotification {
- notif.setFrostAlert(enable, ringtone)
+ fun withAlert(context: Context, enable: Boolean, ringtone: String): FrostNotification {
+ notif.setFrostAlert(context, enable, ringtone)
return this
}
diff --git a/app/src/main/kotlin/com/pitchedapps/frost/services/NotificationService.kt b/app/src/main/kotlin/com/pitchedapps/frost/services/NotificationService.kt
index 0eee5558..1d983f14 100644
--- a/app/src/main/kotlin/com/pitchedapps/frost/services/NotificationService.kt
+++ b/app/src/main/kotlin/com/pitchedapps/frost/services/NotificationService.kt
@@ -132,7 +132,7 @@ class NotificationService : BaseJobService() {
private fun generalNotification(id: Int, textRes: Int, withDefaults: Boolean) {
val notifBuilder = frostNotification(NOTIF_CHANNEL_GENERAL)
- .setFrostAlert(withDefaults, Prefs.notificationRingtone)
+ .setFrostAlert(this, withDefaults, Prefs.notificationRingtone)
.setContentTitle(string(R.string.frost_name))
.setContentText(string(textRes))
NotificationManagerCompat.from(this).notify(id, notifBuilder.build())
diff --git a/app/src/main/kotlin/com/pitchedapps/frost/services/NotificationUtils.kt b/app/src/main/kotlin/com/pitchedapps/frost/services/NotificationUtils.kt
index 96c601e4..35bf5de2 100644
--- a/app/src/main/kotlin/com/pitchedapps/frost/services/NotificationUtils.kt
+++ b/app/src/main/kotlin/com/pitchedapps/frost/services/NotificationUtils.kt
@@ -34,6 +34,7 @@ import ca.allanwang.kau.utils.string
import com.pitchedapps.frost.R
import com.pitchedapps.frost.utils.L
import com.pitchedapps.frost.utils.Prefs
+import com.pitchedapps.frost.utils.frostUri
/**
* Created by Allan Wang on 07/04/18.
@@ -85,7 +86,7 @@ fun Context.frostNotification(id: String) =
* Delegates to channels if Android O and up
* Otherwise uses our provided preferences
*/
-fun NotificationCompat.Builder.setFrostAlert(enable: Boolean, ringtone: String): NotificationCompat.Builder {
+fun NotificationCompat.Builder.setFrostAlert(context: Context, enable: Boolean, ringtone: String): NotificationCompat.Builder {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
setGroupAlertBehavior(
if (enable) NotificationCompat.GROUP_ALERT_CHILDREN
@@ -97,8 +98,7 @@ fun NotificationCompat.Builder.setFrostAlert(enable: Boolean, ringtone: String):
var defaults = 0
if (Prefs.notificationVibrate) defaults = defaults or Notification.DEFAULT_VIBRATE
if (Prefs.notificationSound) {
- // Ringtones have uris of format /content:/media/...; Uri.parse is okay
- if (ringtone.isNotBlank()) setSound(Uri.parse(ringtone))
+ if (ringtone.isNotBlank()) setSound(context.frostUri(ringtone))
else defaults = defaults or Notification.DEFAULT_SOUND
}
if (Prefs.notificationLights) defaults = defaults or Notification.DEFAULT_LIGHTS