Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

New feature: Favorite cards #369

Open
wants to merge 25 commits into
base: master
Choose a base branch
from
Open
Changes from 1 commit
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
e545418
setting favorites possible
t351206 Jul 18, 2020
92878e5
setting favorites possible
t351206 Jul 18, 2020
d244c48
Tests adapted to changes
t351206 Jul 18, 2020
b7db633
added new database tests
t351206 Jul 19, 2020
489feae
bugfix database test updateGiftCardOnlyStar
t351206 Jul 19, 2020
afff769
fixed test bugs
t351206 Jul 19, 2020
cb49598
fixed databaseImport bug
t351206 Jul 19, 2020
87b9172
Database import bug fixed
t351206 Jul 19, 2020
5f78953
fixed Databasetest sort starred
t351206 Jul 19, 2020
a07312f
update roboelectric to 4.3.1
t351206 Jul 19, 2020
c4ef1e7
.gitignore reverted
t351206 Jul 19, 2020
d17d6c2
fixed some of the review issues
t351206 Jul 22, 2020
e39c627
exchange menu title starred <-> unstarred
t351206 Jul 22, 2020
be374a1
No import/export of StarStatus by ImportUriHelper
t351206 Jul 23, 2020
6831872
unused variable removed in ImportUriHelper
t351206 Jul 23, 2020
0591aab
string names changed for better readability
t351206 Jul 24, 2020
5fcd4c0
test added
t351206 Jul 25, 2020
007590a
test added
t351206 Jul 25, 2020
767d186
more tests added and ImportURIHelper issue fixed
t351206 Jul 27, 2020
53db564
test added for check of starring/unstarring
t351206 Jul 30, 2020
ff59a80
added german translation
t351206 Jul 30, 2020
0d77ea4
cursorAdapter and layout file changed to include star
t351206 Jul 31, 2020
e1f90bf
import of old csv file format enabled
t351206 Aug 1, 2020
47441e6
unused import removed
t351206 Aug 1, 2020
8cfa531
clipboardPatchFile
t351206 Aug 1, 2020
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
Next Next commit
setting favorites possible
t351206 committed Jul 18, 2020
commit e5454187c0aaa1332277e45b2e4d5735cd925ef9
Original file line number Diff line number Diff line change
@@ -25,7 +25,8 @@ public void exportData(DBHelper db, OutputStreamWriter output) throws IOExceptio
DBHelper.LoyaltyCardDbIds.CARD_ID,
DBHelper.LoyaltyCardDbIds.HEADER_COLOR,
DBHelper.LoyaltyCardDbIds.HEADER_TEXT_COLOR,
DBHelper.LoyaltyCardDbIds.BARCODE_TYPE);
DBHelper.LoyaltyCardDbIds.BARCODE_TYPE,
DBHelper.LoyaltyCardDbIds.STARRED);

Cursor cursor = db.getLoyaltyCardCursor();

@@ -39,7 +40,8 @@ public void exportData(DBHelper db, OutputStreamWriter output) throws IOExceptio
card.cardId,
card.headerColor,
card.headerTextColor,
card.barcodeType);
card.barcodeType,
card.starred);

if(Thread.currentThread().isInterrupted())
{
Original file line number Diff line number Diff line change
@@ -142,6 +142,11 @@ private void importLoyaltyCard(SQLiteDatabase database, DBHelper helper, CSVReco
headerTextColor = extractInt(DBHelper.LoyaltyCardDbIds.HEADER_TEXT_COLOR, record, true);
}

helper.insertLoyaltyCard(database, id, store, note, cardId, barcodeType, headerColor, headerTextColor);
Integer starred = extractInt(DBHelper.LoyaltyCardDbIds.STARRED, record, true);
if (starred == null) {
throw new FormatException("No Favorite listed, but is required");
}

helper.insertLoyaltyCard(database, id, store, note, cardId, barcodeType, headerColor, headerTextColor, starred);
}
}
32 changes: 27 additions & 5 deletions app/src/main/java/protect/card_locker/DBHelper.java
Original file line number Diff line number Diff line change
@@ -11,7 +11,7 @@ public class DBHelper extends SQLiteOpenHelper
{
public static final String DATABASE_NAME = "LoyaltyCards.db";
public static final int ORIGINAL_DATABASE_VERSION = 1;
public static final int DATABASE_VERSION = 3;
public static final int DATABASE_VERSION = 4;

static class LoyaltyCardDbIds
{
@@ -23,6 +23,7 @@ static class LoyaltyCardDbIds
public static final String HEADER_TEXT_COLOR = "headertextcolor";
public static final String CARD_ID = "cardid";
public static final String BARCODE_TYPE = "barcodetype";
public static final String STARRED = "starred";
}

public DBHelper(Context context)
@@ -41,7 +42,8 @@ public void onCreate(SQLiteDatabase db)
LoyaltyCardDbIds.HEADER_COLOR + " INTEGER," +
LoyaltyCardDbIds.HEADER_TEXT_COLOR + " INTEGER," +
LoyaltyCardDbIds.CARD_ID + " TEXT not null," +
LoyaltyCardDbIds.BARCODE_TYPE + " TEXT not null)");
LoyaltyCardDbIds.BARCODE_TYPE + " TEXT not null," +
LoyaltyCardDbIds.STARRED + " INTEGER DEFAULT '0' )");
}

