Send null queries to ViewModel
This commit is contained in:
@@ -5,6 +5,7 @@ import gq.kirmanak.mealient.database.recipe.entity.FullRecipeEntity
|
||||
import gq.kirmanak.mealient.database.recipe.entity.RecipeSummaryEntity
|
||||
|
||||
interface RecipeRepo {
|
||||
|
||||
fun createPager(): Pager<Int, RecipeSummaryEntity>
|
||||
|
||||
suspend fun clearLocalData()
|
||||
@@ -13,5 +14,5 @@ interface RecipeRepo {
|
||||
|
||||
suspend fun loadRecipeInfo(recipeId: String): FullRecipeEntity?
|
||||
|
||||
fun setSearchName(name: String?)
|
||||
fun updateNameQuery(name: String?)
|
||||
}
|
||||
@@ -56,8 +56,8 @@ class RecipeRepoImpl @Inject constructor(
|
||||
return recipeInfo
|
||||
}
|
||||
|
||||
override fun setSearchName(name: String?) {
|
||||
logger.v { "setSearchName() called with: name = $name" }
|
||||
override fun updateNameQuery(name: String?) {
|
||||
logger.v { "updateNameQuery() called with: name = $name" }
|
||||
pagingSourceFactory.setQuery(name)
|
||||
invalidatingPagingSourceFactory.invalidate()
|
||||
}
|
||||
|
||||
@@ -52,14 +52,21 @@ class MainActivity : AppCompatActivity(R.layout.main_activity) {
|
||||
|
||||
override fun onNewIntent(intent: Intent?) {
|
||||
super.onNewIntent(intent)
|
||||
if (Intent.ACTION_SEARCH == intent?.action) {
|
||||
intent.getStringExtra(SearchManager.QUERY)?.also { query ->
|
||||
viewModel.onSearchQuery(query)
|
||||
}
|
||||
logger.v { "onNewIntent() called with: intent = $intent" }
|
||||
when (intent?.action) {
|
||||
Intent.ACTION_SEARCH -> onNewSearch(intent)
|
||||
else -> logger.w { "Unexpected intent!" }
|
||||
}
|
||||
}
|
||||
|
||||
private fun onNewSearch(intent: Intent) {
|
||||
logger.v { "onNewSearch() called with: intent = $intent" }
|
||||
val query = intent.getStringExtra(SearchManager.QUERY)
|
||||
viewModel.onSearchQuery(query)
|
||||
}
|
||||
|
||||
private fun configureNavGraph() {
|
||||
logger.v { "configureNavGraph() called" }
|
||||
viewModel.startDestination.observeOnce(this) {
|
||||
logger.d { "configureNavGraph: received destination" }
|
||||
val graph = navController.navInflater.inflate(R.navigation.nav_graph)
|
||||
|
||||
@@ -55,8 +55,8 @@ class MainActivityViewModel @Inject constructor(
|
||||
viewModelScope.launch { authRepo.logout() }
|
||||
}
|
||||
|
||||
fun onSearchQuery(query: String) {
|
||||
fun onSearchQuery(query: String?) {
|
||||
logger.v { "onSearchQuery() called with: query = $query" }
|
||||
recipeRepo.setSearchName(query)
|
||||
recipeRepo.updateNameQuery(query)
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user