Add more verbose logging

This commit is contained in:
Kirill Kamakin
2021-11-20 20:32:37 +03:00
parent 32b9e2b32c
commit 8239f11f13
8 changed files with 36 additions and 16 deletions

View File

@@ -4,6 +4,7 @@ import androidx.recyclerview.widget.RecyclerView
import gq.kirmanak.mealient.R import gq.kirmanak.mealient.R
import gq.kirmanak.mealient.data.recipes.db.entity.RecipeSummaryEntity import gq.kirmanak.mealient.data.recipes.db.entity.RecipeSummaryEntity
import gq.kirmanak.mealient.databinding.ViewHolderRecipeBinding import gq.kirmanak.mealient.databinding.ViewHolderRecipeBinding
import timber.log.Timber
class RecipeViewHolder( class RecipeViewHolder(
private val binding: ViewHolderRecipeBinding, private val binding: ViewHolderRecipeBinding,
@@ -15,8 +16,14 @@ class RecipeViewHolder(
} }
fun bind(item: RecipeSummaryEntity?) { fun bind(item: RecipeSummaryEntity?) {
Timber.v("bind() called with: item = $item")
binding.name.text = item?.name ?: loadingPlaceholder binding.name.text = item?.name ?: loadingPlaceholder
recipeViewModel.loadRecipeImage(binding.image, item) recipeViewModel.loadRecipeImage(binding.image, item)
item?.let { entity -> binding.root.setOnClickListener { clickListener(entity) } } item?.let { entity ->
binding.root.setOnClickListener {
Timber.d("bind: item clicked $entity")
clickListener(entity)
}
}
} }
} }

View File

