mirror of
https://github.com/SimpleMobileTools/Simple-Calendar.git
synced 2025-02-18 20:50:40 +01:00
replace repeat_day and repeat_month with repeat_rule
This commit is contained in:
parent
449432cc75
commit
7a17bce90f
@ -25,6 +25,7 @@ class EventActivity : SimpleActivity(), DBHelper.EventUpdateListener {
|
|||||||
private var mReminder3Minutes = 0
|
private var mReminder3Minutes = 0
|
||||||
private var mRepeatInterval = 0
|
private var mRepeatInterval = 0
|
||||||
private var mRepeatLimit = 0
|
private var mRepeatLimit = 0
|
||||||
|
private var mRepeatRule = 0
|
||||||
private var mEventTypeId = DBHelper.REGULAR_EVENT_TYPE_ID
|
private var mEventTypeId = DBHelper.REGULAR_EVENT_TYPE_ID
|
||||||
private var mDialogTheme = 0
|
private var mDialogTheme = 0
|
||||||
private var mEventOccurrenceTS = 0
|
private var mEventOccurrenceTS = 0
|
||||||
@ -104,6 +105,7 @@ class EventActivity : SimpleActivity(), DBHelper.EventUpdateListener {
|
|||||||
mReminder3Minutes = mEvent.reminder3Minutes
|
mReminder3Minutes = mEvent.reminder3Minutes
|
||||||
mRepeatInterval = mEvent.repeatInterval
|
mRepeatInterval = mEvent.repeatInterval
|
||||||
mRepeatLimit = mEvent.repeatLimit
|
mRepeatLimit = mEvent.repeatLimit
|
||||||
|
mRepeatRule = mEvent.repeatRule
|
||||||
mEventTypeId = mEvent.eventType
|
mEventTypeId = mEvent.eventType
|
||||||
checkRepeatLimit(mRepeatInterval)
|
checkRepeatLimit(mRepeatInterval)
|
||||||
}
|
}
|
||||||
@ -151,6 +153,7 @@ class EventActivity : SimpleActivity(), DBHelper.EventUpdateListener {
|
|||||||
checkRepetitionLimitText()
|
checkRepetitionLimitText()
|
||||||
|
|
||||||
event_repetition_rule_holder.beGoneIf(mRepeatInterval != DAY && mRepeatInterval != MONTH)
|
event_repetition_rule_holder.beGoneIf(mRepeatInterval != DAY && mRepeatInterval != MONTH)
|
||||||
|
checkRepetitionRuleText()
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun showRepetitionLimitDialog() {
|
private fun showRepetitionLimitDialog() {
|
||||||
@ -183,6 +186,10 @@ class EventActivity : SimpleActivity(), DBHelper.EventUpdateListener {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private fun checkRepetitionRuleText() {
|
||||||
|
event_repetition_rule.text = ""
|
||||||
|
}
|
||||||
|
|
||||||
private fun showEventTypeDialog() {
|
private fun showEventTypeDialog() {
|
||||||
SelectEventTypeDialog(this, mEventTypeId) {
|
SelectEventTypeDialog(this, mEventTypeId) {
|
||||||
mEventTypeId = it
|
mEventTypeId = it
|
||||||
@ -304,6 +311,7 @@ class EventActivity : SimpleActivity(), DBHelper.EventUpdateListener {
|
|||||||
repeatInterval = mRepeatInterval
|
repeatInterval = mRepeatInterval
|
||||||
flags = if (event_all_day.isChecked) (mEvent.flags or FLAG_ALL_DAY) else (mEvent.flags.removeFlag(FLAG_ALL_DAY))
|
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
|
repeatLimit = if (repeatInterval == 0) 0 else mRepeatLimit
|
||||||
|
repeatRule = mRepeatRule
|
||||||
eventType = mEventTypeId
|
eventType = mEventTypeId
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -54,6 +54,12 @@ val THURSDAY = 8
|
|||||||
val FRIDAY = 16
|
val FRIDAY = 16
|
||||||
val SATURDAY = 32
|
val SATURDAY = 32
|
||||||
val SUNDAY = 64
|
val SUNDAY = 64
|
||||||
|
val ALL_DAYS = 127
|
||||||
|
|
||||||
|
// repeat_rule for monthly repetition
|
||||||
|
val REPEAT_MONTH_SAME_DAY = 1
|
||||||
|
val REPEAT_MONTH_LAST_DAY = 2
|
||||||
|
val REPEAT_MONTH_EVERY_X = 3
|
||||||
|
|
||||||
// special event flags
|
// special event flags
|
||||||
val FLAG_ALL_DAY = 1
|
val FLAG_ALL_DAY = 1
|
||||||
|
@ -38,8 +38,7 @@ class DBHelper private constructor(val context: Context) : SQLiteOpenHelper(cont
|
|||||||
private val COL_EVENT_ID = "event_id"
|
private val COL_EVENT_ID = "event_id"
|
||||||
private val COL_REPEAT_START = "repeat_start"
|
private val COL_REPEAT_START = "repeat_start"
|
||||||
private val COL_REPEAT_INTERVAL = "repeat_interval"
|
private val COL_REPEAT_INTERVAL = "repeat_interval"
|
||||||
private val COL_REPEAT_MONTH = "repeat_month"
|
private val COL_REPEAT_RULE = "repeat_rule"
|
||||||
private val COL_REPEAT_DAY = "repeat_day"
|
|
||||||
private val COL_REPEAT_LIMIT = "repeat_limit"
|
private val COL_REPEAT_LIMIT = "repeat_limit"
|
||||||
|
|
||||||
private val TYPES_TABLE_NAME = "event_types"
|
private val TYPES_TABLE_NAME = "event_types"
|
||||||
@ -56,7 +55,7 @@ class DBHelper private constructor(val context: Context) : SQLiteOpenHelper(cont
|
|||||||
private val mDb: SQLiteDatabase = writableDatabase
|
private val mDb: SQLiteDatabase = writableDatabase
|
||||||
|
|
||||||
companion object {
|
companion object {
|
||||||
private val DB_VERSION = 10
|
private val DB_VERSION = 11
|
||||||
val DB_NAME = "events.db"
|
val DB_NAME = "events.db"
|
||||||
val REGULAR_EVENT_TYPE_ID = 1
|
val REGULAR_EVENT_TYPE_ID = 1
|
||||||
|
|
||||||
@ -119,11 +118,16 @@ class DBHelper private constructor(val context: Context) : SQLiteOpenHelper(cont
|
|||||||
}
|
}
|
||||||
convertExceptionTimestampToDaycode(db)
|
convertExceptionTimestampToDaycode(db)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (oldVersion < 11) {
|
||||||
|
db.execSQL("ALTER TABLE $META_TABLE_NAME ADD COLUMN $COL_REPEAT_RULE INTEGER NOT NULL DEFAULT 0")
|
||||||
|
setupRepeatRules(db)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun createMetaTable(db: SQLiteDatabase) {
|
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, " +
|
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_LIMIT INTEGER)")
|
"$COL_REPEAT_INTERVAL INTEGER, $COL_REPEAT_LIMIT INTEGER, $COL_REPEAT_RULE INTEGER)")
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun createTypesTable(db: SQLiteDatabase) {
|
private fun createTypesTable(db: SQLiteDatabase) {
|
||||||
@ -202,7 +206,7 @@ class DBHelper private constructor(val context: Context) : SQLiteOpenHelper(cont
|
|||||||
put(COL_REPEAT_START, event.startTS)
|
put(COL_REPEAT_START, event.startTS)
|
||||||
put(COL_REPEAT_INTERVAL, event.repeatInterval)
|
put(COL_REPEAT_INTERVAL, event.repeatInterval)
|
||||||
put(COL_REPEAT_LIMIT, event.repeatLimit)
|
put(COL_REPEAT_LIMIT, event.repeatLimit)
|
||||||
put(COL_REPEAT_DAY, event.repeatDay)
|
put(COL_REPEAT_RULE, event.repeatRule)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -468,7 +472,7 @@ class DBHelper private constructor(val context: Context) : SQLiteOpenHelper(cont
|
|||||||
|
|
||||||
private val allColumns: Array<String>
|
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_REMINDER_MINUTES_2,
|
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, COL_EVENT_TYPE)
|
COL_REMINDER_MINUTES_3, COL_REPEAT_INTERVAL, COL_IMPORT_ID, COL_FLAGS, COL_REPEAT_LIMIT, COL_EVENT_TYPE)
|
||||||
|
|
||||||
private fun fillEvents(cursor: Cursor?): List<Event> {
|
private fun fillEvents(cursor: Cursor?): List<Event> {
|
||||||
val events = ArrayList<Event>()
|
val events = ArrayList<Event>()
|
||||||
@ -482,7 +486,7 @@ class DBHelper private constructor(val context: Context) : SQLiteOpenHelper(cont
|
|||||||
val reminder2Minutes = cursor.getIntValue(COL_REMINDER_MINUTES_2)
|
val reminder2Minutes = cursor.getIntValue(COL_REMINDER_MINUTES_2)
|
||||||
val reminder3Minutes = cursor.getIntValue(COL_REMINDER_MINUTES_3)
|
val reminder3Minutes = cursor.getIntValue(COL_REMINDER_MINUTES_3)
|
||||||
val repeatInterval = cursor.getIntValue(COL_REPEAT_INTERVAL)
|
val repeatInterval = cursor.getIntValue(COL_REPEAT_INTERVAL)
|
||||||
val repeatDay = cursor.getIntValue(COL_REPEAT_DAY)
|
val repeatRule = cursor.getIntValue(COL_REPEAT_RULE)
|
||||||
val title = cursor.getStringValue(COL_TITLE)
|
val title = cursor.getStringValue(COL_TITLE)
|
||||||
val description = cursor.getStringValue(COL_DESCRIPTION)
|
val description = cursor.getStringValue(COL_DESCRIPTION)
|
||||||
val importId = cursor.getStringValue(COL_IMPORT_ID)
|
val importId = cursor.getStringValue(COL_IMPORT_ID)
|
||||||
@ -499,7 +503,7 @@ class DBHelper private constructor(val context: Context) : SQLiteOpenHelper(cont
|
|||||||
}
|
}
|
||||||
|
|
||||||
val event = Event(id, startTS, endTS, title, description, reminder1Minutes, reminder2Minutes, reminder3Minutes,
|
val event = Event(id, startTS, endTS, title, description, reminder1Minutes, reminder2Minutes, reminder3Minutes,
|
||||||
repeatInterval, importId, flags, repeatLimit, repeatDay, eventType, ignoreEventOccurrences)
|
repeatInterval, importId, flags, repeatLimit, repeatRule, eventType, ignoreEventOccurrences)
|
||||||
events.add(event)
|
events.add(event)
|
||||||
} while (cursor.moveToNext())
|
} while (cursor.moveToNext())
|
||||||
}
|
}
|
||||||
@ -578,6 +582,34 @@ class DBHelper private constructor(val context: Context) : SQLiteOpenHelper(cont
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private fun setupRepeatRules(db: SQLiteDatabase) {
|
||||||
|
val projection = arrayOf(COL_EVENT_ID, COL_REPEAT_INTERVAL)
|
||||||
|
val selection = "$COL_REPEAT_INTERVAL = ? OR $COL_REPEAT_INTERVAL = ?"
|
||||||
|
val selectionArgs = arrayOf(DAY.toString(), MONTH.toString())
|
||||||
|
var cursor: Cursor? = null
|
||||||
|
try {
|
||||||
|
cursor = db.query(META_TABLE_NAME, projection, selection, selectionArgs, null, null, null)
|
||||||
|
if (cursor?.moveToFirst() == true) {
|
||||||
|
do {
|
||||||
|
val eventId = cursor.getIntValue(COL_EVENT_ID)
|
||||||
|
val interval = cursor.getIntValue(COL_REPEAT_INTERVAL)
|
||||||
|
var rule = ALL_DAYS
|
||||||
|
if (interval == MONTH) {
|
||||||
|
rule = REPEAT_MONTH_SAME_DAY
|
||||||
|
}
|
||||||
|
|
||||||
|
val values = ContentValues()
|
||||||
|
values.put(COL_REPEAT_RULE, rule)
|
||||||
|
val curSelection = "$COL_EVENT_ID = ?"
|
||||||
|
val curSelectionArgs = arrayOf(eventId.toString())
|
||||||
|
db.update(META_TABLE_NAME, values, curSelection, curSelectionArgs)
|
||||||
|
} while (cursor.moveToNext())
|
||||||
|
}
|
||||||
|
} finally {
|
||||||
|
cursor?.close()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
interface EventUpdateListener {
|
interface EventUpdateListener {
|
||||||
fun eventInserted(event: Event)
|
fun eventInserted(event: Event)
|
||||||
|
|
||||||
|
@ -9,7 +9,7 @@ import java.util.*
|
|||||||
|
|
||||||
data class Event(var id: Int = 0, var startTS: Int = 0, var endTS: Int = 0, var title: String = "", var description: String = "",
|
data class Event(var id: Int = 0, var startTS: Int = 0, var endTS: Int = 0, var title: String = "", var description: String = "",
|
||||||
var reminder1Minutes: Int = -1, var reminder2Minutes: Int = -1, var reminder3Minutes: Int = -1, var repeatInterval: Int = 0,
|
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, var repeatDay: Int = 0,
|
var importId: String? = "", var flags: Int = 0, var repeatLimit: Int = 0, var repeatRule: Int = 0,
|
||||||
var eventType: Int = DBHelper.REGULAR_EVENT_TYPE_ID, var ignoreEventOccurrences: ArrayList<Int> = ArrayList()) : Serializable {
|
var eventType: Int = DBHelper.REGULAR_EVENT_TYPE_ID, var ignoreEventOccurrences: ArrayList<Int> = ArrayList()) : Serializable {
|
||||||
|
|
||||||
companion object {
|
companion object {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user