diff --git a/app/src/main/java/gq/kirmanak/mealient/ui/recipes/RecipeViewHolder.kt b/app/src/main/java/gq/kirmanak/mealient/ui/recipes/RecipeViewHolder.kt index 898bf5b..41f4dc4 100644 --- a/app/src/main/java/gq/kirmanak/mealient/ui/recipes/RecipeViewHolder.kt +++ b/app/src/main/java/gq/kirmanak/mealient/ui/recipes/RecipeViewHolder.kt @@ -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) } \ No newline at end of file diff --git a/app/src/main/res/drawable/ic_favorite_filled.xml b/app/src/main/res/drawable/ic_favorite_filled.xml new file mode 100644 index 0000000..3dcfcb6 --- /dev/null +++ b/app/src/main/res/drawable/ic_favorite_filled.xml @@ -0,0 +1,10 @@ + + + diff --git a/app/src/main/res/drawable/ic_favorite_unfilled.xml b/app/src/main/res/drawable/ic_favorite_unfilled.xml new file mode 100644 index 0000000..3fbbab7 --- /dev/null +++ b/app/src/main/res/drawable/ic_favorite_unfilled.xml @@ -0,0 +1,10 @@ + + + diff --git a/app/src/main/res/layout/view_holder_recipe.xml b/app/src/main/res/layout/view_holder_recipe.xml index a4152b5..9749daa 100644 --- a/app/src/main/res/layout/view_holder_recipe.xml +++ b/app/src/main/res/layout/view_holder_recipe.xml @@ -17,8 +17,7 @@ android:id="@+id/name" android:layout_width="0dp" android:layout_height="wrap_content" - android:layout_marginTop="9dp" - android:layout_marginBottom="5dp" + android:layout_marginVertical="@dimen/margin_small" android:ellipsize="end" android:maxLines="1" android:textAppearance="?textAppearanceHeadline6" @@ -32,18 +31,27 @@ android:id="@+id/image" android:layout_width="0dp" android:layout_height="0dp" - android:layout_marginStart="15dp" - android:layout_marginTop="20dp" - android:layout_marginEnd="13dp" + android:layout_marginHorizontal="@dimen/margin_medium" android:contentDescription="@string/content_description_view_holder_recipe_image" android:scaleType="centerCrop" app:layout_constraintBottom_toTopOf="@+id/name" app:layout_constraintDimensionRatio="2:1" app:layout_constraintEnd_toEndOf="parent" app:layout_constraintStart_toStartOf="parent" - app:layout_constraintTop_toTopOf="parent" + app:layout_constraintTop_toBottomOf="@id/favorite_icon" app:layout_constraintVertical_chainStyle="packed" app:shapeAppearance="?shapeAppearanceCornerMedium" tools:srcCompat="@drawable/placeholder_recipe" /> + + \ No newline at end of file diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index c0e1fcf..0ad1898 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -57,4 +57,6 @@ Recipe saved successfully. Something went wrong. Progress indicator + Item is favorite + Item is not favorite \ No newline at end of file