Skip to content

Commit

Permalink
moved to correct callback (#2821)
Browse files Browse the repository at this point in the history
Co-authored-by: Gino Miceli <228050+gino-m@users.noreply.github.com>
  • Loading branch information
anandwana001 and gino-m authored Nov 25, 2024
1 parent 59ae309 commit cf32b10
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -44,9 +44,9 @@ class DownloadProgressDialogFragment : AbstractDialogFragment() {
}

fun setVisibility(childFragmentManager: FragmentManager, newVisibility: Boolean) {
if (newVisibility && !isVisible) {
if (newVisibility && !isAdded && !isVisible) {
show(childFragmentManager, this::class.simpleName)
} else if (!newVisibility && isVisible) {
} else if (!newVisibility && isAdded && isVisible) {
dismiss()
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,15 +36,12 @@ class OfflineAreaSelectorFragment : AbstractMapContainerFragment() {
private lateinit var viewModel: OfflineAreaSelectorViewModel
private lateinit var mapContainerViewModel: HomeScreenMapContainerViewModel

private var downloadProgressDialogFragment = DownloadProgressDialogFragment()
private var downloadProgressDialogFragment: DownloadProgressDialogFragment? = null

override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
mapContainerViewModel = getViewModel(HomeScreenMapContainerViewModel::class.java)
viewModel = getViewModel(OfflineAreaSelectorViewModel::class.java)
viewModel.isDownloadProgressVisible.observe(this) {
downloadProgressDialogFragment.setVisibility(childFragmentManager, it)
}
}

override fun onCreateView(
Expand All @@ -59,6 +56,16 @@ class OfflineAreaSelectorFragment : AbstractMapContainerFragment() {
return binding.root
}

override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
super.onViewCreated(view, savedInstanceState)
viewModel.isDownloadProgressVisible.observe(viewLifecycleOwner) {
if (downloadProgressDialogFragment == null) {
downloadProgressDialogFragment = DownloadProgressDialogFragment()
}
downloadProgressDialogFragment?.setVisibility(childFragmentManager, it)
}
}

override fun onMapReady(map: MapFragment) {
// Observe events emitted by the ViewModel.
viewLifecycleOwner.lifecycleScope.launch {
Expand Down

0 comments on commit cf32b10

Please sign in to comment.