show the reminder remaining time or Saving... at updating events
This commit is contained in:
parent
00d2edbe50
commit
9c62ac5b86
|
@ -46,7 +46,7 @@ ext {
|
|||
}
|
||||
|
||||
dependencies {
|
||||
implementation 'com.simplemobiletools:commons:4.3.27'
|
||||
implementation 'com.simplemobiletools:commons:4.3.28'
|
||||
implementation 'joda-time:joda-time:2.9.9'
|
||||
implementation 'com.facebook.stetho:stetho:1.5.0'
|
||||
implementation 'com.android.support:multidex:1.0.3'
|
||||
|
|
|
@ -673,13 +673,11 @@ class EventActivity : SimpleActivity() {
|
|||
|
||||
private fun storeEvent(wasRepeatable: Boolean) {
|
||||
if (mEvent.id == 0) {
|
||||
dbHelper.insert(mEvent, true) {
|
||||
dbHelper.insert(mEvent, true, this) {
|
||||
if (DateTime.now().isAfter(mEventStartDateTime.millis)) {
|
||||
if (mEvent.repeatInterval == 0 && mEvent.getReminders().isNotEmpty()) {
|
||||
notifyEvent(mEvent)
|
||||
}
|
||||
} else {
|
||||
toast(R.string.event_added)
|
||||
}
|
||||
|
||||
finish()
|
||||
|
@ -688,8 +686,8 @@ class EventActivity : SimpleActivity() {
|
|||
if (mRepeatInterval > 0 && wasRepeatable) {
|
||||
EditRepeatingEventDialog(this) {
|
||||
if (it) {
|
||||
dbHelper.update(mEvent, true) {
|
||||
eventUpdated()
|
||||
dbHelper.update(mEvent, true, this) {
|
||||
finish()
|
||||
}
|
||||
} else {
|
||||
dbHelper.addEventRepeatException(mEvent.id, mEventOccurrenceTS, true)
|
||||
|
@ -701,25 +699,19 @@ class EventActivity : SimpleActivity() {
|
|||
repeatLimit = 0
|
||||
}
|
||||
|
||||
dbHelper.insert(mEvent, true) {
|
||||
toast(R.string.event_updated)
|
||||
dbHelper.insert(mEvent, true, this) {
|
||||
finish()
|
||||
}
|
||||
}
|
||||
}
|
||||
} else {
|
||||
dbHelper.update(mEvent, true) {
|
||||
eventUpdated()
|
||||
dbHelper.update(mEvent, true, this) {
|
||||
finish()
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private fun eventUpdated() {
|
||||
toast(R.string.event_updated)
|
||||
finish()
|
||||
}
|
||||
|
||||
private fun updateStartTexts() {
|
||||
updateStartDateText()
|
||||
updateStartTimeText()
|
||||
|
|
|
@ -77,8 +77,9 @@ fun Context.scheduleAllEvents() {
|
|||
}
|
||||
}
|
||||
|
||||
fun Context.scheduleNextEventReminder(event: Event?, dbHelper: DBHelper) {
|
||||
if (event == null || event.getReminders().isEmpty()) {
|
||||
fun Context.scheduleNextEventReminder(event: Event, dbHelper: DBHelper, activity: SimpleActivity? = null) {
|
||||
if (event.getReminders().isEmpty()) {
|
||||
activity?.toast(R.string.saving)
|
||||
return
|
||||
}
|
||||
|
||||
|
@ -89,20 +90,29 @@ fun Context.scheduleNextEventReminder(event: Event?, dbHelper: DBHelper) {
|
|||
for (curEvent in it) {
|
||||
for (curReminder in reminderSeconds) {
|
||||
if (curEvent.getEventStartTS() - curReminder > now) {
|
||||
scheduleEventIn((curEvent.getEventStartTS() - curReminder) * 1000L, curEvent)
|
||||
scheduleEventIn((curEvent.getEventStartTS() - curReminder) * 1000L, curEvent, activity)
|
||||
return@getEvents
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
activity?.toast(R.string.saving)
|
||||
}
|
||||
}
|
||||
|
||||
fun Context.scheduleEventIn(notifTS: Long, event: Event) {
|
||||
fun Context.scheduleEventIn(notifTS: Long, event: Event, activity: SimpleActivity? = null) {
|
||||
if (notifTS < System.currentTimeMillis()) {
|
||||
activity?.toast(R.string.saving)
|
||||
return
|
||||
}
|
||||
|
||||
if (activity != null) {
|
||||
val secondsTillNotification = (notifTS - System.currentTimeMillis()) / 1000
|
||||
val msg = String.format(getString(R.string.reminder_triggers_in), formatSecondsToTimeString(secondsTillNotification.toInt()))
|
||||
activity.toast(msg)
|
||||
}
|
||||
|
||||
val pendingIntent = getNotificationIntent(applicationContext, event)
|
||||
val alarmManager = getSystemService(Context.ALARM_SERVICE) as AlarmManager
|
||||
AlarmManagerCompat.setExactAndAllowWhileIdle(alarmManager, AlarmManager.RTC_WAKEUP, notifTS, pendingIntent)
|
||||
|
|
|
@ -10,6 +10,7 @@ import android.database.sqlite.SQLiteQueryBuilder
|
|||
import android.text.TextUtils
|
||||
import android.util.SparseIntArray
|
||||
import com.simplemobiletools.calendar.R
|
||||
import com.simplemobiletools.calendar.activities.SimpleActivity
|
||||
import com.simplemobiletools.calendar.extensions.*
|
||||
import com.simplemobiletools.calendar.models.Event
|
||||
import com.simplemobiletools.calendar.models.EventType
|
||||
|
@ -200,7 +201,7 @@ class DBHelper private constructor(val context: Context) : SQLiteOpenHelper(cont
|
|||
addEventType(eventType, db)
|
||||
}
|
||||
|
||||
fun insert(event: Event, addToCalDAV: Boolean, callback: (id: Int) -> Unit) {
|
||||
fun insert(event: Event, addToCalDAV: Boolean, activity: SimpleActivity? = null, callback: (id: Int) -> Unit) {
|
||||
if (event.startTS > event.endTS) {
|
||||
callback(0)
|
||||
return
|
||||
|
@ -216,7 +217,7 @@ class DBHelper private constructor(val context: Context) : SQLiteOpenHelper(cont
|
|||
}
|
||||
|
||||
context.updateWidgets()
|
||||
context.scheduleNextEventReminder(event, this)
|
||||
context.scheduleNextEventReminder(event, this, activity)
|
||||
|
||||
if (addToCalDAV && event.source != SOURCE_SIMPLE_CALENDAR && context.config.caldavSync) {
|
||||
CalDAVHandler(context).insertCalDAVEvent(event)
|
||||
|
@ -254,7 +255,7 @@ class DBHelper private constructor(val context: Context) : SQLiteOpenHelper(cont
|
|||
}
|
||||
}
|
||||
|
||||
fun update(event: Event, updateAtCalDAV: Boolean, callback: (() -> Unit)? = null) {
|
||||
fun update(event: Event, updateAtCalDAV: Boolean, activity: SimpleActivity? = null, callback: (() -> Unit)? = null) {
|
||||
val values = fillEventValues(event)
|
||||
val selection = "$COL_ID = ?"
|
||||
val selectionArgs = arrayOf(event.id.toString())
|
||||
|
@ -269,7 +270,7 @@ class DBHelper private constructor(val context: Context) : SQLiteOpenHelper(cont
|
|||
}
|
||||
|
||||
context.updateWidgets()
|
||||
context.scheduleNextEventReminder(event, this)
|
||||
context.scheduleNextEventReminder(event, this, activity)
|
||||
if (updateAtCalDAV && event.source != SOURCE_SIMPLE_CALENDAR && context.config.caldavSync) {
|
||||
CalDAVHandler(context).updateCalDAVEvent(event)
|
||||
}
|
||||
|
@ -548,7 +549,9 @@ class DBHelper private constructor(val context: Context) : SQLiteOpenHelper(cont
|
|||
mDb.insert(EXCEPTIONS_TABLE_NAME, null, it)
|
||||
|
||||
val parentEvent = getEventWithId(parentEventId)
|
||||
context.scheduleNextEventReminder(parentEvent, this)
|
||||
if (parentEvent != null) {
|
||||
context.scheduleNextEventReminder(parentEvent, this)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue