add all-day events in week fragment in a dynamically added relative layout
This commit is contained in:
parent
0d96caf25d
commit
6801f9bcbf
|
@ -9,7 +9,6 @@ import android.os.Bundle
|
|||
import android.support.v4.app.Fragment
|
||||
import android.view.*
|
||||
import android.widget.ImageView
|
||||
import android.widget.LinearLayout
|
||||
import android.widget.RelativeLayout
|
||||
import android.widget.TextView
|
||||
import com.simplemobiletools.calendar.R
|
||||
|
@ -47,7 +46,8 @@ class WeekFragment : Fragment(), WeeklyCalendar {
|
|||
private var clickStartTime = 0L
|
||||
private var selectedGrid: View? = null
|
||||
private var todayColumnIndex = -1
|
||||
private var events: List<Event> = ArrayList()
|
||||
private var events = ArrayList<Event>()
|
||||
private var allDayHolders = ArrayList<RelativeLayout>()
|
||||
|
||||
lateinit var inflater: LayoutInflater
|
||||
lateinit var mView: View
|
||||
|
@ -167,7 +167,7 @@ class WeekFragment : Fragment(), WeeklyCalendar {
|
|||
private fun initGrid() {
|
||||
(0..6).map { getColumnWithId(it) }
|
||||
.forEachIndexed { index, layout ->
|
||||
activity.runOnUiThread { layout.removeAllViews() }
|
||||
layout.removeAllViews()
|
||||
layout.setOnTouchListener { view, motionEvent ->
|
||||
checkGridClick(motionEvent, index, layout)
|
||||
true
|
||||
|
@ -211,7 +211,7 @@ class WeekFragment : Fragment(), WeeklyCalendar {
|
|||
}
|
||||
}
|
||||
|
||||
override fun updateWeeklyCalendar(events: List<Event>) {
|
||||
override fun updateWeeklyCalendar(events: ArrayList<Event>) {
|
||||
this.events = events
|
||||
updateEvents()
|
||||
}
|
||||
|
@ -220,13 +220,26 @@ class WeekFragment : Fragment(), WeeklyCalendar {
|
|||
if (mWasDestroyed)
|
||||
return
|
||||
|
||||
activity.runOnUiThread {
|
||||
if (context != null)
|
||||
addEvents()
|
||||
}
|
||||
}
|
||||
|
||||
private fun addEvents() {
|
||||
val filtered = context.getFilteredEvents(events)
|
||||
|
||||
initGrid()
|
||||
allDayHolders.clear()
|
||||
week_all_day_holder?.removeAllViews()
|
||||
|
||||
val allDaysLine = inflater.inflate(R.layout.all_day_events_holder_line, null, false) as RelativeLayout
|
||||
week_all_day_holder.addView(allDaysLine)
|
||||
allDayHolders.add(allDaysLine)
|
||||
|
||||
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()
|
||||
activity.runOnUiThread { mView.week_all_day_holder.removeAllViews() }
|
||||
|
||||
var hadAllDayEvent = false
|
||||
val sorted = filtered.sortedWith(compareBy({ it.startTS }, { it.endTS }, { it.title }, { it.description }))
|
||||
|
@ -246,14 +259,12 @@ class WeekFragment : Fragment(), WeeklyCalendar {
|
|||
(inflater.inflate(R.layout.week_event_marker, null, false) as TextView).apply {
|
||||
background = ColorDrawable(MainActivity.eventTypeColors.get(event.eventType, primaryColor))
|
||||
text = event.title
|
||||
activity.runOnUiThread {
|
||||
layout.addView(this)
|
||||
y = startMinutes * minuteHeight
|
||||
(layoutParams as RelativeLayout.LayoutParams).apply {
|
||||
width = layout.width - 1
|
||||
minHeight = if (event.startTS == event.endTS) minimalHeight else (duration * minuteHeight).toInt() - 1
|
||||
}
|
||||
}
|
||||
setOnClickListener {
|
||||
Intent(activity.applicationContext, EventActivity::class.java).apply {
|
||||
putExtra(EVENT_OCCURRENCE_TS, event.startTS)
|
||||
|
@ -278,7 +289,6 @@ class WeekFragment : Fragment(), WeeklyCalendar {
|
|||
val todayColumn = getColumnWithId(todayColumnIndex)
|
||||
(inflater.inflate(R.layout.week_now_marker, null, false) as ImageView).apply {
|
||||
setColorFilter(primaryColor, PorterDuff.Mode.SRC_IN)
|
||||
activity.runOnUiThread {
|
||||
mView.week_events_holder.addView(this, 0)
|
||||
val extraWidth = (todayColumn.width * 0.3).toInt()
|
||||
val markerHeight = resources.getDimension(R.dimen.weekly_view_now_height).toInt()
|
||||
|
@ -291,7 +301,6 @@ class WeekFragment : Fragment(), WeeklyCalendar {
|
|||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private fun checkTopHolderHeight() {
|
||||
mView.week_top_holder.viewTreeObserver.addOnGlobalLayoutListener(object : ViewTreeObserver.OnGlobalLayoutListener {
|
||||
|
@ -318,12 +327,11 @@ class WeekFragment : Fragment(), WeeklyCalendar {
|
|||
val firstDayIndex = (startDateTimeInWeek.dayOfWeek - if (context.config.isSundayFirst) 0 else 1) % 7
|
||||
val daysCnt = Days.daysBetween(Formatter.getDateTimeFromTS(minTS), Formatter.getDateTimeFromTS(maxTS)).days
|
||||
|
||||
activity.runOnUiThread {
|
||||
if (activity == null)
|
||||
return@runOnUiThread
|
||||
return
|
||||
|
||||
mView.week_all_day_holder.addView(this)
|
||||
(layoutParams as LinearLayout.LayoutParams).apply {
|
||||
allDayHolders[0].addView(this)
|
||||
(layoutParams as RelativeLayout.LayoutParams).apply {
|
||||
topMargin = mRes.getDimension(R.dimen.tiny_margin).toInt()
|
||||
leftMargin = getColumnWithId(firstDayIndex).x.toInt()
|
||||
bottomMargin = 1
|
||||
|
@ -346,7 +354,6 @@ class WeekFragment : Fragment(), WeeklyCalendar {
|
|||
}
|
||||
}
|
||||
})
|
||||
}
|
||||
setOnClickListener {
|
||||
Intent(activity.applicationContext, EventActivity::class.java).apply {
|
||||
putExtra(EVENT_ID, event.id)
|
||||
|
|
|
@ -7,17 +7,13 @@ import com.simplemobiletools.calendar.models.Event
|
|||
import java.util.*
|
||||
|
||||
class WeeklyCalendarImpl(val mCallback: WeeklyCalendar, val mContext: Context) {
|
||||
var mEvents: List<Event>
|
||||
|
||||
init {
|
||||
mEvents = ArrayList<Event>()
|
||||
}
|
||||
var mEvents = ArrayList<Event>()
|
||||
|
||||
fun updateWeeklyCalendar(weekStartTS: Int) {
|
||||
val startTS = weekStartTS
|
||||
val endTS = startTS + WEEK_SECONDS
|
||||
mContext.dbHelper.getEvents(startTS, endTS) {
|
||||
mEvents = it
|
||||
mEvents = it as ArrayList<Event>
|
||||
mCallback.updateWeeklyCalendar(it)
|
||||
}
|
||||
}
|
||||
|
|
|
@ -3,5 +3,5 @@ package com.simplemobiletools.calendar.interfaces
|
|||
import com.simplemobiletools.calendar.models.Event
|
||||
|
||||
interface WeeklyCalendar {
|
||||
fun updateWeeklyCalendar(events: List<Event>)
|
||||
fun updateWeeklyCalendar(events: ArrayList<Event>)
|
||||
}
|
||||
|
|
|
@ -0,0 +1,5 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<RelativeLayout
|
||||
xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"/>
|
|
@ -169,7 +169,8 @@
|
|||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_below="@+id/week_letters_holder"
|
||||
android:orientation="vertical"/>
|
||||
android:orientation="vertical">
|
||||
|
||||
</LinearLayout>
|
||||
</RelativeLayout>
|
||||
</RelativeLayout>
|
||||
|
|
Loading…
Reference in New Issue