in LocationUpdatesBackgroundKotlin/app/src/main/java/com/google/android/gms/location/sample/locationupdatesbackgroundkotlin/ui/LocationUpdateFragment.kt [81:111]
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
super.onViewCreated(view, savedInstanceState)
locationUpdateViewModel.receivingLocationUpdates.observe(
viewLifecycleOwner,
androidx.lifecycle.Observer { receivingLocation ->
updateStartOrStopButtonState(receivingLocation)
}
)
locationUpdateViewModel.locationListLiveData.observe(
viewLifecycleOwner,
androidx.lifecycle.Observer { locations ->
locations?.let {
Log.d(TAG, "Got ${locations.size} locations")
if (locations.isEmpty()) {
binding.locationOutputTextView.text =
getString(R.string.emptyLocationDatabaseMessage)
} else {
val outputStringBuilder = StringBuilder("")
for (location in locations) {
outputStringBuilder.append(location.toString() + "\n")
}
binding.locationOutputTextView.text = outputStringBuilder.toString()
}
}
}
)
}