Skip to content

Commit

Permalink
all: modern back press (fixes #2028) (#2029)
Browse files Browse the repository at this point in the history
Co-authored-by: dogi <[email protected]>
  • Loading branch information
Okuro3499 and dogi authored Jun 4, 2024
1 parent 8eb1368 commit 9293980
Showing 1 changed file with 8 additions and 2 deletions.
10 changes: 8 additions & 2 deletions app/src/main/kotlin/io/treehouses/remote/InitialActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import android.view.MenuItem
import android.view.View
import android.view.inputmethod.InputMethodManager
import android.widget.Toast
import androidx.activity.OnBackPressedCallback
import androidx.appcompat.app.ActionBarDrawerToggle
import androidx.appcompat.app.AlertDialog
import androidx.appcompat.widget.Toolbar
Expand Down Expand Up @@ -58,6 +59,12 @@ class InitialActivity : BaseInitialActivity() {
}
checkStatusNow()
openCallFragment(HomeFragment())

onBackPressedDispatcher.addCallback(this, object : OnBackPressedCallback(true) {
override fun handleOnBackPressed() {
handleCustomOnBackPressed()
}
})
}

private fun startGPSService() {
Expand Down Expand Up @@ -85,8 +92,7 @@ class InitialActivity : BaseInitialActivity() {
bind.navView.setNavigationItemSelectedListener(this)
}

override fun onBackPressed() {
super.onBackPressed()
fun handleCustomOnBackPressed() {
if (bind.drawerLayout.isDrawerOpen(GravityCompat.START)) bind.drawerLayout.closeDrawer(GravityCompat.START)
else {
val f = supportFragmentManager.findFragmentById(R.id.fragment_container)
Expand Down

0 comments on commit 9293980

Please sign in to comment.