From ee64a90b35003698faff8162a232854401bdbe67 Mon Sep 17 00:00:00 2001 From: tibbi Date: Thu, 24 Feb 2022 22:55:00 +0100 Subject: [PATCH] properly toggle the Mark in/complete task button --- .../calendar/pro/activities/TaskActivity.kt | 30 ++++++++++++------- app/src/main/res/layout/activity_task.xml | 2 +- 2 files changed, 20 insertions(+), 12 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 95fc39c58..b9a5be91e 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 @@ -8,6 +8,7 @@ import android.os.Bundle import android.view.Menu import android.view.MenuItem import android.view.WindowManager +import androidx.core.content.ContextCompat import com.simplemobiletools.calendar.pro.R import com.simplemobiletools.calendar.pro.dialogs.SelectEventTypeDialog import com.simplemobiletools.calendar.pro.extensions.* @@ -157,17 +158,7 @@ class TaskActivity : SimpleActivity() { mEventTypeId = mTask.eventType task_title.setText(mTask.title) task_description.setText(mTask.description) - - mark_complete.setOnClickListener { toggleCompletion() } - mark_complete.beVisible() - - val markCompleteBgColor = if (isWhiteTheme()) { - Color.WHITE - } else { - getAdjustedPrimaryColor() - } - - mark_complete.setTextColor(markCompleteBgColor.getContrastColor()) + setupMarkCompleteButton() } private fun setupNewTask() { @@ -282,6 +273,23 @@ class TaskActivity : SimpleActivity() { task_time.beGoneIf(isChecked) } + private fun setupMarkCompleteButton() { + toggle_mark_complete.setOnClickListener { toggleCompletion() } + toggle_mark_complete.beVisible() + if (mTask.isTaskCompleted()) { + toggle_mark_complete.background = ContextCompat.getDrawable(this, R.drawable.button_background_stroke) + toggle_mark_complete.setText(R.string.mark_incomplete) + toggle_mark_complete.setTextColor(config.textColor) + } else { + val markCompleteBgColor = if (isWhiteTheme()) { + Color.WHITE + } else { + getAdjustedPrimaryColor() + } + toggle_mark_complete.setTextColor(markCompleteBgColor.getContrastColor()) + } + } + private fun toggleCompletion() { if (mTask.isTaskCompleted()) { mTask.flags = mTask.flags.removeBit(FLAG_TASK_COMPLETED) diff --git a/app/src/main/res/layout/activity_task.xml b/app/src/main/res/layout/activity_task.xml index ade8622cc..8b5d1e7b4 100644 --- a/app/src/main/res/layout/activity_task.xml +++ b/app/src/main/res/layout/activity_task.xml @@ -172,7 +172,7 @@ android:importantForAccessibility="no" />