Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -159,9 +159,11 @@ class MainActivity : SimpleActivity(), RefreshRecyclerViewListener {
private var mStoredUse24HourFormat = false
private var mStoredDimPastEvents = true
private var mStoredDimCompletedTasks = true
private var mStoredHighlightWeekends = false
private var mStoredHighlightSaturdays = false
private var mStoredHighlightSundays = false
private var mStoredStartWeekWithCurrentDay = false
private var mStoredHighlightWeekendsColor = 0
private var mStoredHighlightSaturdaysColor = 0
private var mStoredHighlightSundaysColor = 0

// search results have endless scrolling, so reaching the top/bottom fetches further results
private var minFetchedSearchTS = 0L
Expand Down Expand Up @@ -252,7 +254,7 @@ class MainActivity : SimpleActivity(), RefreshRecyclerViewListener {
super.onResume()
if (mStoredTextColor != getProperTextColor() || mStoredBackgroundColor != getProperBackgroundColor() || mStoredPrimaryColor != getProperPrimaryColor()
|| mStoredDayCode != Formatter.getTodayCode() || mStoredDimPastEvents != config.dimPastEvents || mStoredDimCompletedTasks != config.dimCompletedTasks
|| mStoredHighlightWeekends != config.highlightWeekends || mStoredHighlightWeekendsColor != config.highlightWeekendsColor
|| mStoredHighlightSaturdays != config.highlightSaturdays || mStoredHighlightSundays != config.highlightSundays || mStoredHighlightSaturdaysColor != config.highlightSaturdaysColor || mStoredHighlightSundaysColor != config.highlightSundaysColor
) {
updateViewPager()
}
Expand Down Expand Up @@ -407,8 +409,10 @@ class MainActivity : SimpleActivity(), RefreshRecyclerViewListener {
mStoredUse24HourFormat = use24HourFormat
mStoredDimPastEvents = dimPastEvents
mStoredDimCompletedTasks = dimCompletedTasks
mStoredHighlightWeekends = highlightWeekends
mStoredHighlightWeekendsColor = highlightWeekendsColor
mStoredHighlightSaturdays = highlightSaturdays
mStoredHighlightSaturdaysColor = highlightSaturdaysColor
mStoredHighlightSundays = highlightSundays
mStoredHighlightSundaysColor = highlightSundaysColor
mStoredMidnightSpan = showMidnightSpanningEventsAtTop
mStoredStartWeekWithCurrentDay = startWeekWithCurrentDay
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,10 @@ import org.fossify.calendar.helpers.DISPLAY_DESCRIPTION
import org.fossify.calendar.helpers.DISPLAY_PAST_EVENTS
import org.fossify.calendar.helpers.EVENTS_LIST_VIEW
import org.fossify.calendar.helpers.Formatter
import org.fossify.calendar.helpers.HIGHLIGHT_WEEKENDS
import org.fossify.calendar.helpers.HIGHLIGHT_WEEKENDS_COLOR
import org.fossify.calendar.helpers.HIGHLIGHT_SATURDAYS
import org.fossify.calendar.helpers.HIGHLIGHT_SATURDAYS_COLOR
import org.fossify.calendar.helpers.HIGHLIGHT_SUNDAYS
import org.fossify.calendar.helpers.HIGHLIGHT_SUNDAYS_COLOR
import org.fossify.calendar.helpers.IcsExporter
import org.fossify.calendar.helpers.LAST_EVENT_REMINDER_MINUTES
import org.fossify.calendar.helpers.LAST_EVENT_REMINDER_MINUTES_2
Expand Down Expand Up @@ -187,8 +189,10 @@ class SettingsActivity : SimpleActivity() {
setupHourFormat()
setupAllowCreatingTasks()
setupStartWeekOn()
setupHighlightWeekends()
setupHighlightWeekendsColor()
setupHighlightSaturdays()
setupHighlightSaturdaysColor()
setupHighlightSundays()
setupHighlightSundaysColor()
setupDeleteAllEvents()
setupDisplayDescription()
setupReplaceDescription()
Expand Down Expand Up @@ -508,29 +512,60 @@ class SettingsActivity : SimpleActivity() {
}
}

private fun setupHighlightWeekends() = binding.apply {
settingsHighlightWeekends.isChecked = config.highlightWeekends
settingsHighlightWeekendsColorHolder.beVisibleIf(config.highlightWeekends)
settingsHighlightWeekendsHolder.setOnClickListener {
settingsHighlightWeekends.toggle()
config.highlightWeekends = settingsHighlightWeekends.isChecked
settingsHighlightWeekendsColorHolder.beVisibleIf(config.highlightWeekends)
private fun setupHighlightSaturdays() = binding.apply {
settingsHighlightSaturdays.isChecked = config.highlightSaturdays
settingsHighlightSaturdaysColorHolder.beVisibleIf(config.highlightSaturdays)
settingsHighlightSaturdaysHolder.setOnClickListener {
settingsHighlightSaturdays.toggle()
config.highlightSaturdays = settingsHighlightSaturdays.isChecked
settingsHighlightSaturdaysColorHolder.beVisibleIf(config.highlightSaturdays)
}
}

private fun setupHighlightWeekendsColor() = binding.apply {
settingsHighlightWeekendsColor.setFillWithStroke(
config.highlightWeekendsColor,
private fun setupHighlightSaturdaysColor() = binding.apply {
settingsHighlightSaturdaysColor.setFillWithStroke(
config.highlightSaturdaysColor,
getProperBackgroundColor()
)
settingsHighlightWeekendsColorHolder.setOnClickListener {
settingsHighlightSaturdaysColorHolder.setOnClickListener {
ColorPickerDialog(
activity = this@SettingsActivity,
color = config.highlightWeekendsColor
color = config.highlightSaturdaysColor
) { wasPositivePressed, color ->
if (wasPositivePressed) {
config.highlightWeekendsColor = color
settingsHighlightWeekendsColor.setFillWithStroke(
config.highlightSaturdaysColor = color
settingsHighlightSaturdaysColor.setFillWithStroke(
color,
getProperBackgroundColor()
)
}
}
}
}

private fun setupHighlightSundays() = binding.apply {
settingsHighlightSundays.isChecked = config.highlightSundays
settingsHighlightSundaysColorHolder.beVisibleIf(config.highlightSundays)
settingsHighlightSundaysHolder.setOnClickListener {
settingsHighlightSundays.toggle()
config.highlightSundays = settingsHighlightSundays.isChecked
settingsHighlightSundaysColorHolder.beVisibleIf(config.highlightSundays)
}
}

private fun setupHighlightSundaysColor() = binding.apply {
settingsHighlightSundaysColor.setFillWithStroke(
config.highlightSundaysColor,
getProperBackgroundColor()
)
settingsHighlightSundaysColorHolder.setOnClickListener {
ColorPickerDialog(
activity = this@SettingsActivity,
color = config.highlightSundaysColor
) { wasPositivePressed, color ->
if (wasPositivePressed) {
config.highlightSundaysColor = color
settingsHighlightSundaysColor.setFillWithStroke(
color,
getProperBackgroundColor()
)
Expand Down Expand Up @@ -1154,8 +1189,10 @@ class SettingsActivity : SimpleActivity() {
put(SNOOZE_TIME, config.snoozeTime)
put(USE_24_HOUR_FORMAT, config.use24HourFormat)
put(FIRST_DAY_OF_WEEK, config.firstDayOfWeek)
put(HIGHLIGHT_WEEKENDS, config.highlightWeekends)
put(HIGHLIGHT_WEEKENDS_COLOR, config.highlightWeekendsColor)
put(HIGHLIGHT_SATURDAYS, config.highlightSaturdays)
put(HIGHLIGHT_SATURDAYS_COLOR, config.highlightSaturdaysColor)
put(HIGHLIGHT_SUNDAYS, config.highlightSundays)
put(HIGHLIGHT_SUNDAYS_COLOR, config.highlightSundaysColor)
put(ALLOW_CREATING_TASKS, config.allowCreatingTasks)
}

Expand Down Expand Up @@ -1270,8 +1307,10 @@ class SettingsActivity : SimpleActivity() {
USE_24_HOUR_FORMAT -> config.use24HourFormat = value.toBoolean()
SUNDAY_FIRST -> config.firstDayOfWeek = DateTimeConstants.SUNDAY
FIRST_DAY_OF_WEEK -> config.firstDayOfWeek = value.toInt()
HIGHLIGHT_WEEKENDS -> config.highlightWeekends = value.toBoolean()
HIGHLIGHT_WEEKENDS_COLOR -> config.highlightWeekendsColor = value.toInt()
HIGHLIGHT_SATURDAYS -> config.highlightSaturdays = value.toBoolean()
HIGHLIGHT_SATURDAYS_COLOR -> config.highlightSaturdaysColor = value.toInt()
HIGHLIGHT_SUNDAYS -> config.highlightSundays = value.toBoolean()
HIGHLIGHT_SUNDAYS_COLOR -> config.highlightSundaysColor = value.toInt()
ALLOW_CREATING_TASKS -> config.allowCreatingTasks = value.toBoolean()
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,8 @@ import org.fossify.calendar.databinding.TopNavigationBinding
import org.fossify.calendar.databinding.WidgetConfigMonthlyBinding
import org.fossify.calendar.extensions.addDayEvents
import org.fossify.calendar.extensions.config
import org.fossify.calendar.extensions.isWeekendIndex
import org.fossify.calendar.extensions.isSaturdayIndex
import org.fossify.calendar.extensions.isSundayIndex
import org.fossify.calendar.helpers.MonthlyCalendarImpl
import org.fossify.calendar.helpers.MyWidgetMonthlyProvider
import org.fossify.calendar.interfaces.MonthlyCalendar
Expand Down Expand Up @@ -174,8 +175,10 @@ class WidgetMonthlyConfigureActivity : SimpleActivity(), MonthlyCalendar {

for (i in 0 until daysLength) {
val day = mDays!![i]
val dayTextColor = if (config.highlightWeekends && day.isWeekend) {
config.highlightWeekendsColor
val dayTextColor = if (config.highlightSaturdays && day.isSaturday) {
config.highlightSaturdaysColor
} else if (config.highlightSundays && day.isSunday) {
config.highlightSundaysColor
} else {
mTextColor
}
Expand Down Expand Up @@ -222,11 +225,14 @@ class WidgetMonthlyConfigureActivity : SimpleActivity(), MonthlyCalendar {
}

private fun updateLabels() {
val weekendsTextColor = config.highlightWeekendsColor
val saturdaysTextColor = config.highlightSaturdaysColor
val sundaysTextColor = config.highlightSundaysColor
binding.configCalendar.firstRow.apply {
arrayOf(label0, label1, label2, label3, label4, label5, label6).forEachIndexed { index, textView ->
val textColor = if (config.highlightWeekends && isWeekendIndex(index)) {
weekendsTextColor
val textColor = if (config.highlightSaturdays && isSaturdayIndex(index)) {
saturdaysTextColor
} else if (config.highlightSundays && isSundayIndex(index)) {
sundaysTextColor
} else {
mTextColor
}
Expand Down
19 changes: 16 additions & 3 deletions app/src/main/kotlin/org/fossify/calendar/extensions/Context.kt
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,8 @@ import org.fossify.calendar.helpers.getActivityToOpen
import org.fossify.calendar.helpers.getNextAutoBackupTime
import org.fossify.calendar.helpers.getNowSeconds
import org.fossify.calendar.helpers.getPreviousAutoBackupTime
import org.fossify.calendar.helpers.isWeekend
import org.fossify.calendar.helpers.isSaturday
import org.fossify.calendar.helpers.isSunday
import org.fossify.calendar.interfaces.CalendarsDao
import org.fossify.calendar.interfaces.EventsDao
import org.fossify.calendar.interfaces.TasksDao
Expand Down Expand Up @@ -1057,7 +1058,7 @@ fun Context.getProperDayIndexInWeek(date: DateTime): Int {
return dayIndex
}

fun Context.isWeekendIndex(dayIndex: Int): Boolean {
fun Context.isSaturdayIndex(dayIndex: Int): Boolean {
val firstDayOfWeek = config.firstDayOfWeek
val shiftedIndex = (dayIndex + firstDayOfWeek) % 7
val dayOfWeek = if (shiftedIndex == 0) {
Expand All @@ -1066,7 +1067,19 @@ fun Context.isWeekendIndex(dayIndex: Int): Boolean {
shiftedIndex
}

return isWeekend(dayOfWeek)
return isSaturday(dayOfWeek)
}

fun Context.isSundayIndex(dayIndex: Int): Boolean {
val firstDayOfWeek = config.firstDayOfWeek
val shiftedIndex = (dayIndex + firstDayOfWeek) % 7
val dayOfWeek = if (shiftedIndex == 0) {
DateTimeConstants.SUNDAY
} else {
shiftedIndex
}

return isSunday(dayOfWeek)
}

fun Context.isTaskCompleted(event: Event): Boolean {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,8 @@ import org.fossify.calendar.helpers.TYPE_TASK
import org.fossify.calendar.helpers.WEEK_START_TIMESTAMP
import org.fossify.calendar.helpers.WeeklyCalendarImpl
import org.fossify.calendar.helpers.getActivityToOpen
import org.fossify.calendar.helpers.isWeekend
import org.fossify.calendar.helpers.isSaturday
import org.fossify.calendar.helpers.isSunday
import org.fossify.calendar.interfaces.WeekFragmentListener
import org.fossify.calendar.interfaces.WeeklyCalendar
import org.fossify.calendar.models.Event
Expand Down Expand Up @@ -118,7 +119,8 @@ class WeekFragment : Fragment(), WeeklyCalendar {
private var wasExtraHeightAdded = false
private var dimPastEvents = true
private var dimCompletedTasks = true
private var highlightWeekends = false
private var highlightSaturdays = false
private var highlightSundays = false
private var wasScaled = false
private var isPrintVersion = false
private var selectedGrid: View? = null
Expand Down Expand Up @@ -148,7 +150,8 @@ class WeekFragment : Fragment(), WeeklyCalendar {
weekDateTime = Formatter.getDateTimeFromTS(weekTimestamp)
dimPastEvents = config.dimPastEvents
dimCompletedTasks = config.dimCompletedTasks
highlightWeekends = config.highlightWeekends
highlightSaturdays = config.highlightSaturdays
highlightSundays = config.highlightSundays
primaryColor = requireContext().getProperPrimaryColor()
allDayRows.add(HashSet())
}
Expand Down Expand Up @@ -291,7 +294,8 @@ class WeekFragment : Fragment(), WeeklyCalendar {

val textColor = when {
!isPrintVersion && todayCode == dayCode -> primaryColor
highlightWeekends && isWeekend(curDay.dayOfWeek) -> config.highlightWeekendsColor
highlightSaturdays && isSaturday(curDay.dayOfWeek) -> config.highlightSaturdaysColor
highlightSundays && isSunday(curDay.dayOfWeek) -> config.highlightSundaysColor
isPrintVersion -> resources.getColor(org.fossify.commons.R.color.theme_light_text_color)
else -> requireContext().getProperTextColor()
}
Expand Down
24 changes: 17 additions & 7 deletions app/src/main/kotlin/org/fossify/calendar/helpers/Config.kt
Original file line number Diff line number Diff line change
Expand Up @@ -284,15 +284,25 @@ class Config(context: Context) : BaseConfig(context) {
get() = prefs.getInt(WEEKLY_VIEW_DAYS, 7)
set(weeklyViewDays) = prefs.edit().putInt(WEEKLY_VIEW_DAYS, weeklyViewDays).apply()

var highlightWeekends: Boolean
get() = prefs.getBoolean(HIGHLIGHT_WEEKENDS, false)
set(highlightWeekends) = prefs.edit().putBoolean(HIGHLIGHT_WEEKENDS, highlightWeekends)
var highlightSaturdays: Boolean
get() = prefs.getBoolean(HIGHLIGHT_SATURDAYS, false)
set(highlightSaturdays) = prefs.edit().putBoolean(HIGHLIGHT_SATURDAYS, highlightSaturdays)
.apply()

var highlightWeekendsColor: Int
get() = prefs.getInt(HIGHLIGHT_WEEKENDS_COLOR, context.resources.getColor(R.color.red_text))
set(highlightWeekendsColor) = prefs.edit()
.putInt(HIGHLIGHT_WEEKENDS_COLOR, highlightWeekendsColor).apply()
var highlightSaturdaysColor: Int
get() = prefs.getInt(HIGHLIGHT_SATURDAYS_COLOR, context.resources.getColor(R.color.red_text))
set(highlightSaturdaysColor) = prefs.edit()
.putInt(HIGHLIGHT_SATURDAYS_COLOR, highlightSaturdaysColor).apply()

var highlightSundays: Boolean
get() = prefs.getBoolean(HIGHLIGHT_SUNDAYS, false)
set(highlightSundays) = prefs.edit().putBoolean(HIGHLIGHT_SUNDAYS, highlightSundays)
.apply()

var highlightSundaysColor: Int
get() = prefs.getInt(HIGHLIGHT_SUNDAYS_COLOR, context.resources.getColor(R.color.red_text))
set(highlightSundaysColor) = prefs.edit()
.putInt(HIGHLIGHT_SUNDAYS_COLOR, highlightSundaysColor).apply()

var lastUsedEventSpan: Int
get() = prefs.getInt(LAST_USED_EVENT_SPAN, YEAR_SECONDS)
Expand Down
17 changes: 12 additions & 5 deletions app/src/main/kotlin/org/fossify/calendar/helpers/Constants.kt
Original file line number Diff line number Diff line change
Expand Up @@ -135,8 +135,10 @@ const val EXPORT_TASKS = "export_tasks"
const val EXPORT_PAST_EVENTS = "export_past_events"
const val WEEKLY_VIEW_ITEM_HEIGHT_MULTIPLIER = "weekly_view_item_height_multiplier"
const val WEEKLY_VIEW_DAYS = "weekly_view_days"
const val HIGHLIGHT_WEEKENDS = "highlight_weekends"
const val HIGHLIGHT_WEEKENDS_COLOR = "highlight_weekends_color"
const val HIGHLIGHT_SATURDAYS = "highlight_saturdays"
const val HIGHLIGHT_SUNDAYS = "highlight_sundays"
const val HIGHLIGHT_SATURDAYS_COLOR = "highlight_saturdays_color"
const val HIGHLIGHT_SUNDAYS_COLOR = "highlight_sundays_color"
const val LAST_USED_EVENT_SPAN = "last_used_event_span"
const val ALLOW_CREATING_TASKS = "allow_creating_tasks"
const val WAS_FILTERED_OUT_WARNING_SHOWN = "was_filtered_out_warning_shown"
Expand Down Expand Up @@ -295,9 +297,14 @@ const val ACTION_MARK_COMPLETED = "ACTION_MARK_COMPLETED"

fun getNowSeconds() = System.currentTimeMillis() / 1000L

fun isWeekend(dayOfWeek: Int): Boolean {
val weekendDays = listOf(DateTimeConstants.SATURDAY, DateTimeConstants.SUNDAY)
return dayOfWeek in weekendDays
fun isSaturday(dayOfWeek: Int): Boolean {
val saturDays = listOf(DateTimeConstants.SATURDAY)
return dayOfWeek in saturDays
}

fun isSunday(dayOfWeek: Int): Boolean {
val sunDays = listOf(DateTimeConstants.SUNDAY)
return dayOfWeek in sunDays
}

fun getActivityToOpen(isTask: Boolean) = if (isTask) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@ package org.fossify.calendar.helpers
import android.content.Context
import org.fossify.calendar.extensions.eventsHelper
import org.fossify.calendar.extensions.getProperDayIndexInWeek
import org.fossify.calendar.extensions.isWeekendIndex
import org.fossify.calendar.extensions.isSaturdayIndex
import org.fossify.calendar.extensions.isSundayIndex
import org.fossify.calendar.extensions.seconds
import org.fossify.calendar.interfaces.MonthlyCalendar
import org.fossify.calendar.models.DayMonthly
Expand Down Expand Up @@ -70,7 +71,7 @@ class MonthlyCalendarImpl(val callback: MonthlyCalendar, val context: Context) {

val newDay = curDay.withDayOfMonth(value)
val dayCode = Formatter.getDayCodeFromDateTime(newDay)
val day = DayMonthly(value, isThisMonth, isToday, dayCode, newDay.weekOfWeekyear, ArrayList(), i, context.isWeekendIndex(i))
val day = DayMonthly(value, isThisMonth, isToday, dayCode, newDay.weekOfWeekyear, ArrayList(), i, context.isSaturdayIndex(i), context.isSundayIndex(i))
days.add(day)
value++
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -120,8 +120,10 @@ class MyWidgetMonthlyProvider : AppWidgetProvider() {
for (i in 0 until len) {
val day = days[i]

val dayTextColor = if (context.config.highlightWeekends && day.isWeekend) {
context.config.highlightWeekendsColor
val dayTextColor = if (context.config.highlightSaturdays && day.isSaturday) {
context.config.highlightSaturdaysColor
} else if (context.config.highlightSundays && day.isSunday) {
context.config.highlightSundaysColor
} else {
textColor
}
Expand Down Expand Up @@ -240,8 +242,10 @@ class MyWidgetMonthlyProvider : AppWidgetProvider() {

for (i in 0..6) {
val id = resources.getIdentifier("label_$i", "id", packageName)
val dayTextColor = if (context.config.highlightWeekends && context.isWeekendIndex(i)) {
context.config.highlightWeekendsColor
val dayTextColor = if (context.config.highlightSaturdays && context.isSaturdayIndex(i)) {
context.config.highlightSaturdaysColor
} else if (context.config.highlightSundays && context.isSundayIndex(i)) {
context.config.highlightSundaysColor
} else {
textColor
}
Expand Down
Loading
Loading