Extract recipe info adapters to ViewModel
This commit is contained in:
@@ -37,6 +37,9 @@ class RecipeInfoFragment : BottomSheetDialogFragment() {
|
|||||||
super.onViewCreated(view, savedInstanceState)
|
super.onViewCreated(view, savedInstanceState)
|
||||||
Timber.v("onViewCreated() called with: view = $view, savedInstanceState = $savedInstanceState")
|
Timber.v("onViewCreated() called with: view = $view, savedInstanceState = $savedInstanceState")
|
||||||
|
|
||||||
|
binding.ingredientsList.adapter = viewModel.recipeIngredientsAdapter
|
||||||
|
binding.instructionsList.adapter = viewModel.recipeInstructionsAdapter
|
||||||
|
|
||||||
viewModel.loadRecipeImage(binding.image, arguments.recipeSlug)
|
viewModel.loadRecipeImage(binding.image, arguments.recipeSlug)
|
||||||
viewModel.loadRecipeInfo(arguments.recipeId, arguments.recipeSlug)
|
viewModel.loadRecipeInfo(arguments.recipeId, arguments.recipeSlug)
|
||||||
|
|
||||||
@@ -44,14 +47,6 @@ class RecipeInfoFragment : BottomSheetDialogFragment() {
|
|||||||
Timber.d("onViewCreated: full info $it")
|
Timber.d("onViewCreated: full info $it")
|
||||||
binding.title.text = it.recipeSummaryEntity.name
|
binding.title.text = it.recipeSummaryEntity.name
|
||||||
binding.description.text = it.recipeSummaryEntity.description
|
binding.description.text = it.recipeSummaryEntity.description
|
||||||
|
|
||||||
val recipeIngredientsAdapter = RecipeIngredientsAdapter()
|
|
||||||
binding.ingredientsList.adapter = recipeIngredientsAdapter
|
|
||||||
recipeIngredientsAdapter.submitList(it.recipeIngredients)
|
|
||||||
|
|
||||||
val recipeInstructionsAdapter = RecipeInstructionsAdapter()
|
|
||||||
binding.instructionsList.adapter = recipeInstructionsAdapter
|
|
||||||
recipeInstructionsAdapter.submitList(it.recipeInstructions)
|
|
||||||
}
|
}
|
||||||
(requireActivity() as? AppCompatActivity)?.supportActionBar?.title = null
|
(requireActivity() as? AppCompatActivity)?.supportActionBar?.title = null
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -20,6 +20,8 @@ class RecipeInfoViewModel @Inject constructor(
|
|||||||
) : ViewModel() {
|
) : ViewModel() {
|
||||||
private val _recipeInfo = MutableLiveData<FullRecipeInfo>()
|
private val _recipeInfo = MutableLiveData<FullRecipeInfo>()
|
||||||
val recipeInfo: LiveData<FullRecipeInfo> = _recipeInfo
|
val recipeInfo: LiveData<FullRecipeInfo> = _recipeInfo
|
||||||
|
val recipeIngredientsAdapter = RecipeIngredientsAdapter()
|
||||||
|
val recipeInstructionsAdapter = RecipeInstructionsAdapter()
|
||||||
|
|
||||||
fun loadRecipeImage(view: ImageView, recipeSlug: String) {
|
fun loadRecipeImage(view: ImageView, recipeSlug: String) {
|
||||||
Timber.v("loadRecipeImage() called with: view = $view, recipeSlug = $recipeSlug")
|
Timber.v("loadRecipeImage() called with: view = $view, recipeSlug = $recipeSlug")
|
||||||
@@ -36,6 +38,8 @@ class RecipeInfoViewModel @Inject constructor(
|
|||||||
}.onSuccess {
|
}.onSuccess {
|
||||||
Timber.d("loadRecipeInfo: received recipe info = $it")
|
Timber.d("loadRecipeInfo: received recipe info = $it")
|
||||||
_recipeInfo.value = it
|
_recipeInfo.value = it
|
||||||
|
recipeIngredientsAdapter.submitList(it.recipeIngredients)
|
||||||
|
recipeInstructionsAdapter.submitList(it.recipeInstructions)
|
||||||
}.onFailure {
|
}.onFailure {
|
||||||
Timber.e(it, "loadRecipeInfo: can't load recipe info")
|
Timber.e(it, "loadRecipeInfo: can't load recipe info")
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user