add some more things related to max repetition limit
This commit is contained in:
parent
e34efa0db5
commit
08ed97f4d6
|
@ -23,6 +23,7 @@ class EventActivity : SimpleActivity(), DBHelper.EventUpdateListener {
|
|||
private var mWasEndTimeSet = false
|
||||
private var mReminderMinutes = 0
|
||||
private var mRepeatInterval = 0
|
||||
private var mRepeatLimit = 0
|
||||
private var mDialogTheme = 0
|
||||
|
||||
lateinit var mEventStartDateTime: DateTime
|
||||
|
@ -87,6 +88,8 @@ class EventActivity : SimpleActivity(), DBHelper.EventUpdateListener {
|
|||
event_description.setText(mEvent.description)
|
||||
mReminderMinutes = mEvent.reminderMinutes
|
||||
mRepeatInterval = mEvent.repeatInterval
|
||||
mRepeatLimit = mEvent.repeatLimit
|
||||
checkRepeatLimitVisibility(mRepeatLimit)
|
||||
}
|
||||
|
||||
private fun setupNewEvent(dateTime: DateTime) {
|
||||
|
@ -107,13 +110,26 @@ class EventActivity : SimpleActivity(), DBHelper.EventUpdateListener {
|
|||
EventRepeatIntervalDialog(this, mRepeatInterval) {
|
||||
mRepeatInterval = it
|
||||
updateRepetitionText()
|
||||
event_repetition_limit.beGoneIf(it == 0)
|
||||
event_repetition_limit_label.beGoneIf(it == 0)
|
||||
checkRepeatLimitVisibility(it)
|
||||
}
|
||||
}
|
||||
|
||||
private fun showRepetitionLimitDialog() {
|
||||
private fun checkRepeatLimitVisibility(limit: Int) {
|
||||
event_repetition_limit.beGoneIf(limit == 0)
|
||||
event_repetition_limit_label.beGoneIf(limit == 0)
|
||||
}
|
||||
|
||||
private fun showRepetitionLimitDialog() {
|
||||
val now = (System.currentTimeMillis() / 1000).toInt()
|
||||
val repeatLimitDateTime = Formatter.getDateTimeFromTS(if (mRepeatLimit != 0) mRepeatLimit else now)
|
||||
DatePickerDialog(this, mDialogTheme, repetitionLimitDateSetListener, repeatLimitDateTime.year, repeatLimitDateTime.monthOfYear - 1,
|
||||
repeatLimitDateTime.dayOfMonth).show()
|
||||
}
|
||||
|
||||
private val repetitionLimitDateSetListener = DatePickerDialog.OnDateSetListener { view, year, monthOfYear, dayOfMonth ->
|
||||
val repeatLimitDateTime = DateTime().withDate(year, monthOfYear + 1, dayOfMonth).withTime(0, 0, 0, 0)
|
||||
event_repetition_limit.text = Formatter.getDate(applicationContext, repeatLimitDateTime, false)
|
||||
mRepeatLimit = repeatLimitDateTime.seconds()
|
||||
}
|
||||
|
||||
private fun updateReminderText() {
|
||||
|
@ -189,6 +205,7 @@ class EventActivity : SimpleActivity(), DBHelper.EventUpdateListener {
|
|||
reminderMinutes = mReminderMinutes
|
||||
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
|
||||
}
|
||||
|
||||
if (mEvent.id == 0) {
|
||||
|
|
|
@ -32,6 +32,7 @@ class DBHelper(context: Context) : SQLiteOpenHelper(context, DB_NAME, null, DB_V
|
|||
private val COL_REPEAT_INTERVAL = "repeat_interval"
|
||||
private val COL_REPEAT_MONTH = "repeat_month"
|
||||
private val COL_REPEAT_DAY = "repeat_day"
|
||||
private val COL_REPEAT_LIMIT = "repeat_limit"
|
||||
|
||||
private var mEventsListener: EventUpdateListener? = null
|
||||
private var context: Context? = null
|
||||
|
@ -73,12 +74,13 @@ class DBHelper(context: Context) : SQLiteOpenHelper(context, DB_NAME, null, DB_V
|
|||
|
||||
if (oldVersion < 5) {
|
||||
db.execSQL("ALTER TABLE $MAIN_TABLE_NAME ADD COLUMN $COL_FLAGS INTEGER")
|
||||
db.execSQL("ALTER TABLE $META_TABLE_NAME ADD COLUMN $COL_REPEAT_LIMIT INTEGER")
|
||||
}
|
||||
}
|
||||
|
||||
private fun createMetaTable(db: SQLiteDatabase) {
|
||||
db.execSQL("CREATE TABLE $META_TABLE_NAME ($COL_ID INTEGER PRIMARY KEY, $COL_EVENT_ID INTEGER UNIQUE, $COL_REPEAT_START INTEGER, " +
|
||||
"$COL_REPEAT_INTERVAL INTEGER, $COL_REPEAT_MONTH INTEGER, $COL_REPEAT_DAY INTEGER)")
|
||||
"$COL_REPEAT_INTERVAL INTEGER, $COL_REPEAT_MONTH INTEGER, $COL_REPEAT_DAY INTEGER, $COL_REPEAT_LIMIT INTEGER)")
|
||||
}
|
||||
|
||||
fun insert(event: Event, insertListener: (event: Event) -> Unit) {
|
||||
|
@ -137,6 +139,7 @@ class DBHelper(context: Context) : SQLiteOpenHelper(context, DB_NAME, null, DB_V
|
|||
put(COL_EVENT_ID, event.id)
|
||||
put(COL_REPEAT_START, event.startTS)
|
||||
put(COL_REPEAT_INTERVAL, repeatInterval)
|
||||
put(COL_REPEAT_LIMIT, event.repeatLimit)
|
||||
|
||||
if (repeatInterval == MONTH || repeatInterval == YEAR) {
|
||||
put(COL_REPEAT_DAY, dateTime.dayOfMonth)
|
||||
|
@ -259,7 +262,7 @@ class DBHelper(context: Context) : SQLiteOpenHelper(context, DB_NAME, null, DB_V
|
|||
|
||||
private val allColumns: Array<String>
|
||||
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_MONTH, COL_REPEAT_DAY, COL_IMPORT_ID, COL_FLAGS, COL_REPEAT_LIMIT)
|
||||
|
||||
private fun fillEvents(cursor: Cursor?): List<Event> {
|
||||
val events = ArrayList<Event>()
|
||||
|
@ -275,7 +278,8 @@ class DBHelper(context: Context) : SQLiteOpenHelper(context, DB_NAME, null, DB_V
|
|||
val description = cursor.getStringValue(COL_DESCRIPTION)
|
||||
val importId = cursor.getStringValue(COL_IMPORT_ID)
|
||||
val flags = cursor.getIntValue(COL_FLAGS)
|
||||
events.add(Event(id, startTS, endTS, title, description, reminderMinutes, repeatInterval, importId, flags))
|
||||
val repeatLimit = cursor.getIntValue(COL_REPEAT_LIMIT)
|
||||
events.add(Event(id, startTS, endTS, title, description, reminderMinutes, repeatInterval, importId, flags, repeatLimit))
|
||||
} while (cursor.moveToNext())
|
||||
}
|
||||
} finally {
|
||||
|
|
|
@ -30,14 +30,17 @@ object Formatter {
|
|||
return date
|
||||
}
|
||||
|
||||
fun getDayTitle(context: Context, dayCode: String): String {
|
||||
fun getDayTitle(context: Context, dayCode: String, addDayOfWeek: Boolean = true): String {
|
||||
val date = getDateFromCode(context, dayCode)
|
||||
val dateTime = getDateTimeFromCode(dayCode)
|
||||
val day = dateTime.toString(DAY_OF_WEEK_PATTERN)
|
||||
return "$date ($day)"
|
||||
return if (addDayOfWeek)
|
||||
"$date ($day)"
|
||||
else
|
||||
date
|
||||
}
|
||||
|
||||
fun getDate(context: Context, dateTime: DateTime) = getDayTitle(context, getDayCodeFromDateTime(dateTime))
|
||||
fun getDate(context: Context, dateTime: DateTime, addDayOfWeek: Boolean = true) = getDayTitle(context, getDayCodeFromDateTime(dateTime), addDayOfWeek)
|
||||
|
||||
fun getTime(context: Context, dateTime: DateTime) = dateTime.toString(getTimePattern(context))
|
||||
|
||||
|
|
|
@ -6,7 +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) : Serializable {
|
||||
var reminderMinutes: Int = 0, var repeatInterval: Int = 0, var importId: String = "", var flags: Int = 0,
|
||||
var repeatLimit: Int = 0) : Serializable {
|
||||
|
||||
companion object {
|
||||
private val serialVersionUID = -32456795132344616L
|
||||
|
|
Loading…
Reference in New Issue