Extract recipe view holder to separate file

This commit is contained in:
Kirill Kamakin
2021-11-14 18:48:29 +03:00
parent 5040582fdf
commit 99c5d24a98
2 changed files with 15 additions and 11 deletions

View File

@@ -0,0 +1,15 @@
package gq.kirmanak.mealie.ui.recipes
import androidx.recyclerview.widget.RecyclerView
import gq.kirmanak.mealie.data.recipes.db.RecipeEntity
import gq.kirmanak.mealie.databinding.ViewHolderRecipeBinding
class RecipeViewHolder(
private val binding: ViewHolderRecipeBinding,
private val recipeViewModel: RecipeViewModel
) : RecyclerView.ViewHolder(binding.root) {
fun bind(item: RecipeEntity?) {
binding.name.text = item?.name
recipeViewModel.loadRecipeImage(binding.image, item)
}
}

View File

@@ -4,7 +4,6 @@ import android.view.LayoutInflater
import android.view.ViewGroup
import androidx.paging.PagingDataAdapter
import androidx.recyclerview.widget.DiffUtil
import androidx.recyclerview.widget.RecyclerView
import gq.kirmanak.mealie.data.recipes.db.RecipeEntity
import gq.kirmanak.mealie.databinding.ViewHolderRecipeBinding
import timber.log.Timber
@@ -25,16 +24,6 @@ class RecipesPagingAdapter(
}
}
class RecipeViewHolder(
private val binding: ViewHolderRecipeBinding,
private val recipeViewModel: RecipeViewModel
) : RecyclerView.ViewHolder(binding.root) {
fun bind(item: RecipeEntity?) {
binding.name.text = item?.name
recipeViewModel.loadRecipeImage(binding.image, item)
}
}
private object RecipeDiffCallback : DiffUtil.ItemCallback<RecipeEntity>() {
override fun areItemsTheSame(oldItem: RecipeEntity, newItem: RecipeEntity): Boolean {
return oldItem.localId == newItem.localId