mirror of
https://github.com/CatimaLoyalty/Android.git
synced 2026-05-18 05:36:39 -04:00
Move store name below card image
This commit is contained in:
@@ -4,6 +4,7 @@ import android.content.Context;
|
||||
import android.content.SharedPreferences;
|
||||
import android.content.res.Resources;
|
||||
import android.database.Cursor;
|
||||
import android.graphics.Bitmap;
|
||||
import android.graphics.Color;
|
||||
import android.graphics.drawable.Drawable;
|
||||
import android.util.SparseBooleanArray;
|
||||
@@ -41,7 +42,7 @@ public class LoyaltyCardCursorAdapter extends BaseCursorAdapter<LoyaltyCardCurso
|
||||
protected SparseBooleanArray mSelectedItems;
|
||||
protected SparseBooleanArray mAnimationItemsIndex;
|
||||
private boolean mReverseAllAnimations = false;
|
||||
private boolean mAlwaysShowName;
|
||||
private boolean mShowNameBelowThumbnail;
|
||||
private boolean mShowNote;
|
||||
private boolean mShowBalance;
|
||||
private boolean mShowValidity;
|
||||
@@ -75,21 +76,21 @@ public class LoyaltyCardCursorAdapter extends BaseCursorAdapter<LoyaltyCardCurso
|
||||
SharedPreferences cardDetailsPref = mContext.getSharedPreferences(
|
||||
mContext.getString(R.string.sharedpreference_card_details),
|
||||
Context.MODE_PRIVATE);
|
||||
mAlwaysShowName = cardDetailsPref.getBoolean(mContext.getString(R.string.sharedpreference_card_details_always_show_name), false);
|
||||
mShowNameBelowThumbnail = cardDetailsPref.getBoolean(mContext.getString(R.string.sharedpreference_card_details_show_name_below_thumbnail), false);
|
||||
mShowNote = cardDetailsPref.getBoolean(mContext.getString(R.string.sharedpreference_card_details_show_note), true);
|
||||
mShowBalance = cardDetailsPref.getBoolean(mContext.getString(R.string.sharedpreference_card_details_show_balance), true);
|
||||
mShowValidity = cardDetailsPref.getBoolean(mContext.getString(R.string.sharedpreference_card_details_show_validity), true);
|
||||
}
|
||||
|
||||
public void alwaysShowName(boolean show) {
|
||||
mAlwaysShowName = show;
|
||||
public void showNameBelowThumbnail(boolean show) {
|
||||
mShowNameBelowThumbnail = show;
|
||||
notifyDataSetChanged();
|
||||
|
||||
saveDetailState(R.string.sharedpreference_card_details_always_show_name, show);
|
||||
saveDetailState(R.string.sharedpreference_card_details_show_name_below_thumbnail, show);
|
||||
}
|
||||
|
||||
public boolean alwaysShowingName() {
|
||||
return mAlwaysShowName;
|
||||
public boolean showingNameBelowThumbnail() {
|
||||
return mShowNameBelowThumbnail;
|
||||
}
|
||||
|
||||
public void showNote(boolean show) {
|
||||
@@ -130,28 +131,24 @@ public class LoyaltyCardCursorAdapter extends BaseCursorAdapter<LoyaltyCardCurso
|
||||
builder.setTitle(R.string.action_show_details);
|
||||
builder.setMultiChoiceItems(
|
||||
new String[]{
|
||||
mContext.getString(R.string.always_show_name),
|
||||
mContext.getString(R.string.show_name_below_image_thumbnail),
|
||||
mContext.getString(R.string.show_note),
|
||||
mContext.getString(R.string.show_balance),
|
||||
mContext.getString(R.string.show_validity)
|
||||
},
|
||||
new boolean[]{
|
||||
alwaysShowingName(),
|
||||
showingNameBelowThumbnail(),
|
||||
showingNote(),
|
||||
showingBalance(),
|
||||
showingValidity()
|
||||
},
|
||||
(dialogInterface, i, b) -> {
|
||||
if (i == 0) {
|
||||
alwaysShowName(b);
|
||||
} else if (i == 1) {
|
||||
showNote(b);
|
||||
} else if (i == 2) {
|
||||
showBalance(b);
|
||||
} else if (i == 3) {
|
||||
showValidity(b);
|
||||
} else {
|
||||
throw new IndexOutOfBoundsException("No such index exists in LoyaltyCardCursorAdapter show details view");
|
||||
switch (i) {
|
||||
case 0: showNameBelowThumbnail(b); break;
|
||||
case 1: showNote(b); break;
|
||||
case 2: showBalance(b); break;
|
||||
case 3: showValidity(b); break;
|
||||
default: throw new IndexOutOfBoundsException("No such index exists in LoyaltyCardCursorAdapter show details view");
|
||||
}
|
||||
}
|
||||
);
|
||||
@@ -182,6 +179,13 @@ public class LoyaltyCardCursorAdapter extends BaseCursorAdapter<LoyaltyCardCurso
|
||||
inputHolder.mDivider.setVisibility(View.GONE);
|
||||
|
||||
LoyaltyCard loyaltyCard = LoyaltyCard.toLoyaltyCard(inputCursor);
|
||||
Bitmap icon = Utils.retrieveCardImage(mContext, loyaltyCard.id, ImageLocationType.icon);
|
||||
|
||||
if (mShowNameBelowThumbnail && icon != null) {
|
||||
inputHolder.setStoreField(loyaltyCard.store);
|
||||
} else {
|
||||
inputHolder.setStoreField(null);
|
||||
}
|
||||
|
||||
if (mShowNote && !loyaltyCard.note.isEmpty()) {
|
||||
inputHolder.setNoteField(loyaltyCard.note);
|
||||
@@ -208,7 +212,7 @@ public class LoyaltyCardCursorAdapter extends BaseCursorAdapter<LoyaltyCardCurso
|
||||
}
|
||||
|
||||
inputHolder.mCardIcon.setContentDescription(loyaltyCard.store);
|
||||
Utils.setIconOrTextWithBackground(mContext, loyaltyCard, inputHolder.mCardIcon, inputHolder.mCardText, mAlwaysShowName);
|
||||
Utils.setIconOrTextWithBackground(mContext, loyaltyCard, icon, inputHolder.mCardIcon, inputHolder.mCardText);
|
||||
inputHolder.setIconBackgroundColor(loyaltyCard.headerColor != null ? loyaltyCard.headerColor : androidx.appcompat.R.attr.colorPrimary);
|
||||
|
||||
inputHolder.toggleCardStateIcon(loyaltyCard.starStatus != 0, loyaltyCard.archiveStatus != 0, itemSelected(inputCursor.getPosition()));
|
||||
@@ -296,7 +300,7 @@ public class LoyaltyCardCursorAdapter extends BaseCursorAdapter<LoyaltyCardCurso
|
||||
|
||||
public class LoyaltyCardListItemViewHolder extends RecyclerView.ViewHolder {
|
||||
|
||||
public TextView mCardText, mNoteField, mBalanceField, mValidFromField, mExpiryField;
|
||||
public TextView mCardText, mStoreField, mNoteField, mBalanceField, mValidFromField, mExpiryField;
|
||||
public ImageView mCardIcon, mStarBackground, mStarBorder, mTickIcon, mArchivedBackground;
|
||||
public MaterialCardView mRow;
|
||||
public ConstraintLayout mStar, mArchived;
|
||||
@@ -309,6 +313,7 @@ public class LoyaltyCardCursorAdapter extends BaseCursorAdapter<LoyaltyCardCurso
|
||||
View inputView = loyaltyCardLayoutBinding.getRoot();
|
||||
mRow = loyaltyCardLayoutBinding.row;
|
||||
mDivider = loyaltyCardLayoutBinding.infoDivider;
|
||||
mStoreField = loyaltyCardLayoutBinding.store;
|
||||
mNoteField = loyaltyCardLayoutBinding.note;
|
||||
mBalanceField = loyaltyCardLayoutBinding.balance;
|
||||
mValidFromField = loyaltyCardLayoutBinding.validFrom;
|
||||
@@ -358,6 +363,16 @@ public class LoyaltyCardCursorAdapter extends BaseCursorAdapter<LoyaltyCardCurso
|
||||
field.requestLayout();
|
||||
}
|
||||
|
||||
public void setStoreField(String text) {
|
||||
if (text == null) {
|
||||
mStoreField.setVisibility(View.GONE);
|
||||
} else {
|
||||
mStoreField.setVisibility(View.VISIBLE);
|
||||
mStoreField.setText(text);
|
||||
}
|
||||
mStoreField.requestLayout();
|
||||
}
|
||||
|
||||
public void setNoteField(String text) {
|
||||
if (text == null) {
|
||||
mNoteField.setVisibility(View.GONE);
|
||||
|
||||
@@ -630,7 +630,8 @@ public class LoyaltyCardViewActivity extends CatimaAppCompatActivity implements
|
||||
editButtonIcon.setTint(Utils.needsDarkForeground(complementaryColor) ? Color.BLACK : Color.WHITE);
|
||||
binding.fabEdit.setImageDrawable(editButtonIcon);
|
||||
|
||||
Utils.setIconOrTextWithBackground(this, loyaltyCard, binding.iconImage, binding.iconText, false);
|
||||
Bitmap icon = Utils.retrieveCardImage(this, loyaltyCard.id, ImageLocationType.icon);
|
||||
Utils.setIconOrTextWithBackground(this, loyaltyCard, icon, binding.iconImage, binding.iconText);
|
||||
|
||||
// If the background is very bright, we should use dark icons
|
||||
backgroundNeedsDarkIcons = Utils.needsDarkForeground(backgroundHeaderColor);
|
||||
|
||||
@@ -593,31 +593,22 @@ public class Utils {
|
||||
return result.toString();
|
||||
}
|
||||
|
||||
public static void setIconOrTextWithBackground(Context context, LoyaltyCard loyaltyCard, ImageView backgroundOrIcon, TextView textWhenNoImage, boolean alwaysShowTextView) {
|
||||
Bitmap icon = Utils.retrieveCardImage(context, loyaltyCard.id, ImageLocationType.icon);
|
||||
int headerColor = loyaltyCard.headerColor != null ? loyaltyCard.headerColor : LetterBitmap.getDefaultColor(context, loyaltyCard.store);
|
||||
|
||||
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);
|
||||
|
||||
backgroundOrIcon.setImageBitmap(icon);
|
||||
backgroundOrIcon.setBackgroundColor(Color.TRANSPARENT);
|
||||
} else {
|
||||
textWhenNoImage.setVisibility(View.VISIBLE);
|
||||
|
||||
int headerColor = loyaltyCard.headerColor != null ? loyaltyCard.headerColor : LetterBitmap.getDefaultColor(context, loyaltyCard.store);
|
||||
|
||||
backgroundOrIcon.setImageBitmap(null);
|
||||
backgroundOrIcon.setBackgroundColor(headerColor);
|
||||
}
|
||||
|
||||
if (icon == null || alwaysShowTextView) {
|
||||
textWhenNoImage.setVisibility(View.VISIBLE);
|
||||
textWhenNoImage.setText(loyaltyCard.store);
|
||||
textWhenNoImage.setTextColor(Utils.needsDarkForeground(headerColor) ? Color.BLACK : Color.WHITE);
|
||||
// Add a small shadow layer if there is an icon to increase readability
|
||||
if (icon != null) {
|
||||
textWhenNoImage.setShadowLayer(1, 1, 1, Utils.needsDarkForeground(headerColor) ? Color.WHITE : Color.BLACK);
|
||||
} else {
|
||||
textWhenNoImage.setShadowLayer(0, 0, 0, Color.TRANSPARENT);
|
||||
}
|
||||
} else {
|
||||
textWhenNoImage.setVisibility(View.GONE);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -18,7 +18,7 @@
|
||||
android:outlineProvider="none"
|
||||
app:cardCornerRadius="8dp"
|
||||
app:strokeWidth="0dp"
|
||||
app:layout_constraintBottom_toTopOf="@+id/note"
|
||||
app:layout_constraintBottom_toTopOf="@+id/store"
|
||||
app:layout_constraintDimensionRatio="85.6f:53.98f"
|
||||
app:layout_constraintTop_toTopOf="parent">
|
||||
|
||||
@@ -129,6 +129,23 @@
|
||||
|
||||
</com.google.android.material.card.MaterialCardView>
|
||||
|
||||
<TextView
|
||||
android:id="@+id/store"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginStart="8dp"
|
||||
android:layout_marginEnd="8dp"
|
||||
android:layout_marginBottom="4dp"
|
||||
android:textAppearance="?attr/textAppearanceHeadlineMedium"
|
||||
android:textColor="?android:attr/textColorSecondary"
|
||||
android:visibility="gone"
|
||||
tools:visibility="visible"
|
||||
app:layout_constraintTop_toBottomOf="@+id/icon_layout"
|
||||
app:layout_constraintBottom_toTopOf="@+id/note"
|
||||
app:layout_constraintEnd_toEndOf="parent"
|
||||
app:layout_constraintStart_toStartOf="parent"
|
||||
tools:text="Example store"/>
|
||||
|
||||
<TextView
|
||||
android:id="@+id/note"
|
||||
android:layout_width="match_parent"
|
||||
@@ -140,7 +157,7 @@
|
||||
android:textColor="?android:attr/textColorSecondary"
|
||||
android:visibility="gone"
|
||||
tools:visibility="visible"
|
||||
app:layout_constraintTop_toBottomOf="@+id/icon_layout"
|
||||
app:layout_constraintTop_toBottomOf="@+id/store"
|
||||
app:layout_constraintBottom_toTopOf="@+id/info_divider"
|
||||
app:layout_constraintEnd_toEndOf="parent"
|
||||
app:layout_constraintStart_toStartOf="parent"
|
||||
|
||||
@@ -223,7 +223,7 @@
|
||||
<string name="settings_key_locale" translatable="false">pref_locale</string>
|
||||
<string name="settings_system_locale">System</string>
|
||||
<string name="selectColor">Select color</string>
|
||||
<string name="setIcon">Set icon</string>
|
||||
<string name="setIcon">Set thumbnail</string>
|
||||
<string name="setting_key_theme_color" translatable="false">pref_theme_color</string>
|
||||
<string name="settings_theme_color">Theme color</string>
|
||||
<string name="settings_catima_theme">Catima</string>
|
||||
@@ -312,13 +312,13 @@
|
||||
<string name="openBackImageInGalleryApp">Open back image in gallery app</string>
|
||||
<string name="setBarcodeHeight">Set barcode height</string>
|
||||
<string name="donate">Donate</string>
|
||||
<string name="icon_header_click_text">Long press to edit icon</string>
|
||||
<string name="always_show_name">Always show name</string>
|
||||
<string name="icon_header_click_text">Long press to edit thumbnail</string>
|
||||
<string name="show_name_below_image_thumbnail">Show name below image thumbnail</string>
|
||||
<string name="show_note">Show note</string>
|
||||
<string name="show_balance">Show balance</string>
|
||||
<string name="show_validity">Show validity</string>
|
||||
<string name="sharedpreference_card_details_always_show_name" translatable="false">sharedpreference_card_details_always_show_name</string>
|
||||
<string name="sharedpreference_card_details_show_note" translatable="false">sharedpreference_card_details_show_note</string>
|
||||
<string name="sharedpreference_card_details_show_balance" translatable="false">sharedpreference_card_details_show_balance</string>
|
||||
<string name="sharedpreference_card_details_show_validity" translatable="false">sharedpreference_card_details_show_validity</string>
|
||||
<string name="sharedpreference_card_details_show_name_below_thumbnail" translatable="false">sharedpreference_card_details_show_name_below_thumbnail</string>
|
||||
</resources>
|
||||
|
||||
Reference in New Issue
Block a user