add some logic to adding all-day events to lines

This commit is contained in:
tibbi 2017-05-23 22:07:27 +02:00
parent 4dfa54009d
commit 41369041cf
1 changed files with 45 additions and 4 deletions

View File

@ -48,6 +48,7 @@ class WeekFragment : Fragment(), WeeklyCalendar {
private var todayColumnIndex = -1 private var todayColumnIndex = -1
private var events = ArrayList<Event>() private var events = ArrayList<Event>()
private var allDayHolders = ArrayList<RelativeLayout>() private var allDayHolders = ArrayList<RelativeLayout>()
private var allDayRows = ArrayList<HashSet<Int>>()
lateinit var inflater: LayoutInflater lateinit var inflater: LayoutInflater
lateinit var mView: View lateinit var mView: View
@ -61,6 +62,7 @@ class WeekFragment : Fragment(), WeeklyCalendar {
mWeekTimestamp = arguments.getInt(WEEK_START_TIMESTAMP) mWeekTimestamp = arguments.getInt(WEEK_START_TIMESTAMP)
primaryColor = context.config.primaryColor primaryColor = context.config.primaryColor
mRes = resources mRes = resources
allDayRows.add(HashSet())
mView = inflater.inflate(R.layout.fragment_week, container, false).apply { mView = inflater.inflate(R.layout.fragment_week, container, false).apply {
week_events_scrollview.setOnScrollviewListener(object : MyScrollView.ScrollViewListener { week_events_scrollview.setOnScrollviewListener(object : MyScrollView.ScrollViewListener {
@ -231,11 +233,11 @@ class WeekFragment : Fragment(), WeeklyCalendar {
initGrid() initGrid()
allDayHolders.clear() allDayHolders.clear()
allDayRows.clear()
allDayRows.add(HashSet<Int>())
week_all_day_holder?.removeAllViews() week_all_day_holder?.removeAllViews()
val allDaysLine = inflater.inflate(R.layout.all_day_events_holder_line, null, false) as RelativeLayout addNewLine()
week_all_day_holder.addView(allDaysLine)
allDayHolders.add(allDaysLine)
val fullHeight = mRes.getDimension(R.dimen.weekly_view_events_height) val fullHeight = mRes.getDimension(R.dimen.weekly_view_events_height)
val minuteHeight = fullHeight / (24 * 60) val minuteHeight = fullHeight / (24 * 60)
@ -283,6 +285,12 @@ class WeekFragment : Fragment(), WeeklyCalendar {
addCurrentTimeIndicator(minuteHeight) addCurrentTimeIndicator(minuteHeight)
} }
private fun addNewLine() {
val allDaysLine = inflater.inflate(R.layout.all_day_events_holder_line, null, false) as RelativeLayout
week_all_day_holder.addView(allDaysLine)
allDayHolders.add(allDaysLine)
}
fun addCurrentTimeIndicator(minuteHeight: Float) { fun addCurrentTimeIndicator(minuteHeight: Float) {
if (todayColumnIndex != -1) { if (todayColumnIndex != -1) {
val minutes = DateTime().minuteOfDay val minutes = DateTime().minuteOfDay
@ -330,7 +338,40 @@ class WeekFragment : Fragment(), WeeklyCalendar {
if (activity == null) if (activity == null)
return return
allDayHolders[0].addView(this) var doesEventFit: Boolean
val cnt = allDayRows.size - 1
var wasEventHandled = false
var drawAtLine = 0
for (index in 0..cnt) {
doesEventFit = true
drawAtLine = index
val row = allDayRows[index]
for (i in firstDayIndex..firstDayIndex + daysCnt) {
if (row.contains(i)) {
doesEventFit = false
}
}
for (dayIndex in firstDayIndex..firstDayIndex + daysCnt) {
if (doesEventFit) {
row.add(dayIndex)
wasEventHandled = true
} else if (index == cnt) {
if (allDayRows.size == index + 1) {
allDayRows.add(HashSet<Int>())
addNewLine()
drawAtLine++
wasEventHandled = true
}
allDayRows.last().add(dayIndex)
}
}
if (wasEventHandled) {
break
}
}
allDayHolders[drawAtLine].addView(this)
(layoutParams as RelativeLayout.LayoutParams).apply { (layoutParams as RelativeLayout.LayoutParams).apply {
topMargin = mRes.getDimension(R.dimen.tiny_margin).toInt() topMargin = mRes.getDimension(R.dimen.tiny_margin).toInt()
leftMargin = getColumnWithId(firstDayIndex).x.toInt() leftMargin = getColumnWithId(firstDayIndex).x.toInt()