improving some weekly view overlapping

This commit is contained in:
tibbi 2019-02-14 16:28:26 +01:00
parent c97628fdfc
commit df241feea0
2 changed files with 22 additions and 10 deletions

View File

@ -0,0 +1,5 @@
package com.simplemobiletools.calendar.pro.extensions
import android.util.Range
fun Range<Int>.touch(other: Range<Int>) = (upper > other.lower && lower < other.upper) || (other.upper > lower && other.lower < upper)

View File

@ -20,6 +20,7 @@ import com.simplemobiletools.calendar.pro.activities.EventActivity
import com.simplemobiletools.calendar.pro.extensions.config import com.simplemobiletools.calendar.pro.extensions.config
import com.simplemobiletools.calendar.pro.extensions.eventsHelper import com.simplemobiletools.calendar.pro.extensions.eventsHelper
import com.simplemobiletools.calendar.pro.extensions.seconds import com.simplemobiletools.calendar.pro.extensions.seconds
import com.simplemobiletools.calendar.pro.extensions.touch
import com.simplemobiletools.calendar.pro.helpers.* import com.simplemobiletools.calendar.pro.helpers.*
import com.simplemobiletools.calendar.pro.helpers.Formatter import com.simplemobiletools.calendar.pro.helpers.Formatter
import com.simplemobiletools.calendar.pro.interfaces.WeekFragmentListener import com.simplemobiletools.calendar.pro.interfaces.WeekFragmentListener
@ -70,10 +71,6 @@ class WeekFragment : Fragment(), WeeklyCalendar {
override fun onCreate(savedInstanceState: Bundle?) { override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState) super.onCreate(savedInstanceState)
context!!.eventsHelper.getEventTypes(activity!!, false) {
it.map { eventTypeColors.put(it.id!!, it.color) }
}
mRes = context!!.resources mRes = context!!.resources
mConfig = context!!.config mConfig = context!!.config
mRowHeight = mRes.getDimension(R.dimen.weekly_view_row_height) mRowHeight = mRes.getDimension(R.dimen.weekly_view_row_height)
@ -106,6 +103,10 @@ class WeekFragment : Fragment(), WeeklyCalendar {
override fun onResume() { override fun onResume() {
super.onResume() super.onResume()
context!!.eventsHelper.getEventTypes(activity!!, false) {
it.map { eventTypeColors.put(it.id!!, it.color) }
}
setupDayLabels() setupDayLabels()
updateCalendar() updateCalendar()
@ -294,13 +295,19 @@ class WeekFragment : Fragment(), WeeklyCalendar {
val dayCode = Formatter.getDayCodeFromDateTime(startDateTime) val dayCode = Formatter.getDayCodeFromDateTime(startDateTime)
var overlappingEvents = 0 var overlappingEvents = 0
var currentEventOverlapIndex = 0 var currentEventOverlapIndex = 0
eventTimeRanges[dayCode]!!.forEachIndexed { index, eventWeeklyView -> var foundCurrentEvent = false
if (eventWeeklyView.range.contains(range)) {
overlappingEvents++
}
if (eventWeeklyView.id == event.id) { eventTimeRanges[dayCode]!!.forEachIndexed { index, eventWeeklyView ->
currentEventOverlapIndex = index if (eventWeeklyView.range.touch(range)) {
overlappingEvents++
if (eventWeeklyView.id == event.id) {
foundCurrentEvent = true
}
if (!foundCurrentEvent) {
currentEventOverlapIndex++
}
} }
} }