EdricChan03 / studybuddy-android

A study buddy with features such as tasks, resources and more!
https://studybuddy.page.link/home
MIT License
16 stars 9 forks source link

[Refactor] Rewrite `ModalBottomSheetFragment` to use fragment args #738

Closed EdricChan03 closed 1 month ago

EdricChan03 commented 2 months ago

The DSL logic for setting items/other related state should instead be handled on the consumer's end rather than the fragment itself, i.e. only passing in a hard-coded list of items.

https://github.com/EdricChan03/studybuddy-android/blob/2b56189da613569f683f4ba7d28634701e3bb056/ui/widgets/modal-bottom-sheet/src/main/kotlin/com/edricchan/studybuddy/ui/widgets/modalbottomsheet/views/ModalBottomSheetFragment.kt#L69-L133

The methods above should be removed entirely, utilising Fragment arguments instead:

class ModalBottomSheetFragment {
  companion object {
    fun newInstance(
      items: List<ModalBottomSheetItem>,
      headerTitle: String? = null,
      hideDragHandle: Boolean = false
    ) = ModalBottomSheetFragment().apply {
      arguments = bundleOf(
        TAG_ITEMS to items,
        // etc
      )
    }
  }
}

Which can then be retrieved using the Fragment arguments:

class ModalBottomSheetFragment {
  val items get() = arguments?.getParcelableArrayList(...)
  // etc
}

We would need to phase out the existing APIs however 🙃


See also #737