Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,12 @@ public void onBindViewHolder(LoyaltyCardListItemViewHolder inputHolder, Cursor i
inputHolder.setExtraField(inputHolder.mExpiryField, null, null, false);
}

if (mLoyaltyCardListDisplayOptions.showingCardId() && !loyaltyCard.cardId.isEmpty()) {
inputHolder.setExtraField(inputHolder.mCardIdField, loyaltyCard.cardId, null, showDivider);
} else {
inputHolder.setExtraField(inputHolder.mCardIdField, null, null, false);
}

inputHolder.mCardIcon.setContentDescription(loyaltyCard.store);
Utils.setIconOrTextWithBackground(mContext, loyaltyCard, icon, inputHolder.mCardIcon, inputHolder.mCardText, new Settings(mContext).getPreferredColumnCount());

Expand Down Expand Up @@ -211,7 +217,7 @@ public interface CardAdapterListener {

public class LoyaltyCardListItemViewHolder extends RecyclerView.ViewHolder {

public TextView mCardText, mStoreField, mNoteField, mBalanceField, mValidFromField, mExpiryField;
public TextView mCardText, mStoreField, mNoteField, mBalanceField, mValidFromField, mExpiryField, mCardIdField;

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think the card ID should probably be displayed as one of the first options, as for those who will use this feature it is probably something they want to refer to often ("yeah my customer ID is 123456").

I'm not quite sure if before or after the note makes most sense, but I'd say it is probably easiest and most consistent to put it after the note but before everything else.

public ImageView mCardIcon, mTickIcon;
public MaterialCardView mRow;
public ConstraintLayout mStar, mArchived;
Expand All @@ -227,6 +233,7 @@ protected LoyaltyCardListItemViewHolder(LoyaltyCardLayoutBinding loyaltyCardLayo
mBalanceField = loyaltyCardLayoutBinding.balance;
mValidFromField = loyaltyCardLayoutBinding.validFrom;
mExpiryField = loyaltyCardLayoutBinding.expiry;
mCardIdField = loyaltyCardLayoutBinding.cardId;
mCardIcon = loyaltyCardLayoutBinding.thumbnail;
mCardText = loyaltyCardLayoutBinding.thumbnailText;
mStar = loyaltyCardLayoutBinding.star;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ public static class LoyaltyCardDisplayOption {
private boolean mShowNote;
private boolean mShowBalance;
private boolean mShowValidity;
private boolean mShowCardId;
private boolean mShowArchivedCards;

public LoyaltyCardListDisplayOptionsManager(Context context, @NonNull Runnable refreshCardsCallback, @Nullable Runnable swapCursorCallback) {
Expand All @@ -52,6 +53,7 @@ public LoyaltyCardListDisplayOptionsManager(Context context, @NonNull Runnable r
mShowNote = mCardDetailsPref.getBoolean(mContext.getString(R.string.sharedpreference_card_details_show_note), true);
mShowBalance = mCardDetailsPref.getBoolean(mContext.getString(R.string.sharedpreference_card_details_show_balance), true);
mShowValidity = mCardDetailsPref.getBoolean(mContext.getString(R.string.sharedpreference_card_details_show_validity), true);
mShowCardId = mCardDetailsPref.getBoolean(mContext.getString(R.string.sharedpreference_card_details_show_card_id), false);
mShowArchivedCards = mCardDetailsPref.getBoolean(mContext.getString(R.string.sharedpreference_card_details_show_archived_cards), true);
}

Expand Down Expand Up @@ -105,6 +107,17 @@ public boolean showingValidity() {
return mShowValidity;
}

public void showCardId(boolean show) {
mShowCardId = show;
mRefreshCardsCallback.run();

saveDetailState(R.string.sharedpreference_card_details_show_card_id, show);
}

public boolean showingCardId() {
return mShowCardId;
}

public void showArchivedCards(boolean show) {
if (mSwapCursorCallback == null) {
throw new IllegalStateException("No swap cursor callback is available, can not manage archive state");
Expand Down Expand Up @@ -147,6 +160,11 @@ public void showDisplayOptionsDialog() {
showingValidity(),
this::showValidity
));
displayOptions.add(new LoyaltyCardDisplayOption(
mContext.getString(R.string.show_card_id),
showingCardId(),
this::showCardId
));

// Hide "Show archived cards" option unless the callback exists
if (mSwapCursorCallback != null) {
Expand Down
10 changes: 10 additions & 0 deletions app/src/main/res/drawable/ic_card_id_24dp.xml

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this barcode from the Google/Android Studio built in fonts? https://fonts.google.com/icons?selected=Material+Symbols+Outlined:barcode:FILL@0;wght@400;GRAD@0;opsz@24&icon.query=barc&icon.size=24&icon.color=%231f1f1f&icon.platform=android

It makes sense and we can keep this, I'm just checking to make sure for copyright reasons that it's just one of the default icons we can freely use.

Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="24dp"
android:height="24dp"
android:viewportWidth="24"
android:viewportHeight="24"
android:tint="?attr/colorControlNormal">
<path
android:fillColor="@android:color/white"
android:pathData="M2,6h2v12L2,18L2,6zM5,6h1v12L5,18L5,6zM7,6h3v12L7,18L7,6zM11,6h1v12h-1L11,6zM13,6h2v12h-2L13,6zM16,6h2v12h-2L16,6zM19,6h1v12h-1L19,6zM21,6h1v12h-1L21,6z"/>
</vector>
21 changes: 20 additions & 1 deletion app/src/main/res/layout/loyalty_card_layout.xml
Original file line number Diff line number Diff line change
Expand Up @@ -213,11 +213,30 @@
android:drawablePadding="4dp"
android:visibility="gone"
app:layout_constraintTop_toBottomOf="@+id/validFrom"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintBottom_toTopOf="@+id/cardId"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
tools:visibility="visible"
tools:text="Tomorrow"/>

<TextView
android:id="@+id/cardId"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center_vertical"
android:layout_marginStart="8dp"
android:layout_marginEnd="8dp"
android:layout_marginBottom="4dp"
android:textAppearance="?attr/textAppearanceBody2"
app:drawableLeftCompat="@drawable/ic_card_id_24dp"
android:drawablePadding="4dp"
android:visibility="gone"
app:layout_constraintTop_toBottomOf="@+id/expiry"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
tools:visibility="visible"
tools:text="1234567890"/>

</androidx.constraintlayout.widget.ConstraintLayout>
</com.google.android.material.card.MaterialCardView>
2 changes: 2 additions & 0 deletions app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -280,10 +280,12 @@
<string name="show_note">Show note</string>
<string name="show_balance">Show balance</string>
<string name="show_validity">Show validity</string>
<string name="show_card_id">Show card ID</string>
<string name="sharedpreference_card_details_show_name_below_thumbnail" translatable="false">sharedpreference_card_details_show_name_below_thumbnail</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_card_id" translatable="false">sharedpreference_card_details_show_card_id</string>
<string name="sharedpreference_card_details_show_archived_cards" translatable="false">sharedpreference_card_details_show_archived_cards</string>
<string name="settings_category_title_cards">Card view</string>
<string name="settings_category_title_cards_overview">Cards overview</string>
Expand Down
69 changes: 69 additions & 0 deletions app/src/test/java/protect/card_locker/MainActivityTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@

import androidx.appcompat.widget.SearchView;
import androidx.recyclerview.widget.RecyclerView;
import androidx.test.core.app.ApplicationProvider;

import com.google.android.material.tabs.TabLayout;
import com.google.zxing.BarcodeFormat;
Expand Down Expand Up @@ -116,6 +117,74 @@ public void addOneLoyaltyCard() {
database.close();
}

@Test
public void cardIdHiddenByDefault() {
ActivityController activityController = Robolectric.buildActivity(MainActivity.class).create();

Activity mainActivity = (Activity) activityController.get();
activityController.start();
activityController.resume();
activityController.visible();

RecyclerView list = mainActivity.findViewById(R.id.list);

SQLiteDatabase database = TestHelpers.getEmptyDb(mainActivity).getWritableDatabase();
DBHelper.insertLoyaltyCard(database, "store", "", null, null, new BigDecimal("0"), null, "1234567890", null, CatimaBarcode.fromBarcode(BarcodeFormat.UPC_A), StandardCharsets.ISO_8859_1, Color.BLACK, 0, null, 0);

activityController.pause();
activityController.resume();
activityController.visible();

assertEquals(1, list.getAdapter().getItemCount());

list.measure(0, 0);
list.layout(0, 0, 100, 1000);
Comment on lines +140 to +141

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think this is exactly necessary, it's used in the addFourLoyaltyCardsTwoStarred test because those are four cards and the RecyclerView might otherwise not show them, but I think keeping it is also not necessarily an issue. But might be good to also copy the comment from the other test ( // Make sure there is enough space to render all) over so it's clear this is to ensure the RecyclerView is given enough space


// Card ID is hidden by default
TextView cardIdField = list.findViewHolderForAdapterPosition(0).itemView.findViewById(R.id.cardId);
assertEquals(View.GONE, cardIdField.getVisibility());

database.close();
}

@Test
public void showCardIdDisplayOption() {
// The display option is read in the adapter's constructor (during onCreate), so the
// preference must be set before the activity is built.
SharedPreferences cardDetailsPref = ApplicationProvider.getApplicationContext().getSharedPreferences(
ApplicationProvider.getApplicationContext().getString(R.string.sharedpreference_card_details),
Activity.MODE_PRIVATE);
cardDetailsPref.edit().putBoolean(
ApplicationProvider.getApplicationContext().getString(R.string.sharedpreference_card_details_show_card_id), true).apply();

ActivityController activityController = Robolectric.buildActivity(MainActivity.class).create();

Activity mainActivity = (Activity) activityController.get();
activityController.start();
activityController.resume();
activityController.visible();

RecyclerView list = mainActivity.findViewById(R.id.list);

SQLiteDatabase database = TestHelpers.getEmptyDb(mainActivity).getWritableDatabase();
DBHelper.insertLoyaltyCard(database, "store", "", null, null, new BigDecimal("0"), null, "1234567890", null, CatimaBarcode.fromBarcode(BarcodeFormat.UPC_A), StandardCharsets.ISO_8859_1, Color.BLACK, 0, null, 0);

activityController.pause();
activityController.resume();
activityController.visible();

assertEquals(1, list.getAdapter().getItemCount());

list.measure(0, 0);
list.layout(0, 0, 100, 1000);
Comment on lines +178 to +179

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same here


TextView cardIdField = list.findViewHolderForAdapterPosition(0).itemView.findViewById(R.id.cardId);
assertEquals(View.VISIBLE, cardIdField.getVisibility());
assertEquals("1234567890", cardIdField.getText().toString());

database.close();
}

@Test
public void addFourLoyaltyCardsTwoStarred() // Main screen showing starred cards on top correctly
{
Expand Down