schedule the event reminder right after inserting/updating

This commit is contained in:
tibbi 2017-02-06 20:50:41 +01:00
parent 9865af1cd6
commit e4fe47f81b
6 changed files with 15 additions and 14 deletions

View File

@ -10,7 +10,10 @@ import android.view.WindowManager
import com.simplemobiletools.calendar.R
import com.simplemobiletools.calendar.dialogs.EventReminderDialog
import com.simplemobiletools.calendar.dialogs.EventRepeatIntervalDialog
import com.simplemobiletools.calendar.extensions.*
import com.simplemobiletools.calendar.extensions.config
import com.simplemobiletools.calendar.extensions.getAppropriateTheme
import com.simplemobiletools.calendar.extensions.getReminderText
import com.simplemobiletools.calendar.extensions.seconds
import com.simplemobiletools.calendar.helpers.*
import com.simplemobiletools.calendar.models.Event
import com.simplemobiletools.commons.dialogs.ConfirmationDialog
@ -383,12 +386,10 @@ class EventActivity : SimpleActivity(), DBHelper.EventUpdateListener {
} else {
toast(R.string.event_added)
}
scheduleNotifications(event)
finish()
}
override fun eventUpdated(event: Event) {
scheduleNotifications(event)
toast(R.string.event_updated)
finish()
}

View File

@ -41,7 +41,7 @@ fun Context.updateListWidget() {
}
}
fun Context.scheduleNextEventNotifications(event: Event) {
fun Context.scheduleNextEventReminder(event: Event) {
var startTS = event.startTS - event.reminder1Minutes * 60
var newTS = startTS
if (event.repeatInterval == DAY || event.repeatInterval == WEEK || event.repeatInterval == BIWEEK) {
@ -67,11 +67,11 @@ private fun getNewTS(ts: Int, isMonthly: Boolean): Int {
return dateTime.seconds()
}
fun Context.scheduleNotifications(event: Event) {
fun Context.scheduleReminder(event: Event) {
if (event.getRemindersCount() == 0)
return
scheduleNextEventNotifications(event)
scheduleNextEventReminder(event)
}
fun Context.scheduleEventIn(notifTS: Int, event: Event) {

View File

@ -7,6 +7,7 @@ import android.database.sqlite.SQLiteDatabase
import android.database.sqlite.SQLiteOpenHelper
import android.database.sqlite.SQLiteQueryBuilder
import android.text.TextUtils
import com.simplemobiletools.calendar.extensions.scheduleReminder
import com.simplemobiletools.calendar.extensions.seconds
import com.simplemobiletools.calendar.extensions.updateWidgets
import com.simplemobiletools.calendar.models.Event
@ -105,6 +106,7 @@ class DBHelper(context: Context) : SQLiteOpenHelper(context, DB_NAME, null, DB_V
}
context?.updateWidgets()
context?.scheduleReminder(event)
mEventsListener?.eventInserted(event)
insertListener.invoke(event)
}
@ -124,6 +126,7 @@ class DBHelper(context: Context) : SQLiteOpenHelper(context, DB_NAME, null, DB_V
}
context?.updateWidgets()
context?.scheduleReminder(event)
mEventsListener?.eventUpdated(event)
}

View File

@ -1,7 +1,6 @@
package com.simplemobiletools.calendar.helpers
import android.content.Context
import com.simplemobiletools.calendar.extensions.scheduleNotifications
import com.simplemobiletools.calendar.extensions.seconds
import com.simplemobiletools.calendar.helpers.IcsParser.ImportResult.*
import com.simplemobiletools.calendar.models.Event
@ -59,9 +58,7 @@ class IcsParser {
continue
val event = Event(0, curStart, curEnd, curTitle, curDescription, reminderMinutes, -1, -1, importId = curImportId, flags = curFlags)
dbHelper.insert(event) {
context.scheduleNotifications(event)
}
dbHelper.insert(event) { }
eventsImported++
resetValues()
}

View File

@ -3,7 +3,7 @@ package com.simplemobiletools.calendar.receivers
import android.content.BroadcastReceiver
import android.content.Context
import android.content.Intent
import com.simplemobiletools.calendar.extensions.scheduleNextEventNotifications
import com.simplemobiletools.calendar.extensions.scheduleNextEventReminder
import com.simplemobiletools.calendar.helpers.DBHelper
class BootCompletedReceiver : BroadcastReceiver() {
@ -11,7 +11,7 @@ class BootCompletedReceiver : BroadcastReceiver() {
override fun onReceive(context: Context, arg1: Intent) {
val events = DBHelper(context).getEventsAtReboot()
for (event in events) {
context.scheduleNextEventNotifications(event)
context.scheduleNextEventReminder(event)
}
}
}

View File

@ -10,7 +10,7 @@ import android.net.Uri
import com.simplemobiletools.calendar.R
import com.simplemobiletools.calendar.activities.EventActivity
import com.simplemobiletools.calendar.extensions.config
import com.simplemobiletools.calendar.extensions.scheduleNextEventNotifications
import com.simplemobiletools.calendar.extensions.scheduleNextEventReminder
import com.simplemobiletools.calendar.extensions.updateListWidget
import com.simplemobiletools.calendar.helpers.DBHelper
import com.simplemobiletools.calendar.helpers.EVENT_ID
@ -36,7 +36,7 @@ class NotificationReceiver : BroadcastReceiver() {
notificationManager.notify(id, notification)
if (event.repeatInterval != 0)
context.scheduleNextEventNotifications(event)
context.scheduleNextEventReminder(event)
}
private fun getEventTime(startTime: String, endTime: String) = if (startTime == endTime) startTime else "$startTime - $endTime"