Skip to content

replace: this with appropriate lifecycle owner #224

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Nov 17, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ abstract class BaseAnalyticsFragment : Fragment(), AnalyticsScreenName {
override fun onResume() {
super.onResume()

firebaseAnalytics.setCurrentScreen(activity!!, getString(screenName), null)
firebaseAnalytics.setCurrentScreen(requireActivity(), getString(screenName), null)
}

fun logAnalyticsEvent(event: Event, vararg params: Param) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,24 +37,24 @@ class FormsFragment : ViewModelFragment<FormsViewModel>() {

override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
super.onViewCreated(view, savedInstanceState)
viewModel.pollingStation().observe(this, Observer {
viewModel.pollingStation().observe(viewLifecycleOwner, Observer {
pollingStationBarText.text =
getString(R.string.polling_station, it.pollingStationNumber, it.countyName)
})

viewModel.title().observe(this, Observer {
viewModel.title().observe(viewLifecycleOwner, Observer {
(activity as MainActivity).setTitle(it)
})

viewModel.selectedForm().observe(this, Observer {
viewModel.selectedForm().observe(viewLifecycleOwner, Observer {
childFragmentManager.replaceFragment(
R.id.content,
QuestionsListFragment(),
bundleOf(Pair(FORM, Parcels.wrap(it))),
QuestionsListFragment.TAG
)
})
viewModel.selectedQuestion().observe(this, Observer {
viewModel.selectedQuestion().observe(viewLifecycleOwner, Observer {
childFragmentManager.replaceFragment(
R.id.content,
QuestionsDetailsFragment(),
Expand All @@ -65,7 +65,7 @@ class FormsFragment : ViewModelFragment<FormsViewModel>() {
QuestionsDetailsFragment.TAG
)
})
viewModel.navigateToNotes().observe(this, Observer {
viewModel.navigateToNotes().observe(viewLifecycleOwner, Observer {
childFragmentManager.replaceFragment(
R.id.content,
NoteFragment(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,15 +41,15 @@ class FormsListFragment : ViewModelFragment<FormsViewModel>() {

override fun onAttach(context: Context) {
super.onAttach(context)
viewModel = getSharedViewModel(from = { parentFragment!! })
viewModel = getSharedViewModel(from = { requireParentFragment() })
}

override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
super.onViewCreated(view, savedInstanceState)
viewModel.forms().observe(this, Observer {
viewModel.forms().observe(viewLifecycleOwner, Observer {
formAdapter.items = it
})
viewModel.syncVisibility().observe(this, Observer {
viewModel.syncVisibility().observe(viewLifecycleOwner, Observer {
syncGroup.visibility = it
})

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,16 +37,16 @@ class QuestionsListFragment : ViewModelFragment<QuestionsViewModel>() {

override fun onAttach(context: Context) {
super.onAttach(context)
baseViewModel = getSharedViewModel(from = { parentFragment!! })
baseViewModel = getSharedViewModel(from = { requireParentFragment() })
}

override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
super.onViewCreated(view, savedInstanceState)

viewModel.questions().observe(this, Observer {
viewModel.questions().observe(viewLifecycleOwner, Observer {
questionAdapter.items = it
})
viewModel.title().observe(this, Observer {
viewModel.title().observe(viewLifecycleOwner, Observer {
baseViewModel.setTitle(it)
})
viewModel.setData(Parcels.unwrap<FormDetails>(arguments?.getParcelable((FORM))))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,8 +54,8 @@ class NoteFragment : ViewModelFragment<NoteViewModel>(), PermissionManager.Permi
private lateinit var permissionManager: PermissionManager
override fun onAttach(context: Context) {
super.onAttach(context)
permissionManager = PermissionManager(activity!!, this)
baseViewModel = getSharedViewModel(from = { parentFragment!! })
permissionManager = PermissionManager(requireActivity(), this)
baseViewModel = getSharedViewModel(from = { requireParentFragment() })
}

override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
Expand All @@ -68,15 +68,15 @@ class NoteFragment : ViewModelFragment<NoteViewModel>(), PermissionManager.Permi
.color(Color.TRANSPARENT)
.sizeResId(R.dimen.small_margin).build()
)
viewModel.title().observe(this, Observer {
viewModel.title().observe(viewLifecycleOwner, Observer {
baseViewModel.setTitle(it)
})

viewModel.setData(Parcels.unwrap<Question>(arguments?.getParcelable((Constants.QUESTION))))
viewModel.notes().observe(this, Observer {
viewModel.notes().observe(viewLifecycleOwner, Observer {
noteAdapter.items = it
})
viewModel.filesNames().observe(this, Observer {
viewModel.filesNames().observe(viewLifecycleOwner, Observer {
noteFileContainer.visibility = View.VISIBLE
noteFileContainer.removeAllViews()
it.forEach { filename ->
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ class PollingStationDetailsFragment : ViewModelFragment<PollingStationViewModel>

override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
super.onViewCreated(view, savedInstanceState)
viewModel.pollingStation().observe(this, Observer {
viewModel.pollingStation().observe(viewLifecycleOwner, Observer {
pollingStationBarText.text = it
})
viewModel.setTitle(getString(R.string.title_polling_station))
Expand All @@ -45,10 +45,10 @@ class PollingStationDetailsFragment : ViewModelFragment<PollingStationViewModel>
viewModel.notifyChangeRequested()
activity?.onBackPressed()
}
viewModel.departureTime().observe(this, Observer {
viewModel.departureTime().observe(viewLifecycleOwner, Observer {
departureTime.text = it
})
viewModel.arrivalTime().observe(this, Observer {
viewModel.arrivalTime().observe(viewLifecycleOwner, Observer {
arrivalTime.text = it
})
arrivalTime.setOnClickListener {
Expand Down Expand Up @@ -83,7 +83,7 @@ class PollingStationDetailsFragment : ViewModelFragment<PollingStationViewModel>
}
})
}
viewModel.selectedPollingStation().observe(this, Observer {
viewModel.selectedPollingStation().observe(viewLifecycleOwner, Observer {
setSelection(it)
})
setContinueButton()
Expand All @@ -100,7 +100,7 @@ class PollingStationDetailsFragment : ViewModelFragment<PollingStationViewModel>
private fun showDatePicker(dateTitleId: Int, timeTitleId: Int, listener: DateTimeListener) {
val now = Calendar.getInstance()
val datePickerDialog = DatePickerDialog(
activity!!,
requireActivity(),
DatePickerDialog.OnDateSetListener { _, year, month, day ->
showTimePicker(timeTitleId, year, month, day, listener)
}, now.get(Calendar.YEAR), now.get(Calendar.MONTH), now.get(Calendar.DAY_OF_MONTH)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ class PollingStationSelectionFragment : ViewModelFragment<PollingStationSelectio
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
countySpinnerAdapter =
ArrayAdapter(activity!!, R.layout.item_spinner, mutableListOf())
ArrayAdapter(requireActivity(), R.layout.item_spinner, mutableListOf())
countySpinnerAdapter.setDropDownViewResource(R.layout.support_simple_spinner_dropdown_item)
}

Expand Down