Fix absent recipe refresh on authorization
This commit is contained in:
@@ -123,15 +123,6 @@ class RecipesListFragment : Fragment(R.layout.fragment_recipes_list) {
|
||||
logger.v { "setupRecipeAdapter: received refresh request" }
|
||||
recipesAdapter.refresh()
|
||||
}
|
||||
|
||||
viewModel.isAuthorized.observe(viewLifecycleOwner) { isAuthorized ->
|
||||
logger.v { "setupRecipeAdapter: isAuthorized changed to $isAuthorized" }
|
||||
if (isAuthorized != null) {
|
||||
if (isAuthorized) recipesAdapter.refresh()
|
||||
// else is ignored to avoid the removal of the non-public recipes
|
||||
viewModel.onAuthorizationChangeHandled()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private fun onLoadFailure(error: Throwable) {
|
||||
|
||||
@@ -1,6 +1,9 @@
|
||||
package gq.kirmanak.mealient.ui.recipes
|
||||
|
||||
import androidx.lifecycle.*
|
||||
import androidx.lifecycle.LiveData
|
||||
import androidx.lifecycle.ViewModel
|
||||
import androidx.lifecycle.liveData
|
||||
import androidx.lifecycle.viewModelScope
|
||||
import androidx.paging.cachedIn
|
||||
import dagger.hilt.android.lifecycle.HiltViewModel
|
||||
import gq.kirmanak.mealient.data.auth.AuthRepo
|
||||
@@ -20,21 +23,13 @@ class RecipesListViewModel @Inject constructor(
|
||||
|
||||
val pagingData = recipeRepo.createPager().flow.cachedIn(viewModelScope)
|
||||
|
||||
private val _isAuthorized = MutableLiveData<Boolean?>(null)
|
||||
val isAuthorized: LiveData<Boolean?> = _isAuthorized
|
||||
|
||||
init {
|
||||
authRepo.isAuthorizedFlow.valueUpdatesOnly().onEach {
|
||||
logger.v { "Authorization state changed to $it" }
|
||||
_isAuthorized.postValue(it)
|
||||
authRepo.isAuthorizedFlow.valueUpdatesOnly().onEach { hasAuthorized ->
|
||||
logger.v { "Authorization state changed to $hasAuthorized" }
|
||||
if (hasAuthorized) recipeRepo.refreshRecipes()
|
||||
}.launchIn(viewModelScope)
|
||||
}
|
||||
|
||||
fun onAuthorizationChangeHandled() {
|
||||
logger.v { "onAuthorizationSuccessHandled() called" }
|
||||
_isAuthorized.postValue(null)
|
||||
}
|
||||
|
||||
fun refreshRecipeInfo(recipeSlug: String): LiveData<Result<Unit>> {
|
||||
logger.v { "refreshRecipeInfo called with: recipeSlug = $recipeSlug" }
|
||||
return liveData {
|
||||
|
||||
Reference in New Issue
Block a user