add a button for marking tasks complete

This commit is contained in:
tibbi 2022-02-24 22:42:24 +01:00
parent c1e1ee4685
commit 03237f4ffd
5 changed files with 43 additions and 1 deletions

View File

@ -3,6 +3,7 @@ package com.simplemobiletools.calendar.pro.activities
import android.app.DatePickerDialog
import android.app.TimePickerDialog
import android.content.Intent
import android.graphics.Color
import android.os.Bundle
import android.view.Menu
import android.view.MenuItem
@ -156,6 +157,17 @@ 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())
}
private fun setupNewTask() {
@ -270,6 +282,20 @@ class TaskActivity : SimpleActivity() {
task_time.beGoneIf(isChecked)
}
private fun toggleCompletion() {
if (mTask.isTaskCompleted()) {
mTask.flags = mTask.flags.removeBit(FLAG_TASK_COMPLETED)
} else {
mTask.flags = mTask.flags or FLAG_TASK_COMPLETED
}
ensureBackgroundThread {
eventsDB.updateTaskCompletion(mTask.id!!, mTask.flags)
hideKeyboard()
finish()
}
}
private fun showEventTypeDialog() {
hideKeyboard()
SelectEventTypeDialog(this, mEventTypeId, false, true, false, true) {

View File

@ -122,7 +122,7 @@ const val REPEAT_ORDER_WEEKDAY = 4 // i.e. every 4th sunday
const val FLAG_ALL_DAY = 1
const val FLAG_IS_IN_PAST = 2
const val FLAG_MISSING_YEAR = 4
const val FLAG_TASK_COMPLETE = 8
const val FLAG_TASK_COMPLETED = 8
// constants related to ICS file exporting / importing
const val BEGIN_CALENDAR = "BEGIN:VCALENDAR"

View File

@ -109,6 +109,9 @@ interface EventsDao {
@Query("UPDATE events SET repetition_exceptions = :repetitionExceptions WHERE id = :id AND type = $TYPE_EVENT")
fun updateEventRepetitionExceptions(repetitionExceptions: String, id: Long)
@Query("UPDATE events SET flags = :newFlags WHERE id = :id")
fun updateTaskCompletion(id: Long, newFlags: Int)
@Insert(onConflict = OnConflictStrategy.REPLACE)
fun insertOrUpdate(event: Event): Long

View File

@ -142,6 +142,7 @@ data class Event(
fun getIsAllDay() = flags and FLAG_ALL_DAY != 0
fun hasMissingYear() = flags and FLAG_MISSING_YEAR != 0
fun isTask() = type == TYPE_TASK
fun isTaskCompleted() = flags and FLAG_TASK_COMPLETED != 0
fun getReminders() = listOf(
Reminder(reminder1Minutes, reminder1Type),

View File

@ -170,5 +170,17 @@
android:layout_below="@+id/event_type_holder"
android:background="@color/divider_grey"
android:importantForAccessibility="no" />
<android.widget.TextView
android:id="@+id/mark_complete"
style="@style/ColoredButtonStyle"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@+id/event_type_divider"
android:layout_centerHorizontal="true"
android:layout_marginTop="@dimen/activity_margin"
android:text="@string/mark_completed"
android:visibility="gone" />
</RelativeLayout>
</ScrollView>