From 8ece987f7b25eb9e212449123a8c7e06fb55679f Mon Sep 17 00:00:00 2001 From: tibbi Date: Thu, 24 Feb 2022 11:32:03 +0100 Subject: [PATCH] allow customizing the task event type --- .../calendar/pro/activities/TaskActivity.kt | 42 ++++++++++++++-- app/src/main/res/layout/activity_task.xml | 50 +++++++++++++++++++ 2 files changed, 88 insertions(+), 4 deletions(-) diff --git a/app/src/main/kotlin/com/simplemobiletools/calendar/pro/activities/TaskActivity.kt b/app/src/main/kotlin/com/simplemobiletools/calendar/pro/activities/TaskActivity.kt index 2d192d2e0..43b73a0f9 100644 --- a/app/src/main/kotlin/com/simplemobiletools/calendar/pro/activities/TaskActivity.kt +++ b/app/src/main/kotlin/com/simplemobiletools/calendar/pro/activities/TaskActivity.kt @@ -7,7 +7,9 @@ import android.view.Menu import android.view.MenuItem import android.view.WindowManager import com.simplemobiletools.calendar.pro.R +import com.simplemobiletools.calendar.pro.dialogs.SelectEventTypeDialog import com.simplemobiletools.calendar.pro.extensions.config +import com.simplemobiletools.calendar.pro.extensions.eventTypesDB import com.simplemobiletools.calendar.pro.extensions.seconds import com.simplemobiletools.calendar.pro.helpers.* import com.simplemobiletools.calendar.pro.helpers.Formatter @@ -20,6 +22,7 @@ import java.util.* class TaskActivity : SimpleActivity() { private var mDialogTheme = 0 + private var mEventTypeId = REGULAR_EVENT_TYPE_ID private lateinit var mTaskDateTime: DateTime private lateinit var mTask: Event @@ -35,7 +38,7 @@ class TaskActivity : SimpleActivity() { mDialogTheme = getDialogTheme() updateColors() val taskId = intent.getLongExtra(TASK_ID, 0L) - gotTask(null) + gotTask(savedInstanceState, null) } override fun onCreateOptionsMenu(menu: Menu): Boolean { @@ -59,13 +62,15 @@ class TaskActivity : SimpleActivity() { return true } - private fun gotTask(task: Event?) { + private fun gotTask(savedInstanceState: Bundle?, task: Event?) { if (task != null) { mTask = task } else { mTask = Event(null) } + mEventTypeId = if (config.defaultEventTypeId == -1L) config.lastUsedLocalEventTypeId else config.defaultEventTypeId + task_all_day.setOnCheckedChangeListener { compoundButton, isChecked -> toggleAllDay(isChecked) } task_all_day_holder.setOnClickListener { task_all_day.toggle() @@ -73,10 +78,15 @@ class TaskActivity : SimpleActivity() { task_date.setOnClickListener { setupDate() } task_time.setOnClickListener { setupTime() } + event_type_holder.setOnClickListener { showEventTypeDialog() } setupNewTask() - updateDateText() - updateTimeText() + + if (savedInstanceState == null) { + updateEventType() + updateDateText() + updateTimeText() + } } private fun setupNewTask() { @@ -99,12 +109,15 @@ class TaskActivity : SimpleActivity() { return } + config.lastUsedLocalEventTypeId = mEventTypeId mTask.apply { startTS = mTaskDateTime.withSecondOfMinute(0).withMillisOfSecond(0).seconds() title = newTitle description = task_description.value flags = mTask.flags.addBitIf(task_all_day.isChecked, FLAG_ALL_DAY) lastUpdated = System.currentTimeMillis() + eventType = mEventTypeId + type = TYPE_TASK } ensureBackgroundThread { @@ -167,8 +180,29 @@ class TaskActivity : SimpleActivity() { task_time.beGoneIf(isChecked) } + private fun showEventTypeDialog() { + hideKeyboard() + SelectEventTypeDialog(this, mEventTypeId, false, true, false, true) { + mEventTypeId = it.id!! + updateEventType() + } + } + + private fun updateEventType() { + ensureBackgroundThread { + val eventType = eventTypesDB.getEventTypeWithId(mEventTypeId) + if (eventType != null) { + runOnUiThread { + event_type.text = eventType.title + event_type_color.setFillWithStroke(eventType.color, config.backgroundColor) + } + } + } + } + private fun updateColors() { updateTextColors(task_scrollview) task_time_image.applyColorFilter(config.textColor) + event_type_image.applyColorFilter(config.textColor) } } diff --git a/app/src/main/res/layout/activity_task.xml b/app/src/main/res/layout/activity_task.xml index 0838bce5d..1a0b7f9c4 100644 --- a/app/src/main/res/layout/activity_task.xml +++ b/app/src/main/res/layout/activity_task.xml @@ -112,5 +112,55 @@ android:textSize="@dimen/day_text_size" tools:text="00:00" /> + + + + + + + + + + +