diff --git a/app/src/main/java/io/heckel/ntfy/db/Database.kt b/app/src/main/java/io/heckel/ntfy/db/Database.kt index 62daf0a..effdba0 100644 --- a/app/src/main/java/io/heckel/ntfy/db/Database.kt +++ b/app/src/main/java/io/heckel/ntfy/db/Database.kt @@ -18,6 +18,7 @@ data class Subscription( @ColumnInfo(name = "mutedUntil") val mutedUntil: Long, @ColumnInfo(name = "minPriority") val minPriority: Int, @ColumnInfo(name = "autoDelete") val autoDelete: Long, // Seconds + //@ColumnInfo(name = "insistent") val insistent: Boolean?, // Seconds @ColumnInfo(name = "lastNotificationId") val lastNotificationId: String?, // Used for polling, with since= @ColumnInfo(name = "icon") val icon: String?, // content://-URI (or later other identifier) @ColumnInfo(name = "upAppId") val upAppId: String?, // UnifiedPush application package name diff --git a/app/src/main/java/io/heckel/ntfy/msg/NotificationService.kt b/app/src/main/java/io/heckel/ntfy/msg/NotificationService.kt index 6f46ca6..f491168 100644 --- a/app/src/main/java/io/heckel/ntfy/msg/NotificationService.kt +++ b/app/src/main/java/io/heckel/ntfy/msg/NotificationService.kt @@ -319,6 +319,7 @@ class NotificationService(val context: Context) { */ class DeleteBroadcastReceiver : BroadcastReceiver() { override fun onReceive(context: Context, intent: Intent) { + Log.d(TAG, "Media player: Stopping insistent ring") val mediaPlayer = Repository.getInstance(context).mediaPlayer mediaPlayer.stop() } @@ -392,20 +393,22 @@ class NotificationService(val context: Context) { return } try { - Log.d(TAG, "Playing insistent alarm") val mediaPlayer = repository.mediaPlayer val audioManager = context.getSystemService(Context.AUDIO_SERVICE) as AudioManager val alert = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION) if (audioManager.getStreamVolume(AudioManager.STREAM_ALARM) != 0) { + Log.d(TAG, "Media player: Playing insistent alarm on alarm channel") mediaPlayer.reset() mediaPlayer.setDataSource(context, alert) mediaPlayer.setAudioAttributes(AudioAttributes.Builder().setUsage(AudioAttributes.USAGE_ALARM).build()) mediaPlayer.isLooping = true; mediaPlayer.prepare() mediaPlayer.start() + } else { + Log.d(TAG, "Media player: Alarm volume is 0; not playing insistent alarm") } } catch (e: Exception) { - Log.w(TAG, "Failed playing insistent alarm", e) + Log.w(TAG, "Media player: Failed to play insistent alarm", e) } } diff --git a/app/src/main/java/io/heckel/ntfy/ui/DetailActivity.kt b/app/src/main/java/io/heckel/ntfy/ui/DetailActivity.kt index 0eec67b..e900d70 100644 --- a/app/src/main/java/io/heckel/ntfy/ui/DetailActivity.kt +++ b/app/src/main/java/io/heckel/ntfy/ui/DetailActivity.kt @@ -254,6 +254,13 @@ class DetailActivity : AppCompatActivity(), ActionMode.Callback, NotificationFra // Mark this subscription as "open" so we don't receive notifications for it repository.detailViewSubscriptionId.set(subscriptionId) + + // Stop insistent playback (if running, otherwise it'll throw) + try { + repository.mediaPlayer.stop() + } catch (_: Exception) { + // Ignore errors + } } override fun onResume() { @@ -297,7 +304,6 @@ class DetailActivity : AppCompatActivity(), ActionMode.Callback, NotificationFra } } } - repository.mediaPlayer.stop() } override fun onCreateOptionsMenu(menu: Menu): Boolean { diff --git a/app/src/main/java/io/heckel/ntfy/ui/DetailSettingsActivity.kt b/app/src/main/java/io/heckel/ntfy/ui/DetailSettingsActivity.kt index 91b41d1..e5108a3 100644 --- a/app/src/main/java/io/heckel/ntfy/ui/DetailSettingsActivity.kt +++ b/app/src/main/java/io/heckel/ntfy/ui/DetailSettingsActivity.kt @@ -110,6 +110,7 @@ class DetailSettingsActivity : AppCompatActivity() { loadMutedUntilPref() loadMinPriorityPref() loadAutoDeletePref() + //loadInsistentMaxPriority() loadIconSetPref() loadIconRemovePref() } else { @@ -252,7 +253,30 @@ class DetailSettingsActivity : AppCompatActivity() { maybeAppendGlobal(summary, global) } } - +/* + private fun loadInsistentMaxPriority() { + val appBaseUrl = getString(R.string.app_base_url) + val prefId = context?.getString(R.string.detail_settings_notifications_instant_key) ?: return + val pref: SwitchPreference? = findPreference(prefId) + pref?.isVisible = true + pref?.isChecked = subscription.instant + pref?.preferenceDataStore = object : PreferenceDataStore() { + override fun putBoolean(key: String?, value: Boolean) { + save(subscription.copy(instant = value), refresh = true) + } + override fun getBoolean(key: String?, defValue: Boolean): Boolean { + return subscription.instant + } + } + pref?.summaryProvider = Preference.SummaryProvider { preference -> + if (preference.isChecked) { + getString(R.string.detail_settings_notifications_instant_summary_on) + } else { + getString(R.string.detail_settings_notifications_instant_summary_off) + } + } + } +*/ private fun loadIconSetPref() { val prefId = context?.getString(R.string.detail_settings_appearance_icon_set_key) ?: return iconSetPref = findPreference(prefId) ?: return diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index b8ea38b..77089bc 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -280,8 +280,8 @@ After one month After 3 months Keep alerting for highest priority - Max priority notifications continuously play the notification sound until dismissed. This overrides Do Not Disturb mode. - Max priority notifications alert only once. If enabled, the notification sound will repeat and override Do Not Disturb mode. + Max priority notifications continuously alert until dismissed + If enabled, the notification sound will continuously repeat until dismissed General Default server Enter your server\'s root URL to use your own server as a default when subscribing to new topics and/or sharing to topics.