Add snooze short

This commit is contained in:
Philipp Heckel 2026-04-03 20:44:35 -04:00
parent 0f3f1bd3e1
commit 90112fbbd0
4 changed files with 21 additions and 17 deletions

View file

@ -139,7 +139,8 @@
android:exported="false">
<intent-filter>
<action android:name="io.heckel.ntfy.CONNECTION_ALERT_DISMISS"/>
<action android:name="io.heckel.ntfy.CONNECTION_ALERT_SNOOZE"/>
<action android:name="io.heckel.ntfy.CONNECTION_ALERT_SNOOZE_SHORT"/>
<action android:name="io.heckel.ntfy.CONNECTION_ALERT_SNOOZE_LONG"/>
<action android:name="io.heckel.ntfy.CONNECTION_ALERT_NEVER"/>
</intent-filter>
</receiver>

View file

@ -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"
}
}

View file

@ -340,7 +340,6 @@ class SettingsActivity : AppCompatActivity(), PreferenceFragmentCompat.OnPrefere
connectionAlert?.summaryProvider = Preference.SummaryProvider<ListPreference> { 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)

View file

@ -170,7 +170,6 @@
</string-array>
<string-array name="settings_advanced_connection_alert_entries">
<item>@string/settings_advanced_connection_alert_never</item>
<item>After 30 seconds (testing)</item>
<item>@string/settings_advanced_connection_alert_five_minutes</item>
<item>@string/settings_advanced_connection_alert_fifteen_minutes</item>
<item>@string/settings_advanced_connection_alert_one_hour</item>
@ -179,7 +178,6 @@
</string-array>
<string-array name="settings_advanced_connection_alert_values">
<item>0</item>
<item>30</item>
<item>300</item>
<item>900</item>
<item>3600</item>