From f4c97b5e1e639f68ccfef8e1b27ae49c1107af4d Mon Sep 17 00:00:00 2001 From: tibbi Date: Fri, 25 Feb 2022 21:43:58 +0100 Subject: [PATCH] strike through completed tasks at all views --- .../activities/WidgetListConfigureActivity.kt | 5 +++++ .../calendar/pro/adapters/DayEventsAdapter.kt | 11 ++++------- .../calendar/pro/adapters/EventListAdapter.kt | 6 ++---- .../pro/adapters/EventListWidgetAdapter.kt | 3 ++- .../calendar/pro/extensions/Context.kt | 3 ++- .../calendar/pro/extensions/TextView.kt | 11 +++++++++++ .../calendar/pro/fragments/WeekFragment.kt | 1 + .../calendar/pro/models/Event.kt | 2 +- .../calendar/pro/models/ListEvent.kt | 6 ++++-- .../calendar/pro/models/MonthViewEvent.kt | 16 ++++++++++++++-- .../calendar/pro/views/MonthView.kt | 3 ++- 11 files changed, 48 insertions(+), 19 deletions(-) diff --git a/app/src/main/kotlin/com/simplemobiletools/calendar/pro/activities/WidgetListConfigureActivity.kt b/app/src/main/kotlin/com/simplemobiletools/calendar/pro/activities/WidgetListConfigureActivity.kt index 39f20d9dd..3320eb4de 100644 --- a/app/src/main/kotlin/com/simplemobiletools/calendar/pro/activities/WidgetListConfigureActivity.kt +++ b/app/src/main/kotlin/com/simplemobiletools/calendar/pro/activities/WidgetListConfigureActivity.kt @@ -233,6 +233,7 @@ class WidgetListConfigureActivity : SimpleActivity() { "", false, false, + false, false ) ) @@ -249,6 +250,7 @@ class WidgetListConfigureActivity : SimpleActivity() { "", false, false, + false, false ) ) @@ -271,6 +273,7 @@ class WidgetListConfigureActivity : SimpleActivity() { "", false, false, + false, false ) ) @@ -287,6 +290,7 @@ class WidgetListConfigureActivity : SimpleActivity() { "", false, false, + false, false ) ) @@ -303,6 +307,7 @@ class WidgetListConfigureActivity : SimpleActivity() { "", false, false, + false, false ) ) diff --git a/app/src/main/kotlin/com/simplemobiletools/calendar/pro/adapters/DayEventsAdapter.kt b/app/src/main/kotlin/com/simplemobiletools/calendar/pro/adapters/DayEventsAdapter.kt index 0f28c4ef2..0ab467661 100644 --- a/app/src/main/kotlin/com/simplemobiletools/calendar/pro/adapters/DayEventsAdapter.kt +++ b/app/src/main/kotlin/com/simplemobiletools/calendar/pro/adapters/DayEventsAdapter.kt @@ -1,21 +1,17 @@ package com.simplemobiletools.calendar.pro.adapters +import android.graphics.Paint import android.view.Menu import android.view.View import android.view.ViewGroup import com.simplemobiletools.calendar.pro.R import com.simplemobiletools.calendar.pro.activities.SimpleActivity import com.simplemobiletools.calendar.pro.dialogs.DeleteEventDialog -import com.simplemobiletools.calendar.pro.extensions.config -import com.simplemobiletools.calendar.pro.extensions.eventsHelper -import com.simplemobiletools.calendar.pro.extensions.handleEventDeleting -import com.simplemobiletools.calendar.pro.extensions.shareEvents +import com.simplemobiletools.calendar.pro.extensions.* import com.simplemobiletools.calendar.pro.helpers.Formatter import com.simplemobiletools.calendar.pro.models.Event import com.simplemobiletools.commons.adapters.MyRecyclerViewAdapter -import com.simplemobiletools.commons.extensions.adjustAlpha -import com.simplemobiletools.commons.extensions.applyColorFilter -import com.simplemobiletools.commons.extensions.beVisibleIf +import com.simplemobiletools.commons.extensions.* import com.simplemobiletools.commons.helpers.MEDIUM_ALPHA import com.simplemobiletools.commons.helpers.ensureBackgroundThread import com.simplemobiletools.commons.views.MyRecyclerView @@ -84,6 +80,7 @@ class DayEventsAdapter(activity: SimpleActivity, val events: ArrayList, r event_item_holder.isSelected = selectedKeys.contains(event.id?.toInt()) event_item_holder.background.applyColorFilter(textColor) event_item_title.text = event.title + event_item_title.checkViewStrikeThrough(event.isTaskCompleted()) event_item_time.text = if (event.getIsAllDay()) allDayString else Formatter.getTimeFromTS(context, event.startTS) if (event.startTS != event.endTS && !event.getIsAllDay()) { event_item_time.text = "${event_item_time.text} - ${Formatter.getTimeFromTS(context, event.endTS)}" diff --git a/app/src/main/kotlin/com/simplemobiletools/calendar/pro/adapters/EventListAdapter.kt b/app/src/main/kotlin/com/simplemobiletools/calendar/pro/adapters/EventListAdapter.kt index 57a56591f..97ecd9438 100644 --- a/app/src/main/kotlin/com/simplemobiletools/calendar/pro/adapters/EventListAdapter.kt +++ b/app/src/main/kotlin/com/simplemobiletools/calendar/pro/adapters/EventListAdapter.kt @@ -6,10 +6,7 @@ import android.view.ViewGroup import com.simplemobiletools.calendar.pro.R import com.simplemobiletools.calendar.pro.activities.SimpleActivity import com.simplemobiletools.calendar.pro.dialogs.DeleteEventDialog -import com.simplemobiletools.calendar.pro.extensions.config -import com.simplemobiletools.calendar.pro.extensions.eventsHelper -import com.simplemobiletools.calendar.pro.extensions.handleEventDeleting -import com.simplemobiletools.calendar.pro.extensions.shareEvents +import com.simplemobiletools.calendar.pro.extensions.* import com.simplemobiletools.calendar.pro.helpers.* import com.simplemobiletools.calendar.pro.helpers.Formatter import com.simplemobiletools.calendar.pro.models.ListEvent @@ -134,6 +131,7 @@ class EventListAdapter( event_item_holder.isSelected = selectedKeys.contains(listEvent.hashCode()) event_item_holder.background.applyColorFilter(textColor) event_item_title.text = listEvent.title + event_item_title.checkViewStrikeThrough(listEvent.isTaskCompleted) event_item_time.text = if (listEvent.isAllDay) allDayString else Formatter.getTimeFromTS(context, listEvent.startTS) if (listEvent.startTS != listEvent.endTS) { if (!listEvent.isAllDay) { diff --git a/app/src/main/kotlin/com/simplemobiletools/calendar/pro/adapters/EventListWidgetAdapter.kt b/app/src/main/kotlin/com/simplemobiletools/calendar/pro/adapters/EventListWidgetAdapter.kt index 7aa8cec28..6e4c03422 100644 --- a/app/src/main/kotlin/com/simplemobiletools/calendar/pro/adapters/EventListWidgetAdapter.kt +++ b/app/src/main/kotlin/com/simplemobiletools/calendar/pro/adapters/EventListWidgetAdapter.kt @@ -217,7 +217,8 @@ class EventListWidgetAdapter(val context: Context, val intent: Intent) : RemoteV it.location, it.isPastEvent, it.repeatInterval > 0, - it.isTask() + it.isTask(), + it.isTaskCompleted() ) listItems.add(listEvent) } diff --git a/app/src/main/kotlin/com/simplemobiletools/calendar/pro/extensions/Context.kt b/app/src/main/kotlin/com/simplemobiletools/calendar/pro/extensions/Context.kt index 6b736fe5f..4713d0129 100644 --- a/app/src/main/kotlin/com/simplemobiletools/calendar/pro/extensions/Context.kt +++ b/app/src/main/kotlin/com/simplemobiletools/calendar/pro/extensions/Context.kt @@ -555,7 +555,8 @@ fun Context.getEventListItems(events: List, addSectionDays: Boolean = tru it.location, it.isPastEvent, it.repeatInterval > 0, - it.isTask() + it.isTask(), + it.isTaskCompleted() ) listItems.add(listEvent) } diff --git a/app/src/main/kotlin/com/simplemobiletools/calendar/pro/extensions/TextView.kt b/app/src/main/kotlin/com/simplemobiletools/calendar/pro/extensions/TextView.kt index cb765cf4d..5b977fefe 100644 --- a/app/src/main/kotlin/com/simplemobiletools/calendar/pro/extensions/TextView.kt +++ b/app/src/main/kotlin/com/simplemobiletools/calendar/pro/extensions/TextView.kt @@ -1,10 +1,13 @@ package com.simplemobiletools.calendar.pro.extensions import android.content.res.Resources +import android.graphics.Paint import android.graphics.drawable.BitmapDrawable import android.widget.TextView import androidx.core.graphics.drawable.toBitmap +import com.simplemobiletools.commons.extensions.addBit import com.simplemobiletools.commons.extensions.applyColorFilter +import com.simplemobiletools.commons.extensions.removeBit fun TextView.addResizedBackgroundDrawable(res: Resources, drawableHeight: Int, primaryColor: Int, drawableId: Int) { val baseDrawable = res.getDrawable(drawableId).toBitmap(drawableHeight, drawableHeight) @@ -12,3 +15,11 @@ fun TextView.addResizedBackgroundDrawable(res: Resources, drawableHeight: Int, p scaledDrawable.applyColorFilter(primaryColor) background = scaledDrawable } + +fun TextView.checkViewStrikeThrough(addFlag: Boolean) { + paintFlags = if (addFlag) { + paintFlags.addBit(Paint.STRIKE_THRU_TEXT_FLAG) + } else { + paintFlags.removeBit(Paint.STRIKE_THRU_TEXT_FLAG) + } +} diff --git a/app/src/main/kotlin/com/simplemobiletools/calendar/pro/fragments/WeekFragment.kt b/app/src/main/kotlin/com/simplemobiletools/calendar/pro/fragments/WeekFragment.kt index 076532b5e..1f64a0547 100644 --- a/app/src/main/kotlin/com/simplemobiletools/calendar/pro/fragments/WeekFragment.kt +++ b/app/src/main/kotlin/com/simplemobiletools/calendar/pro/fragments/WeekFragment.kt @@ -546,6 +546,7 @@ class WeekFragment : Fragment(), WeeklyCalendar { background = ColorDrawable(backgroundColor) setTextColor(textColor) text = event.title + checkViewStrikeThrough(event.isTaskCompleted()) contentDescription = text dayColumn.addView(this) y = currentEventWeeklyView!!.range.lower * minuteHeight diff --git a/app/src/main/kotlin/com/simplemobiletools/calendar/pro/models/Event.kt b/app/src/main/kotlin/com/simplemobiletools/calendar/pro/models/Event.kt index 07b64877f..f614a830e 100644 --- a/app/src/main/kotlin/com/simplemobiletools/calendar/pro/models/Event.kt +++ b/app/src/main/kotlin/com/simplemobiletools/calendar/pro/models/Event.kt @@ -142,7 +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 isTaskCompleted() = isTask() && flags and FLAG_TASK_COMPLETED != 0 fun getReminders() = listOf( Reminder(reminder1Minutes, reminder1Type), diff --git a/app/src/main/kotlin/com/simplemobiletools/calendar/pro/models/ListEvent.kt b/app/src/main/kotlin/com/simplemobiletools/calendar/pro/models/ListEvent.kt index 2a9e6b6ac..512178635 100644 --- a/app/src/main/kotlin/com/simplemobiletools/calendar/pro/models/ListEvent.kt +++ b/app/src/main/kotlin/com/simplemobiletools/calendar/pro/models/ListEvent.kt @@ -1,4 +1,6 @@ package com.simplemobiletools.calendar.pro.models -data class ListEvent(var id: Long, var startTS: Long, var endTS: Long, var title: String, var description: String, var isAllDay: Boolean, var color: Int, - var location: String, var isPastEvent: Boolean, var isRepeatable: Boolean, var isTask: Boolean) : ListItem() +data class ListEvent( + var id: Long, var startTS: Long, var endTS: Long, var title: String, var description: String, var isAllDay: Boolean, var color: Int, + var location: String, var isPastEvent: Boolean, var isRepeatable: Boolean, var isTask: Boolean, var isTaskCompleted: Boolean +) : ListItem() diff --git a/app/src/main/kotlin/com/simplemobiletools/calendar/pro/models/MonthViewEvent.kt b/app/src/main/kotlin/com/simplemobiletools/calendar/pro/models/MonthViewEvent.kt index e4a8890d5..5fa8b9ded 100644 --- a/app/src/main/kotlin/com/simplemobiletools/calendar/pro/models/MonthViewEvent.kt +++ b/app/src/main/kotlin/com/simplemobiletools/calendar/pro/models/MonthViewEvent.kt @@ -1,4 +1,16 @@ package com.simplemobiletools.calendar.pro.models -data class MonthViewEvent(val id: Long, val title: String, val startTS: Long, val endTS: Long, val color: Int, val startDayIndex: Int, val daysCnt: Int, val originalStartDayIndex: Int, - val isAllDay: Boolean, val isPastEvent: Boolean) +data class MonthViewEvent( + val id: Long, + val title: String, + val startTS: Long, + val endTS: Long, + val color: Int, + val startDayIndex: Int, + val daysCnt: Int, + val originalStartDayIndex: Int, + val isAllDay: Boolean, + val isPastEvent: Boolean, + val isTask: Boolean, + val isTaskCompleted: Boolean +) diff --git a/app/src/main/kotlin/com/simplemobiletools/calendar/pro/views/MonthView.kt b/app/src/main/kotlin/com/simplemobiletools/calendar/pro/views/MonthView.kt index 40d0f7119..97c75afe5 100644 --- a/app/src/main/kotlin/com/simplemobiletools/calendar/pro/views/MonthView.kt +++ b/app/src/main/kotlin/com/simplemobiletools/calendar/pro/views/MonthView.kt @@ -122,7 +122,7 @@ class MonthView(context: Context, attrs: AttributeSet, defStyle: Int) : View(con val validDayEvent = isDayValid(event, day.code) if ((lastEvent == null || lastEvent.startDayIndex + daysCnt <= day.indexOnMonthView) && !validDayEvent) { val monthViewEvent = MonthViewEvent(event.id!!, event.title, event.startTS, event.endTS, event.color, day.indexOnMonthView, - daysCnt, day.indexOnMonthView, event.getIsAllDay(), event.isPastEvent) + daysCnt, day.indexOnMonthView, event.getIsAllDay(), event.isPastEvent, event.isTask(), event.isTaskCompleted()) allEvents.add(monthViewEvent) } } @@ -331,6 +331,7 @@ class MonthView(context: Context, attrs: AttributeSet, defStyle: Int) : View(con val curPaint = Paint(eventTitlePaint) curPaint.color = paintColor + curPaint.isStrikeThruText = event.isTaskCompleted return curPaint }