scheduleReminder in seconds

This commit is contained in:
Milos Kozak 2021-12-29 10:40:52 +01:00
parent e14cdd7c2a
commit aee036e200
5 changed files with 11 additions and 9 deletions

View file

@ -348,7 +348,7 @@ class CarbsDialog : DialogFragmentWithDate() {
}) })
} }
if (useAlarm && carbs > 0 && timeOffset > 0) { if (useAlarm && carbs > 0 && timeOffset > 0) {
carbTimer.scheduleReminder(dateUtil.now() + T.mins(timeOffset.toLong()).msecs()) carbTimer.scheduleReminder(T.mins(timeOffset.toLong()).secs())
} }
}, null) }, null)
} }

View file

@ -24,8 +24,8 @@ class CarbTimer @Inject constructor(
private val timerUtil: TimerUtil private val timerUtil: TimerUtil
) { ) {
fun scheduleReminder(time: Long, text: String? = null) = fun scheduleReminder(seconds: Long, text: String? = null) =
timerUtil.scheduleReminder(time, text ?: rh.gs(R.string.timetoeat)) timerUtil.scheduleReminder(seconds, text ?: rh.gs(R.string.timetoeat))
fun scheduleEatReminder() { fun scheduleEatReminder() {
val event = AutomationEvent(injector).apply { val event = AutomationEvent(injector).apply {

View file

@ -456,7 +456,7 @@ class BolusWizard @Inject constructor(
} }
if (useAlarm && carbs > 0 && carbTime > 0) { if (useAlarm && carbs > 0 && carbTime > 0) {
carbTimer.scheduleReminder(dateUtil.now() + T.mins(carbTime.toLong()).msecs()) carbTimer.scheduleReminder(T.mins(carbTime.toLong()).secs())
} }
} }
}) })

View file

@ -38,7 +38,7 @@ class ActionAlarm(injector: HasAndroidInjector) : Action(injector) {
override fun isValid(): Boolean = true // empty alarm will show app name override fun isValid(): Boolean = true // empty alarm will show app name
override fun doAction(callback: Callback) { override fun doAction(callback: Callback) {
timerUtil.scheduleReminder(dateUtil.now() + T.secs(10L).msecs(), text.value.takeIf { it.isNotBlank() } timerUtil.scheduleReminder(10, text.value.takeIf { it.isNotBlank() }
?: rh.gs(R.string.app_name)) ?: rh.gs(R.string.app_name))
callback.result(PumpEnactResult(injector).success(true).comment(R.string.ok))?.run() callback.result(PumpEnactResult(injector).success(true).comment(R.string.ok))?.run()
} }

View file

@ -15,13 +15,15 @@ class TimerUtil @Inject constructor(
private val dateUtil: DateUtil private val dateUtil: DateUtil
) { ) {
fun scheduleReminder(time: Long, text: String? = null) { /**
* Schedule alarm in @seconds
*/
fun scheduleReminder(seconds: Long, text: String) {
Intent(AlarmClock.ACTION_SET_TIMER).apply { Intent(AlarmClock.ACTION_SET_TIMER).apply {
val length: Int = ((time - dateUtil.now()) / 1000).toInt()
flags = flags or Intent.FLAG_ACTIVITY_NEW_TASK flags = flags or Intent.FLAG_ACTIVITY_NEW_TASK
putExtra(AlarmClock.EXTRA_LENGTH, length) putExtra(AlarmClock.EXTRA_LENGTH, seconds)
putExtra(AlarmClock.EXTRA_SKIP_UI, true) putExtra(AlarmClock.EXTRA_SKIP_UI, true)
putExtra(AlarmClock.EXTRA_MESSAGE, text ?: rh.gs(R.string.app_name)) putExtra(AlarmClock.EXTRA_MESSAGE, text)
context.startActivity(this) context.startActivity(this)
} }
} }