Skip to content

Commit 8f4aa38

Browse files
authored
Merge pull request #1718 from Naveen3Singh/dim_completed_tasks
Add 'Dim completed tasks' preference
2 parents 6a361c2 + 739e846 commit 8f4aa38

12 files changed

Lines changed: 108 additions & 16 deletions

File tree

app/src/main/kotlin/com/simplemobiletools/calendar/pro/activities/MainActivity.kt

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,7 @@ class MainActivity : SimpleActivity(), RefreshRecyclerViewListener {
8080
private var mStoredMidnightSpan = true
8181
private var mStoredUse24HourFormat = false
8282
private var mStoredDimPastEvents = true
83+
private var mStoredDimCompletedTasks = true
8384
private var mStoredHighlightWeekends = false
8485
private var mStoredStartWeekWithCurrentDay = false
8586
private var mStoredHighlightWeekendsColor = 0
@@ -156,8 +157,8 @@ class MainActivity : SimpleActivity(), RefreshRecyclerViewListener {
156157
override fun onResume() {
157158
super.onResume()
158159
if (mStoredTextColor != getProperTextColor() || mStoredBackgroundColor != getProperBackgroundColor() || mStoredPrimaryColor != getProperPrimaryColor()
159-
|| mStoredDayCode != Formatter.getTodayCode() || mStoredDimPastEvents != config.dimPastEvents || mStoredHighlightWeekends != config.highlightWeekends
160-
|| mStoredHighlightWeekendsColor != config.highlightWeekendsColor
160+
|| mStoredDayCode != Formatter.getTodayCode() || mStoredDimPastEvents != config.dimPastEvents || mStoredDimCompletedTasks != config.dimCompletedTasks
161+
|| mStoredHighlightWeekends != config.highlightWeekends || mStoredHighlightWeekendsColor != config.highlightWeekendsColor
161162
) {
162163
updateViewPager()
163164
}
@@ -300,6 +301,7 @@ class MainActivity : SimpleActivity(), RefreshRecyclerViewListener {
300301
mStoredIsSundayFirst = isSundayFirst
301302
mStoredUse24HourFormat = use24HourFormat
302303
mStoredDimPastEvents = dimPastEvents
304+
mStoredDimCompletedTasks = dimCompletedTasks
303305
mStoredHighlightWeekends = highlightWeekends
304306
mStoredHighlightWeekendsColor = highlightWeekendsColor
305307
mStoredMidnightSpan = showMidnightSpanningEventsAtTop

app/src/main/kotlin/com/simplemobiletools/calendar/pro/activities/SettingsActivity.kt

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,7 @@ class SettingsActivity : SimpleActivity() {
8585
setupCustomizeWidgetColors()
8686
setupViewToOpenFromListWidget()
8787
setupDimEvents()
88+
setupDimCompletedTasks()
8889
setupAllowChangingTimeZones()
8990
updateTextColors(settings_holder)
9091
checkPrimaryColor()
@@ -319,12 +320,12 @@ class SettingsActivity : SimpleActivity() {
319320

320321
ensureBackgroundThread {
321322
if (newCalendarIds.isNotEmpty()) {
322-
val existingEventTypeNames = eventsHelper.getEventTypesSync().map { it.getDisplayTitle().toLowerCase() } as ArrayList<String>
323+
val existingEventTypeNames = eventsHelper.getEventTypesSync().map { it.getDisplayTitle().lowercase(Locale.getDefault()) } as ArrayList<String>
323324
getSyncedCalDAVCalendars().forEach {
324325
val calendarTitle = it.getFullTitle()
325-
if (!existingEventTypeNames.contains(calendarTitle.toLowerCase())) {
326+
if (!existingEventTypeNames.contains(calendarTitle.lowercase(Locale.getDefault()))) {
326327
val eventType = EventType(null, it.displayName, it.color, it.id, it.displayName, it.accountName)
327-
existingEventTypeNames.add(calendarTitle.toLowerCase())
328+
existingEventTypeNames.add(calendarTitle.lowercase(Locale.getDefault()))
328329
eventsHelper.insertOrUpdateEventType(this, eventType)
329330
}
330331
}
@@ -732,6 +733,14 @@ class SettingsActivity : SimpleActivity() {
732733
}
733734
}
734735

736+
private fun setupDimCompletedTasks() {
737+
settings_dim_completed_tasks.isChecked = config.dimCompletedTasks
738+
settings_dim_completed_tasks_holder.setOnClickListener {
739+
settings_dim_completed_tasks.toggle()
740+
config.dimCompletedTasks = settings_dim_completed_tasks.isChecked
741+
}
742+
}
743+
735744
private fun setupAllowChangingTimeZones() {
736745
settings_allow_changing_time_zones.isChecked = config.allowChangingTimeZones
737746
settings_allow_changing_time_zones_holder.setOnClickListener {
@@ -870,6 +879,7 @@ class SettingsActivity : SimpleActivity() {
870879
put(SHOW_GRID, config.showGrid)
871880
put(LOOP_REMINDERS, config.loopReminders)
872881
put(DIM_PAST_EVENTS, config.dimPastEvents)
882+
put(DIM_COMPLETED_TASKS, config.dimCompletedTasks)
873883
put(ALLOW_CHANGING_TIME_ZONES, config.allowChangingTimeZones)
874884
put(USE_PREVIOUS_EVENT_REMINDERS, config.usePreviousEventReminders)
875885
put(DEFAULT_REMINDER_1, config.defaultReminder1)
@@ -975,6 +985,7 @@ class SettingsActivity : SimpleActivity() {
975985
SHOW_GRID -> config.showGrid = value.toBoolean()
976986
LOOP_REMINDERS -> config.loopReminders = value.toBoolean()
977987
DIM_PAST_EVENTS -> config.dimPastEvents = value.toBoolean()
988+
DIM_COMPLETED_TASKS -> config.dimCompletedTasks = value.toBoolean()
978989
ALLOW_CHANGING_TIME_ZONES -> config.allowChangingTimeZones = value.toBoolean()
979990
USE_PREVIOUS_EVENT_REMINDERS -> config.usePreviousEventReminders = value.toBoolean()
980991
DEFAULT_REMINDER_1 -> config.defaultReminder1 = value.toInt()

app/src/main/kotlin/com/simplemobiletools/calendar/pro/adapters/DayEventsAdapter.kt

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ class DayEventsAdapter(activity: SimpleActivity, val events: ArrayList<Event>, r
2727
private val displayDescription = activity.config.displayDescription
2828
private val replaceDescriptionWithLocation = activity.config.replaceDescription
2929
private val dimPastEvents = activity.config.dimPastEvents
30+
private val dimCompletedTasks = activity.config.dimCompletedTasks
3031
private var isPrintVersion = false
3132
private val mediumMargin = activity.resources.getDimension(R.dimen.medium_margin).toInt()
3233

@@ -76,6 +77,7 @@ class DayEventsAdapter(activity: SimpleActivity, val events: ArrayList<Event>, r
7677
} else {
7778
activity.getProperTextColor()
7879
}
80+
7981
notifyDataSetChanged()
8082
}
8183

@@ -95,7 +97,14 @@ class DayEventsAdapter(activity: SimpleActivity, val events: ArrayList<Event>, r
9597
event_item_color_bar.background.applyColorFilter(event.color)
9698

9799
var newTextColor = textColor
98-
if (dimPastEvents && event.isPastEvent && !isPrintVersion) {
100+
101+
val adjustAlpha = if (event.isTask()) {
102+
dimCompletedTasks && event.isTaskCompleted()
103+
} else {
104+
dimPastEvents && event.isPastEvent && !isPrintVersion
105+
}
106+
107+
if (adjustAlpha) {
99108
newTextColor = newTextColor.adjustAlpha(MEDIUM_ALPHA)
100109
}
101110

@@ -110,6 +119,7 @@ class DayEventsAdapter(activity: SimpleActivity, val events: ArrayList<Event>, r
110119
} else {
111120
mediumMargin
112121
}
122+
113123
(event_item_title.layoutParams as ConstraintLayout.LayoutParams).marginStart = startMargin
114124
}
115125
}

app/src/main/kotlin/com/simplemobiletools/calendar/pro/adapters/EventListAdapter.kt

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ class EventListAdapter(
3434
private val displayDescription = activity.config.displayDescription
3535
private val replaceDescription = activity.config.replaceDescription
3636
private val dimPastEvents = activity.config.dimPastEvents
37+
private val dimCompletedTasks = activity.config.dimCompletedTasks
3738
private val now = getNowSeconds()
3839
private var use24HourFormat = activity.config.use24HourFormat
3940
private var currentItemsHash = listItems.hashCode()
@@ -156,7 +157,12 @@ class EventListAdapter(
156157
newTextColor = properPrimaryColor
157158
}
158159

159-
if (dimPastEvents && listEvent.isPastEvent && !isPrintVersion) {
160+
val adjustAlpha = if (listEvent.isTask) {
161+
dimCompletedTasks && listEvent.isTaskCompleted
162+
} else {
163+
dimPastEvents && listEvent.isPastEvent && !isPrintVersion
164+
}
165+
if (adjustAlpha) {
160166
newTextColor = newTextColor.adjustAlpha(MEDIUM_ALPHA)
161167
}
162168
} else if (listEvent.startTS <= now && listEvent.endTS >= now && !isPrintVersion) {

app/src/main/kotlin/com/simplemobiletools/calendar/pro/adapters/EventListWidgetAdapter.kt

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ class EventListWidgetAdapter(val context: Context, val intent: Intent) : RemoteV
3030
private var displayDescription = context.config.displayDescription
3131
private var replaceDescription = context.config.replaceDescription
3232
private var dimPastEvents = context.config.dimPastEvents
33+
private var dimCompletedTasks = context.config.dimCompletedTasks
3334
private var mediumFontSize = context.getWidgetFontSize()
3435
private var smallMargin = context.resources.getDimension(R.dimen.small_margin).toInt()
3536
private var normalMargin = context.resources.getDimension(R.dimen.normal_margin).toInt()
@@ -44,6 +45,7 @@ class EventListWidgetAdapter(val context: Context, val intent: Intent) : RemoteV
4445
displayDescription = context.config.displayDescription
4546
replaceDescription = context.config.replaceDescription
4647
dimPastEvents = context.config.dimPastEvents
48+
dimCompletedTasks = context.config.dimCompletedTasks
4749
mediumFontSize = context.getWidgetFontSize()
4850
}
4951

@@ -101,7 +103,7 @@ class EventListWidgetAdapter(val context: Context, val intent: Intent) : RemoteV
101103
setText(R.id.event_item_time, "$timeText\n$descriptionText")
102104
}
103105

104-
if (dimPastEvents && item.isPastEvent) {
106+
if (item.isTask && item.isTaskCompleted && dimCompletedTasks || dimPastEvents && item.isPastEvent) {
105107
curTextColor = weakTextColor
106108
}
107109

app/src/main/kotlin/com/simplemobiletools/calendar/pro/fragments/WeekFragment.kt

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,7 @@ class WeekFragment : Fragment(), WeeklyCalendar {
6161
private var wasFragmentInit = false
6262
private var wasExtraHeightAdded = false
6363
private var dimPastEvents = true
64+
private var dimCompletedTasks = true
6465
private var highlightWeekends = false
6566
private var wasScaled = false
6667
private var isPrintVersion = false
@@ -89,6 +90,7 @@ class WeekFragment : Fragment(), WeeklyCalendar {
8990
defaultRowHeight = res.getDimension(R.dimen.weekly_view_row_height)
9091
weekTimestamp = requireArguments().getLong(WEEK_START_TIMESTAMP)
9192
dimPastEvents = config.dimPastEvents
93+
dimCompletedTasks = config.dimCompletedTasks
9294
highlightWeekends = config.highlightWeekends
9395
primaryColor = requireContext().getProperPrimaryColor()
9496
allDayRows.add(HashSet())
@@ -550,7 +552,14 @@ class WeekFragment : Fragment(), WeeklyCalendar {
550552
var backgroundColor = eventTypeColors.get(event.eventType, primaryColor)
551553
var textColor = backgroundColor.getContrastColor()
552554
val currentEventWeeklyView = eventTimeRanges[currentDayCode]!!.get(event.id)
553-
if (dimPastEvents && event.isPastEvent && !isPrintVersion) {
555+
556+
val adjustAlpha = if (event.isTask()) {
557+
dimCompletedTasks && event.isTaskCompleted()
558+
} else {
559+
dimPastEvents && event.isPastEvent && !isPrintVersion
560+
}
561+
562+
if (adjustAlpha) {
554563
backgroundColor = backgroundColor.adjustAlpha(MEDIUM_ALPHA)
555564
textColor = textColor.adjustAlpha(HIGHER_ALPHA)
556565
}
@@ -684,10 +693,18 @@ class WeekFragment : Fragment(), WeeklyCalendar {
684693
(inflater.inflate(R.layout.week_all_day_event_marker, null, false) as ConstraintLayout).apply {
685694
var backgroundColor = eventTypeColors.get(event.eventType, primaryColor)
686695
var textColor = backgroundColor.getContrastColor()
687-
if (dimPastEvents && event.isPastEvent && !isPrintVersion) {
696+
697+
val adjustAlpha = if (event.isTask()) {
698+
dimCompletedTasks && event.isTaskCompleted()
699+
} else {
700+
dimPastEvents && event.isPastEvent && !isPrintVersion
701+
}
702+
703+
if (adjustAlpha) {
688704
backgroundColor = backgroundColor.adjustAlpha(LOWER_ALPHA)
689705
textColor = textColor.adjustAlpha(HIGHER_ALPHA)
690706
}
707+
691708
background = ColorDrawable(backgroundColor)
692709

693710
week_event_label.apply {

app/src/main/kotlin/com/simplemobiletools/calendar/pro/helpers/Config.kt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -138,6 +138,10 @@ class Config(context: Context) : BaseConfig(context) {
138138
get() = prefs.getBoolean(DIM_PAST_EVENTS, true)
139139
set(dimPastEvents) = prefs.edit().putBoolean(DIM_PAST_EVENTS, dimPastEvents).apply()
140140

141+
var dimCompletedTasks: Boolean
142+
get() = prefs.getBoolean(DIM_COMPLETED_TASKS, true)
143+
set(dimCompletedTasks) = prefs.edit().putBoolean(DIM_COMPLETED_TASKS, dimCompletedTasks).apply()
144+
141145
fun getSyncedCalendarIdsAsList() =
142146
caldavSyncedCalendarIds.split(",").filter { it.trim().isNotEmpty() }.map { Integer.parseInt(it) }.toMutableList() as ArrayList<Int>
143147

app/src/main/kotlin/com/simplemobiletools/calendar/pro/helpers/Constants.kt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,7 @@ const val REPLACE_DESCRIPTION = "replace_description"
8787
const val SHOW_GRID = "show_grid"
8888
const val LOOP_REMINDERS = "loop_reminders"
8989
const val DIM_PAST_EVENTS = "dim_past_events"
90+
const val DIM_COMPLETED_TASKS = "dim_completed_tasks"
9091
const val LAST_SOUND_URI = "last_sound_uri"
9192
const val LAST_REMINDER_CHANNEL_ID = "last_reminder_channel_ID"
9293
const val REMINDER_AUDIO_STREAM = "reminder_audio_stream"

app/src/main/kotlin/com/simplemobiletools/calendar/pro/helpers/MyWidgetMonthlyProvider.kt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,7 @@ class MyWidgetMonthlyProvider : AppWidgetProvider() {
9797
val displayWeekNumbers = context.config.showWeekNumbers
9898
val textColor = context.config.widgetTextColor
9999
val dimPastEvents = context.config.dimPastEvents
100+
val dimCompletedTasks = context.config.dimCompletedTasks
100101
val smallerFontSize = context.getWidgetFontSize() - 3f
101102
val res = context.resources
102103
val len = days.size
@@ -140,7 +141,7 @@ class MyWidgetMonthlyProvider : AppWidgetProvider() {
140141
var backgroundColor = it.color
141142
var eventTextColor = backgroundColor.getContrastColor()
142143

143-
if (!day.isThisMonth || (dimPastEvents && it.isPastEvent)) {
144+
if (it.isTask() && it.isTaskCompleted() && dimCompletedTasks || !day.isThisMonth || (dimPastEvents && it.isPastEvent)) {
144145
eventTextColor = eventTextColor.adjustAlpha(MEDIUM_ALPHA)
145146
backgroundColor = backgroundColor.adjustAlpha(MEDIUM_ALPHA)
146147
}
Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,12 @@
11
package com.simplemobiletools.calendar.pro.models
22

3-
data class DayMonthly(val value: Int, val isThisMonth: Boolean, val isToday: Boolean, val code: String, val weekOfYear: Int, var dayEvents: ArrayList<Event>,
4-
var indexOnMonthView: Int, var isWeekend: Boolean)
3+
data class DayMonthly(
4+
val value: Int,
5+
val isThisMonth: Boolean,
6+
val isToday: Boolean,
7+
val code: String,
8+
val weekOfYear: Int,
9+
var dayEvents: ArrayList<Event>,
10+
var indexOnMonthView: Int,
11+
var isWeekend: Boolean
12+
)

0 commit comments

Comments
 (0)