Skip to content

Commit

Permalink
fix for searchview anormal behavior
Browse files Browse the repository at this point in the history
  • Loading branch information
Nephys222 committed Sep 6, 2022
1 parent f66fdf1 commit ca3734a
Showing 1 changed file with 2 additions and 15 deletions.
17 changes: 2 additions & 15 deletions app/src/main/java/com/github/libretube/activities/MainActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -162,8 +162,6 @@ class MainActivity : BaseActivity() {
// new way of handling back presses
onBackPressedDispatcher.addCallback(object : OnBackPressedCallback(true) {
override fun handleOnBackPressed() {
// remove focus from search
removeSearchFocus()
navController.popBackStack(R.id.searchFragment, false)

if (binding.mainMotionLayout.progress == 0F) {
Expand Down Expand Up @@ -260,6 +258,7 @@ class MainActivity : BaseActivity() {
val bundle = Bundle()
bundle.putString("query", query)
navController.navigate(R.id.searchResultFragment, bundle)
searchViewModel.setQuery("")
return true
}

Expand All @@ -284,24 +283,12 @@ class MainActivity : BaseActivity() {
override fun onMenuItemActionCollapse(p0: MenuItem): Boolean {
val currentFragmentId = navController.currentDestination?.id
if (currentFragmentId == R.id.searchFragment || currentFragmentId == R.id.searchResultFragment) {
try {
onBackPressedDispatcher.onBackPressed()
} catch (e: Exception) {
e.printStackTrace()
}
navController.popBackStack()
}
return true
}
}
)

searchView.setOnCloseListener {
if (navController.currentDestination?.id == R.id.searchFragment) {
searchViewModel.setQuery(null)
onBackPressedDispatcher.onBackPressed()
}
false
}
return super.onCreateOptionsMenu(menu)
}

Expand Down

0 comments on commit ca3734a

Please sign in to comment.