Skip to content

Commit

Permalink
Fix search being cleared sometimes
Browse files Browse the repository at this point in the history
  • Loading branch information
cemrich committed Dec 23, 2023
1 parent c35a496 commit 992d746
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,11 @@ import androidx.navigation.NavController
import androidx.navigation.NavDestination
import androidx.navigation.fragment.NavHostFragment
import androidx.navigation.navOptions
import androidx.navigation.ui.*
import androidx.navigation.ui.AppBarConfiguration
import androidx.navigation.ui.navigateUp
import androidx.navigation.ui.onNavDestinationSelected
import androidx.navigation.ui.setupActionBarWithNavController
import androidx.navigation.ui.setupWithNavController
import androidx.preference.PreferenceManager
import com.google.android.material.appbar.AppBarLayout
import com.google.android.material.appbar.AppBarLayout.LayoutParams.SCROLL_FLAG_ENTER_ALWAYS
Expand Down Expand Up @@ -140,8 +144,11 @@ class MainActivity : AppCompatActivity(), MenuProvider {
}
}
it.editText.setOnFocusChangeListener { _, hasFocus ->
if (hasFocus) {
searchViewModel.enterQueryMode()
if (hasFocus &&
it.currentTransitionState != SearchView.TransitionState.SHOWN &&
navController.currentDestination?.id != R.id.searchResultsFragment
) {
searchViewModel.enterNewSearch()
}
}
it.editText.setOnEditorActionListener { _, _, _ ->
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -173,13 +173,17 @@ class SearchViewModel(
}
}

fun enterQueryMode() {
fun enterNewSearch() {
_searchState.tryEmit(SeachState.Query)
clearTempData()
}

fun enterLastSearch() {
_searchState.tryEmit(SeachState.Query)
}

fun exitToNone() {
_searchState.tryEmit(SeachState.None)
clearTempData()
}

fun exitToResults() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ class SearchResultsFragment : Fragment(), MenuProvider, MediathekShowListItemLis
override fun onMenuItemSelected(menuItem: MenuItem): Boolean {
return when (menuItem.itemId) {
R.id.menu_search -> {
viewModel.enterQueryMode()
viewModel.enterLastSearch()
true
}

Expand All @@ -134,7 +134,7 @@ class SearchResultsFragment : Fragment(), MenuProvider, MediathekShowListItemLis
}

override fun onToolbarClicked() {
viewModel.enterQueryMode()
viewModel.enterLastSearch()
}

override fun onShowClicked(show: MediathekShow) {
Expand Down

0 comments on commit 992d746

Please sign in to comment.