@Override
@@ -62,11 +64,18 @@ public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion)
db.execSQL("ALTER TABLE " + LoyaltyCardDbIds.TABLE
+ " ADD COLUMN " + LoyaltyCardDbIds.HEADER_TEXT_COLOR + " INTEGER");
}
// Upgrade from version 3 to version 4
if(oldVersion < 4 && newVersion >= 4)
{
db.execSQL("ALTER TABLE " + LoyaltyCardDbIds.TABLE
+ " ADD COLUMN " + LoyaltyCardDbIds.STARRED + " INTEGER DEFAULT '0'");

}
}

public long insertLoyaltyCard(final String store, final String note, final String cardId,
final String barcodeType, final Integer headerColor,
final Integer headerTextColor)
final Integer headerTextColor, final Integer starred)
{
SQLiteDatabase db = getWritableDatabase();
ContentValues contentValues = new ContentValues();
@@ -76,14 +85,15 @@ public long insertLoyaltyCard(final String store, final String note, final Strin
contentValues.put(LoyaltyCardDbIds.BARCODE_TYPE, barcodeType);
contentValues.put(LoyaltyCardDbIds.HEADER_COLOR, headerColor);
contentValues.put(LoyaltyCardDbIds.HEADER_TEXT_COLOR, headerTextColor);
contentValues.put(LoyaltyCardDbIds.STARRED, starred);
final long newId = db.insert(LoyaltyCardDbIds.TABLE, null, contentValues);
return newId;
}

public boolean insertLoyaltyCard(final SQLiteDatabase db, final int id,
final String store, final String note, final String cardId,
final String barcodeType, final Integer headerColor,
final Integer headerTextColor)
final Integer headerTextColor, final Integer starred)
{
ContentValues contentValues = new ContentValues();
contentValues.put(LoyaltyCardDbIds.ID, id);
@@ -93,6 +103,7 @@ public boolean insertLoyaltyCard(final SQLiteDatabase db, final int id,
contentValues.put(LoyaltyCardDbIds.BARCODE_TYPE, barcodeType);
contentValues.put(LoyaltyCardDbIds.HEADER_COLOR, headerColor);
contentValues.put(LoyaltyCardDbIds.HEADER_TEXT_COLOR, headerTextColor);
contentValues.put(LoyaltyCardDbIds.STARRED,starred);
final long newId = db.insert(LoyaltyCardDbIds.TABLE, null, contentValues);
return (newId != -1);
}
@@ -116,6 +127,17 @@ public boolean updateLoyaltyCard(final int id, final String store, final String
return (rowsUpdated == 1);
}

public boolean updateLoyaltyCard(final int id, final Integer starred)
{
SQLiteDatabase db = getWritableDatabase();
ContentValues contentValues = new ContentValues();
contentValues.put(LoyaltyCardDbIds.STARRED,starred);
int rowsUpdated = db.update(LoyaltyCardDbIds.TABLE, contentValues,
LoyaltyCardDbIds.ID + "=?",
new String[]{Integer.toString(id)});
return (rowsUpdated == 1);
}

public LoyaltyCard getLoyaltyCard(final int id)
{
SQLiteDatabase db = getReadableDatabase();
@@ -166,7 +188,7 @@ public Cursor getLoyaltyCardCursor(final String filter)
Cursor res = db.rawQuery("select * from " + LoyaltyCardDbIds.TABLE +
" WHERE " + LoyaltyCardDbIds.STORE + " LIKE ? " +
" OR " + LoyaltyCardDbIds.NOTE + " LIKE ? " +
" ORDER BY " + LoyaltyCardDbIds.STORE + " COLLATE NOCASE ASC", selectionArgs, null);
" ORDER BY " + LoyaltyCardDbIds.STARRED + " DESC," + LoyaltyCardDbIds.STORE + " COLLATE NOCASE ASC", selectionArgs, null);
return res;
}

