Display favorite icon on recipe holders

This commit is contained in:
Kirill Kamakin
2022-12-13 19:31:53 +01:00
parent aefb974cb3
commit 3eb99206e8
5 changed files with 56 additions and 6 deletions

View File

@@ -1,5 +1,7 @@
package gq.kirmanak.mealient.ui.recipes
import android.view.View
import androidx.annotation.StringRes
import androidx.recyclerview.widget.RecyclerView
import gq.kirmanak.mealient.R
import gq.kirmanak.mealient.database.recipe.entity.RecipeSummaryEntity
@@ -43,6 +45,24 @@ class RecipeViewHolder private constructor(
logger.d { "bind: item clicked $entity" }
clickListener(entity)
}
binding.favoriteIcon.setImageResource(
if (item.isFavorite) {
R.drawable.ic_favorite_filled
} else {
R.drawable.ic_favorite_unfilled
}
)
binding.favoriteIcon.setContentDescription(
if (item.isFavorite) {
R.string.view_holder_recipe_favorite_content_description
} else {
R.string.view_holder_recipe_non_favorite_content_description
}
)
}
}
}
private fun View.setContentDescription(@StringRes resId: Int) {
contentDescription = context.getString(resId)
}