From 5bb05c04c09304e6b6fe945ffe9ccfb729ca53c7 Mon Sep 17 00:00:00 2001 From: tibbi Date: Thu, 5 Nov 2020 12:02:23 +0100 Subject: [PATCH] disable Today alarms, if no longer valid --- .../main/kotlin/com/simplemobiletools/clock/App.kt | 2 +- .../clock/fragments/AlarmFragment.kt | 14 ++++++++++++++ 2 files changed, 15 insertions(+), 1 deletion(-) diff --git a/app/src/main/kotlin/com/simplemobiletools/clock/App.kt b/app/src/main/kotlin/com/simplemobiletools/clock/App.kt index 637a07b0..abdd5b92 100644 --- a/app/src/main/kotlin/com/simplemobiletools/clock/App.kt +++ b/app/src/main/kotlin/com/simplemobiletools/clock/App.kt @@ -85,7 +85,7 @@ class App : Application(), LifecycleObserver { @Subscribe(threadMode = ThreadMode.MAIN) fun onMessageEvent(event: TimerState.Finish) { val pendingIntent = getOpenTimerTabIntent() - val notification = getTimerNotification(pendingIntent, false) //MAYBE IN FUTURE ADD TIME TO NOTIFICATION + val notification = getTimerNotification(pendingIntent, false) val notificationManager = getSystemService(Context.NOTIFICATION_SERVICE) as NotificationManager notificationManager.notify(TIMER_NOTIF_ID, notification) diff --git a/app/src/main/kotlin/com/simplemobiletools/clock/fragments/AlarmFragment.kt b/app/src/main/kotlin/com/simplemobiletools/clock/fragments/AlarmFragment.kt index b42d3f7a..752c828c 100644 --- a/app/src/main/kotlin/com/simplemobiletools/clock/fragments/AlarmFragment.kt +++ b/app/src/main/kotlin/com/simplemobiletools/clock/fragments/AlarmFragment.kt @@ -12,11 +12,14 @@ import com.simplemobiletools.clock.adapters.AlarmsAdapter import com.simplemobiletools.clock.dialogs.EditAlarmDialog import com.simplemobiletools.clock.extensions.* import com.simplemobiletools.clock.helpers.DEFAULT_ALARM_MINUTES +import com.simplemobiletools.clock.helpers.TODAY_BIT +import com.simplemobiletools.clock.helpers.getCurrentDayMinutes import com.simplemobiletools.clock.helpers.getTomorrowBit import com.simplemobiletools.clock.interfaces.ToggleAlarmInterface import com.simplemobiletools.clock.models.Alarm import com.simplemobiletools.commons.extensions.toast import com.simplemobiletools.commons.extensions.updateTextColors +import com.simplemobiletools.commons.helpers.ensureBackgroundThread import com.simplemobiletools.commons.models.AlarmSound import kotlinx.android.synthetic.main.fragment_alarm.view.* import java.util.* @@ -70,6 +73,17 @@ class AlarmFragment : Fragment(), ToggleAlarmInterface { private fun setupAlarms() { alarms = context?.dbHelper?.getAlarms() ?: return + if (context?.getNextAlarm()?.isEmpty() == true) { + alarms.forEach { + if (it.days == TODAY_BIT && it.isEnabled && it.timeInMinutes <= getCurrentDayMinutes()) { + it.isEnabled = false + ensureBackgroundThread { + context?.dbHelper?.updateAlarmEnabledState(it.id, false) + } + } + } + } + val currAdapter = view.alarms_list.adapter if (currAdapter == null) { AlarmsAdapter(activity as SimpleActivity, alarms, this, view.alarms_list) {