From 90112fbbd046212ade6a1490c7c9c7ae7709f304 Mon Sep 17 00:00:00 2001 From: Philipp Heckel Date: Fri, 3 Apr 2026 20:44:35 -0400 Subject: [PATCH] Add snooze short --- app/src/main/AndroidManifest.xml | 3 +- .../heckel/ntfy/service/SubscriberService.kt | 32 +++++++++++-------- .../io/heckel/ntfy/ui/SettingsActivity.kt | 1 - app/src/main/res/values/values.xml | 2 -- 4 files changed, 21 insertions(+), 17 deletions(-) diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index e585a747..4305b77a 100644 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -139,7 +139,8 @@ android:exported="false"> - + + diff --git a/app/src/main/java/io/heckel/ntfy/service/SubscriberService.kt b/app/src/main/java/io/heckel/ntfy/service/SubscriberService.kt index 86970d94..06b4a7c1 100644 --- a/app/src/main/java/io/heckel/ntfy/service/SubscriberService.kt +++ b/app/src/main/java/io/heckel/ntfy/service/SubscriberService.kt @@ -360,10 +360,13 @@ class SubscriberService : Service() { val contentIntent = PendingIntent.getActivity(this, 0, Intent(this, MainActivity::class.java), PendingIntent.FLAG_IMMUTABLE) - val snoozeIntent = PendingIntent.getBroadcast(this, 0, - Intent(this, ConnectionAlertBroadcastReceiver::class.java).apply { action = CONNECTION_ALERT_ACTION_SNOOZE }, + val snoozeShortIntent = PendingIntent.getBroadcast(this, 0, + Intent(this, ConnectionAlertBroadcastReceiver::class.java).apply { action = CONNECTION_ALERT_ACTION_SNOOZE_SHORT }, PendingIntent.FLAG_UPDATE_CURRENT or PendingIntent.FLAG_IMMUTABLE) - val disableIntent = PendingIntent.getBroadcast(this, 0, + val snoozeIntent = PendingIntent.getBroadcast(this, 0, + Intent(this, ConnectionAlertBroadcastReceiver::class.java).apply { action = CONNECTION_ALERT_ACTION_SNOOZE_LONG }, + PendingIntent.FLAG_UPDATE_CURRENT or PendingIntent.FLAG_IMMUTABLE) + val neverAlertIntent = PendingIntent.getBroadcast(this, 0, Intent(this, ConnectionAlertBroadcastReceiver::class.java).apply { action = CONNECTION_ALERT_ACTION_NEVER }, PendingIntent.FLAG_UPDATE_CURRENT or PendingIntent.FLAG_IMMUTABLE) val deleteIntent = PendingIntent.getBroadcast(this, 0, @@ -379,8 +382,9 @@ class SubscriberService : Service() { .setContentIntent(contentIntent) .setOnlyAlertOnce(true) .setDeleteIntent(deleteIntent) - .addAction(NotificationCompat.Action.Builder(0, getString(R.string.connection_alert_action_snooze, CONNECTION_ALERT_SNOOZE_HOURS), snoozeIntent).build()) - .addAction(NotificationCompat.Action.Builder(0, getString(R.string.connection_alert_action_never), disableIntent).build()) + .addAction(NotificationCompat.Action.Builder(0, getString(R.string.connection_alert_action_snooze, CONNECTION_ALERT_SNOOZE_SHORT_HOURS), snoozeShortIntent).build()) + .addAction(NotificationCompat.Action.Builder(0, getString(R.string.connection_alert_action_snooze, CONNECTION_ALERT_SNOOZE_LONG_HOURS), snoozeIntent).build()) + .addAction(NotificationCompat.Action.Builder(0, getString(R.string.connection_alert_action_never), neverAlertIntent).build()) .build() Log.d(TAG, "Showing connection alert notification") @@ -499,11 +503,11 @@ class SubscriberService : Service() { val repository = Repository.getInstance(context) val notificationManager = context.getSystemService(NOTIFICATION_SERVICE) as NotificationManager when (intent.action) { - CONNECTION_ALERT_ACTION_DISMISS -> { - repository.setConnectionAlertSnoozeUntilTime(System.currentTimeMillis() + CONNECTION_ALERT_DISMISS_MILLIS) + CONNECTION_ALERT_ACTION_DISMISS, CONNECTION_ALERT_ACTION_SNOOZE_SHORT -> { + repository.setConnectionAlertSnoozeUntilTime(System.currentTimeMillis() + CONNECTION_ALERT_SNOOZE_SHORT_MILLIS) } - CONNECTION_ALERT_ACTION_SNOOZE -> { - repository.setConnectionAlertSnoozeUntilTime(System.currentTimeMillis() + CONNECTION_ALERT_SNOOZE_MILLIS) + CONNECTION_ALERT_ACTION_SNOOZE_LONG -> { + repository.setConnectionAlertSnoozeUntilTime(System.currentTimeMillis() + CONNECTION_ALERT_SNOOZE_LONG_MILLIS) } CONNECTION_ALERT_ACTION_NEVER -> { repository.setConnectionAlertSeconds(Repository.CONNECTION_ALERT_NEVER) @@ -535,11 +539,13 @@ class SubscriberService : Service() { private const val NOTIFICATION_RECEIVED_WAKELOCK_TIMEOUT_MILLIS = 10 * 60 * 1000L /*10 minutes*/ const val NOTIFICATION_CONNECTION_ALERT_ID = 2587 - private const val CONNECTION_ALERT_SNOOZE_HOURS = 8 - private const val CONNECTION_ALERT_SNOOZE_MILLIS = CONNECTION_ALERT_SNOOZE_HOURS * ONE_HOUR_MILLIS - private const val CONNECTION_ALERT_DISMISS_MILLIS = ONE_HOUR_MILLIS + private const val CONNECTION_ALERT_SNOOZE_SHORT_HOURS = 1 + private const val CONNECTION_ALERT_SNOOZE_SHORT_MILLIS = CONNECTION_ALERT_SNOOZE_SHORT_HOURS * ONE_HOUR_MILLIS + private const val CONNECTION_ALERT_SNOOZE_LONG_HOURS = 8 + private const val CONNECTION_ALERT_SNOOZE_LONG_MILLIS = CONNECTION_ALERT_SNOOZE_LONG_HOURS * ONE_HOUR_MILLIS private const val CONNECTION_ALERT_ACTION_DISMISS = "io.heckel.ntfy.CONNECTION_ALERT_DISMISS" - private const val CONNECTION_ALERT_ACTION_SNOOZE = "io.heckel.ntfy.CONNECTION_ALERT_SNOOZE" + private const val CONNECTION_ALERT_ACTION_SNOOZE_SHORT = "io.heckel.ntfy.CONNECTION_ALERT_SNOOZE_SHORT" + private const val CONNECTION_ALERT_ACTION_SNOOZE_LONG = "io.heckel.ntfy.CONNECTION_ALERT_SNOOZE_LONG" private const val CONNECTION_ALERT_ACTION_NEVER = "io.heckel.ntfy.CONNECTION_ALERT_NEVER" } } diff --git a/app/src/main/java/io/heckel/ntfy/ui/SettingsActivity.kt b/app/src/main/java/io/heckel/ntfy/ui/SettingsActivity.kt index 629aa922..f7914af5 100644 --- a/app/src/main/java/io/heckel/ntfy/ui/SettingsActivity.kt +++ b/app/src/main/java/io/heckel/ntfy/ui/SettingsActivity.kt @@ -340,7 +340,6 @@ class SettingsActivity : AppCompatActivity(), PreferenceFragmentCompat.OnPrefere connectionAlert?.summaryProvider = Preference.SummaryProvider { pref -> when (pref.value.toLongOrNull() ?: repository.getConnectionAlertSeconds()) { Repository.CONNECTION_ALERT_NEVER -> getString(R.string.settings_advanced_connection_alert_summary_never) - 30L -> "Alert after 30 seconds (testing)" Repository.CONNECTION_ALERT_FIVE_MINUTES_SECONDS -> getString(R.string.settings_advanced_connection_alert_summary_five_minutes) Repository.CONNECTION_ALERT_FIFTEEN_MINUTES_SECONDS -> getString(R.string.settings_advanced_connection_alert_summary_fifteen_minutes) Repository.CONNECTION_ALERT_ONE_HOUR_SECONDS -> getString(R.string.settings_advanced_connection_alert_summary_one_hour) diff --git a/app/src/main/res/values/values.xml b/app/src/main/res/values/values.xml index 19c732b1..0bb4bca9 100644 --- a/app/src/main/res/values/values.xml +++ b/app/src/main/res/values/values.xml @@ -170,7 +170,6 @@ @string/settings_advanced_connection_alert_never - After 30 seconds (testing) @string/settings_advanced_connection_alert_five_minutes @string/settings_advanced_connection_alert_fifteen_minutes @string/settings_advanced_connection_alert_one_hour @@ -179,7 +178,6 @@ 0 - 30 300 900 3600