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
Show file tree
Hide file tree
Changes from all commits
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
3 changes: 3 additions & 0 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,9 @@ dependencies {
compile "com.vanniktech:vntnumberpickerpreference:1.0.0"
testCompile 'junit:junit:4.12'
testCompile "org.robolectric:robolectric:4.0.2"



}

task findbugs(type: FindBugs, dependsOn: 'assembleDebug') {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,4 @@ public ApplicationTest()
{
super(Application.class);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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.STAR_STATUS);

Cursor cursor = db.getLoyaltyCardCursor();

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

if(Thread.currentThread().isInterrupted())
{
Expand Down
10 changes: 9 additions & 1 deletion app/src/main/java/protect/card_locker/CsvDatabaseImporter.java
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,14 @@ 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);
int starStatus = 0;
try {
starStatus = extractInt(DBHelper.LoyaltyCardDbIds.STAR_STATUS, record, false);
} catch (FormatException _ ) {
// This field did not exist in versions 0.28 and before
// We catch this exception so we can still import old backups
}
if (starStatus != 1) starStatus = 0;
helper.insertLoyaltyCard(database, id, store, note, cardId, barcodeType, headerColor, headerTextColor, starStatus);
}
}
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
Expand Up @@ -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
{
Expand All @@ -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 STAR_STATUS = "starstatus";
}

public DBHelper(Context context)
Expand All @@ -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.STAR_STATUS + " INTEGER DEFAULT '0' )");
}

@Override
Expand All @@ -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.STAR_STATUS + " 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 int starStatus)
{
SQLiteDatabase db = getWritableDatabase();
ContentValues contentValues = new ContentValues();
Expand All @@ -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.STAR_STATUS, starStatus);
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 int starStatus)
{
ContentValues contentValues = new ContentValues();
contentValues.put(LoyaltyCardDbIds.ID, id);
Expand All @@ -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.STAR_STATUS,starStatus);
final long newId = db.insert(LoyaltyCardDbIds.TABLE, null, contentValues);
return (newId != -1);
}
Expand All @@ -116,6 +127,17 @@ public boolean updateLoyaltyCard(final int id, final String store, final String
return (rowsUpdated == 1);
}

public boolean updateLoyaltyCardStarStatus(final int id, final int starStatus)
{
SQLiteDatabase db = getWritableDatabase();
ContentValues contentValues = new ContentValues();
contentValues.put(LoyaltyCardDbIds.STAR_STATUS,starStatus);
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();
Expand Down Expand Up @@ -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.STAR_STATUS + " DESC," + LoyaltyCardDbIds.STORE + " COLLATE NOCASE ASC", selectionArgs, null);
return res;
}

Expand Down
10 changes: 8 additions & 2 deletions app/src/main/java/protect/card_locker/ImportURIHelper.java
Original file line number Diff line number Diff line change
Expand Up @@ -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 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;
Expand Down Expand Up @@ -43,6 +46,8 @@ public LoyaltyCard parse(Uri uri) throws InvalidObjectException {
String note = uri.getQueryParameter(NOTE);
String cardId = uri.getQueryParameter(CARD_ID);
String barcodeType = uri.getQueryParameter(BARCODE_TYPE);
if (store == null || note == null || cardId == null || barcodeType == null) throw new InvalidObjectException("Not a valid import URI");

String unparsedHeaderColor = uri.getQueryParameter(HEADER_COLOR);
if(unparsedHeaderColor != null)
{
Expand All @@ -53,7 +58,8 @@ 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, 0);
} catch (NullPointerException | NumberFormatException ex) {
throw new InvalidObjectException("Not a valid import URI");
}
Expand All @@ -77,7 +83,7 @@ protected Uri toUri(LoyaltyCard loyaltyCard) {
{
uriBuilder.appendQueryParameter(HEADER_TEXT_COLOR, loyaltyCard.headerTextColor.toString());
}

//StarStatus will not be exported
return uriBuilder.build();
}

Expand Down
9 changes: 7 additions & 2 deletions app/src/main/java/protect/card_locker/LoyaltyCard.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,10 @@ public class LoyaltyCard
@Nullable
public final Integer headerTextColor;

public final int starStatus;

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 int starStatus)
{
this.id = id;
this.store = store;
Expand All @@ -27,6 +29,7 @@ public LoyaltyCard(final int id, final String store, final String note, final St
this.barcodeType = barcodeType;
this.headerColor = headerColor;
this.headerTextColor = headerTextColor;
this.starStatus = starStatus;
}

public static LoyaltyCard toLoyaltyCard(Cursor cursor)
Expand All @@ -36,6 +39,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));
int starred = cursor.getInt(cursor.getColumnIndexOrThrow(DBHelper.LoyaltyCardDbIds.STAR_STATUS));


int headerColorColumn = cursor.getColumnIndexOrThrow(DBHelper.LoyaltyCardDbIds.HEADER_COLOR);
int headerTextColorColumn = cursor.getColumnIndexOrThrow(DBHelper.LoyaltyCardDbIds.HEADER_TEXT_COLOR);
Expand All @@ -53,6 +58,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
Expand Up @@ -38,6 +38,7 @@ public void bindView(View view, Context context, Cursor cursor)
ImageView thumbnail = view.findViewById(R.id.thumbnail);
TextView storeField = (TextView) view.findViewById(R.id.store);
TextView noteField = (TextView) view.findViewById(R.id.note);
ImageView star = view.findViewById(R.id.star);

