use the Reminder model class at fetching event reminders
This commit is contained in:
parent
1eb798e1ca
commit
f8028e0c16
|
@ -879,7 +879,7 @@ class EventActivity : SimpleActivity() {
|
||||||
if (mEvent.id == null || mEvent.id == null) {
|
if (mEvent.id == null || mEvent.id == null) {
|
||||||
eventsHelper.insertEvent(mEvent, true, true) {
|
eventsHelper.insertEvent(mEvent, true, true) {
|
||||||
if (DateTime.now().isAfter(mEventStartDateTime.millis)) {
|
if (DateTime.now().isAfter(mEventStartDateTime.millis)) {
|
||||||
if (mEvent.repeatInterval == 0 && mEvent.getReminders().isNotEmpty()) {
|
if (mEvent.repeatInterval == 0 && mEvent.getReminders().any { it.type == REMINDER_NOTIFICATION }) {
|
||||||
notifyEvent(mEvent)
|
notifyEvent(mEvent)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -80,7 +80,8 @@ fun Context.scheduleAllEvents() {
|
||||||
}
|
}
|
||||||
|
|
||||||
fun Context.scheduleNextEventReminder(event: Event, showToasts: Boolean) {
|
fun Context.scheduleNextEventReminder(event: Event, showToasts: Boolean) {
|
||||||
if (event.getReminders().isEmpty()) {
|
val validReminders = event.getReminders().filter { it.type == REMINDER_NOTIFICATION }
|
||||||
|
if (validReminders.isEmpty()) {
|
||||||
if (showToasts) {
|
if (showToasts) {
|
||||||
toast(R.string.saving)
|
toast(R.string.saving)
|
||||||
}
|
}
|
||||||
|
@ -88,7 +89,7 @@ fun Context.scheduleNextEventReminder(event: Event, showToasts: Boolean) {
|
||||||
}
|
}
|
||||||
|
|
||||||
val now = getNowSeconds()
|
val now = getNowSeconds()
|
||||||
val reminderSeconds = event.getReminders().reversed().map { it * 60 }
|
val reminderSeconds = validReminders.reversed().map { it.minutes * 60 }
|
||||||
eventsHelper.getEvents(now, now + YEAR, event.id!!, false) {
|
eventsHelper.getEvents(now, now + YEAR, event.id!!, false) {
|
||||||
if (it.isNotEmpty()) {
|
if (it.isNotEmpty()) {
|
||||||
for (curEvent in it) {
|
for (curEvent in it) {
|
||||||
|
@ -159,7 +160,7 @@ fun Context.getRepetitionText(seconds: Int) = when (seconds) {
|
||||||
}
|
}
|
||||||
|
|
||||||
fun Context.notifyRunningEvents() {
|
fun Context.notifyRunningEvents() {
|
||||||
eventsHelper.getRunningEvents().filter { it.getReminders().isNotEmpty() }.forEach {
|
eventsHelper.getRunningEvents().filter { it.getReminders().any { it.type == REMINDER_NOTIFICATION } }.forEach {
|
||||||
notifyEvent(it)
|
notifyEvent(it)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -120,7 +120,11 @@ data class Event(
|
||||||
|
|
||||||
fun getIsAllDay() = flags and FLAG_ALL_DAY != 0
|
fun getIsAllDay() = flags and FLAG_ALL_DAY != 0
|
||||||
|
|
||||||
fun getReminders() = setOf(reminder1Minutes, reminder2Minutes, reminder3Minutes).filter { it != REMINDER_OFF }
|
fun getReminders() = setOf(
|
||||||
|
Reminder(reminder1Minutes, reminder1Type),
|
||||||
|
Reminder(reminder2Minutes, reminder2Type),
|
||||||
|
Reminder(reminder3Minutes, reminder3Type)
|
||||||
|
).filter { it.minutes != REMINDER_OFF }
|
||||||
|
|
||||||
// properly return the start time of all-day events as midnight
|
// properly return the start time of all-day events as midnight
|
||||||
fun getEventStartTS(): Long {
|
fun getEventStartTS(): Long {
|
||||||
|
|
|
@ -10,6 +10,7 @@ import com.simplemobiletools.calendar.pro.extensions.scheduleNextEventReminder
|
||||||
import com.simplemobiletools.calendar.pro.extensions.updateListWidget
|
import com.simplemobiletools.calendar.pro.extensions.updateListWidget
|
||||||
import com.simplemobiletools.calendar.pro.helpers.EVENT_ID
|
import com.simplemobiletools.calendar.pro.helpers.EVENT_ID
|
||||||
import com.simplemobiletools.calendar.pro.helpers.Formatter
|
import com.simplemobiletools.calendar.pro.helpers.Formatter
|
||||||
|
import com.simplemobiletools.calendar.pro.helpers.REMINDER_NOTIFICATION
|
||||||
|
|
||||||
class NotificationReceiver : BroadcastReceiver() {
|
class NotificationReceiver : BroadcastReceiver() {
|
||||||
override fun onReceive(context: Context, intent: Intent) {
|
override fun onReceive(context: Context, intent: Intent) {
|
||||||
|
@ -30,7 +31,7 @@ class NotificationReceiver : BroadcastReceiver() {
|
||||||
|
|
||||||
context.updateListWidget()
|
context.updateListWidget()
|
||||||
val event = context.eventsDB.getEventWithId(id)
|
val event = context.eventsDB.getEventWithId(id)
|
||||||
if (event == null || event.getReminders().isEmpty()) {
|
if (event == null || event.getReminders().none { it.type == REMINDER_NOTIFICATION }) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue