From 9f8d59f0d4c19fd0daccad1e96bde2129932de04 Mon Sep 17 00:00:00 2001 From: Naveen Date: Thu, 28 Sep 2023 20:58:20 +0530 Subject: [PATCH] Strikethrough events when status is set to "Not going" --- .../activities/WidgetListConfigureActivity.kt | 100 ++++++------------ .../calendar/pro/adapters/DayEventsAdapter.kt | 2 +- .../calendar/pro/adapters/EventListAdapter.kt | 2 +- .../pro/adapters/EventListWidgetAdapter.kt | 32 +++--- .../calendar/pro/extensions/Context.kt | 5 +- .../calendar/pro/extensions/Event.kt | 2 + .../calendar/pro/extensions/ListEvent.kt | 5 + .../calendar/pro/extensions/MonthViewEvent.kt | 5 + .../calendar/pro/fragments/WeekFragment.kt | 4 +- .../pro/helpers/MyWidgetMonthlyProvider.kt | 7 +- .../calendar/pro/models/Event.kt | 5 + .../calendar/pro/models/ListEvent.kt | 36 ++++++- .../calendar/pro/models/MonthViewEvent.kt | 3 +- .../calendar/pro/views/MonthView.kt | 17 ++- 14 files changed, 125 insertions(+), 100 deletions(-) create mode 100644 app/src/main/kotlin/com/simplemobiletools/calendar/pro/extensions/ListEvent.kt create mode 100644 app/src/main/kotlin/com/simplemobiletools/calendar/pro/extensions/MonthViewEvent.kt 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 e15266f88..f5bcd57b1 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 @@ -232,36 +232,24 @@ class WidgetListConfigureActivity : SimpleActivity() { var time = dateTime.withHourOfDay(7) listItems.add( - ListEvent( - 1, - time.seconds(), - time.plusMinutes(30).seconds(), - getString(R.string.sample_title_1), - getString(R.string.sample_description_1), - false, - getProperPrimaryColor(), - "", - false, - false, - false, - false + ListEvent.empty.copy( + id = 1, + startTS = time.seconds(), + endTS = time.plusMinutes(30).seconds(), + title = getString(R.string.sample_title_1), + description = getString(R.string.sample_description_1), + color = getProperPrimaryColor(), ) ) time = dateTime.withHourOfDay(8) listItems.add( - ListEvent( - 2, - time.seconds(), - time.plusHours(1).seconds(), - getString(R.string.sample_title_2), - getString(R.string.sample_description_2), - false, - getProperPrimaryColor(), - "", - false, - false, - false, - false + ListEvent.empty.copy( + id = 2, + startTS = time.seconds(), + endTS = time.plusHours(1).seconds(), + title = getString(R.string.sample_title_2), + description = getString(R.string.sample_description_2), + color = getProperPrimaryColor(), ) ) @@ -272,53 +260,35 @@ class WidgetListConfigureActivity : SimpleActivity() { time = dateTime.withHourOfDay(8) listItems.add( - ListEvent( - 3, - time.seconds(), - time.plusHours(1).seconds(), - getString(R.string.sample_title_3), - "", - false, - getProperPrimaryColor(), - "", - false, - false, - false, - false + ListEvent.empty.copy( + id = 3, + startTS = time.seconds(), + endTS = time.plusHours(1).seconds(), + title = getString(R.string.sample_title_3), + description = "", + color = getProperPrimaryColor(), ) ) time = dateTime.withHourOfDay(13) listItems.add( - ListEvent( - 4, - time.seconds(), - time.plusHours(1).seconds(), - getString(R.string.sample_title_4), - getString(R.string.sample_description_4), - false, - getProperPrimaryColor(), - "", - false, - false, - false, - false + ListEvent.empty.copy( + id = 4, + startTS = time.seconds(), + endTS = time.plusHours(1).seconds(), + title = getString(R.string.sample_title_4), + description = getString(R.string.sample_description_4), + color = getProperPrimaryColor(), ) ) time = dateTime.withHourOfDay(18) listItems.add( - ListEvent( - 5, - time.seconds(), - time.plusMinutes(10).seconds(), - getString(R.string.sample_title_5), - "", - false, - getProperPrimaryColor(), - "", - false, - false, - false, - false + ListEvent.empty.copy( + id = 5, + startTS = time.seconds(), + endTS = time.plusMinutes(10).seconds(), + title = getString(R.string.sample_title_5), + description = "", + color = getProperPrimaryColor(), ) ) 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 b94af644e..a9ce96abf 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 @@ -90,7 +90,7 @@ class DayEventsAdapter(activity: SimpleActivity, val events: ArrayList, r eventItemHolder.isSelected = selectedKeys.contains(event.id?.toInt()) eventItemHolder.background.applyColorFilter(textColor) eventItemTitle.text = event.title - eventItemTitle.checkViewStrikeThrough(event.isTaskCompleted()) + eventItemTitle.checkViewStrikeThrough(event.shouldStrikeThrough()) eventItemTime.text = if (event.getIsAllDay()) allDayString else Formatter.getTimeFromTS(activity, event.startTS) if (event.startTS != event.endTS) { val startDayCode = Formatter.getDayCodeFromTS(event.startTS) 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 33b541a5c..e29ef3301 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 @@ -136,7 +136,7 @@ class EventListAdapter( eventItemHolder.isSelected = selectedKeys.contains(listEvent.hashCode()) eventItemHolder.background.applyColorFilter(textColor) eventItemTitle.text = listEvent.title - eventItemTitle.checkViewStrikeThrough(listEvent.isTaskCompleted) + eventItemTitle.checkViewStrikeThrough(listEvent.shouldStrikeThrough()) eventItemTime.text = if (listEvent.isAllDay) allDayString else Formatter.getTimeFromTS(activity, 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 d643f3788..daa4a6bc1 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 @@ -6,10 +6,7 @@ import android.graphics.Paint import android.widget.RemoteViews import android.widget.RemoteViewsService import com.simplemobiletools.calendar.pro.R -import com.simplemobiletools.calendar.pro.extensions.config -import com.simplemobiletools.calendar.pro.extensions.eventsHelper -import com.simplemobiletools.calendar.pro.extensions.getWidgetFontSize -import com.simplemobiletools.calendar.pro.extensions.seconds +import com.simplemobiletools.calendar.pro.extensions.* import com.simplemobiletools.calendar.pro.helpers.* import com.simplemobiletools.calendar.pro.models.* import com.simplemobiletools.commons.extensions.* @@ -120,7 +117,7 @@ class EventListWidgetAdapter(val context: Context, val intent: Intent) : RemoteV setViewPadding(R.id.event_item_title, normalMargin, 0, smallMargin, 0) } - if (item.isTaskCompleted) { + if (item.shouldStrikeThrough()) { setInt(R.id.event_item_title, "setPaintFlags", Paint.ANTI_ALIAS_FLAG or Paint.STRIKE_THRU_TEXT_FLAG) } else { setInt(R.id.event_item_title, "setPaintFlags", Paint.ANTI_ALIAS_FLAG) @@ -226,18 +223,19 @@ class EventListWidgetAdapter(val context: Context, val intent: Intent) : RemoteV } val listEvent = ListEvent( - event.id!!, - event.startTS, - event.endTS, - event.title, - event.description, - event.getIsAllDay(), - event.color, - event.location, - event.isPastEvent, - event.repeatInterval > 0, - event.isTask(), - event.isTaskCompleted() + id = event.id!!, + startTS = event.startTS, + endTS = event.endTS, + title = event.title, + description = event.description, + isAllDay = event.getIsAllDay(), + color = event.color, + location = event.location, + isPastEvent = event.isPastEvent, + isRepeatable = event.repeatInterval > 0, + isTask = event.isTask(), + isTaskCompleted = event.isTaskCompleted(), + isAttendeeInviteDeclined = event.isAttendeeInviteDeclined() ) 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 ad40259a6..1b69ca2ca 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 @@ -601,7 +601,7 @@ fun Context.addDayEvents(day: DayMonthly, linearLayout: LinearLayout, res: Resou dayMonthlyEventId.apply { setTextColor(textColor) text = it.title.replace(" ", "\u00A0") // allow word break by char - checkViewStrikeThrough(it.isTaskCompleted()) + checkViewStrikeThrough(it.shouldStrikeThrough()) contentDescription = it.title } @@ -669,7 +669,8 @@ fun Context.getEventListItems(events: List, addSectionDays: Boolean = tru it.isPastEvent, it.repeatInterval > 0, it.isTask(), - it.isTaskCompleted() + it.isTaskCompleted(), + it.isAttendeeInviteDeclined() ) listItems.add(listEvent) } diff --git a/app/src/main/kotlin/com/simplemobiletools/calendar/pro/extensions/Event.kt b/app/src/main/kotlin/com/simplemobiletools/calendar/pro/extensions/Event.kt index de9908b4c..c31d4f872 100644 --- a/app/src/main/kotlin/com/simplemobiletools/calendar/pro/extensions/Event.kt +++ b/app/src/main/kotlin/com/simplemobiletools/calendar/pro/extensions/Event.kt @@ -40,3 +40,5 @@ fun Event.maybeAdjustRepeatLimitCount(original: Event, occurrenceTS: Long) { this.repeatLimit = newRepeatLimit } } + +fun Event.shouldStrikeThrough() = isTaskCompleted() || isAttendeeInviteDeclined() diff --git a/app/src/main/kotlin/com/simplemobiletools/calendar/pro/extensions/ListEvent.kt b/app/src/main/kotlin/com/simplemobiletools/calendar/pro/extensions/ListEvent.kt new file mode 100644 index 000000000..406929d18 --- /dev/null +++ b/app/src/main/kotlin/com/simplemobiletools/calendar/pro/extensions/ListEvent.kt @@ -0,0 +1,5 @@ +package com.simplemobiletools.calendar.pro.extensions + +import com.simplemobiletools.calendar.pro.models.ListEvent + +fun ListEvent.shouldStrikeThrough() = isTaskCompleted || isAttendeeInviteDeclined diff --git a/app/src/main/kotlin/com/simplemobiletools/calendar/pro/extensions/MonthViewEvent.kt b/app/src/main/kotlin/com/simplemobiletools/calendar/pro/extensions/MonthViewEvent.kt new file mode 100644 index 000000000..440cd66aa --- /dev/null +++ b/app/src/main/kotlin/com/simplemobiletools/calendar/pro/extensions/MonthViewEvent.kt @@ -0,0 +1,5 @@ +package com.simplemobiletools.calendar.pro.extensions + +import com.simplemobiletools.calendar.pro.models.MonthViewEvent + +fun MonthViewEvent.shouldStrikeThrough() = isTaskCompleted || isAttendeeInviteDeclined 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 9901b212f..691a19798 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 @@ -645,7 +645,7 @@ class WeekFragment : Fragment(), WeeklyCalendar { } text = event.title - checkViewStrikeThrough(event.isTaskCompleted()) + checkViewStrikeThrough(event.shouldStrikeThrough()) contentDescription = text minHeight = if (event.startTS == event.endTS) { @@ -785,7 +785,7 @@ class WeekFragment : Fragment(), WeeklyCalendar { setTextColor(textColor) maxLines = if (event.isTask()) 1 else 2 text = event.title - checkViewStrikeThrough(event.isTaskCompleted()) + checkViewStrikeThrough(event.shouldStrikeThrough()) contentDescription = text } diff --git a/app/src/main/kotlin/com/simplemobiletools/calendar/pro/helpers/MyWidgetMonthlyProvider.kt b/app/src/main/kotlin/com/simplemobiletools/calendar/pro/helpers/MyWidgetMonthlyProvider.kt index b4bca7ec9..fb74792e5 100644 --- a/app/src/main/kotlin/com/simplemobiletools/calendar/pro/helpers/MyWidgetMonthlyProvider.kt +++ b/app/src/main/kotlin/com/simplemobiletools/calendar/pro/helpers/MyWidgetMonthlyProvider.kt @@ -12,10 +12,7 @@ import android.view.View import android.widget.RemoteViews import com.simplemobiletools.calendar.pro.R import com.simplemobiletools.calendar.pro.activities.SplashActivity -import com.simplemobiletools.calendar.pro.extensions.config -import com.simplemobiletools.calendar.pro.extensions.getWidgetFontSize -import com.simplemobiletools.calendar.pro.extensions.isWeekendIndex -import com.simplemobiletools.calendar.pro.extensions.launchNewEventOrTaskActivity +import com.simplemobiletools.calendar.pro.extensions.* import com.simplemobiletools.calendar.pro.interfaces.MonthlyCalendar import com.simplemobiletools.calendar.pro.models.DayMonthly import com.simplemobiletools.calendar.pro.models.Event @@ -155,7 +152,7 @@ class MyWidgetMonthlyProvider : AppWidgetProvider() { applyColorFilter(R.id.day_monthly_task_image, eventTextColor) setInt(R.id.day_monthly_event_background, "setColorFilter", it.color) - if (it.isTaskCompleted()) { + if (it.shouldStrikeThrough()) { setInt(R.id.day_monthly_event_id, "setPaintFlags", Paint.ANTI_ALIAS_FLAG or Paint.STRIKE_THRU_TEXT_FLAG) } else { setInt(R.id.day_monthly_event_id, "setPaintFlags", Paint.ANTI_ALIAS_FLAG) 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 28c896287..315ed828b 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 @@ -1,5 +1,6 @@ package com.simplemobiletools.calendar.pro.models +import android.provider.CalendarContract.Attendees import androidx.collection.LongSparseArray import androidx.room.ColumnInfo import androidx.room.Entity @@ -209,4 +210,8 @@ data class Event( DateTimeZone.getDefault().id } } + + fun isAttendeeInviteDeclined() = attendees.any { + it.isMe && it.status == Attendees.ATTENDEE_STATUS_DECLINED + } } 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 512178635..def5ce0ce 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,6 +1,36 @@ 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, var isTaskCompleted: Boolean -) : ListItem() + 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, + var isAttendeeInviteDeclined: Boolean +) : ListItem() { + + companion object { + val empty = ListEvent( + id = 0, + startTS = 0, + endTS = 0, + title = "", + description = "", + isAllDay = false, + color = 0, + location = "", + isPastEvent = false, + isRepeatable = false, + isTask = false, + isTaskCompleted = false, + isAttendeeInviteDeclined = false + ) + } +} 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 5fa8b9ded..1caa8a4cc 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 @@ -12,5 +12,6 @@ data class MonthViewEvent( val isAllDay: Boolean, val isPastEvent: Boolean, val isTask: Boolean, - val isTaskCompleted: Boolean + val isTaskCompleted: Boolean, + val isAttendeeInviteDeclined: 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 6ae6180f4..3c9432024 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 @@ -130,8 +130,19 @@ class MonthView(context: Context, attrs: AttributeSet, defStyle: Int) : View(con val daysCnt = getEventLastingDaysCount(event) val monthViewEvent = MonthViewEvent( - event.id!!, event.title, event.startTS, event.endTS, event.color, dayIndexOnMonthView, - daysCnt, dayIndexOnMonthView, event.getIsAllDay(), event.isPastEvent, event.isTask(), event.isTaskCompleted() + id = event.id!!, + title = event.title, + startTS = event.startTS, + endTS = event.endTS, + color = event.color, + startDayIndex = dayIndexOnMonthView, + daysCnt = daysCnt, + originalStartDayIndex = dayIndexOnMonthView, + isAllDay = event.getIsAllDay(), + isPastEvent = event.isPastEvent, + isTask = event.isTask(), + isTaskCompleted = event.isTaskCompleted(), + isAttendeeInviteDeclined = event.isAttendeeInviteDeclined() ) allEvents.add(monthViewEvent) } @@ -370,7 +381,7 @@ class MonthView(context: Context, attrs: AttributeSet, defStyle: Int) : View(con val curPaint = Paint(eventTitlePaint) curPaint.color = paintColor - curPaint.isStrikeThruText = event.isTaskCompleted + curPaint.isStrikeThruText = event.shouldStrikeThrough() return curPaint }