diff --git a/app/src/main/kotlin/com/simplemobiletools/calendar/activities/EventActivity.kt b/app/src/main/kotlin/com/simplemobiletools/calendar/activities/EventActivity.kt index a7b606e95..dc164a652 100644 --- a/app/src/main/kotlin/com/simplemobiletools/calendar/activities/EventActivity.kt +++ b/app/src/main/kotlin/com/simplemobiletools/calendar/activities/EventActivity.kt @@ -21,7 +21,9 @@ import org.joda.time.DateTime class EventActivity : SimpleActivity(), DBHelper.EventUpdateListener { private var mWasEndDateSet = false private var mWasEndTimeSet = false - private var mReminderMinutes = 0 + private var mReminder1Minutes = 0 + private var mReminder2Minutes = 0 + private var mReminder3Minutes = 0 private var mRepeatInterval = 0 private var mRepeatLimit = 0 private var mDialogTheme = 0 @@ -44,7 +46,9 @@ class EventActivity : SimpleActivity(), DBHelper.EventUpdateListener { setupEditEvent() } else { mEvent = Event() - mReminderMinutes = config.defaultReminderMinutes + mReminder1Minutes = config.defaultReminderMinutes + mReminder2Minutes = 0 + mReminder3Minutes = 0 val startTS = intent.getIntExtra(NEW_EVENT_START_TS, 0) if (startTS == 0) return @@ -52,7 +56,9 @@ class EventActivity : SimpleActivity(), DBHelper.EventUpdateListener { setupNewEvent(Formatter.getDateTimeFromTS(startTS)) } - updateReminderText() + updateReminder1Text() + updateReminder2Text() + updateReminder3Text() updateRepetitionText() updateStartDate() updateStartTime() @@ -68,10 +74,13 @@ class EventActivity : SimpleActivity(), DBHelper.EventUpdateListener { event_end_time.setOnClickListener { setupEndTime() } event_all_day.setOnCheckedChangeListener { compoundButton, isChecked -> toggleAllDay(isChecked) } - event_reminder.setOnClickListener { showReminderDialog() } event_repetition.setOnClickListener { showRepeatIntervalDialog() } event_repetition_limit.setOnClickListener { showRepetitionLimitDialog() } + event_reminder_1.setOnClickListener { showReminder1Dialog() } + event_reminder_2.setOnClickListener { showReminder2Dialog() } + event_reminder_3.setOnClickListener { showReminder3Dialog() } + if (mEvent.flags and FLAG_ALL_DAY != 0) event_all_day.toggle() @@ -86,7 +95,9 @@ class EventActivity : SimpleActivity(), DBHelper.EventUpdateListener { mEventEndDateTime = Formatter.getDateTimeFromTS(mEvent.endTS) event_title.setText(mEvent.title) event_description.setText(mEvent.description) - mReminderMinutes = mEvent.reminderMinutes + mReminder1Minutes = mEvent.reminder1Minutes + mReminder2Minutes = mEvent.reminder2Minutes + mReminder3Minutes = mEvent.reminder3Minutes mRepeatInterval = mEvent.repeatInterval mRepeatLimit = mEvent.repeatLimit checkRepeatLimit(mRepeatInterval) @@ -99,10 +110,24 @@ class EventActivity : SimpleActivity(), DBHelper.EventUpdateListener { mEventEndDateTime = mEventStartDateTime.plusHours(1) } - private fun showReminderDialog() { - EventReminderDialog(this, mReminderMinutes) { - mReminderMinutes = it - updateReminderText() + private fun showReminder1Dialog() { + EventReminderDialog(this, mReminder1Minutes) { + mReminder1Minutes = it + updateReminder1Text() + } + } + + private fun showReminder2Dialog() { + EventReminderDialog(this, mReminder2Minutes) { + mReminder2Minutes = it + updateReminder2Text() + } + } + + private fun showReminder3Dialog() { + EventReminderDialog(this, mReminder3Minutes) { + mReminder3Minutes = it + updateReminder3Text() } } @@ -146,8 +171,16 @@ class EventActivity : SimpleActivity(), DBHelper.EventUpdateListener { } } - private fun updateReminderText() { - event_reminder.text = getReminderText(mReminderMinutes) + private fun updateReminder1Text() { + event_reminder_1.text = getReminderText(mReminder1Minutes) + } + + private fun updateReminder2Text() { + event_reminder_2.text = getReminderText(mReminder2Minutes) + } + + private fun updateReminder3Text() { + event_reminder_2.text = getReminderText(mReminder3Minutes) } private fun updateRepetitionText() { @@ -216,7 +249,9 @@ class EventActivity : SimpleActivity(), DBHelper.EventUpdateListener { endTS = newEndTS title = newTitle description = newDescription - reminderMinutes = mReminderMinutes + reminder1Minutes = mReminder1Minutes + reminder2Minutes = mReminder2Minutes + reminder3Minutes = mReminder3Minutes repeatInterval = mRepeatInterval flags = if (event_all_day.isChecked) (mEvent.flags or FLAG_ALL_DAY) else (mEvent.flags.removeFlag(FLAG_ALL_DAY)) repeatLimit = if (repeatInterval == 0) 0 else mRepeatLimit diff --git a/app/src/main/kotlin/com/simplemobiletools/calendar/extensions/Context.kt b/app/src/main/kotlin/com/simplemobiletools/calendar/extensions/Context.kt index aabcee3ba..572bc9b05 100644 --- a/app/src/main/kotlin/com/simplemobiletools/calendar/extensions/Context.kt +++ b/app/src/main/kotlin/com/simplemobiletools/calendar/extensions/Context.kt @@ -42,7 +42,7 @@ fun Context.updateListWidget() { } fun Context.scheduleNextEvent(event: Event) { - var startTS = event.startTS - event.reminderMinutes * 60 + var startTS = event.startTS - event.reminder1Minutes * 60 var newTS = startTS if (event.repeatInterval == DAY || event.repeatInterval == WEEK || event.repeatInterval == BIWEEK) { while (startTS < System.currentTimeMillis() / 1000 + 5) { @@ -68,7 +68,7 @@ private fun getNewTS(ts: Int, isMonthly: Boolean): Int { } fun Context.scheduleNotification(event: Event) { - if (event.reminderMinutes == REMINDER_OFF) + if (event.reminder1Minutes == REMINDER_OFF && event.reminder2Minutes == REMINDER_OFF && event.reminder3Minutes == REMINDER_OFF) return scheduleNextEvent(event) diff --git a/app/src/main/kotlin/com/simplemobiletools/calendar/helpers/DBHelper.kt b/app/src/main/kotlin/com/simplemobiletools/calendar/helpers/DBHelper.kt index 46fded574..43b17d114 100644 --- a/app/src/main/kotlin/com/simplemobiletools/calendar/helpers/DBHelper.kt +++ b/app/src/main/kotlin/com/simplemobiletools/calendar/helpers/DBHelper.kt @@ -23,6 +23,8 @@ class DBHelper(context: Context) : SQLiteOpenHelper(context, DB_NAME, null, DB_V private val COL_TITLE = "title" private val COL_DESCRIPTION = "description" private val COL_REMINDER_MINUTES = "reminder_minutes" + private val COL_REMINDER_MINUTES_2 = "reminder_minutes_2" + private val COL_REMINDER_MINUTES_3 = "reminder_minutes_3" private val COL_IMPORT_ID = "import_id" private val COL_FLAGS = "flags" @@ -39,7 +41,7 @@ class DBHelper(context: Context) : SQLiteOpenHelper(context, DB_NAME, null, DB_V companion object { private val DB_NAME = "events.db" - private val DB_VERSION = 5 + private val DB_VERSION = 6 lateinit private var mDb: SQLiteDatabase } @@ -54,7 +56,8 @@ class DBHelper(context: Context) : SQLiteOpenHelper(context, DB_NAME, null, DB_V override fun onCreate(db: SQLiteDatabase) { db.execSQL("CREATE TABLE $MAIN_TABLE_NAME ($COL_ID INTEGER PRIMARY KEY, $COL_START_TS INTEGER, $COL_END_TS INTEGER, $COL_TITLE TEXT, " + - "$COL_DESCRIPTION TEXT, $COL_REMINDER_MINUTES INTEGER, $COL_IMPORT_ID TEXT, $COL_FLAGS INTEGER)") + "$COL_DESCRIPTION TEXT, $COL_REMINDER_MINUTES INTEGER, $COL_REMINDER_MINUTES_2 INTEGER, $COL_REMINDER_MINUTES_3 INTEGER, " + + "$COL_IMPORT_ID TEXT, $COL_FLAGS INTEGER)") createMetaTable(db) } @@ -76,6 +79,11 @@ class DBHelper(context: Context) : SQLiteOpenHelper(context, DB_NAME, null, DB_V db.execSQL("ALTER TABLE $MAIN_TABLE_NAME ADD COLUMN $COL_FLAGS INTEGER NOT NULL DEFAULT 0") db.execSQL("ALTER TABLE $META_TABLE_NAME ADD COLUMN $COL_REPEAT_LIMIT INTEGER NOT NULL DEFAULT 0") } + + if (oldVersion < 6) { + db.execSQL("ALTER TABLE $MAIN_TABLE_NAME ADD COLUMN $COL_REMINDER_MINUTES_2 INTEGER NOT NULL DEFAULT -1") + db.execSQL("ALTER TABLE $MAIN_TABLE_NAME ADD COLUMN $COL_REMINDER_MINUTES_3 INTEGER NOT NULL DEFAULT -1") + } } private fun createMetaTable(db: SQLiteDatabase) { @@ -125,7 +133,9 @@ class DBHelper(context: Context) : SQLiteOpenHelper(context, DB_NAME, null, DB_V put(COL_END_TS, event.endTS) put(COL_TITLE, event.title) put(COL_DESCRIPTION, event.description) - put(COL_REMINDER_MINUTES, event.reminderMinutes) + put(COL_REMINDER_MINUTES, event.reminder1Minutes) + put(COL_REMINDER_MINUTES_2, event.reminder2Minutes) + put(COL_REMINDER_MINUTES_3, event.reminder3Minutes) put(COL_IMPORT_ID, event.importId) put(COL_FLAGS, event.flags) } @@ -220,7 +230,8 @@ class DBHelper(context: Context) : SQLiteOpenHelper(context, DB_NAME, null, DB_V for (e in events) { while (e.startTS < toTS && (e.repeatLimit == 0 || e.repeatLimit > e.endTS)) { if (e.startTS > fromTS) { - val newEvent = Event(e.id, e.startTS, e.endTS, e.title, e.description, e.reminderMinutes, e.repeatInterval, e.importId, e.flags) + val newEvent = Event(e.id, e.startTS, e.endTS, e.title, e.description, e.reminder1Minutes, e.reminder2Minutes, e.reminder3Minutes, + e.repeatInterval, e.importId, e.flags) newEvents.add(newEvent) } e.addIntervalTime() @@ -261,8 +272,8 @@ class DBHelper(context: Context) : SQLiteOpenHelper(context, DB_NAME, null, DB_V } private val allColumns: Array - get() = arrayOf("$MAIN_TABLE_NAME.$COL_ID", COL_START_TS, COL_END_TS, COL_TITLE, COL_DESCRIPTION, COL_REMINDER_MINUTES, COL_REPEAT_INTERVAL, - COL_REPEAT_MONTH, COL_REPEAT_DAY, COL_IMPORT_ID, COL_FLAGS, COL_REPEAT_LIMIT) + get() = arrayOf("$MAIN_TABLE_NAME.$COL_ID", COL_START_TS, COL_END_TS, COL_TITLE, COL_DESCRIPTION, COL_REMINDER_MINUTES, COL_REMINDER_MINUTES_2, + COL_REMINDER_MINUTES_3, COL_REPEAT_INTERVAL, COL_REPEAT_MONTH, COL_REPEAT_DAY, COL_IMPORT_ID, COL_FLAGS, COL_REPEAT_LIMIT) private fun fillEvents(cursor: Cursor?): List { val events = ArrayList() @@ -272,14 +283,17 @@ class DBHelper(context: Context) : SQLiteOpenHelper(context, DB_NAME, null, DB_V val id = cursor.getIntValue(COL_ID) val startTS = cursor.getIntValue(COL_START_TS) val endTS = cursor.getIntValue(COL_END_TS) - val reminderMinutes = cursor.getIntValue(COL_REMINDER_MINUTES) + val reminder1Minutes = cursor.getIntValue(COL_REMINDER_MINUTES) + val reminder2Minutes = cursor.getIntValue(COL_REMINDER_MINUTES_2) + val reminder3Minutes = cursor.getIntValue(COL_REMINDER_MINUTES_3) val repeatInterval = cursor.getIntValue(COL_REPEAT_INTERVAL) val title = cursor.getStringValue(COL_TITLE) val description = cursor.getStringValue(COL_DESCRIPTION) val importId = cursor.getStringValue(COL_IMPORT_ID) val flags = cursor.getIntValue(COL_FLAGS) val repeatLimit = cursor.getIntValue(COL_REPEAT_LIMIT) - events.add(Event(id, startTS, endTS, title, description, reminderMinutes, repeatInterval, importId, flags, repeatLimit)) + events.add(Event(id, startTS, endTS, title, description, reminder1Minutes, reminder2Minutes, reminder3Minutes, + repeatInterval, importId, flags, repeatLimit)) } while (cursor.moveToNext()) } } finally { diff --git a/app/src/main/kotlin/com/simplemobiletools/calendar/helpers/IcsParser.kt b/app/src/main/kotlin/com/simplemobiletools/calendar/helpers/IcsParser.kt index ddc426903..161da002c 100644 --- a/app/src/main/kotlin/com/simplemobiletools/calendar/helpers/IcsParser.kt +++ b/app/src/main/kotlin/com/simplemobiletools/calendar/helpers/IcsParser.kt @@ -58,7 +58,7 @@ class IcsParser { if (curTitle.isEmpty() || curStart == -1 || curEnd == -1 || importIDs.contains(curImportId)) continue - val event = Event(0, curStart, curEnd, curTitle, curDescription, reminderMinutes, importId = curImportId, flags = curFlags) + val event = Event(0, curStart, curEnd, curTitle, curDescription, reminderMinutes, -1, -1, importId = curImportId, flags = curFlags) dbHelper.insert(event) { context.scheduleNotification(event) } diff --git a/app/src/main/kotlin/com/simplemobiletools/calendar/models/Event.kt b/app/src/main/kotlin/com/simplemobiletools/calendar/models/Event.kt index f54b90f90..5396cc059 100644 --- a/app/src/main/kotlin/com/simplemobiletools/calendar/models/Event.kt +++ b/app/src/main/kotlin/com/simplemobiletools/calendar/models/Event.kt @@ -6,8 +6,8 @@ import org.joda.time.DateTime import java.io.Serializable data class Event(var id: Int = 0, var startTS: Int = 0, var endTS: Int = 0, var title: String = "", var description: String = "", - var reminderMinutes: Int = 0, var repeatInterval: Int = 0, var importId: String? = "", var flags: Int = 0, - var repeatLimit: Int = 0) : Serializable { + var reminder1Minutes: Int = -1, var reminder2Minutes: Int = -1, var reminder3Minutes: Int = -1, var repeatInterval: Int = 0, + var importId: String? = "", var flags: Int = 0, var repeatLimit: Int = 0) : Serializable { companion object { private val serialVersionUID = -32456795132344616L diff --git a/app/src/main/kotlin/com/simplemobiletools/calendar/receivers/NotificationReceiver.kt b/app/src/main/kotlin/com/simplemobiletools/calendar/receivers/NotificationReceiver.kt index f4ee99ba2..f5418a06d 100644 --- a/app/src/main/kotlin/com/simplemobiletools/calendar/receivers/NotificationReceiver.kt +++ b/app/src/main/kotlin/com/simplemobiletools/calendar/receivers/NotificationReceiver.kt @@ -15,6 +15,7 @@ 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() { @@ -26,7 +27,7 @@ class NotificationReceiver : BroadcastReceiver() { return val event = DBHelper(context).getEvent(id) - if (event == null || event.reminderMinutes == -1) + if (event == null || (event.reminder1Minutes == REMINDER_OFF && event.reminder2Minutes == REMINDER_OFF && event.reminder3Minutes == REMINDER_OFF)) return val pendingIntent = getPendingIntent(context, event) diff --git a/app/src/main/res/layout/activity_event.xml b/app/src/main/res/layout/activity_event.xml index 02d2fb029..794fbe41a 100644 --- a/app/src/main/res/layout/activity_event.xml +++ b/app/src/main/res/layout/activity_event.xml @@ -9,7 +9,8 @@ + android:layout_height="wrap_content" + android:paddingBottom="@dimen/medium_margin"> + + + +