From b160b1dca883bf9218b423486e58f9888c367aac Mon Sep 17 00:00:00 2001 From: Sylvia van Os Date: Wed, 28 Feb 2024 18:55:28 +0100 Subject: [PATCH] Fix background colour not being set for images in card view --- .../card_locker/LoyaltyCardCursorAdapter.java | 8 +---- .../main/java/protect/card_locker/Utils.java | 29 ++++++++++++------- 2 files changed, 19 insertions(+), 18 deletions(-) diff --git a/app/src/main/java/protect/card_locker/LoyaltyCardCursorAdapter.java b/app/src/main/java/protect/card_locker/LoyaltyCardCursorAdapter.java index a73e80487..6b807b7ec 100644 --- a/app/src/main/java/protect/card_locker/LoyaltyCardCursorAdapter.java +++ b/app/src/main/java/protect/card_locker/LoyaltyCardCursorAdapter.java @@ -123,8 +123,7 @@ public class LoyaltyCardCursorAdapter extends BaseCursorAdapter$1"); } - public static void setIconOrTextWithBackground(Context context, LoyaltyCard loyaltyCard, Bitmap icon, ImageView backgroundOrIcon, TextView textWhenNoImage) { - if (icon != null) { - Log.d("onResume", "setting icon image"); - textWhenNoImage.setVisibility(View.GONE); + /** + * Sets an icon or text with background on the given ImageView and/or TextView, including background colour. + * + * @param context Android context + * @param loyaltyCard Loyalty Card + * @param icon Bitmap of the icon to set, or null + * @param backgroundOrIcon ImageView to draw the icon and background on to + * @param textWhenNoImage TextView to write the loyalty card name into if icon is null + * @return background colour + */ + public static int setIconOrTextWithBackground(Context context, LoyaltyCard loyaltyCard, Bitmap icon, ImageView backgroundOrIcon, TextView textWhenNoImage) { + int headerColor = getHeaderColor(context, loyaltyCard); + backgroundOrIcon.setImageBitmap(icon); + backgroundOrIcon.setBackgroundColor(headerColor); - backgroundOrIcon.setImageBitmap(icon); - backgroundOrIcon.setBackgroundColor(Color.TRANSPARENT); + if (icon != null) { + textWhenNoImage.setVisibility(View.GONE); } else { textWhenNoImage.setVisibility(View.VISIBLE); - - int headerColor = getHeaderColor(context, loyaltyCard); - - backgroundOrIcon.setImageBitmap(null); - backgroundOrIcon.setBackgroundColor(headerColor); textWhenNoImage.setText(loyaltyCard.store); textWhenNoImage.setTextColor(Utils.needsDarkForeground(headerColor) ? Color.BLACK : Color.WHITE); } + + return headerColor; } public static boolean installedFromGooglePlay(Context context) {