Skip to content
This repository has been archived by the owner on Jul 24, 2023. It is now read-only.

Replace with recommended #485

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
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 @@ -71,14 +71,14 @@ class SleepTrackerFragment : Fragment() {

// Specify the current activity as the lifecycle owner of the binding.
// This is necessary so that the binding can observe LiveData updates.
binding.setLifecycleOwner(this)
binding.lifecycleOwner = this

// Add an Observer on the state variable for showing a Snackbar message
// when the CLEAR button is pressed.
sleepTrackerViewModel.showSnackBarEvent.observe(this, Observer {
sleepTrackerViewModel.showSnackBarEvent.observe(viewLifecycleOwner, Observer {
if (it == true) { // Observed state is true.
Snackbar.make(
activity!!.findViewById(android.R.id.content),
requireActivity().findViewById(android.R.id.content),
getString(R.string.cleared_message),
Snackbar.LENGTH_SHORT // How long to display the message.
).show()
Expand All @@ -89,7 +89,7 @@ class SleepTrackerFragment : Fragment() {
})

// Add an Observer on the state variable for Navigating when STOP button is pressed.
sleepTrackerViewModel.navigateToSleepQuality.observe(this, Observer { night ->
sleepTrackerViewModel.navigateToSleepQuality.observe(viewLifecycleOwner, Observer { night ->
night?.let {
// We need to get the navController from this, because button is not ready, and it
// just has to be a view. For some reason, this only matters if we hit stop again
Expand Down