Skip to content

Commit

Permalink
Update var names and remove obsolete warning
Browse files Browse the repository at this point in the history
  • Loading branch information
shobhitagarwal1612 committed Dec 22, 2024
1 parent 0938f68 commit b944ca7
Showing 1 changed file with 6 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -30,20 +30,17 @@ import kotlinx.coroutines.launch
@AndroidEntryPoint
class CaptureLocationTaskMapFragment @Inject constructor() : AbstractMapFragmentWithControls() {

private lateinit var mapViewModel: CaptureLocationTaskMapViewModel
private val viewModel: CaptureLocationTaskViewModel by lazy {
// Access to this viewModel is lazy for testing. This is because the NavHostController could
// not be initialized before the Fragment under test is created, leading to
// hiltNavGraphViewModels() to fail when called on launch.
private lateinit var viewModel: CaptureLocationTaskMapViewModel
private val parentViewModel: CaptureLocationTaskViewModel by lazy {
dataCollectionViewModel.getTaskViewModel(taskId) as CaptureLocationTaskViewModel
}

override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
mapViewModel = getViewModel(CaptureLocationTaskMapViewModel::class.java)
viewModel = getViewModel(CaptureLocationTaskMapViewModel::class.java)
}

override fun getMapViewModel(): BaseMapViewModel = mapViewModel
override fun getMapViewModel(): BaseMapViewModel = viewModel

override fun onCreateView(
inflater: LayoutInflater,
Expand All @@ -52,13 +49,13 @@ class CaptureLocationTaskMapFragment @Inject constructor() : AbstractMapFragment
): View {
val root = super.onCreateView(inflater, container, savedInstanceState)
viewLifecycleOwner.lifecycleScope.launch {
getMapViewModel().getLocationUpdates().collect { viewModel.updateLocation(it) }
getMapViewModel().getLocationUpdates().collect { parentViewModel.updateLocation(it) }
}
return root
}

override fun onMapReady(map: MapFragment) {
super.onMapReady(map)
viewLifecycleOwner.lifecycleScope.launch { viewModel.onMapReady(mapViewModel) }
viewLifecycleOwner.lifecycleScope.launch { parentViewModel.onMapReady(viewModel) }
}
}

0 comments on commit b944ca7

Please sign in to comment.