diff --git a/app/src/main/java/com/github/libretube/activities/MainActivity.kt b/app/src/main/java/com/github/libretube/activities/MainActivity.kt index 1d09692b9..58751d4d4 100644 --- a/app/src/main/java/com/github/libretube/activities/MainActivity.kt +++ b/app/src/main/java/com/github/libretube/activities/MainActivity.kt @@ -165,8 +165,6 @@ class MainActivity : BaseActivity() { // new way of handling back presses onBackPressedDispatcher.addCallback(object : OnBackPressedCallback(true) { override fun handleOnBackPressed() { - navController.popBackStack(R.id.searchFragment, false) - if (binding.mainMotionLayout.progress == 0F) { try { minimizePlayer() @@ -289,6 +287,13 @@ class MainActivity : BaseActivity() { } override fun onQueryTextChange(newText: String?): Boolean { + // prevent malicious navigation when the search view is getting collapsed + if (navController.currentDestination?.id == R.id.searchResultFragment && + (newText == null || newText == "") + ) { + return false + } + if (navController.currentDestination?.id != R.id.searchFragment) { val bundle = Bundle() bundle.putString("query", newText) @@ -296,6 +301,7 @@ class MainActivity : BaseActivity() { } else { searchViewModel.setQuery(newText) } + return true } })