diff --git a/app/src/main/kotlin/com/simplemobiletools/calendar/pro/activities/SettingsActivity.kt b/app/src/main/kotlin/com/simplemobiletools/calendar/pro/activities/SettingsActivity.kt
index 52096ddca..26c2bc34b 100644
--- a/app/src/main/kotlin/com/simplemobiletools/calendar/pro/activities/SettingsActivity.kt
+++ b/app/src/main/kotlin/com/simplemobiletools/calendar/pro/activities/SettingsActivity.kt
@@ -54,6 +54,7 @@ class SettingsActivity : SimpleActivity() {
setupWeekNumbers()
setupShowGrid()
setupWeeklyStart()
+ setupMidnightSpanEvents()
setupVibrate()
setupReminderSound()
setupReminderAudioStream()
@@ -322,6 +323,14 @@ class SettingsActivity : SimpleActivity() {
}
}
+ private fun setupMidnightSpanEvents() {
+ settings_midnight_span_event.isChecked = config.showMidnightSpanningEventsAtTop
+ settings_midnight_span_events_holder.setOnClickListener {
+ settings_midnight_span_event.toggle()
+ config.showMidnightSpanningEventsAtTop = settings_midnight_span_event.isChecked
+ }
+ }
+
private fun setupWeekNumbers() {
settings_week_numbers.isChecked = config.showWeekNumbers
settings_week_numbers_holder.setOnClickListener {
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 f5ba0dbe9..d3d70b480 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
@@ -398,102 +398,132 @@ class WeekFragment : Fragment(), WeeklyCalendar {
for (event in events) {
val startDateTime = Formatter.getDateTimeFromTS(event.startTS)
+ val startDayCode = Formatter.getDayCodeFromDateTime(startDateTime)
val endDateTime = Formatter.getDateTimeFromTS(event.endTS)
- if (!event.getIsAllDay() && Formatter.getDayCodeFromDateTime(startDateTime) == Formatter.getDayCodeFromDateTime(endDateTime)) {
- val startMinutes = startDateTime.minuteOfDay
- val duration = endDateTime.minuteOfDay - startMinutes
- val range = Range(startMinutes, startMinutes + maxOf(1,duration))
+ val endDayCode = Formatter.getDayCodeFromDateTime(endDateTime)
+
+ if (event.getIsAllDay() || ((startDayCode != endDayCode) && config.showMidnightSpanningEventsAtTop)) {
+ continue
+ }
+
+ var currentDateTime = startDateTime
+ var currentDayCode = Formatter.getDayCodeFromDateTime(currentDateTime)
+ do {
+ val startMinutes = when (currentDayCode == startDayCode) {
+ true -> (startDateTime.minuteOfDay)
+ else -> 0
+ }
+ val duration = when (currentDayCode == endDayCode) {
+ true -> (endDateTime.minuteOfDay - startMinutes)
+ else -> 1440
+ }
+ val range = Range(startMinutes, startMinutes + duration)
val eventWeekly = EventWeeklyView(event.id!!, range)
- val dayCode = Formatter.getDayCodeFromDateTime(startDateTime)
- if (!eventTimeRanges.containsKey(dayCode)) {
- eventTimeRanges[dayCode] = ArrayList()
+ if (!eventTimeRanges.containsKey(currentDayCode)) {
+ eventTimeRanges[currentDayCode] = ArrayList()
}
+ eventTimeRanges[currentDayCode]?.add(eventWeekly)
- eventTimeRanges[dayCode]?.add(eventWeekly)
- }
+ currentDateTime = currentDateTime.plusDays(1)
+ currentDayCode = Formatter.getDayCodeFromDateTime(currentDateTime)
+ } while(currentDayCode.toInt() <= endDayCode.toInt())
}
for (event in events) {
val startDateTime = Formatter.getDateTimeFromTS(event.startTS)
+ val startDayCode = Formatter.getDayCodeFromDateTime(startDateTime)
val endDateTime = Formatter.getDateTimeFromTS(event.endTS)
- if (event.getIsAllDay() || Formatter.getDayCodeFromDateTime(startDateTime) != Formatter.getDayCodeFromDateTime(endDateTime)) {
+ val endDayCode = Formatter.getDayCodeFromDateTime(endDateTime)
+ if (event.getIsAllDay() || ((startDayCode != endDayCode) && config.showMidnightSpanningEventsAtTop)) {
addAllDayEvent(event)
- } else {
- val dayCode = Formatter.getDayCodeFromDateTime(startDateTime)
- val dayOfWeek = dayColumns.indexOfFirst { it.tag == dayCode }
- if (dayOfWeek == -1 || dayOfWeek >= config.weeklyViewDays) {
- continue
- }
-
- val startMinutes = startDateTime.minuteOfDay
- val duration = endDateTime.minuteOfDay - startMinutes
- val range = Range(startMinutes, startMinutes + maxOf(1, duration))
-
- var overlappingEvents = 0
- var currentEventOverlapIndex = 0
- var foundCurrentEvent = false
-
- eventTimeRanges[dayCode]!!.forEachIndexed { index, eventWeeklyView ->
- if (eventWeeklyView.range.touch(range)) {
- overlappingEvents++
-
- if (eventWeeklyView.id == event.id) {
- foundCurrentEvent = true
- }
-
- if (!foundCurrentEvent) {
- currentEventOverlapIndex++
- }
- }
- }
-
- val dayColumn = dayColumns[dayOfWeek]
- (inflater.inflate(R.layout.week_event_marker, null, false) as TextView).apply {
- var backgroundColor = eventTypeColors.get(event.eventType, primaryColor)
- var textColor = backgroundColor.getContrastColor()
- if (dimPastEvents && event.isPastEvent && !isPrintVersion) {
- backgroundColor = backgroundColor.adjustAlpha(LOWER_ALPHA)
- textColor = textColor.adjustAlpha(HIGHER_ALPHA)
+ }
+ else {
+ var currentDateTime = startDateTime
+ var currentDayCode = Formatter.getDayCodeFromDateTime(currentDateTime)
+ do {
+ val dayOfWeek = dayColumns.indexOfFirst { it.tag == currentDayCode }
+ if (dayOfWeek == -1 || dayOfWeek >= config.weeklyViewDays) {
+ continue
}
- background = ColorDrawable(backgroundColor)
- setTextColor(textColor)
- text = event.title
- contentDescription = text
- dayColumn.addView(this)
- y = startMinutes * minuteHeight
- (layoutParams as RelativeLayout.LayoutParams).apply {
- width = dayColumn.width - 1
- width /= Math.max(overlappingEvents, 1)
- if (overlappingEvents > 1) {
- x = width * currentEventOverlapIndex.toFloat()
- if (currentEventOverlapIndex != 0) {
- x += density
+ val startMinutes = when (currentDayCode == startDayCode) {
+ true -> (startDateTime.minuteOfDay)
+ else -> 0
+ }
+ val duration = when (currentDayCode == endDayCode) {
+ true -> (endDateTime.minuteOfDay - startMinutes)
+ else -> 1440
+ }
+ val range = Range(startMinutes, startMinutes + duration)
+ var overlappingEvents = 0
+ var currentEventOverlapIndex = 0
+ var foundCurrentEvent = false
+
+ eventTimeRanges[currentDayCode]!!.forEachIndexed { index, eventWeeklyView ->
+ if (eventWeeklyView.range.touch(range)) {
+ overlappingEvents++
+
+ if (eventWeeklyView.id == event.id) {
+ foundCurrentEvent = true
}
- width -= density
- if (currentEventOverlapIndex + 1 != overlappingEvents) {
+ if (!foundCurrentEvent) {
+ currentEventOverlapIndex++
+ }
+ }
+ }
+
+ val dayColumn = dayColumns[dayOfWeek]
+ (inflater.inflate(R.layout.week_event_marker, null, false) as TextView).apply {
+ var backgroundColor = eventTypeColors.get(event.eventType, primaryColor)
+ var textColor = backgroundColor.getContrastColor()
+ if (dimPastEvents && event.isPastEvent && !isPrintVersion) {
+ backgroundColor = backgroundColor.adjustAlpha(LOWER_ALPHA)
+ textColor = textColor.adjustAlpha(HIGHER_ALPHA)
+ }
+
+ background = ColorDrawable(backgroundColor)
+ setTextColor(textColor)
+ text = event.title
+ contentDescription = text
+ dayColumn.addView(this)
+ y = startMinutes * minuteHeight
+ (layoutParams as RelativeLayout.LayoutParams).apply {
+ width = dayColumn.width - 1
+ width /= Math.max(overlappingEvents, 1)
+ if (overlappingEvents > 1) {
+ x = width * currentEventOverlapIndex.toFloat()
if (currentEventOverlapIndex != 0) {
- width -= density
+ x += density
+ }
+
+ width -= density
+ if (currentEventOverlapIndex + 1 != overlappingEvents) {
+ if (currentEventOverlapIndex != 0) {
+ width -= density
+ }
}
}
- }
- minHeight = if (event.startTS == event.endTS) {
- minimalHeight
- } else {
- (duration * minuteHeight).toInt() - 1
+ minHeight = if (event.startTS == event.endTS) {
+ minimalHeight
+ } else {
+ (duration * minuteHeight).toInt() - 1
+ }
+ }
+ setOnClickListener {
+ Intent(context, EventActivity::class.java).apply {
+ putExtra(EVENT_ID, event.id!!)
+ putExtra(EVENT_OCCURRENCE_TS, event.startTS)
+ startActivity(this)
+ }
}
}
- setOnClickListener {
- Intent(context, EventActivity::class.java).apply {
- putExtra(EVENT_ID, event.id!!)
- putExtra(EVENT_OCCURRENCE_TS, event.startTS)
- startActivity(this)
- }
- }
- }
+
+ currentDateTime = currentDateTime.plusDays(1)
+ currentDayCode = Formatter.getDayCodeFromDateTime(currentDateTime)
+ } while(currentDayCode.toInt() <= endDayCode.toInt())
}
}
diff --git a/app/src/main/kotlin/com/simplemobiletools/calendar/pro/helpers/Config.kt b/app/src/main/kotlin/com/simplemobiletools/calendar/pro/helpers/Config.kt
index bb7f963f6..477e22940 100644
--- a/app/src/main/kotlin/com/simplemobiletools/calendar/pro/helpers/Config.kt
+++ b/app/src/main/kotlin/com/simplemobiletools/calendar/pro/helpers/Config.kt
@@ -23,6 +23,10 @@ class Config(context: Context) : BaseConfig(context) {
get() = prefs.getInt(START_WEEKLY_AT, 7)
set(startWeeklyAt) = prefs.edit().putInt(START_WEEKLY_AT, startWeeklyAt).apply()
+ var showMidnightSpanningEventsAtTop: Boolean
+ get() = prefs.getBoolean(SHOW_MIDNIGHT_SPANNING_EVENTS_AT_TOP, true)
+ set(midnightSpanning) = prefs.edit().putBoolean(SHOW_MIDNIGHT_SPANNING_EVENTS_AT_TOP, midnightSpanning).apply()
+
var vibrateOnReminder: Boolean
get() = prefs.getBoolean(VIBRATE, false)
set(vibrate) = prefs.edit().putBoolean(VIBRATE, vibrate).apply()
diff --git a/app/src/main/kotlin/com/simplemobiletools/calendar/pro/helpers/Constants.kt b/app/src/main/kotlin/com/simplemobiletools/calendar/pro/helpers/Constants.kt
index 962cbedd1..e292260e5 100644
--- a/app/src/main/kotlin/com/simplemobiletools/calendar/pro/helpers/Constants.kt
+++ b/app/src/main/kotlin/com/simplemobiletools/calendar/pro/helpers/Constants.kt
@@ -45,6 +45,7 @@ const val YEAR = 31536000
// Shared Preferences
const val WEEK_NUMBERS = "week_numbers"
const val START_WEEKLY_AT = "start_weekly_at"
+const val SHOW_MIDNIGHT_SPANNING_EVENTS_AT_TOP = "show_midnight_spanning_events_at_top"
const val VIBRATE = "vibrate"
const val REMINDER_SOUND_URI = "reminder_sound_uri"
const val REMINDER_SOUND_TITLE = "reminder_sound_title"
diff --git a/app/src/main/res/layout/activity_settings.xml b/app/src/main/res/layout/activity_settings.xml
index f7b2940d8..39e3d6aee 100644
--- a/app/src/main/res/layout/activity_settings.xml
+++ b/app/src/main/res/layout/activity_settings.xml
@@ -679,6 +679,28 @@
+
+
+
+
+
+