add a Dismiss button to the alarm reminder
This commit is contained in:
parent
49edf70f61
commit
10c5b07c90
|
@ -85,7 +85,9 @@
|
|||
|
||||
<receiver android:name=".receivers.AlarmReceiver"/>
|
||||
|
||||
<receiver android:name=".receivers.TimerReceiver"/>
|
||||
<receiver android:name=".receivers.HideTimerReceiver"/>
|
||||
|
||||
<receiver android:name=".receivers.HideAlarmReceiver"/>
|
||||
|
||||
<receiver android:name=".receivers.DateTimeWidgetUpdateReceiver"/>
|
||||
|
||||
|
|
|
@ -25,7 +25,8 @@ import com.simplemobiletools.clock.models.AlarmSound
|
|||
import com.simplemobiletools.clock.models.MyTimeZone
|
||||
import com.simplemobiletools.clock.receivers.AlarmReceiver
|
||||
import com.simplemobiletools.clock.receivers.DateTimeWidgetUpdateReceiver
|
||||
import com.simplemobiletools.clock.receivers.TimerReceiver
|
||||
import com.simplemobiletools.clock.receivers.HideAlarmReceiver
|
||||
import com.simplemobiletools.clock.receivers.HideTimerReceiver
|
||||
import com.simplemobiletools.clock.services.SnoozeService
|
||||
import com.simplemobiletools.commons.extensions.formatMinutesToTimeString
|
||||
import com.simplemobiletools.commons.extensions.getAdjustedPrimaryColor
|
||||
|
@ -277,7 +278,7 @@ fun Context.getTimerNotification(pendingIntent: PendingIntent, addDeleteIntent:
|
|||
.setAutoCancel(true)
|
||||
.setSound(Uri.parse(config.timerSoundUri), AudioManager.STREAM_SYSTEM)
|
||||
.setChannelId(channelId)
|
||||
.addAction(R.drawable.ic_cross, getString(R.string.dismiss), if (addDeleteIntent) reminderActivityIntent else getTimerPendingIntent())
|
||||
.addAction(R.drawable.ic_cross, getString(R.string.dismiss), if (addDeleteIntent) reminderActivityIntent else getHideTimerPendingIntent())
|
||||
|
||||
if (addDeleteIntent) {
|
||||
builder.setDeleteIntent(reminderActivityIntent)
|
||||
|
@ -297,11 +298,16 @@ fun Context.getTimerNotification(pendingIntent: PendingIntent, addDeleteIntent:
|
|||
return notification
|
||||
}
|
||||
|
||||
fun Context.getTimerPendingIntent(): PendingIntent {
|
||||
val intent = Intent(this, TimerReceiver::class.java)
|
||||
fun Context.getHideTimerPendingIntent(): PendingIntent {
|
||||
val intent = Intent(this, HideTimerReceiver::class.java)
|
||||
return PendingIntent.getBroadcast(this, TIMER_NOTIF_ID, intent, PendingIntent.FLAG_UPDATE_CURRENT)
|
||||
}
|
||||
|
||||
fun Context.getHideAlarmPendingIntent(alarm: Alarm): PendingIntent {
|
||||
val intent = Intent(this, HideAlarmReceiver::class.java)
|
||||
return PendingIntent.getBroadcast(this, alarm.id, intent, PendingIntent.FLAG_UPDATE_CURRENT)
|
||||
}
|
||||
|
||||
@SuppressLint("NewApi")
|
||||
fun Context.getAlarmNotification(pendingIntent: PendingIntent, alarm: Alarm, addDeleteIntent: Boolean): Notification {
|
||||
val channelId = "alarm_channel"
|
||||
|
@ -328,6 +334,7 @@ fun Context.getAlarmNotification(pendingIntent: PendingIntent, alarm: Alarm, add
|
|||
.setAutoCancel(true)
|
||||
.setSound(Uri.parse(alarm.soundUri), AudioManager.STREAM_ALARM)
|
||||
.setChannelId(channelId)
|
||||
.addAction(R.drawable.ic_cross, getString(R.string.dismiss), if (addDeleteIntent) reminderActivityIntent else getHideAlarmPendingIntent(alarm))
|
||||
.addAction(R.drawable.ic_snooze, getString(R.string.snooze), getSnoozePendingIntent(alarm, addDeleteIntent))
|
||||
|
||||
if (addDeleteIntent) {
|
||||
|
|
|
@ -4,10 +4,11 @@ import android.content.BroadcastReceiver
|
|||
import android.content.Context
|
||||
import android.content.Intent
|
||||
import com.simplemobiletools.clock.extensions.hideNotification
|
||||
import com.simplemobiletools.clock.helpers.TIMER_NOTIF_ID
|
||||
import com.simplemobiletools.clock.helpers.ALARM_ID
|
||||
|
||||
class TimerReceiver : BroadcastReceiver() {
|
||||
class HideAlarmReceiver : BroadcastReceiver() {
|
||||
override fun onReceive(context: Context, intent: Intent) {
|
||||
context.hideNotification(TIMER_NOTIF_ID)
|
||||
val id = intent.getIntExtra(ALARM_ID, -1)
|
||||
context.hideNotification(id)
|
||||
}
|
||||
}
|
|
@ -0,0 +1,12 @@
|
|||
package com.simplemobiletools.clock.receivers
|
||||
|
||||
import android.content.BroadcastReceiver
|
||||
import android.content.Context
|
||||
import android.content.Intent
|
||||
import com.simplemobiletools.clock.extensions.hideTimerNotification
|
||||
|
||||
class HideTimerReceiver : BroadcastReceiver() {
|
||||
override fun onReceive(context: Context, intent: Intent) {
|
||||
context.hideTimerNotification()
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue