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