Show groups archived count (#930)

Fixes #924
This commit is contained in:
alajemba-vik
2022-07-06 21:21:59 +00:00
committed by GitHub
parent 31dc05f6b2
commit d5100b97f3
3 changed files with 32 additions and 1 deletions

View File

@@ -577,6 +577,22 @@ public class DBHelper extends SQLiteOpenHelper {
whereAttrs(LoyaltyCardDbIds.ARCHIVE_STATUS), withArgs(1));
}
public static int getArchivedCardsCount(SQLiteDatabase database, final String groupName) {
Cursor data = database.rawQuery(
"select * from " + LoyaltyCardDbIds.TABLE + " c " +
" LEFT JOIN " + LoyaltyCardDbIdsGroups.TABLE + " cg " +
" ON c." + LoyaltyCardDbIds.ID + " = cg." + LoyaltyCardDbIdsGroups.cardID +
" where " + LoyaltyCardDbIds.ARCHIVE_STATUS + " = 1" +
" AND " + LoyaltyCardDbIdsGroups.groupID + "= ?",
withArgs(groupName)
);
int count = data.getCount();
data.close();
return count;
}
public static Cursor getLoyaltyCardCursor(SQLiteDatabase database) {
// An empty string will match everything
return getLoyaltyCardCursor(database, LoyaltyCardArchiveFilter.All);

View File

@@ -1,6 +1,7 @@
package protect.card_locker;
import android.content.Context;
import android.content.res.Resources;
import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase;
import android.view.LayoutInflater;
@@ -43,8 +44,18 @@ public class GroupCursorAdapter extends BaseCursorAdapter<GroupCursorAdapter.Gro
inputHolder.mName.setText(group._id);
int groupCardCount = DBHelper.getGroupCardCount(mDatabase, group._id);
inputHolder.mCardCount.setText(mContext.getResources().getQuantityString(R.plurals.groupCardCount, groupCardCount, groupCardCount));
int archivedCardCount = DBHelper.getArchivedCardsCount(mDatabase, group._id);
Resources resources = mContext.getResources();
String cardCountText;
if (archivedCardCount > 0) {
cardCountText = resources.getQuantityString(R.plurals.groupCardCountWithArchived, groupCardCount, groupCardCount, archivedCardCount);
} else {
cardCountText = resources.getQuantityString(R.plurals.groupCardCount, groupCardCount, groupCardCount);
}
inputHolder.mCardCount.setText(cardCountText);
inputHolder.mName.setTextSize(mSettings.getFontSizeMax(mSettings.getMediumFont()));
inputHolder.mCardCount.setTextSize(mSettings.getFontSizeMax(mSettings.getSmallFont()));

View File

@@ -286,4 +286,8 @@
<string name="overflowMenu" translatable="false">Overflow menu</string>
<string name="noUnarchivedCardsMessage">No unarchived cards exist</string>
<string name="failedLaunchingPhotoPicker">Could not find a supported gallery app</string>
<plurals name="groupCardCountWithArchived">
<item quantity="one"><xliff:g>%1$d</xliff:g> card (<xliff:g id="archivedCount">%2$d</xliff:g> archived)</item>
<item quantity="other"><xliff:g>%1$d</xliff:g> cards (<xliff:g id="archivedCount">%2$d</xliff:g> archived)</item>
</plurals>
</resources>