2018-07-13 21:09:43 +00:00
|
|
|
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.*
|
2018-07-14 19:43:24 +00:00
|
|
|
import org.jetbrains.anko.doAsync
|
|
|
|
import org.jetbrains.anko.uiThread
|
2018-07-13 21:09:43 +00:00
|
|
|
import java.util.*
|
|
|
|
|
|
|
|
class ConventionDayFragment : Fragment() {
|
|
|
|
companion object {
|
|
|
|
fun newInstance(scheduleManager: ScheduleManager, day: GregorianCalendarRange): Fragment {
|
|
|
|
return ConventionDayFragment().apply {
|
|
|
|
arguments = Bundle().apply {
|
|
|
|
putSerializable("dayRange", day)
|
2018-07-14 19:43:24 +00:00
|
|
|
putSerializable("scheduleManager", scheduleManager)
|
2018-07-13 21:09:43 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
lateinit var scheduleManager: ScheduleManager
|
|
|
|
lateinit var day: GregorianCalendarRange
|
|
|
|
|
|
|
|
override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View? {
|
|
|
|
arguments?.apply {
|
|
|
|
day = getSerializable("dayRange")!! as GregorianCalendarRange
|
2018-07-14 19:43:24 +00:00
|
|
|
scheduleManager = getSerializable("scheduleManager") as ScheduleManager
|
2018-07-13 21:09:43 +00:00
|
|
|
}
|
|
|
|
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
|
2018-07-14 19:43:24 +00:00
|
|
|
doAsync {
|
|
|
|
scheduleManager.addObserver { _: Observable?, _: Any? ->
|
|
|
|
(0..(adapter.itemCount - 1)).forEach { pos: Int ->
|
|
|
|
uiThread {
|
|
|
|
adapter.notifyItemChanged(pos)
|
|
|
|
}
|
|
|
|
}
|
2018-07-13 21:09:43 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
return rootView
|
|
|
|
}
|
|
|
|
}
|