add event type to event model

This commit is contained in:
tibbi 2017-02-11 20:08:06 +01:00
parent 951a03ec7c
commit 80f38ddcb9
4 changed files with 52 additions and 9 deletions

View File

@ -65,6 +65,7 @@ class EventActivity : SimpleActivity(), DBHelper.EventUpdateListener {
updateStartTime()
updateEndDate()
updateEndTime()
updateEventType()
mWasEndDateSet = event != null
mWasEndTimeSet = event != null
@ -82,6 +83,8 @@ class EventActivity : SimpleActivity(), DBHelper.EventUpdateListener {
event_reminder_2.setOnClickListener { showReminder2Dialog() }
event_reminder_3.setOnClickListener { showReminder3Dialog() }
event_type.setOnClickListener { }
if (mEvent.flags and FLAG_ALL_DAY != 0)
event_all_day.toggle()
@ -219,6 +222,10 @@ class EventActivity : SimpleActivity(), DBHelper.EventUpdateListener {
event_repetition.text = getRepetitionToString(mRepeatInterval)
}
private fun updateEventType() {
}
private fun getRepetitionToString(seconds: Int) = getString(when (seconds) {
DAY -> R.string.daily
WEEK -> R.string.weekly
@ -380,6 +387,7 @@ class EventActivity : SimpleActivity(), DBHelper.EventUpdateListener {
event_time_image.setColorFilter(config.textColor, PorterDuff.Mode.SRC_IN)
event_repetition_image.setColorFilter(config.textColor, PorterDuff.Mode.SRC_IN)
event_reminder_image.setColorFilter(config.textColor, PorterDuff.Mode.SRC_IN)
event_type_image.setColorFilter(config.textColor, PorterDuff.Mode.SRC_IN)
}
override fun eventInserted(event: Event) {

View File

@ -31,7 +31,7 @@ class DBHelper private constructor(val context: Context) : SQLiteOpenHelper(cont
private val COL_REMINDER_MINUTES_3 = "reminder_minutes_3"
private val COL_IMPORT_ID = "import_id"
private val COL_FLAGS = "flags"
private val COL_TYPE = "type"
private val COL_EVENT_TYPE = "event_type"
private val META_TABLE_NAME = "events_meta"
private val COL_EVENT_ID = "event_id"
@ -64,7 +64,7 @@ class DBHelper private constructor(val context: Context) : SQLiteOpenHelper(cont
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_REMINDER_MINUTES_2 INTEGER, $COL_REMINDER_MINUTES_3 INTEGER, " +
"$COL_IMPORT_ID TEXT, $COL_FLAGS INTEGER, $COL_TYPE INTEGER)")
"$COL_IMPORT_ID TEXT, $COL_FLAGS INTEGER, $COL_EVENT_TYPE INTEGER)")
createMetaTable(db)
createTypesTable(db)
@ -95,7 +95,7 @@ class DBHelper private constructor(val context: Context) : SQLiteOpenHelper(cont
if (oldVersion < 7) {
createTypesTable(db)
db.execSQL("ALTER TABLE $MAIN_TABLE_NAME ADD COLUMN $COL_TYPE INTEGER NOT NULL DEFAULT 0")
db.execSQL("ALTER TABLE $MAIN_TABLE_NAME ADD COLUMN $COL_EVENT_TYPE INTEGER NOT NULL DEFAULT 0")
}
}
@ -308,7 +308,7 @@ class DBHelper private constructor(val context: Context) : SQLiteOpenHelper(cont
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.reminder1Minutes, e.reminder2Minutes, e.reminder3Minutes,
e.repeatInterval, e.importId, e.flags)
e.repeatInterval, e.importId, e.flags, e.eventType)
newEvents.add(newEvent)
}
e.addIntervalTime()
@ -350,7 +350,7 @@ class DBHelper private constructor(val context: Context) : SQLiteOpenHelper(cont
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,
COL_REMINDER_MINUTES_3, COL_REPEAT_INTERVAL, COL_REPEAT_MONTH, COL_REPEAT_DAY, COL_IMPORT_ID, COL_FLAGS, COL_REPEAT_LIMIT)
COL_REMINDER_MINUTES_3, COL_REPEAT_INTERVAL, COL_REPEAT_MONTH, COL_REPEAT_DAY, COL_IMPORT_ID, COL_FLAGS, COL_REPEAT_LIMIT, COL_EVENT_TYPE)
private fun fillEvents(cursor: Cursor?): List<Event> {
val events = ArrayList<Event>()
@ -369,8 +369,9 @@ class DBHelper private constructor(val context: Context) : SQLiteOpenHelper(cont
val importId = cursor.getStringValue(COL_IMPORT_ID)
val flags = cursor.getIntValue(COL_FLAGS)
val repeatLimit = cursor.getIntValue(COL_REPEAT_LIMIT)
val eventType = cursor.getIntValue(COL_EVENT_TYPE)
events.add(Event(id, startTS, endTS, title, description, reminder1Minutes, reminder2Minutes, reminder3Minutes,
repeatInterval, importId, flags, repeatLimit))
repeatInterval, importId, flags, repeatLimit, eventType))
} while (cursor.moveToNext())
}
} finally {

View File

@ -7,7 +7,7 @@ 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 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 {
var importId: String? = "", var flags: Int = 0, var repeatLimit: Int = 0, var eventType: Int = DBHelper.REGULAR_EVENT_ID) : Serializable {
companion object {
private val serialVersionUID = -32456795132344616L
@ -31,7 +31,5 @@ data class Event(var id: Int = 0, var startTS: Int = 0, var endTS: Int = 0, var
val isAllDay = flags and FLAG_ALL_DAY != 0
fun getRemindersCount() = getReminders().count()
fun getReminders() = setOf(reminder1Minutes, reminder2Minutes, reminder3Minutes).filter { it != REMINDER_OFF }
}

View File

@ -267,5 +267,41 @@
android:textSize="@dimen/day_text_size"
android:visibility="gone"/>
<ImageView
android:id="@+id/event_repetition_divider"
android:layout_width="match_parent"
android:layout_height="1px"
android:layout_below="@+id/event_repetition_limit"
android:layout_marginBottom="@dimen/medium_margin"
android:layout_marginTop="@dimen/medium_margin"
android:background="@color/darker_divider"/>
<ImageView
android:id="@+id/event_type_image"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_alignBottom="@+id/event_type"
android:layout_alignTop="@+id/event_type"
android:layout_below="@+id/event_date_time_divider"
android:layout_marginLeft="@dimen/normal_margin"
android:layout_marginStart="@dimen/normal_margin"
android:alpha="0.8"
android:padding="@dimen/medium_margin"
android:src="@drawable/ic_color"/>
<com.simplemobiletools.commons.views.MyTextView
android:id="@+id/event_type"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="@+id/event_repetition_divider"
android:layout_marginLeft="@dimen/small_margin"
android:layout_marginStart="@dimen/small_margin"
android:layout_toEndOf="@+id/event_type_image"
android:layout_toRightOf="@+id/event_type_image"
android:background="?attr/selectableItemBackground"
android:paddingBottom="@dimen/normal_margin"
android:paddingTop="@dimen/normal_margin"
android:textSize="@dimen/day_text_size"/>
</RelativeLayout>
</ScrollView>