Skip to content

Commit

Permalink
Merge branch 'master' into anandwana001/2857/survey-converter-code-clean
Browse files Browse the repository at this point in the history
  • Loading branch information
anandwana001 authored Dec 19, 2024
2 parents cb815c8 + 1ca9a52 commit 013c2d3
Showing 1 changed file with 13 additions and 5 deletions.
18 changes: 13 additions & 5 deletions ground/src/main/java/com/google/android/ground/MainActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import android.app.AlertDialog
import android.content.Intent
import android.os.Bundle
import android.view.ViewGroup
import androidx.activity.OnBackPressedCallback
import androidx.appcompat.app.AppCompatDelegate
import androidx.compose.runtime.getValue
import androidx.compose.runtime.mutableStateOf
Expand Down Expand Up @@ -85,6 +86,18 @@ class MainActivity : AbstractActivity() {
lifecycleScope.launch {
viewModel.navigationRequests.filterNotNull().collect { updateUi(binding.root, it) }
}

onBackPressedDispatcher.addCallback(
this,
object : OnBackPressedCallback(true) {
override fun handleOnBackPressed() {
if (!dispatchBackPressed()) {
isEnabled = false
onBackPressedDispatcher.onBackPressed()
}
}
},
)
}

private fun updateUi(viewGroup: ViewGroup, uiState: MainUiState) {
Expand Down Expand Up @@ -182,11 +195,6 @@ class MainActivity : AbstractActivity() {
}
}

@Deprecated("Deprecated in Java")
override fun onBackPressed() {
if (!dispatchBackPressed()) super.onBackPressed()
}

private fun dispatchBackPressed(): Boolean {
val fragmentManager = navHostFragment.childFragmentManager
val currentFragment = fragmentManager.findFragmentById(R.id.nav_host_fragment)
Expand Down

0 comments on commit 013c2d3

Please sign in to comment.