mirror of
https://github.com/CatimaLoyalty/Android.git
synced 2026-05-17 05:09:08 -04:00
Group together multiple barcodes of same store
This commit is contained in:
@@ -173,13 +173,36 @@ public class DBHelper extends SQLiteOpenHelper
|
||||
return res;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a cursor only containing the first loyalty card of the given store.
|
||||
*
|
||||
* @param filter
|
||||
* @return Cursor
|
||||
*/
|
||||
public Cursor getOneLoyaltyCardPerStoreCursor(final String filter)
|
||||
{
|
||||
String actualFilter = String.format("%%%s%%", filter);
|
||||
String[] selectionArgs = { actualFilter, actualFilter };
|
||||
|
||||
SQLiteDatabase db = getReadableDatabase();
|
||||
|
||||
Cursor res = db.rawQuery("select * from " + LoyaltyCardDbIds.TABLE +
|
||||
" WHERE " + LoyaltyCardDbIds.STORE + " LIKE ? " +
|
||||
" OR " + LoyaltyCardDbIds.NOTE + " LIKE ? " +
|
||||
" GROUP BY " + LoyaltyCardDbIds.STORE +
|
||||
" HAVING MIN(" + LoyaltyCardDbIds.ID + ")" +
|
||||
" ORDER BY " + LoyaltyCardDbIds.STORE + " COLLATE NOCASE ASC", selectionArgs, null);
|
||||
return res;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a list of all loyalty cards of the given store.
|
||||
*
|
||||
* @param store
|
||||
* @return List<LoyaltyCard>
|
||||
*/
|
||||
public List<LoyaltyCard> getLoyaltyCardsForStore(String store) {
|
||||
public List<LoyaltyCard> getLoyaltyCardsForStore(String store)
|
||||
{
|
||||
List<LoyaltyCard> loyaltyCards = new ArrayList<>();
|
||||
|
||||
SQLiteDatabase db = getReadableDatabase();
|
||||
|
||||
@@ -14,11 +14,13 @@ import protect.card_locker.preferences.Settings;
|
||||
class LoyaltyCardCursorAdapter extends CursorAdapter
|
||||
{
|
||||
Settings settings;
|
||||
DBHelper dbHelper;
|
||||
|
||||
public LoyaltyCardCursorAdapter(Context context, Cursor cursor)
|
||||
{
|
||||
super(context, cursor, 0);
|
||||
settings = new Settings(context);
|
||||
dbHelper = new DBHelper(context);
|
||||
}
|
||||
|
||||
// The newView method is used to inflate a new view and return it,
|
||||
@@ -42,15 +44,25 @@ class LoyaltyCardCursorAdapter extends CursorAdapter
|
||||
// Extract properties from cursor
|
||||
LoyaltyCard loyaltyCard = LoyaltyCard.toLoyaltyCard(cursor);
|
||||
|
||||
// Get amount of cards for this store
|
||||
int cardCount = dbHelper.getLoyaltyCardsForStore(loyaltyCard.store).size();
|
||||
|
||||
// Populate fields with extracted properties
|
||||
storeField.setText(loyaltyCard.store);
|
||||
|
||||
storeField.setTextSize(settings.getCardTitleListFontSize());
|
||||
|
||||
if(loyaltyCard.note.isEmpty() == false)
|
||||
if(cardCount > 1 || !loyaltyCard.note.isEmpty())
|
||||
{
|
||||
noteField.setVisibility(View.VISIBLE);
|
||||
noteField.setText(loyaltyCard.note);
|
||||
if(cardCount > 1)
|
||||
{
|
||||
noteField.setText(context.getResources().getString(R.string.cardBarcodeCount, cardCount));
|
||||
}
|
||||
else
|
||||
{
|
||||
noteField.setText(loyaltyCard.note);
|
||||
}
|
||||
noteField.setTextSize(settings.getCardNoteListFontSize());
|
||||
}
|
||||
else
|
||||
|
||||
@@ -145,7 +145,7 @@ public class MainActivity extends AppCompatActivity
|
||||
noMatchingCardsText.setVisibility(View.GONE);
|
||||
}
|
||||
|
||||
Cursor cardCursor = db.getLoyaltyCardCursor(filterText);
|
||||
Cursor cardCursor = db.getOneLoyaltyCardPerStoreCursor(filterText);
|
||||
|
||||
final LoyaltyCardCursorAdapter adapter = new LoyaltyCardCursorAdapter(this, cardCursor);
|
||||
cardList.setAdapter(adapter);
|
||||
|
||||
@@ -7,6 +7,7 @@
|
||||
|
||||
<string name="noGiftCards">You don\'t have any loyalty cards at the moment. Click the "+" (plus) button up top to get started.\n\nLoyalty Card Locker lets you carry your loyalty cards on your phone, so they are always within reach.</string>
|
||||
<string name="noMatchingGiftCards">No loyalty cards match the search filter. Please try some different terms.</string>
|
||||
<string name="cardBarcodeCount">%1$d barcodes</string>
|
||||
|
||||
<string name="storeName">Store</string>
|
||||
<string name="note">Note</string>
|
||||
|
||||
Reference in New Issue
Block a user