Swipe to snooze (#2839)

pull/2849/head^2
elmuffo 4 weeks ago committed by GitHub
parent c793a300cc
commit a1da71d3e1
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

@ -3,10 +3,12 @@ package org.tasks.notifications
import android.content.BroadcastReceiver import android.content.BroadcastReceiver
import android.content.Context import android.content.Context
import android.content.Intent import android.content.Intent
import com.todoroo.astrid.alarms.AlarmService
import dagger.hilt.android.AndroidEntryPoint import dagger.hilt.android.AndroidEntryPoint
import kotlinx.coroutines.CoroutineScope import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.launch import kotlinx.coroutines.launch
import org.tasks.injection.ApplicationScope import org.tasks.injection.ApplicationScope
import org.tasks.preferences.Preferences
import timber.log.Timber import timber.log.Timber
import javax.inject.Inject import javax.inject.Inject
@ -14,12 +16,23 @@ import javax.inject.Inject
class NotificationClearedReceiver : BroadcastReceiver() { class NotificationClearedReceiver : BroadcastReceiver() {
@Inject lateinit var notificationManager: NotificationManager @Inject lateinit var notificationManager: NotificationManager
@Inject @ApplicationScope lateinit var scope: CoroutineScope @Inject @ApplicationScope lateinit var scope: CoroutineScope
@Inject lateinit var preferences: Preferences
@Inject lateinit var alarmService: AlarmService
override fun onReceive(context: Context, intent: Intent) { override fun onReceive(context: Context, intent: Intent) {
val notificationId = intent.getLongExtra(NotificationManager.EXTRA_NOTIFICATION_ID, -1L) val notificationId = intent.getLongExtra(NotificationManager.EXTRA_NOTIFICATION_ID, -1L)
Timber.d("cleared $notificationId") Timber.d("cleared $notificationId")
if (notificationId <= 0L) return
scope.launch { scope.launch {
notificationManager.cancel(notificationId) if (preferences.useSwipeToSnooze()) {
var snoozeTime = preferences.swipeToSnoozeIntervalMS()
// snoozing for 0ms will cause the alarm service to miss this notification
// so sleep for 1s instead
if (snoozeTime == 0L) snoozeTime = 1000L
alarmService.snooze(snoozeTime, listOf(notificationId))
} else {
notificationManager.cancel(notificationId)
}
} }
} }
} }

@ -468,7 +468,13 @@ class Preferences @JvmOverloads constructor(
fun bundleNotifications(): Boolean = getBoolean(R.string.p_bundle_notifications, true) fun bundleNotifications(): Boolean = getBoolean(R.string.p_bundle_notifications, true)
fun usePersistentReminders(): Boolean = fun usePersistentReminders(): Boolean =
AndroidUtilities.preUpsideDownCake() && getBoolean(R.string.p_rmd_persistent, true) AndroidUtilities.preUpsideDownCake() && getBoolean(R.string.p_rmd_persistent, true)
fun useSwipeToSnooze(): Boolean =
getBoolean(R.string.p_rmd_swipe_to_snooze_enabled, false)
fun swipeToSnoozeIntervalMS(): Long =
getIntegerFromString(R.string.p_rmd_swipe_to_snooze_time_minutes, 0).toLong()
var isSyncOngoing: Boolean var isSyncOngoing: Boolean
get() = syncFlags.any { getBoolean(it, false) } get() = syncFlags.any { getBoolean(it, false) }

@ -16,6 +16,14 @@
<item>@string/none</item> <item>@string/none</item>
</string-array> </string-array>
<string-array name="swipe_to_snooze_times">
<item>@string/swipe_to_snooze_time_immediately</item>
<item>@string/swipe_to_snooze_time_15_minutes</item>
<item>@string/swipe_to_snooze_time_30_minutes</item>
<item>@string/swipe_to_snooze_time_1_hour</item>
<item>@string/swipe_to_snooze_time_24_hours</item>
</string-array>
<string-array name="reminder_ring_modes"> <string-array name="reminder_ring_modes">
<item>@string/ring_once</item> <item>@string/ring_once</item>
<item>@string/ring_five_times</item> <item>@string/ring_five_times</item>

@ -75,6 +75,17 @@
<!-- whether "clear all notifications" clears astrid notifications --> <!-- whether "clear all notifications" clears astrid notifications -->
<string name="p_rmd_persistent">notif_annoy</string> <string name="p_rmd_persistent">notif_annoy</string>
<string name="p_rmd_swipe_to_snooze_enabled">notif_swipe_to_snooze_enabled</string>
<string name="p_rmd_swipe_to_snooze_time_minutes">notif_swipe_to_snooze_time_minutes</string>
<string-array name="swipe_to_snooze_time_values">
<item>0</item>
<item>15</item>
<item>30</item>
<item>60</item>
<item>1440</item>
</string-array>
<!-- whether to vibrate phone when reminder fires --> <!-- whether to vibrate phone when reminder fires -->
<string name="p_rmd_vibrate">notif_vibrate</string> <string name="p_rmd_vibrate">notif_vibrate</string>

@ -150,6 +150,14 @@ File %1$s contained %2$s.\n\n
<string name="rmd_EPr_rmd_time_desc">Notifications for tasks without due times will appear at %s</string> <string name="rmd_EPr_rmd_time_desc">Notifications for tasks without due times will appear at %s</string>
<string name="persistent_notifications">Persistent notifications</string> <string name="persistent_notifications">Persistent notifications</string>
<string name="persistent_notifications_description">Persistent notifications cannot be cleared</string> <string name="persistent_notifications_description">Persistent notifications cannot be cleared</string>
<string name="swipe_to_snooze_title">Swipe to snooze</string>
<string name="swipe_to_snooze_description">Snooze time</string>
<string name="swipe_to_snooze_time_description">A cleared notification will be snoozed and recreated %s</string>
<string name="swipe_to_snooze_time_immediately">immediately</string>
<string name="swipe_to_snooze_time_15_minutes">after 15 minutes</string>
<string name="swipe_to_snooze_time_30_minutes">after 30 minutes</string>
<string name="swipe_to_snooze_time_1_hour">after 1 hour</string>
<string name="swipe_to_snooze_time_24_hours">after 24 hours</string>
<string name="rmd_EPr_defaultRemind_title">Random reminders</string> <string name="rmd_EPr_defaultRemind_title">Random reminders</string>
<string name="default_random_reminder_disabled">Disabled</string> <string name="default_random_reminder_disabled">Disabled</string>
<string name="default_random_reminder_hourly">Hourly</string> <string name="default_random_reminder_hourly">Hourly</string>

@ -71,6 +71,23 @@
android:summary="@string/more_notification_settings_summary" android:summary="@string/more_notification_settings_summary"
app:icon="@drawable/ic_open_in_new_24px" /> app:icon="@drawable/ic_open_in_new_24px" />
<PreferenceCategory android:title="@string/swipe_to_snooze_title">
<SwitchPreferenceCompat
android:defaultValue="false"
android:key="@string/p_rmd_swipe_to_snooze_enabled"
android:title="@string/enabled" />
<ListPreference
android:defaultValue="15"
android:entries="@array/swipe_to_snooze_times"
android:entryValues="@array/swipe_to_snooze_time_values"
android:key="@string/p_rmd_swipe_to_snooze_time_minutes"
android:summary="@string/swipe_to_snooze_time_description"
android:title="@string/swipe_to_snooze_description"
android:dependency="@string/p_rmd_swipe_to_snooze_enabled" />
</PreferenceCategory>
<PreferenceCategory android:title="@string/default_reminder"> <PreferenceCategory android:title="@string/default_reminder">
<SwitchPreferenceCompat <SwitchPreferenceCompat

Loading…
Cancel
Save