9 changes: 8 additions & 1 deletion app/src/main/java/protect/card_locker/ImportURIHelper.java
Original file line number Diff line number Diff line change
@@ -10,9 +10,12 @@ public class ImportURIHelper {
private static final String NOTE = DBHelper.LoyaltyCardDbIds.NOTE;
private static final String CARD_ID = DBHelper.LoyaltyCardDbIds.CARD_ID;
private static final String BARCODE_TYPE = DBHelper.LoyaltyCardDbIds.BARCODE_TYPE;
private static final String STARRED = DBHelper.LoyaltyCardDbIds.STARRED;

private static final String HEADER_COLOR = DBHelper.LoyaltyCardDbIds.HEADER_COLOR;
private static final String HEADER_TEXT_COLOR = DBHelper.LoyaltyCardDbIds.HEADER_TEXT_COLOR;


private final Context context;
private final String host;
private final String path;
@@ -38,11 +41,15 @@ public LoyaltyCard parse(Uri uri) throws InvalidObjectException {
// These values are allowed to be null
Integer headerColor = null;
Integer headerTextColor = null;
Integer starred;

String store = uri.getQueryParameter(STORE);
String note = uri.getQueryParameter(NOTE);
String cardId = uri.getQueryParameter(CARD_ID);
String barcodeType = uri.getQueryParameter(BARCODE_TYPE);
if (uri.getBooleanQueryParameter(STARRED, false) == false) starred = 0;
else starred = 1;

String unparsedHeaderColor = uri.getQueryParameter(HEADER_COLOR);
if(unparsedHeaderColor != null)
{
@@ -53,7 +60,7 @@ public LoyaltyCard parse(Uri uri) throws InvalidObjectException {
{
headerTextColor = Integer.parseInt(unparsedHeaderTextColor);
}
return new LoyaltyCard(-1, store, note, cardId, barcodeType, headerColor, headerTextColor);
return new LoyaltyCard(-1, store, note, cardId, barcodeType, headerColor, headerTextColor, starred);
} catch (NullPointerException | NumberFormatException ex) {
throw new InvalidObjectException("Not a valid import URI");
}
10 changes: 8 additions & 2 deletions app/src/main/java/protect/card_locker/LoyaltyCard.java
Original file line number Diff line number Diff line change
@@ -17,8 +17,11 @@ public class LoyaltyCard
@Nullable
public final Integer headerTextColor;

@Nullable
public final Integer starred;

public LoyaltyCard(final int id, final String store, final String note, final String cardId,
final String barcodeType, final Integer headerColor, final Integer headerTextColor)
final String barcodeType, final Integer headerColor, final Integer headerTextColor,final Integer starred)
{
this.id = id;
this.store = store;
@@ -27,6 +30,7 @@ public LoyaltyCard(final int id, final String store, final String note, final St
this.barcodeType = barcodeType;
this.headerColor = headerColor;
this.headerTextColor = headerTextColor;
this.starred = starred;
}

public static LoyaltyCard toLoyaltyCard(Cursor cursor)
@@ -36,6 +40,8 @@ public static LoyaltyCard toLoyaltyCard(Cursor cursor)
String note = cursor.getString(cursor.getColumnIndexOrThrow(DBHelper.LoyaltyCardDbIds.NOTE));
String cardId = cursor.getString(cursor.getColumnIndexOrThrow(DBHelper.LoyaltyCardDbIds.CARD_ID));
String barcodeType = cursor.getString(cursor.getColumnIndexOrThrow(DBHelper.LoyaltyCardDbIds.BARCODE_TYPE));
Integer starred = cursor.getInt(cursor.getColumnIndexOrThrow(DBHelper.LoyaltyCardDbIds.STARRED));


int headerColorColumn = cursor.getColumnIndexOrThrow(DBHelper.LoyaltyCardDbIds.HEADER_COLOR);
int headerTextColorColumn = cursor.getColumnIndexOrThrow(DBHelper.LoyaltyCardDbIds.HEADER_TEXT_COLOR);
@@ -53,6 +59,6 @@ public static LoyaltyCard toLoyaltyCard(Cursor cursor)
headerTextColor = cursor.getInt(headerTextColorColumn);
}

return new LoyaltyCard(id, store, note, cardId, barcodeType, headerColor, headerTextColor);
return new LoyaltyCard(id, store, note, cardId, barcodeType, headerColor, headerTextColor, starred);
}
}
Original file line number Diff line number Diff line change
@@ -395,13 +395,13 @@ private void doSave()
}

