diff options
Diffstat (limited to 'app/src/main/kotlin/com')
5 files changed, 25 insertions, 12 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 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 91d87e3b..40ff071e 100644 --- a/app/src/main/kotlin/com/pitchedapps/frost/settings/Notifications.kt +++ b/app/src/main/kotlin/com/pitchedapps/frost/settings/Notifications.kt @@ -19,7 +19,6 @@ 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 @@ -39,6 +38,7 @@ import com.pitchedapps.frost.services.fetchNotifications import com.pitchedapps.frost.services.scheduleNotifications import com.pitchedapps.frost.utils.Prefs import com.pitchedapps.frost.utils.frostSnackbar +import com.pitchedapps.frost.utils.frostUri import com.pitchedapps.frost.views.Keywords import kotlinx.coroutines.launch @@ -136,8 +136,7 @@ fun SettingsActivity.getNotificationPrefs(): KPrefAdapterBuilder.() -> Unit = { enabler = Prefs::notificationSound textGetter = { if (it.isBlank()) string(R.string.kau_default) - // Ringtones have uris of format /content:/media/...; Uri.parse is okay - else RingtoneManager.getRingtone(this@getNotificationPrefs, Uri.parse(it)) + else RingtoneManager.getRingtone(this@getNotificationPrefs, frostUri(it)) ?.getTitle(this@getNotificationPrefs) ?: "---" //todo figure out why this happens } @@ -148,8 +147,10 @@ fun SettingsActivity.getNotificationPrefs(): KPrefAdapterBuilder.() -> Unit = { putExtra(RingtoneManager.EXTRA_RINGTONE_SHOW_DEFAULT, true) putExtra(RingtoneManager.EXTRA_RINGTONE_TYPE, RingtoneManager.TYPE_NOTIFICATION) if (item.pref.isNotBlank()) { - // Ringtones have uris of format /content:/media/...; Uri.parse is okay - putExtra(RingtoneManager.EXTRA_RINGTONE_EXISTING_URI, Uri.parse(item.pref)) + putExtra( + RingtoneManager.EXTRA_RINGTONE_EXISTING_URI, + frostUri(item.pref) + ) } } startActivityForResult(intent, code) diff --git a/app/src/main/kotlin/com/pitchedapps/frost/utils/Utils.kt b/app/src/main/kotlin/com/pitchedapps/frost/utils/Utils.kt index 00e9a1b9..8ad0d432 100644 --- a/app/src/main/kotlin/com/pitchedapps/frost/utils/Utils.kt +++ b/app/src/main/kotlin/com/pitchedapps/frost/utils/Utils.kt @@ -347,6 +347,18 @@ fun Context.frostUriFromFile(file: File): Uri = file ) +/** + * Gets uri from our own resolver if it's a file, or return the parsed uri otherwise + */ +fun Context.frostUri(entry: String): Uri { + val uri = Uri.parse(entry) + val path = uri.path + if (uri.scheme == "file" && path != null) { + return frostUriFromFile(File(path)) + } + return uri +} + inline fun Context.sendFrostEmail(@StringRes subjectId: Int, crossinline builder: EmailBuilder.() -> Unit) = sendFrostEmail(string(subjectId), builder) |