@@ -8,6 +8,7 @@ import gq.kirmanak.mealient.data.recipes.RecipeImageLoader
import gq.kirmanak.mealient.data.recipes.RecipeRepo import gq.kirmanak.mealient.data.recipes.RecipeRepo
import gq.kirmanak.mealient.data.recipes.db.entity.RecipeSummaryEntity import gq.kirmanak.mealient.data.recipes.db.entity.RecipeSummaryEntity
import kotlinx.coroutines.launch import kotlinx.coroutines.launch
import timber.log.Timber
import javax.inject.Inject import javax.inject.Inject
@HiltViewModel @HiltViewModel
@@ -18,6 +19,7 @@ class RecipeViewModel @Inject constructor(
val recipeFlow = recipeRepo.createPager().flow val recipeFlow = recipeRepo.createPager().flow
fun loadRecipeImage(view: ImageView, recipeSummary: RecipeSummaryEntity?) { fun loadRecipeImage(view: ImageView, recipeSummary: RecipeSummaryEntity?) {
Timber.v("loadRecipeImage() called with: view = $view, recipeSummary = $recipeSummary")
viewModelScope.launch { viewModelScope.launch {
recipeImageLoader.loadRecipeImage(view, recipeSummary?.slug) recipeImageLoader.loadRecipeImage(view, recipeSummary?.slug)
} }

View File

@@ -45,6 +45,7 @@ class RecipesFragment : Fragment() {
} }
private fun navigateToRecipeInfo(recipeSummaryEntity: RecipeSummaryEntity) { private fun navigateToRecipeInfo(recipeSummaryEntity: RecipeSummaryEntity) {
Timber.v("navigateToRecipeInfo() called with: recipeSummaryEntity = $recipeSummaryEntity")
findNavController().navigate( findNavController().navigate(
RecipesFragmentDirections.actionRecipesFragmentToRecipeInfoFragment( RecipesFragmentDirections.actionRecipesFragmentToRecipeInfoFragment(
recipeSlug = recipeSummaryEntity.slug, recipeSlug = recipeSummaryEntity.slug,

View File

@@ -28,15 +28,11 @@ class RecipesPagingAdapter(
override fun areItemsTheSame( override fun areItemsTheSame(
oldItem: RecipeSummaryEntity, oldItem: RecipeSummaryEntity,
newItem: RecipeSummaryEntity newItem: RecipeSummaryEntity
): Boolean { ): Boolean = oldItem.remoteId == newItem.remoteId
return oldItem.remoteId == newItem.remoteId
}
override fun areContentsTheSame( override fun areContentsTheSame(
oldItem: RecipeSummaryEntity, oldItem: RecipeSummaryEntity,
newItem: RecipeSummaryEntity newItem: RecipeSummaryEntity
): Boolean { ): Boolean = oldItem.name == newItem.name && oldItem.slug == newItem.slug
return oldItem.name == newItem.name && oldItem.slug == newItem.slug
}
} }
} }

View File

@@ -40,6 +40,7 @@ class RecipeInfoFragment : Fragment() {
viewModel.loadRecipeImage(binding.image, arguments.recipeSlug) viewModel.loadRecipeImage(binding.image, arguments.recipeSlug)
viewModel.loadRecipeInfo(arguments.recipeId, arguments.recipeSlug) viewModel.loadRecipeInfo(arguments.recipeId, arguments.recipeSlug)
viewModel.recipeInfo.observe(viewLifecycleOwner) { viewModel.recipeInfo.observe(viewLifecycleOwner) {
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
@@ -58,7 +59,7 @@ class RecipeInfoFragment : Fragment() {
private fun listenToAuthStatuses() { private fun listenToAuthStatuses() {
Timber.v("listenToAuthStatuses() called") Timber.v("listenToAuthStatuses() called")
authViewModel.authenticationStatuses().observe(this) { authViewModel.authenticationStatuses().observe(this) {
Timber.v("listenToAuthStatuses: new auth status = $it") Timber.d("listenToAuthStatuses: new auth status = $it")
if (!it) navigateToAuthFragment() if (!it) navigateToAuthFragment()
} }
} }

View File

@@ -22,6 +22,7 @@ class RecipeInfoViewModel @Inject constructor(
val recipeInfo: LiveData<FullRecipeInfo> = _recipeInfo val recipeInfo: LiveData<FullRecipeInfo> = _recipeInfo
fun loadRecipeImage(view: ImageView, recipeSlug: String) { fun loadRecipeImage(view: ImageView, recipeSlug: String) {
Timber.v("loadRecipeImage() called with: view = $view, recipeSlug = $recipeSlug")
viewModelScope.launch { viewModelScope.launch {
recipeImageLoader.loadRecipeImage(view, recipeSlug) recipeImageLoader.loadRecipeImage(view, recipeSlug)
} }

View File

@@ -8,14 +8,16 @@ import androidx.recyclerview.widget.RecyclerView
import gq.kirmanak.mealient.data.recipes.db.entity.RecipeIngredientEntity import gq.kirmanak.mealient.data.recipes.db.entity.RecipeIngredientEntity
import gq.kirmanak.mealient.databinding.ViewHolderIngredientBinding import gq.kirmanak.mealient.databinding.ViewHolderIngredientBinding
import gq.kirmanak.mealient.ui.recipes.info.RecipeIngredientsAdapter.RecipeIngredientViewHolder import gq.kirmanak.mealient.ui.recipes.info.RecipeIngredientsAdapter.RecipeIngredientViewHolder
import timber.log.Timber
class RecipeIngredientsAdapter() : class RecipeIngredientsAdapter :
ListAdapter<RecipeIngredientEntity, RecipeIngredientViewHolder>(RecipeIngredientDiffCallback) { ListAdapter<RecipeIngredientEntity, RecipeIngredientViewHolder>(RecipeIngredientDiffCallback) {
class RecipeIngredientViewHolder( class RecipeIngredientViewHolder(
private val binding: ViewHolderIngredientBinding private val binding: ViewHolderIngredientBinding
) : RecyclerView.ViewHolder(binding.root) { ) : RecyclerView.ViewHolder(binding.root) {
fun bind(item: RecipeIngredientEntity) { fun bind(item: RecipeIngredientEntity) {
Timber.v("bind() called with: item = $item")
binding.checkBox.text = item.note binding.checkBox.text = item.note
} }
} }
@@ -33,6 +35,7 @@ class RecipeIngredientsAdapter() :
} }
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): RecipeIngredientViewHolder { override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): RecipeIngredientViewHolder {
Timber.v("onCreateViewHolder() called with: parent = $parent, viewType = $viewType")
val inflater = LayoutInflater.from(parent.context) val inflater = LayoutInflater.from(parent.context)
return RecipeIngredientViewHolder( return RecipeIngredientViewHolder(
ViewHolderIngredientBinding.inflate(inflater, parent, false) ViewHolderIngredientBinding.inflate(inflater, parent, false)
@@ -40,6 +43,9 @@ class RecipeIngredientsAdapter() :
} }
override fun onBindViewHolder(holder: RecipeIngredientViewHolder, position: Int) { override fun onBindViewHolder(holder: RecipeIngredientViewHolder, position: Int) {
holder.bind(getItem(position)) Timber.v("onBindViewHolder() called with: holder = $holder, position = $position")
val item = getItem(position)
Timber.d("onBindViewHolder: item is $item")
holder.bind(item)
} }
} }

View File

@@ -8,11 +8,11 @@ import androidx.recyclerview.widget.RecyclerView
import gq.kirmanak.mealient.R import gq.kirmanak.mealient.R
import gq.kirmanak.mealient.data.recipes.db.entity.RecipeInstructionEntity import gq.kirmanak.mealient.data.recipes.db.entity.RecipeInstructionEntity
import gq.kirmanak.mealient.databinding.ViewHolderInstructionBinding import gq.kirmanak.mealient.databinding.ViewHolderInstructionBinding
import gq.kirmanak.mealient.ui.recipes.info.RecipeInstructionsAdapter.RecipeInstructionViewHolder
import timber.log.Timber
class RecipeInstructionsAdapter : class RecipeInstructionsAdapter :
ListAdapter<RecipeInstructionEntity, RecipeInstructionsAdapter.RecipeInstructionViewHolder>( ListAdapter<RecipeInstructionEntity, RecipeInstructionViewHolder>(RecipeInstructionDiffCallback) {
RecipeInstructionDiffCallback
) {
private object RecipeInstructionDiffCallback : private object RecipeInstructionDiffCallback :
DiffUtil.ItemCallback<RecipeInstructionEntity>() { DiffUtil.ItemCallback<RecipeInstructionEntity>() {
@@ -27,9 +27,11 @@ class RecipeInstructionsAdapter :
): Boolean = oldItem == newItem ): Boolean = oldItem == newItem
} }
class RecipeInstructionViewHolder(private val binding: ViewHolderInstructionBinding) : class RecipeInstructionViewHolder(
RecyclerView.ViewHolder(binding.root) { private val binding: ViewHolderInstructionBinding
) : RecyclerView.ViewHolder(binding.root) {
fun bind(item: RecipeInstructionEntity, position: Int) { fun bind(item: RecipeInstructionEntity, position: Int) {
Timber.v("bind() called with: item = $item, position = $position")
binding.step.text = binding.root.resources.getString( binding.step.text = binding.root.resources.getString(
R.string.view_holder_recipe_instructions_step, position + 1 R.string.view_holder_recipe_instructions_step, position + 1
) )
@@ -38,6 +40,7 @@ class RecipeInstructionsAdapter :
} }
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): RecipeInstructionViewHolder { override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): RecipeInstructionViewHolder {
Timber.v("onCreateViewHolder() called with: parent = $parent, viewType = $viewType")
val inflater = LayoutInflater.from(parent.context) val inflater = LayoutInflater.from(parent.context)
return RecipeInstructionViewHolder( return RecipeInstructionViewHolder(
ViewHolderInstructionBinding.inflate(inflater, parent, false) ViewHolderInstructionBinding.inflate(inflater, parent, false)
@@ -45,6 +48,9 @@ class RecipeInstructionsAdapter :
} }
override fun onBindViewHolder(holder: RecipeInstructionViewHolder, position: Int) { override fun onBindViewHolder(holder: RecipeInstructionViewHolder, position: Int) {
holder.bind(getItem(position), position) Timber.v("onBindViewHolder() called with: holder = $holder, position = $position")
val item = getItem(position)
Timber.d("onBindViewHolder: item is $item")
holder.bind(item, position)
} }
} }