// Extract properties from cursor
LoyaltyCard loyaltyCard = LoyaltyCard.toLoyaltyCard(cursor);
Expand All @@ -58,6 +59,9 @@ public void bindView(View view, Context context, Cursor cursor)
noteField.setVisibility(View.GONE);
}

if (loyaltyCard.starStatus!=0) star.setVisibility(View.VISIBLE);
else star.setVisibility(View.GONE);

int tileLetterFontSize = context.getResources().getDimensionPixelSize(R.dimen.tileLetterFontSize);
int pixelSize = context.getResources().getDimensionPixelSize(R.dimen.cardThumbnailSize);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -395,13 +395,13 @@ private void doSave()
}

if(updateLoyaltyCard)
{
{ //update of "starStatus" 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();
Expand Down
26 changes: 26 additions & 0 deletions app/src/main/java/protect/card_locker/LoyaltyCardViewActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ public class LoyaltyCardViewActivity extends AppCompatActivity
String cardIdString;
BarcodeFormat format;

boolean starred;
boolean backgroundNeedsDarkIcons;
boolean barcodeIsFullscreen = false;
ViewGroup.LayoutParams barcodeImageState;
Expand Down Expand Up @@ -302,12 +303,30 @@ public boolean onCreateOptionsMenu(Menu menu)
item.setVisible(false);
}

loyaltyCard = db.getLoyaltyCard(loyaltyCardId);
starred = loyaltyCard.starStatus != 0;

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));

return super.onCreateOptionsMenu(menu);
}


@Override
public boolean onPrepareOptionsMenu(Menu menu) {
super.onPrepareOptionsMenu(menu);
if (starred) {
menu.findItem(R.id.action_star_unstar).setIcon(getIcon(R.drawable.ic_starred_white, backgroundNeedsDarkIcons));
menu.findItem(R.id.action_star_unstar).setTitle(R.string.unstar);
}
else {
menu.findItem(R.id.action_star_unstar).setIcon(getIcon(R.drawable.ic_unstarred_white, backgroundNeedsDarkIcons));
menu.findItem(R.id.action_star_unstar).setTitle(R.string.star);
}
return true;
}

@Override
public boolean onOptionsItemSelected(MenuItem item)
{
Expand Down Expand Up @@ -344,11 +363,18 @@ public boolean onOptionsItemSelected(MenuItem item)
}
rotationEnabled = !rotationEnabled;
return true;

case R.id.action_star_unstar:
starred = !starred;
db.updateLoyaltyCardStarStatus(loyaltyCardId, starred ? 1 : 0);
invalidateOptionsMenu();
return true;
t351206 marked this conversation as resolved.
Show resolved Hide resolved
}

return super.onOptionsItemSelected(item);
}


private void setOrientatonLock(MenuItem item, boolean lock)
{
if(lock)
Expand Down
Binary file added app/src/main/res/drawable-hdpi/ic_starred_white.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added app/src/main/res/drawable-mdpi/ic_starred_white.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added app/src/main/res/drawable-xhdpi/ic_starred_white.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
9 changes: 8 additions & 1 deletion app/src/main/res/layout/loyalty_card_layout.xml
Original file line number Diff line number Diff line change
Expand Up @@ -52,5 +52,12 @@
android:ellipsize="end"
android:textSize="@dimen/noteTextSize"/>
</LinearLayout>

<ImageView
android:id="@+id/star"
android:layout_width="@dimen/cardThumbnailSize"
android:layout_height="@dimen/cardThumbnailSize"
android:layout_marginLeft="@dimen/activity_margin"
android:src="@drawable/ic_starred_white"
android:tint="#000000"
android:contentDescription="@string/starImage"/>
</LinearLayout>
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
Expand Up @@ -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_white"
android:title="@string/star"
app:showAsAction="always" />
</menu>
2 changes: 2 additions & 0 deletions app/src/main/res/values-de/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@
<string name="confirm">Bestätigen</string>
<string name="lockScreen">Rotation blockieren</string>
<string name="unlockScreen">Rotation zulassen</string>
<string name="star">Zu den Favoriten hinzufügen</string>
<string name="unstar">Aus der Favoritenliste entfernen</string>
<string name="deleteTitle">Karte entfernen</string>
<string name="deleteConfirmation">Bitte bestätigen Sie, dass diese Karte gelöscht werden soll.</string>
<string name="ok">Ok</string>
Expand Down
4 changes: 4 additions & 0 deletions app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,9 @@
<string name="barcodeType">Barcode type</string>
<string name="barcodeNoBarcode">This card has no barcode</string>

<string name="star">Add to favorites</string>
<string name="unstar">Remove from favorites</string>

<string name="cancel">Cancel</string>
<string name="save">Save</string>
<string name="capture">Capture Card</string>
Expand Down Expand Up @@ -79,6 +82,7 @@
<string name="copy_to_clipboard_toast">Card ID copied to clipboard</string>

<string name="thumbnailDescription">Thumbnail for card</string>
<string name="starImage">Favorite star</string>

<string name="startIntro">Start Intro</string>
<string name="intro1Title">Welcome to Loyalty Card Keychain\n</string>
Expand Down
Loading