forked from github/szkolny
[Timetable] Fix day fragment crashing on restoring saved instance
This commit is contained in:
parent
0cbba2eb45
commit
56062f5bfa
@ -1,8 +1,10 @@
|
|||||||
package pl.szczodrzynski.edziennik.ui.modules.timetable.v2
|
package pl.szczodrzynski.edziennik.ui.modules.timetable.v2
|
||||||
|
|
||||||
|
import android.os.Bundle
|
||||||
import androidx.fragment.app.Fragment
|
import androidx.fragment.app.Fragment
|
||||||
import androidx.fragment.app.FragmentManager
|
import androidx.fragment.app.FragmentManager
|
||||||
import androidx.fragment.app.FragmentStatePagerAdapter
|
import androidx.fragment.app.FragmentStatePagerAdapter
|
||||||
|
import pl.szczodrzynski.edziennik.ui.modules.timetable.v2.day.TimetableDayFragment
|
||||||
import pl.szczodrzynski.edziennik.utils.models.Date
|
import pl.szczodrzynski.edziennik.utils.models.Date
|
||||||
import pl.szczodrzynski.edziennik.utils.models.Week
|
import pl.szczodrzynski.edziennik.utils.models.Week
|
||||||
|
|
||||||
@ -16,7 +18,11 @@ class TimetablePagerAdapter(val fragmentManager: FragmentManager, val items: Lis
|
|||||||
private val weekEnd by lazy { weekStart.clone().stepForward(0, 0, 6) }
|
private val weekEnd by lazy { weekStart.clone().stepForward(0, 0, 6) }
|
||||||
|
|
||||||
override fun getItem(position: Int): Fragment {
|
override fun getItem(position: Int): Fragment {
|
||||||
return pl.szczodrzynski.edziennik.ui.modules.timetable.v2.day.TimetableDayFragment(items[position])
|
return TimetableDayFragment().apply {
|
||||||
|
arguments = Bundle().apply {
|
||||||
|
putInt("date", items[position].value)
|
||||||
|
}
|
||||||
|
}
|
||||||
/*return TimetableDayFragment().apply {
|
/*return TimetableDayFragment().apply {
|
||||||
arguments = Bundle().also {
|
arguments = Bundle().also {
|
||||||
it.putLong("date", items[position].value.toLong())
|
it.putLong("date", items[position].value.toLong())
|
||||||
|
@ -25,7 +25,7 @@ import pl.szczodrzynski.navlib.getColorFromAttr
|
|||||||
import java.util.*
|
import java.util.*
|
||||||
import kotlin.math.min
|
import kotlin.math.min
|
||||||
|
|
||||||
class TimetableDayFragment(val date: Date) : Fragment() {
|
class TimetableDayFragment() : Fragment() {
|
||||||
companion object {
|
companion object {
|
||||||
private const val TAG = "TimetableDayFragment"
|
private const val TAG = "TimetableDayFragment"
|
||||||
}
|
}
|
||||||
@ -33,6 +33,7 @@ class TimetableDayFragment(val date: Date) : Fragment() {
|
|||||||
private lateinit var app: App
|
private lateinit var app: App
|
||||||
private lateinit var activity: MainActivity
|
private lateinit var activity: MainActivity
|
||||||
private lateinit var b: FragmentTimetableV2DayBinding
|
private lateinit var b: FragmentTimetableV2DayBinding
|
||||||
|
private lateinit var date: Date
|
||||||
|
|
||||||
override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View? {
|
override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View? {
|
||||||
activity = (getActivity() as MainActivity?) ?: return null
|
activity = (getActivity() as MainActivity?) ?: return null
|
||||||
@ -40,7 +41,7 @@ class TimetableDayFragment(val date: Date) : Fragment() {
|
|||||||
return null
|
return null
|
||||||
app = activity.application as App
|
app = activity.application as App
|
||||||
b = FragmentTimetableV2DayBinding.inflate(inflater)
|
b = FragmentTimetableV2DayBinding.inflate(inflater)
|
||||||
Log.d(TAG, "onCreateView, date=$date")
|
date = arguments?.getInt("date")?.let { Date.fromValue(it) } ?: Date.getToday()
|
||||||
return b.root
|
return b.root
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user