add a helper function for counting event reminders

This commit is contained in:
tibbi 2017-02-06 19:21:42 +01:00
parent c5bb4bb001
commit 2f784cf56a
3 changed files with 13 additions and 3 deletions

View File

@ -68,7 +68,7 @@ private fun getNewTS(ts: Int, isMonthly: Boolean): Int {
}
fun Context.scheduleNotification(event: Event) {
if (event.reminder1Minutes == REMINDER_OFF && event.reminder2Minutes == REMINDER_OFF && event.reminder3Minutes == REMINDER_OFF)
if (event.getRemindersCount() == 0)
return
scheduleNextEvent(event)

View File

@ -30,4 +30,15 @@ data class Event(var id: Int = 0, var startTS: Int = 0, var endTS: Int = 0, var
}
val isAllDay = flags and FLAG_ALL_DAY != 0
fun getRemindersCount(): Int {
var cnt = 0
if (reminder1Minutes != REMINDER_OFF)
cnt++
if (reminder2Minutes != REMINDER_OFF)
cnt++
if (reminder3Minutes != REMINDER_OFF)
cnt++
return cnt
}
}

View File

@ -15,7 +15,6 @@ import com.simplemobiletools.calendar.extensions.updateListWidget
import com.simplemobiletools.calendar.helpers.DBHelper
import com.simplemobiletools.calendar.helpers.EVENT_ID
import com.simplemobiletools.calendar.helpers.Formatter
import com.simplemobiletools.calendar.helpers.REMINDER_OFF
import com.simplemobiletools.calendar.models.Event
class NotificationReceiver : BroadcastReceiver() {
@ -27,7 +26,7 @@ class NotificationReceiver : BroadcastReceiver() {
return
val event = DBHelper(context).getEvent(id)
if (event == null || (event.reminder1Minutes == REMINDER_OFF && event.reminder2Minutes == REMINDER_OFF && event.reminder3Minutes == REMINDER_OFF))
if (event == null || event.getRemindersCount() == 0)
return
val pendingIntent = getPendingIntent(context, event)