57 lines
2.2 KiB
Kotlin
57 lines
2.2 KiB
Kotlin
|
package com.adlerosn.brasilfurfest.schedule.fragment
|
||
|
|
||
|
import android.os.Bundle
|
||
|
import android.support.v4.app.Fragment
|
||
|
import android.view.LayoutInflater
|
||
|
import android.view.View
|
||
|
import android.view.ViewGroup
|
||
|
import com.adlerosn.brasilfurfest.R
|
||
|
import com.adlerosn.brasilfurfest.schedule.ScheduleManager
|
||
|
import com.adlerosn.brasilfurfest.schedule.abstractDataTypes.GregorianCalendarRange
|
||
|
import com.adlerosn.brasilfurfest.schedule.adapters.DayHoursAdapter
|
||
|
import com.brandongogetap.stickyheaders.StickyLayoutManager
|
||
|
import kotlinx.android.synthetic.main.fragment_schedule_day.view.*
|
||
|
import java.util.*
|
||
|
|
||
|
class ConventionDayFragment : Fragment() {
|
||
|
companion object {
|
||
|
fun newInstance(scheduleManager: ScheduleManager, day: GregorianCalendarRange): Fragment {
|
||
|
return ConventionDayFragment().apply {
|
||
|
arguments = Bundle().apply {
|
||
|
putSerializable("scheduleManager", scheduleManager)
|
||
|
putSerializable("dayRange", day)
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
|
||
|
lateinit var scheduleManager: ScheduleManager
|
||
|
lateinit var day: GregorianCalendarRange
|
||
|
|
||
|
override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View? {
|
||
|
arguments?.apply {
|
||
|
scheduleManager = getSerializable("scheduleManager")!! as ScheduleManager
|
||
|
day = getSerializable("dayRange")!! as GregorianCalendarRange
|
||
|
}
|
||
|
val rootView = inflater.inflate(R.layout.fragment_schedule_day, container, false)
|
||
|
val adapter = DayHoursAdapter(
|
||
|
activity!!,
|
||
|
day.split(
|
||
|
scheduleManager.convention.splitDayIn
|
||
|
).filter {
|
||
|
it.start >= scheduleManager.convention.startCalendarOn
|
||
|
},
|
||
|
scheduleManager
|
||
|
)
|
||
|
val layoutManager = StickyLayoutManager(context!!, adapter)
|
||
|
layoutManager.elevateHeaders(3)
|
||
|
rootView.stickyDays.layoutManager = layoutManager
|
||
|
rootView.stickyDays.adapter = adapter
|
||
|
scheduleManager.addObserver { _: Observable?, _: Any? ->
|
||
|
(0..(adapter.itemCount - 1)).forEach {
|
||
|
adapter.notifyItemChanged(it)
|
||
|
}
|
||
|
}
|
||
|
return rootView
|
||
|
}
|
||
|
}
|