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 ae02f6e89..47e768def 100644 --- a/app/src/main/kotlin/com/simplemobiletools/calendar/activities/EventActivity.kt +++ b/app/src/main/kotlin/com/simplemobiletools/calendar/activities/EventActivity.kt @@ -30,7 +30,7 @@ class EventActivity : SimpleActivity(), DBHelper.EventUpdateListener { private var mReminder3Minutes = 0 private var mRepeatInterval = 0 private var mRepeatLimit = 0 - private var mEventType = DBHelper.REGULAR_EVENT_ID + private var mEventTypeId = DBHelper.REGULAR_EVENT_ID private var mDialogTheme = 0 lateinit var mEventStartDateTime: DateTime @@ -67,7 +67,7 @@ class EventActivity : SimpleActivity(), DBHelper.EventUpdateListener { updateStartTime() updateEndDate() updateEndTime() - updateEventTypeText() + updateEventType() mWasEndDateSet = event != null mWasEndTimeSet = event != null @@ -85,7 +85,7 @@ class EventActivity : SimpleActivity(), DBHelper.EventUpdateListener { event_reminder_2.setOnClickListener { showReminder2Dialog() } event_reminder_3.setOnClickListener { showReminder3Dialog() } - event_type.setOnClickListener { showEventTypeDialog() } + event_type_holder.setOnClickListener { showEventTypeDialog() } if (mEvent.flags and FLAG_ALL_DAY != 0) event_all_day.toggle() @@ -106,7 +106,7 @@ class EventActivity : SimpleActivity(), DBHelper.EventUpdateListener { mReminder3Minutes = mEvent.reminder3Minutes mRepeatInterval = mEvent.repeatInterval mRepeatLimit = mEvent.repeatLimit - mEventType = mEvent.eventType + mEventTypeId = mEvent.eventType checkRepeatLimit(mRepeatInterval) } @@ -181,9 +181,9 @@ class EventActivity : SimpleActivity(), DBHelper.EventUpdateListener { } private fun showEventTypeDialog() { - SelectEventTypeDialog(this, mEventType) { - mEventType = it - updateEventTypeText() + SelectEventTypeDialog(this, mEventTypeId) { + mEventTypeId = it + updateEventType() } } @@ -232,8 +232,12 @@ class EventActivity : SimpleActivity(), DBHelper.EventUpdateListener { event_repetition.text = getRepetitionToString(mRepeatInterval) } - private fun updateEventTypeText() { - event_type.text = DBHelper.newInstance(applicationContext).getEventTypeTitle(mEventType) + private fun updateEventType() { + val eventType = DBHelper.newInstance(applicationContext).getEventType(mEventTypeId) + if (eventType != null) { + event_type.text = eventType.title + event_type_color.setBackgroundWithStroke(eventType.color, config.backgroundColor) + } } private fun getRepetitionToString(seconds: Int) = getString(when (seconds) { @@ -252,10 +256,7 @@ class EventActivity : SimpleActivity(), DBHelper.EventUpdateListener { override fun onCreateOptionsMenu(menu: Menu): Boolean { menuInflater.inflate(R.menu.menu_event, menu) - val item = menu.findItem(R.id.cab_delete) - if (mEvent.id == 0) { - item.isVisible = false - } + menu.findItem(R.id.cab_delete).isVisible = mEvent.id != 0 return true } @@ -305,7 +306,7 @@ class EventActivity : SimpleActivity(), DBHelper.EventUpdateListener { 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 - eventType = mEventType + eventType = mEventTypeId } if (mEvent.id == 0) { 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 607fbb5de..605f5019d 100644 --- a/app/src/main/kotlin/com/simplemobiletools/calendar/helpers/DBHelper.kt +++ b/app/src/main/kotlin/com/simplemobiletools/calendar/helpers/DBHelper.kt @@ -227,20 +227,22 @@ class DBHelper private constructor(val context: Context) : SQLiteOpenHelper(cont return -1 } - fun getEventTypeTitle(id: Int): String { - val cols = arrayOf(COL_TYPE_TITLE) + fun getEventType(id: Int): EventType? { + val cols = arrayOf(COL_TYPE_TITLE, COL_TYPE_COLOR) val selection = "$COL_TYPE_ID = ?" val selectionArgs = arrayOf(id.toString()) var cursor: Cursor? = null try { cursor = mDb.query(TYPES_TABLE_NAME, cols, selection, selectionArgs, null, null, null) if (cursor?.moveToFirst() == true) { - return cursor.getStringValue(COL_TYPE_TITLE) + val title = cursor.getStringValue(COL_TYPE_TITLE) + val color = cursor.getIntValue(COL_TYPE_COLOR) + return EventType(id, title, color) } } finally { cursor?.close() } - return context.resources.getString(R.string.regular_event) + return null } fun deleteEvents(ids: Array) { diff --git a/app/src/main/res/layout/activity_event.xml b/app/src/main/res/layout/activity_event.xml index 036f590c9..4b6dc1657 100644 --- a/app/src/main/res/layout/activity_event.xml +++ b/app/src/main/res/layout/activity_event.xml @@ -280,8 +280,8 @@ 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_alignBottom="@+id/event_type_holder" + android:layout_alignTop="@+id/event_type_holder" android:layout_below="@+id/event_date_time_divider" android:layout_marginLeft="@dimen/normal_margin" android:layout_marginStart="@dimen/normal_margin" @@ -289,19 +289,36 @@ android:padding="@dimen/medium_margin" android:src="@drawable/ic_color"/> - + android:background="?attr/selectableItemBackground"> + + + + +