if(updateLoyaltyCard)
{
{ //update of "starred" not necessary, since it cannot be changed in this activity (only in ViewActivity)
db.updateLoyaltyCard(loyaltyCardId, store, note, cardId, barcodeType, headingColorValue, headingStoreTextColorValue);
Log.i(TAG, "Updated " + loyaltyCardId + " to " + cardId);
}
else
{
loyaltyCardId = (int)db.insertLoyaltyCard(store, note, cardId, barcodeType, headingColorValue, headingStoreTextColorValue);
loyaltyCardId = (int)db.insertLoyaltyCard(store, note, cardId, barcodeType, headingColorValue, headingStoreTextColorValue, 0);
}

finish();
39 changes: 39 additions & 0 deletions app/src/main/java/protect/card_locker/LoyaltyCardViewActivity.java
Original file line number Diff line number Diff line change
@@ -55,6 +55,7 @@ public class LoyaltyCardViewActivity extends AppCompatActivity
String cardIdString;
BarcodeFormat format;

boolean starred;
boolean backgroundNeedsDarkIcons;
boolean barcodeIsFullscreen = false;
ViewGroup.LayoutParams barcodeImageState;
@@ -174,6 +175,7 @@ public void onResume()
return;
}

starred = loyaltyCard.starred != 0;
String formatString = loyaltyCard.barcodeType;
format = !formatString.isEmpty() ? BarcodeFormat.valueOf(formatString) : null;
cardIdString = loyaltyCard.cardId;
@@ -302,6 +304,12 @@ public boolean onCreateOptionsMenu(Menu menu)
item.setVisible(false);
}

MenuItem starMenuItem = menu.findItem(R.id.action_star_unstar);
if (starred) {
starMenuItem.setIcon(R.drawable.ic_starred);
starMenuItem.setTitle(R.string.starred);
}

menu.findItem(R.id.action_share).setIcon(getIcon(R.drawable.ic_share_white, backgroundNeedsDarkIcons));
menu.findItem(R.id.action_edit).setIcon(getIcon(R.drawable.ic_mode_edit_white_24dp, backgroundNeedsDarkIcons));

@@ -344,11 +352,42 @@ public boolean onOptionsItemSelected(MenuItem item)
}
rotationEnabled = !rotationEnabled;
return true;

case R.id.action_star_unstar:
if (starred)
{
setStarinDB(item, loyaltyCardId, false);
}
else
{
setStarinDB(item, loyaltyCardId, true);
}
starred = !starred;
return true;
}

return super.onOptionsItemSelected(item);
}

private void setStarinDB(MenuItem item,int card_id, boolean setstarred)
{
if(setstarred)
{
item.setIcon(R.drawable.ic_starred);
item.setTitle(R.string.starred);
//only starred has to be changed in db
db.updateLoyaltyCard(card_id, 1);
}
else
{
item.setIcon(R.drawable.ic_unstarred);
item.setTitle(R.string.unstarred);
//only starred has to be changed in db
db.updateLoyaltyCard(card_id, 0);

}
}

private void setOrientatonLock(MenuItem item, boolean lock)
{
if(lock)
5 changes: 5 additions & 0 deletions app/src/main/res/drawable-xxhdpi/ic_starred.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<vector android:height="24dp" android:tint="#FFFFFF"
android:viewportHeight="24.0" android:viewportWidth="24.0"
android:width="24dp" xmlns:android="http://schemas.android.com/apk/res/android">
<path android:fillColor="#FF000000" android:pathData="M12,17.27L18.18,21l-1.64,-7.03L22,9.24l-7.19,-0.61L12,2 9.19,8.63 2,9.24l5.46,4.73L5.82,21z"/>
</vector>
5 changes: 5 additions & 0 deletions app/src/main/res/drawable-xxhdpi/ic_unstarred.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<vector android:height="24dp" android:tint="#FFFFFF"
android:viewportHeight="24.0" android:viewportWidth="24.0"
android:width="24dp" xmlns:android="http://schemas.android.com/apk/res/android">
<path android:fillColor="#FF000000" android:pathData="M22,9.24l-7.19,-0.62L12,2 9.19,8.63 2,9.24l5.46,4.73L5.82,21 12,17.27 18.18,21l-1.63,-7.03L22,9.24zM12,15.4l-3.76,2.27 1,-4.28 -3.32,-2.88 4.38,-0.38L12,6.1l1.71,4.04 4.38,0.38 -3.32,2.88 1,4.28L12,15.4z"/>
</vector>
5 changes: 5 additions & 0 deletions app/src/main/res/menu/card_view_menu.xml
Original file line number Diff line number Diff line change
@@ -17,4 +17,9 @@
android:icon="@drawable/ic_mode_edit_white_24dp"
android:title="@string/edit"
app:showAsAction="always"/>
<item
android:id="@+id/action_star_unstar"
android:icon="@drawable/ic_unstarred"
android:title="@string/unstarred"
app:showAsAction="always" />
</menu>
3 changes: 3 additions & 0 deletions app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
@@ -14,6 +14,9 @@
<string name="barcodeType">Barcode type</string>
<string name="barcodeNoBarcode">This card has no barcode</string>

<string name="starred">Add to favorites</string>
<string name="unstarred">Remove from favorites</string>

<string name="cancel">Cancel</string>
<string name="save">Save</string>
<string name="capture">Capture Card</string>