Skip to content

Commit

Permalink
Merge pull request #17 from kirasok/cancel_on_delete
Browse files Browse the repository at this point in the history
feat(domain): cancel alarm before deleting it
  • Loading branch information
kirasok authored Apr 3, 2024
2 parents 6df42e3 + ab6f79d commit a757135
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,6 @@ object AppModule {
GetAlarms(repository),
GetAlarmById(repository),
InsertAlarm(repository, validator, scheduler),
DeleteAlarm(repository),
DeleteAlarm(repository, scheduler),
)
}
Original file line number Diff line number Diff line change
Expand Up @@ -38,10 +38,11 @@ class InsertAlarm(
}
}

class DeleteAlarm(private val repository: AlarmRepository) {
class DeleteAlarm(private val repository: AlarmRepository, private val scheduler: AlarmScheduler) {
suspend operator fun invoke(
alarm: Alarm,
) {
scheduler.cancel(alarm)
repository.deleteAlarm(alarm)
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -167,13 +167,13 @@ class AlarmService : Service(), MediaPlayer.OnPreparedListener, MediaPlayer.OnEr
val dismissIntent =
Intent(ALARM_ACTION_KEY).putExtra(ALARM_ACTION_KEY, AlarmAction.DISMISS.toString())
val dismissAction =
NotificationCompat.Action.Builder(null, "Dismiss", getPendingIntent(dismissIntent, alarm.id))
NotificationCompat.Action.Builder(null, "Dismiss", getPendingIntent(dismissIntent, 1))
.build()

val snoozeIntent =
Intent(ALARM_ACTION_KEY).putExtra(ALARM_ACTION_KEY, AlarmAction.SNOOZE.toString())
val snoozeAction =
NotificationCompat.Action.Builder(null, "Snooze", getPendingIntent(snoozeIntent, alarm.id))
NotificationCompat.Action.Builder(null, "Snooze", getPendingIntent(snoozeIntent, 2))
.build()

return NotificationCompat.Builder(
Expand All @@ -199,7 +199,7 @@ class AlarmService : Service(), MediaPlayer.OnPreparedListener, MediaPlayer.OnEr

companion object {

const val ALARM_ACTION_KEY = "alarm_action_key"
const val ALARM_ACTION_KEY = "io.github.kirasok.alarm_action_key"

enum class AlarmAction {
DISMISS, SNOOZE
Expand Down

0 comments on commit a757135

Please sign in to comment.