implementing the first part of solving weekly view event overlapping
This commit is contained in:
parent
1f52643556
commit
e7f7e24bdf
|
@ -5,6 +5,7 @@ import android.content.res.Resources
|
|||
import android.graphics.Rect
|
||||
import android.graphics.drawable.ColorDrawable
|
||||
import android.os.Bundle
|
||||
import android.util.Range
|
||||
import android.view.LayoutInflater
|
||||
import android.view.MotionEvent
|
||||
import android.view.View
|
||||
|
@ -24,6 +25,7 @@ import com.simplemobiletools.calendar.pro.helpers.Formatter
|
|||
import com.simplemobiletools.calendar.pro.interfaces.WeekFragmentListener
|
||||
import com.simplemobiletools.calendar.pro.interfaces.WeeklyCalendar
|
||||
import com.simplemobiletools.calendar.pro.models.Event
|
||||
import com.simplemobiletools.calendar.pro.models.EventWeeklyView
|
||||
import com.simplemobiletools.calendar.pro.views.MyScrollView
|
||||
import com.simplemobiletools.commons.extensions.*
|
||||
import com.simplemobiletools.commons.helpers.DAY_SECONDS
|
||||
|
@ -57,6 +59,7 @@ class WeekFragment : Fragment(), WeeklyCalendar {
|
|||
private var allDayHolders = ArrayList<RelativeLayout>()
|
||||
private var allDayRows = ArrayList<HashSet<Int>>()
|
||||
private var eventTypeColors = LongSparseArray<Int>()
|
||||
private var eventTimeRanges = LinkedHashMap<String, ArrayList<EventWeeklyView>>()
|
||||
|
||||
private lateinit var inflater: LayoutInflater
|
||||
private lateinit var mView: View
|
||||
|
@ -242,6 +245,7 @@ class WeekFragment : Fragment(), WeeklyCalendar {
|
|||
initGrid()
|
||||
allDayHolders.clear()
|
||||
allDayRows.clear()
|
||||
eventTimeRanges.clear()
|
||||
allDayRows.add(HashSet())
|
||||
week_all_day_holder?.removeAllViews()
|
||||
|
||||
|
@ -250,22 +254,55 @@ class WeekFragment : Fragment(), WeeklyCalendar {
|
|||
val fullHeight = mRes.getDimension(R.dimen.weekly_view_events_height)
|
||||
val minuteHeight = fullHeight / (24 * 60)
|
||||
val minimalHeight = mRes.getDimension(R.dimen.weekly_view_minimal_event_height).toInt()
|
||||
val density = Math.round(context!!.resources.displayMetrics.density)
|
||||
|
||||
var hadAllDayEvent = false
|
||||
val replaceDescription = mConfig.replaceDescription
|
||||
val sorted = events.sortedWith(compareBy({ it.startTS }, { it.endTS }, { it.title }, { if (replaceDescription) it.location else it.description }))
|
||||
for (event in sorted) {
|
||||
if (event.getIsAllDay() || Formatter.getDayCodeFromTS(event.startTS) != Formatter.getDayCodeFromTS(event.endTS)) {
|
||||
val startDateTime = Formatter.getDateTimeFromTS(event.startTS)
|
||||
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 + duration)
|
||||
val eventWeekly = EventWeeklyView(event.id!!, range)
|
||||
|
||||
val dayCode = Formatter.getDayCodeFromDateTime(startDateTime)
|
||||
if (!eventTimeRanges.containsKey(dayCode)) {
|
||||
eventTimeRanges[dayCode] = ArrayList()
|
||||
}
|
||||
|
||||
eventTimeRanges[dayCode]?.add(eventWeekly)
|
||||
}
|
||||
}
|
||||
|
||||
for (event in sorted) {
|
||||
val startDateTime = Formatter.getDateTimeFromTS(event.startTS)
|
||||
val endDateTime = Formatter.getDateTimeFromTS(event.endTS)
|
||||
if (event.getIsAllDay() || Formatter.getDayCodeFromDateTime(startDateTime) != Formatter.getDayCodeFromDateTime(endDateTime)) {
|
||||
hadAllDayEvent = true
|
||||
addAllDayEvent(event)
|
||||
} else {
|
||||
val startDateTime = Formatter.getDateTimeFromTS(event.startTS)
|
||||
val endDateTime = Formatter.getDateTimeFromTS(event.endTS)
|
||||
val dayOfWeek = startDateTime.plusDays(if (mConfig.isSundayFirst) 1 else 0).dayOfWeek - 1
|
||||
val layout = getColumnWithId(dayOfWeek)
|
||||
|
||||
val startMinutes = startDateTime.minuteOfDay
|
||||
val duration = endDateTime.minuteOfDay - startMinutes
|
||||
val range = Range(startMinutes, startMinutes + duration)
|
||||
|
||||
val dayCode = Formatter.getDayCodeFromDateTime(startDateTime)
|
||||
var overlappingEvents = 0
|
||||
var currentEventOverlapIndex = 0
|
||||
eventTimeRanges[dayCode]!!.forEachIndexed { index, eventWeeklyView ->
|
||||
if (eventWeeklyView.range.contains(range)) {
|
||||
overlappingEvents++
|
||||
}
|
||||
|
||||
if (eventWeeklyView.id == event.id) {
|
||||
currentEventOverlapIndex = index
|
||||
}
|
||||
}
|
||||
|
||||
(inflater.inflate(R.layout.week_event_marker, null, false) as TextView).apply {
|
||||
var backgroundColor = eventTypeColors.get(event.eventType, primaryColor)
|
||||
|
@ -282,11 +319,21 @@ class WeekFragment : Fragment(), WeeklyCalendar {
|
|||
y = startMinutes * minuteHeight
|
||||
(layoutParams as RelativeLayout.LayoutParams).apply {
|
||||
width = layout.width - 1
|
||||
width /= overlappingEvents
|
||||
x = width * currentEventOverlapIndex.toFloat()
|
||||
if (overlappingEvents > 1) {
|
||||
if (currentEventOverlapIndex + 1 == overlappingEvents) {
|
||||
x += density
|
||||
} else {
|
||||
width -= density
|
||||
}
|
||||
}
|
||||
|
||||
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_ID, event.id!!)
|
||||
putExtra(EVENT_OCCURRENCE_TS, event.startTS)
|
||||
startActivity(this)
|
||||
}
|
||||
|
|
|
@ -0,0 +1,5 @@
|
|||
package com.simplemobiletools.calendar.pro.models
|
||||
|
||||
import android.util.Range
|
||||
|
||||
data class EventWeeklyView(val id: Long, val range: Range<Int>)
|
Loading…
Reference in New Issue