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
42 changes: 21 additions & 21 deletions app/src/main/java/protect/card_locker/LoyaltyCardViewActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -815,8 +815,7 @@ public boolean onCreateOptionsMenu(Menu menu) {

@Override
public boolean onPrepareOptionsMenu(Menu menu) {
super.onPrepareOptionsMenu(menu);

boolean result = super.onPrepareOptionsMenu(menu);
if (loyaltyCard != null) {
// Update star status
if (loyaltyCard.starStatus == 1) {
Expand All @@ -829,15 +828,21 @@ public boolean onPrepareOptionsMenu(Menu menu) {

// Update archive/unarchive button
if (loyaltyCard.archiveStatus != 0) {
menu.findItem(R.id.action_unarchive).setVisible(true);
menu.findItem(R.id.action_archive).setVisible(false);
menu.findItem(R.id.action_archive_unarchive).setTitle(R.string.archive);
menu.findItem(R.id.action_archive_unarchive).setIcon(R.drawable.ic_archive);
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
menu.findItem(R.id.action_archive_unarchive).setTooltipText(getString(R.string.archive));
}
Comment on lines +833 to +835
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.

What difference does this setTooltip call make? I'm not seeing any difference between this and the favourite button when I press or long-press it.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

It adds a small tooltip that appears when you long-press or hover over the icon (on Android 8.0+). It’s mainly for accessibility and clarity — helps users understand what the icon does. The difference is subtle, so it’s easy to miss unless you long-press for a moment.

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.

Well, that's the point I'm trying to make: the long-press behaviour is exactly the same for this and the favourite button but the favourite button doesn't have this function call (on Android 15 at least):

image image

For hover, I'm not sure how to test that, any info?

} else {
menu.findItem(R.id.action_unarchive).setVisible(false);
menu.findItem(R.id.action_archive).setVisible(true);
menu.findItem(R.id.action_archive_unarchive).setTitle(R.string.unarchive);
menu.findItem(R.id.action_archive_unarchive).setIcon(R.drawable.ic_unarchive);
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
menu.findItem(R.id.action_archive_unarchive).setTooltipText(getString(R.string.unarchive));
}
}
}

return true;
return result;
}

@Override
Expand Down Expand Up @@ -874,22 +879,17 @@ public boolean onOptionsItemSelected(MenuItem item) {
invalidateOptionsMenu();

return true;
} else if (id == R.id.action_archive) {
DBHelper.updateLoyaltyCardArchiveStatus(database, loyaltyCardId, 1);
Toast.makeText(LoyaltyCardViewActivity.this, R.string.archived, Toast.LENGTH_LONG).show();
} else if (id == R.id.action_archive_unarchive) {
DBHelper.updateLoyaltyCardArchiveStatus(database, loyaltyCardId, loyaltyCard.archiveStatus == 0 ? 1 : 0);
Toast.makeText(LoyaltyCardViewActivity.this, loyaltyCard.archiveStatus == 0 ? R.string.archived : R.string.unarchived, Toast.LENGTH_LONG).show();

ShortcutHelper.removeShortcut(LoyaltyCardViewActivity.this, loyaltyCardId);
new ListWidget().updateAll(LoyaltyCardViewActivity.this);

// Re-init loyaltyCard with new data from DB
onResume();
invalidateOptionsMenu();

return true;
} else if (id == R.id.action_unarchive) {
DBHelper.updateLoyaltyCardArchiveStatus(database, loyaltyCardId, 0);
Toast.makeText(LoyaltyCardViewActivity.this, R.string.unarchived, Toast.LENGTH_LONG).show();
// If we're archiving the card, remove any existing shortcut
// Archived cards also do not show up in the shortcut picker
if (loyaltyCard.archiveStatus == 0) {
ShortcutHelper.removeShortcut(LoyaltyCardViewActivity.this, loyaltyCardId);
}

new ListWidget().updateAll(LoyaltyCardViewActivity.this);
// Re-init loyaltyCard with new data from DB
onResume();
invalidateOptionsMenu();
Expand Down
12 changes: 12 additions & 0 deletions app/src/main/res/drawable/ic_archive.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="24dp"
android:height="24dp"
android:tint="?attr/colorControlNormal"
android:viewportWidth="24"
android:viewportHeight="24">

<path
android:fillColor="@android:color/white"
android:pathData="M20.54,5.23l-1.39,-1.68C18.88,3.21 18.47,3 18,3H6c-0.47,0 -0.88,0.21 -1.16,0.55L3.46,5.23C3.17,5.57 3,6.02 3,6.5V19c0,1.1 0.9,2 2,2h14c1.1,0 2,-0.9 2,-2V6.5c0,-0.48 -0.17,-0.93 -0.46,-1.27zM12,17.5L6.5,12H10v-2h4v2h3.5L12,17.5zM5.12,5l0.81,-1h12l0.94,1H5.12z" />

</vector>
10 changes: 0 additions & 10 deletions app/src/main/res/drawable/ic_overflow_menu.xml

This file was deleted.

5 changes: 5 additions & 0 deletions app/src/main/res/drawable/ic_unarchive.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<vector xmlns:android="http://schemas.android.com/apk/res/android" android:height="24dp" android:tint="?attr/colorControlNormal" android:viewportHeight="24" android:viewportWidth="24" android:width="24dp">

<path android:fillColor="@android:color/white" android:pathData="M20.55,5.22l-1.39,-1.68C18.88,3.21 18.47,3 18,3H6C5.53,3 5.12,3.21 4.85,3.55L3.46,5.22C3.17,5.57 3,6.01 3,6.5V19c0,1.1 0.89,2 2,2h14c1.1,0 2,-0.9 2,-2V6.5C21,6.01 20.83,5.57 20.55,5.22zM12,9.5l5.5,5.5H14v2h-4v-2H6.5L12,9.5zM5.12,5l0.82,-1h12l0.93,1H5.12z"/>

</vector>
38 changes: 12 additions & 26 deletions app/src/main/res/menu/card_view_menu.xml
Original file line number Diff line number Diff line change
Expand Up @@ -15,33 +15,19 @@
app:showAsAction="always" />

<item
android:id="@+id/action_overflow"
android:title="@string/overflowMenu"
android:icon="@drawable/ic_overflow_menu"
app:showAsAction="always">

<menu>

<item
android:id="@+id/action_duplicate"
android:title="@string/duplicateCard"
app:showAsAction="never" />

<item
android:id="@+id/action_archive"
android:title="@string/archive"
app:showAsAction="never"/>
<item
android:id="@+id/action_unarchive"
android:title="@string/unarchive"
app:showAsAction="never"/>
<item
android:id="@+id/action_delete"
android:title="@string/delete"
app:showAsAction="never"/>
android:id="@+id/action_archive_unarchive"
android:icon="@drawable/ic_archive"
android:title="@string/archive"
app:showAsAction="always"/>

</menu>
<item
android:id="@+id/action_duplicate"
android:title="@string/duplicateCard"
app:showAsAction="never" />

</item>
<item
android:id="@+id/action_delete"
android:title="@string/delete"
app:showAsAction="never"/>

</menu>
Original file line number Diff line number Diff line change
Expand Up @@ -1034,11 +1034,13 @@ public void checkMenu() throws IOException {
final Menu menu = shadowOf(activity).getOptionsMenu();
assertTrue(menu != null);

// The share, star and overflow options should be present
assertEquals(menu.size(), 3);
assertEquals(menu.size(), 5);

assertEquals("Share", menu.findItem(R.id.action_share).getTitle().toString());
assertEquals("Add to favorites", menu.findItem(R.id.action_star_unstar).getTitle().toString());
assertEquals("Unarchive", menu.findItem(R.id.action_archive_unarchive).getTitle().toString());
assertEquals("Duplicate", menu.findItem(R.id.action_duplicate).getTitle().toString());
assertEquals("Delete", menu.findItem(R.id.action_delete).getTitle().toString());

database.close();
}
Expand Down Expand Up @@ -1194,8 +1196,7 @@ public void checkPushStarIcon() {
final Menu menu = shadowOf(activity).getOptionsMenu();
assertTrue(menu != null);

// The share, star and overflow options should be present
assertEquals(menu.size(), 3);
assertEquals(menu.size(), 5);

assertEquals("Add to favorites", menu.findItem(R.id.action_star_unstar).getTitle().toString());

Expand All @@ -1207,6 +1208,16 @@ public void checkPushStarIcon() {
shadowOf(getMainLooper()).idle();
assertEquals("Add to favorites", menu.findItem(R.id.action_star_unstar).getTitle().toString());

assertEquals("Unarchive", menu.findItem(R.id.action_archive_unarchive).getTitle().toString());

shadowOf(activity).clickMenuItem(R.id.action_archive_unarchive);
shadowOf(getMainLooper()).idle();
assertEquals("Archive", menu.findItem(R.id.action_archive_unarchive).getTitle().toString());

shadowOf(activity).clickMenuItem(R.id.action_archive_unarchive);
shadowOf(getMainLooper()).idle();
assertEquals("Unarchive", menu.findItem(R.id.action_archive_unarchive).getTitle().toString());

database.close();
}

Expand Down