Added app language support (I think); fragments rely on Bundles instead of constructor parameters to get data, mitigating a source of crashes

This commit is contained in:
denizk0461
2023-04-30 22:47:59 +02:00
parent 7243df0f06
commit 079e66ad50
23 changed files with 619 additions and 472 deletions
@@ -16,13 +16,8 @@ import com.denizk0461.studip.viewmodel.EventPageViewModel
/**
* Fragment that is instantiated by [StudIPEventPageAdapter] to display individual days' pages and
* their events.
*
* @param currentDay current day that is used to show only events of a given day (0 = Monday,
* 4 = Friday)
*/
class EventPageFragment(
private val currentDay: Int,
) : AppFragment(), StudIPEventItemAdapter.OnClickListener {
class EventPageFragment : AppFragment(), StudIPEventItemAdapter.OnClickListener {
// Nullable view binding reference
private var _binding: RecyclerViewBinding? = null
@@ -39,10 +34,23 @@ class EventPageFragment(
/**
* Adapter that manages the page's items
*/
private val eventAdapter = StudIPEventItemAdapter(currentDay, this)
private lateinit var eventAdapter: StudIPEventItemAdapter
/**
* Current day that is used to show only events of a given day (0 = Monday, 4 = Friday)
*/
private var currentDay = -1
// Instantiate the view binding
override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View {
// Retrieve current day to fetch items specifically for that day
currentDay = arguments?.getInt("currentDay") ?: -1
// Instantiate event adapter with the current day
eventAdapter = StudIPEventItemAdapter(currentDay, this)
// Inflate view binding
_binding = RecyclerViewBinding.inflate(inflater, container, false)
return binding.root
}