show the event type color at event screen

This commit is contained in:
tibbi 2017-02-11 23:55:27 +01:00
parent 82213b1ea5
commit 53e9f5cb79
3 changed files with 48 additions and 28 deletions

View File

@ -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) {

View File

@ -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<String>) {

View File

@ -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"/>
<com.simplemobiletools.commons.views.MyTextView
android:id="@+id/event_type"
<RelativeLayout
android:id="@+id/event_type_holder"
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"/>
android:background="?attr/selectableItemBackground">
<com.simplemobiletools.commons.views.MyTextView
android:id="@+id/event_type"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="@dimen/small_margin"
android:layout_marginStart="@dimen/small_margin"
android:paddingBottom="@dimen/normal_margin"
android:paddingTop="@dimen/normal_margin"
android:textSize="@dimen/day_text_size"/>
<ImageView
android:id="@+id/event_type_color"
android:layout_width="@dimen/color_sample_size"
android:layout_height="@dimen/color_sample_size"
android:layout_alignParentEnd="true"
android:layout_alignParentRight="true"
android:layout_centerVertical="true"
android:layout_marginEnd="@dimen/normal_margin"
android:layout_marginRight="@dimen/normal_margin"
android:clickable="false"/>
</RelativeLayout>
</RelativeLayout>
</ScrollView>