Show search request when recipe is closed
This commit is contained in:
@@ -123,7 +123,13 @@ class MainActivity : AppCompatActivity(R.layout.main_activity) {
|
|||||||
logger.e { "setupSearchItem: search item's actionView is null or not SearchView" }
|
logger.e { "setupSearchItem: search item's actionView is null or not SearchView" }
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
searchView.queryHint = getString(R.string.search_recipes_hint)
|
searchView.queryHint = getString(R.string.search_recipes_hint)
|
||||||
|
searchView.isSubmitButtonEnabled = false
|
||||||
|
|
||||||
|
searchView.setQuery(viewModel.lastSearchQuery, false)
|
||||||
|
searchView.isIconified = viewModel.lastSearchQuery.isNullOrBlank()
|
||||||
|
|
||||||
searchView.setOnCloseListener {
|
searchView.setOnCloseListener {
|
||||||
logger.v { "onClose() called" }
|
logger.v { "onClose() called" }
|
||||||
viewModel.onSearchQuery(null)
|
viewModel.onSearchQuery(null)
|
||||||
|
|||||||
@@ -32,6 +32,9 @@ class MainActivityViewModel @Inject constructor(
|
|||||||
private val _startDestination = MutableLiveData<Int>()
|
private val _startDestination = MutableLiveData<Int>()
|
||||||
val startDestination: LiveData<Int> = _startDestination
|
val startDestination: LiveData<Int> = _startDestination
|
||||||
|
|
||||||
|
var lastSearchQuery: String? = null
|
||||||
|
private set
|
||||||
|
|
||||||
init {
|
init {
|
||||||
authRepo.isAuthorizedFlow
|
authRepo.isAuthorizedFlow
|
||||||
.onEach { isAuthorized -> updateUiState { it.copy(isAuthorized = isAuthorized) } }
|
.onEach { isAuthorized -> updateUiState { it.copy(isAuthorized = isAuthorized) } }
|
||||||
@@ -57,6 +60,9 @@ class MainActivityViewModel @Inject constructor(
|
|||||||
|
|
||||||
fun onSearchQuery(query: String?) {
|
fun onSearchQuery(query: String?) {
|
||||||
logger.v { "onSearchQuery() called with: query = $query" }
|
logger.v { "onSearchQuery() called with: query = $query" }
|
||||||
|
if (lastSearchQuery != query) {
|
||||||
|
lastSearchQuery = query
|
||||||
recipeRepo.updateNameQuery(query)
|
recipeRepo.updateNameQuery(query)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user