show the reminder remaining time or Saving... at updating events

This commit is contained in:
tibbi
2018-07-04 20:34:55 +02:00
parent 00d2edbe50
commit 9c62ac5b86
4 changed files with 29 additions and 24 deletions

View File

@@ -46,7 +46,7 @@ ext {
} }
dependencies { dependencies {
implementation 'com.simplemobiletools:commons:4.3.27' implementation 'com.simplemobiletools:commons:4.3.28'
implementation 'joda-time:joda-time:2.9.9' implementation 'joda-time:joda-time:2.9.9'
implementation 'com.facebook.stetho:stetho:1.5.0' implementation 'com.facebook.stetho:stetho:1.5.0'
implementation 'com.android.support:multidex:1.0.3' implementation 'com.android.support:multidex:1.0.3'

View File

@@ -673,13 +673,11 @@ class EventActivity : SimpleActivity() {
private fun storeEvent(wasRepeatable: Boolean) { private fun storeEvent(wasRepeatable: Boolean) {
if (mEvent.id == 0) { if (mEvent.id == 0) {
dbHelper.insert(mEvent, true) { dbHelper.insert(mEvent, true, this) {
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().isNotEmpty()) {
notifyEvent(mEvent) notifyEvent(mEvent)
} }
} else {
toast(R.string.event_added)
} }
finish() finish()
@@ -688,8 +686,8 @@ class EventActivity : SimpleActivity() {
if (mRepeatInterval > 0 && wasRepeatable) { if (mRepeatInterval > 0 && wasRepeatable) {
EditRepeatingEventDialog(this) { EditRepeatingEventDialog(this) {
if (it) { if (it) {
dbHelper.update(mEvent, true) { dbHelper.update(mEvent, true, this) {
eventUpdated() finish()
} }
} else { } else {
dbHelper.addEventRepeatException(mEvent.id, mEventOccurrenceTS, true) dbHelper.addEventRepeatException(mEvent.id, mEventOccurrenceTS, true)
@@ -701,25 +699,19 @@ class EventActivity : SimpleActivity() {
repeatLimit = 0 repeatLimit = 0
} }
dbHelper.insert(mEvent, true) { dbHelper.insert(mEvent, true, this) {
toast(R.string.event_updated)
finish() finish()
} }
} }
} }
} else { } else {
dbHelper.update(mEvent, true) { dbHelper.update(mEvent, true, this) {
eventUpdated() finish()
} }
} }
} }
} }
private fun eventUpdated() {
toast(R.string.event_updated)
finish()
}
private fun updateStartTexts() { private fun updateStartTexts() {
updateStartDateText() updateStartDateText()
updateStartTimeText() updateStartTimeText()

View File

@@ -77,8 +77,9 @@ fun Context.scheduleAllEvents() {
} }
} }
fun Context.scheduleNextEventReminder(event: Event?, dbHelper: DBHelper) { fun Context.scheduleNextEventReminder(event: Event, dbHelper: DBHelper, activity: SimpleActivity? = null) {
if (event == null || event.getReminders().isEmpty()) { if (event.getReminders().isEmpty()) {
activity?.toast(R.string.saving)
return return
} }
@@ -89,20 +90,29 @@ fun Context.scheduleNextEventReminder(event: Event?, dbHelper: DBHelper) {
for (curEvent in it) { for (curEvent in it) {
for (curReminder in reminderSeconds) { for (curReminder in reminderSeconds) {
if (curEvent.getEventStartTS() - curReminder > now) { if (curEvent.getEventStartTS() - curReminder > now) {
scheduleEventIn((curEvent.getEventStartTS() - curReminder) * 1000L, curEvent) scheduleEventIn((curEvent.getEventStartTS() - curReminder) * 1000L, curEvent, activity)
return@getEvents 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()) { if (notifTS < System.currentTimeMillis()) {
activity?.toast(R.string.saving)
return 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 pendingIntent = getNotificationIntent(applicationContext, event)
val alarmManager = getSystemService(Context.ALARM_SERVICE) as AlarmManager val alarmManager = getSystemService(Context.ALARM_SERVICE) as AlarmManager
AlarmManagerCompat.setExactAndAllowWhileIdle(alarmManager, AlarmManager.RTC_WAKEUP, notifTS, pendingIntent) AlarmManagerCompat.setExactAndAllowWhileIdle(alarmManager, AlarmManager.RTC_WAKEUP, notifTS, pendingIntent)

View File

@@ -10,6 +10,7 @@ import android.database.sqlite.SQLiteQueryBuilder
import android.text.TextUtils import android.text.TextUtils
import android.util.SparseIntArray import android.util.SparseIntArray
import com.simplemobiletools.calendar.R import com.simplemobiletools.calendar.R
import com.simplemobiletools.calendar.activities.SimpleActivity
import com.simplemobiletools.calendar.extensions.* import com.simplemobiletools.calendar.extensions.*
import com.simplemobiletools.calendar.models.Event import com.simplemobiletools.calendar.models.Event
import com.simplemobiletools.calendar.models.EventType import com.simplemobiletools.calendar.models.EventType
@@ -200,7 +201,7 @@ class DBHelper private constructor(val context: Context) : SQLiteOpenHelper(cont
addEventType(eventType, db) 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) { if (event.startTS > event.endTS) {
callback(0) callback(0)
return return
@@ -216,7 +217,7 @@ class DBHelper private constructor(val context: Context) : SQLiteOpenHelper(cont
} }
context.updateWidgets() context.updateWidgets()
context.scheduleNextEventReminder(event, this) context.scheduleNextEventReminder(event, this, activity)
if (addToCalDAV && event.source != SOURCE_SIMPLE_CALENDAR && context.config.caldavSync) { if (addToCalDAV && event.source != SOURCE_SIMPLE_CALENDAR && context.config.caldavSync) {
CalDAVHandler(context).insertCalDAVEvent(event) 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 values = fillEventValues(event)
val selection = "$COL_ID = ?" val selection = "$COL_ID = ?"
val selectionArgs = arrayOf(event.id.toString()) val selectionArgs = arrayOf(event.id.toString())
@@ -269,7 +270,7 @@ class DBHelper private constructor(val context: Context) : SQLiteOpenHelper(cont
} }
context.updateWidgets() context.updateWidgets()
context.scheduleNextEventReminder(event, this) context.scheduleNextEventReminder(event, this, activity)
if (updateAtCalDAV && event.source != SOURCE_SIMPLE_CALENDAR && context.config.caldavSync) { if (updateAtCalDAV && event.source != SOURCE_SIMPLE_CALENDAR && context.config.caldavSync) {
CalDAVHandler(context).updateCalDAVEvent(event) CalDAVHandler(context).updateCalDAVEvent(event)
} }
@@ -548,7 +549,9 @@ class DBHelper private constructor(val context: Context) : SQLiteOpenHelper(cont
mDb.insert(EXCEPTIONS_TABLE_NAME, null, it) mDb.insert(EXCEPTIONS_TABLE_NAME, null, it)
val parentEvent = getEventWithId(parentEventId) val parentEvent = getEventWithId(parentEventId)
context.scheduleNextEventReminder(parentEvent, this) if (parentEvent != null) {
context.scheduleNextEventReminder(parentEvent, this)
}
} }
} }