Handle notification for multiple timers

- update title for timer notification in finished state to be the label if it is empty
- remove duration field from the TimerEvent.Reset
This commit is contained in:
Paul Akhamiogu 2021-09-08 09:04:25 +01:00
parent a214ef9327
commit a91bc07dd3
4 changed files with 5 additions and 5 deletions

View File

@ -137,7 +137,7 @@ class TimerAdapter(
} }
private fun resetTimer(timer: Timer) { private fun resetTimer(timer: Timer) {
EventBus.getDefault().post(TimerEvent.Reset(timer.id!!, timer.seconds.secondsToMillis)) EventBus.getDefault().post(TimerEvent.Reset(timer.id!!))
simpleActivity.hideTimerNotification(timer.id!!) simpleActivity.hideTimerNotification(timer.id!!)
} }

View File

@ -311,7 +311,7 @@ fun Context.getTimerNotification(timer: Timer, pendingIntent: PendingIntent, add
val reminderActivityIntent = getReminderActivityIntent() val reminderActivityIntent = getReminderActivityIntent()
val builder = NotificationCompat.Builder(this) val builder = NotificationCompat.Builder(this)
.setContentTitle(getString(R.string.timer)) .setContentTitle(if(timer.label.isEmpty()) getString(R.string.timer) else timer.label)
.setContentText(getString(R.string.time_expired)) .setContentText(getString(R.string.time_expired))
.setSmallIcon(R.drawable.ic_timer) .setSmallIcon(R.drawable.ic_timer)
.setContentIntent(pendingIntent) .setContentIntent(pendingIntent)

View File

@ -2,7 +2,7 @@ package com.simplemobiletools.clock.models
sealed class TimerEvent(open val timerId: Int) { sealed class TimerEvent(open val timerId: Int) {
data class Delete(override val timerId: Int) : TimerEvent(timerId) data class Delete(override val timerId: Int) : TimerEvent(timerId)
data class Reset(override val timerId: Int, val duration: Long) : TimerEvent(timerId) data class Reset(override val timerId: Int) : TimerEvent(timerId)
data class Start(override val timerId: Int, val duration: Long) : TimerEvent(timerId) data class Start(override val timerId: Int, val duration: Long) : TimerEvent(timerId)
data class Pause(override val timerId: Int, val duration: Long) : TimerEvent(timerId) data class Pause(override val timerId: Int, val duration: Long) : TimerEvent(timerId)
data class Finish(override val timerId: Int, val duration: Long) : TimerEvent(timerId) data class Finish(override val timerId: Int, val duration: Long) : TimerEvent(timerId)

View File

@ -6,13 +6,13 @@ import android.content.Intent
import com.simplemobiletools.clock.extensions.hideTimerNotification import com.simplemobiletools.clock.extensions.hideTimerNotification
import com.simplemobiletools.clock.helpers.INVALID_TIMER_ID import com.simplemobiletools.clock.helpers.INVALID_TIMER_ID
import com.simplemobiletools.clock.helpers.TIMER_ID import com.simplemobiletools.clock.helpers.TIMER_ID
import com.simplemobiletools.clock.models.TimerState import com.simplemobiletools.clock.models.TimerEvent
import org.greenrobot.eventbus.EventBus import org.greenrobot.eventbus.EventBus
class HideTimerReceiver : BroadcastReceiver() { class HideTimerReceiver : BroadcastReceiver() {
override fun onReceive(context: Context, intent: Intent) { override fun onReceive(context: Context, intent: Intent) {
val timerId = intent.getIntExtra(TIMER_ID, INVALID_TIMER_ID) val timerId = intent.getIntExtra(TIMER_ID, INVALID_TIMER_ID)
context.hideTimerNotification(timerId) context.hideTimerNotification(timerId)
EventBus.getDefault().post(TimerState.Idle) EventBus.getDefault().post(TimerEvent.Reset(timerId, ))
} }
} }