From d66176e6287ab0ec6042f9cba3b333aad5945ca9 Mon Sep 17 00:00:00 2001 From: Sylvia van Os Date: Wed, 27 Sep 2023 17:52:44 +0200 Subject: [PATCH] Fix incorrect UI updates when toggling showing archive if all cards in group are in archive The callback used by the display options menu bypassed the card counter. This used to work fine as the visible count used to remain the same but when toggling the visibility of archived cards was added to the display menu this caused the UI to get stuck with a wrong idea of how many cards are visible. --- .../protect/card_locker/MainActivity.java | 20 +++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/app/src/main/java/protect/card_locker/MainActivity.java b/app/src/main/java/protect/card_locker/MainActivity.java index d3cd1ccb1..7609e8a04 100644 --- a/app/src/main/java/protect/card_locker/MainActivity.java +++ b/app/src/main/java/protect/card_locker/MainActivity.java @@ -70,7 +70,7 @@ public class MainActivity extends CatimaAppCompatActivity implements LoyaltyCard private View mNoGroupCardsText; private TabLayout groupsTabLayout; - private Runnable mSwapLoyaltyCardListCursor; + private Runnable mUpdateLoyaltyCardListRunnable; private ActivityResultLauncher mBarcodeScannerLauncher; private ActivityResultLauncher mSettingsLauncher; @@ -236,13 +236,8 @@ public class MainActivity extends CatimaAppCompatActivity implements LoyaltyCard mDatabase = new DBHelper(this).getWritableDatabase(); - mSwapLoyaltyCardListCursor = () -> { - Group group = null; - if (mGroup != null) { - group = (Group) mGroup; - } - - mAdapter.swapCursor(DBHelper.getLoyaltyCardCursor(mDatabase, mFilter, group, mOrder, mOrderDirection, mAdapter.showingArchivedCards() ? DBHelper.LoyaltyCardArchiveFilter.All : DBHelper.LoyaltyCardArchiveFilter.Unarchived)); + mUpdateLoyaltyCardListRunnable = () -> { + updateLoyaltyCardList(false); }; groupsTabLayout.addOnTabSelectedListener(new TabLayout.OnTabSelectedListener() { @@ -277,7 +272,7 @@ public class MainActivity extends CatimaAppCompatActivity implements LoyaltyCard mNoGroupCardsText = contentMainBinding.noGroupCardsText; mCardList = contentMainBinding.list; - mAdapter = new LoyaltyCardCursorAdapter(this, null, this, mSwapLoyaltyCardListCursor); + mAdapter = new LoyaltyCardCursorAdapter(this, null, this, mUpdateLoyaltyCardListRunnable); mCardList.setAdapter(mAdapter); registerForContextMenu(mCardList); @@ -432,7 +427,12 @@ public class MainActivity extends CatimaAppCompatActivity implements LoyaltyCard } private void updateLoyaltyCardList(boolean updateCount) { - mSwapLoyaltyCardListCursor.run(); + Group group = null; + if (mGroup != null) { + group = (Group) mGroup; + } + + mAdapter.swapCursor(DBHelper.getLoyaltyCardCursor(mDatabase, mFilter, group, mOrder, mOrderDirection, mAdapter.showingArchivedCards() ? DBHelper.LoyaltyCardArchiveFilter.All : DBHelper.LoyaltyCardArchiveFilter.Unarchived)); if (updateCount) { updateLoyaltyCardCount();