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

Adjust width of barcode #1109

Draft
wants to merge 10 commits into
base: main
Choose a base branch
from
28 changes: 28 additions & 0 deletions app/src/main/java/protect/card_locker/DBHelper.java
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ public static class LoyaltyCardDbIds {
public static final String STAR_STATUS = "starstatus";
public static final String LAST_USED = "lastused";
public static final String ZOOM_LEVEL = "zoomlevel";
public static final String ZOOM_WIDTH = "zoomwidth";
public static final String ARCHIVE_STATUS = "archive";
}

Expand Down Expand Up @@ -105,6 +106,7 @@ public void onCreate(SQLiteDatabase db) {
LoyaltyCardDbIds.STAR_STATUS + " INTEGER DEFAULT '0'," +
LoyaltyCardDbIds.LAST_USED + " INTEGER DEFAULT '0', " +
LoyaltyCardDbIds.ZOOM_LEVEL + " INTEGER DEFAULT '100', " +
LoyaltyCardDbIds.ZOOM_WIDTH + " INTEGER DEFAULT '100', " +
LoyaltyCardDbIds.ARCHIVE_STATUS + " INTEGER DEFAULT '0' )");

// create associative table for cards in groups
Expand Down Expand Up @@ -309,7 +311,10 @@ public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
if (oldVersion < 14 && newVersion >= 14) {
db.execSQL("ALTER TABLE " + LoyaltyCardDbIds.TABLE
+ " ADD COLUMN " + LoyaltyCardDbIds.ZOOM_LEVEL + " INTEGER DEFAULT '100' ");
db.execSQL("ALTER TABLE " + LoyaltyCardDbIds.TABLE
+ " ADD COLUMN " + LoyaltyCardDbIds.ZOOM_WIDTH + " INTEGER DEFAULT '100' ");
Comment on lines +317 to +318
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You need to put the change in a new if statement, right now it will only create ZOOM_WIDTH when upgrading from database version 13 to 14. Users who are already at database version 14 won't be upgraded and the app will crash when trying to access the ZOOM_WIDTH field.

You should also update DATABASE_VERSION at the top of the class.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

16 shouldn't be above 15, please keep consistent ordering.

}

if (oldVersion < 15 && newVersion >= 15) {
db.execSQL("ALTER TABLE " + LoyaltyCardDbIds.TABLE
+ " ADD COLUMN " + LoyaltyCardDbIds.ARCHIVE_STATUS + " INTEGER DEFAULT '0' ");
Expand Down Expand Up @@ -494,6 +499,24 @@ public static boolean updateLoyaltyCardZoomLevel(SQLiteDatabase database, int lo
return (rowsUpdated == 1);
}

/**
* Updates the zoom width of a card.
* @param database database where the card is located
* @param loyaltyCardId id of the card
* @param zoomWidth new zoom width of the card
* @return whether exactly 1 row was updated
*/
public static boolean updateLoyaltyCardZoomWidth(SQLiteDatabase database, int loyaltyCardId, int zoomWidth) {
ContentValues contentValues = new ContentValues();
contentValues.put(LoyaltyCardDbIds.ZOOM_WIDTH, zoomWidth);
Log.d("updateLoyaltyCardZWidth", "Card Id = " + loyaltyCardId + " Zoom width= " + zoomWidth);
int rowsUpdated = database.update(LoyaltyCardDbIds.TABLE, contentValues,
whereAttrs(LoyaltyCardDbIds.ID),
withArgs(loyaltyCardId));
Log.d("updateLoyaltyCardZWidth", "Rows changed = " + rowsUpdated);
return (rowsUpdated == 1);
}

public static boolean updateLoyaltyCardBalance(SQLiteDatabase database, final int id, final BigDecimal newBalance) {
ContentValues contentValues = new ContentValues();
contentValues.put(LoyaltyCardDbIds.BALANCE, newBalance.toString());
Expand Down Expand Up @@ -899,4 +922,9 @@ private static String getDbDirection(LoyaltyCardOrder order, LoyaltyCardOrderDir

return direction == LoyaltyCardOrderDirection.Ascending ? "ASC" : "DESC";
}

public static int getColumnCount(SQLiteDatabase db) {
Cursor cursor = db.rawQuery("SELECT * FROM " + LoyaltyCardDbIds.TABLE + ";", null, null);
return cursor.getColumnCount();
}
Comment on lines +930 to +933
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This seems completely unused.

}
2 changes: 1 addition & 1 deletion app/src/main/java/protect/card_locker/ImportURIHelper.java
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ public LoyaltyCard parse(Uri uri) throws InvalidObjectException {
headerColor = Integer.parseInt(unparsedHeaderColor);
}

return new LoyaltyCard(-1, store, note, expiry, balance, balanceType, cardId, barcodeId, barcodeType, headerColor, 0, Utils.getUnixTime(), 100,0);
return new LoyaltyCard(-1, store, note, expiry, balance, balanceType, cardId, barcodeId, barcodeType, headerColor, 0, Utils.getUnixTime(), 100, 100, 0);
} catch (NullPointerException | NumberFormatException | UnsupportedEncodingException ex) {
throw new InvalidObjectException("Not a valid import URI");
}
Expand Down
30 changes: 29 additions & 1 deletion app/src/main/java/protect/card_locker/LoyaltyCard.java
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ public class LoyaltyCard implements Parcelable {
public final int archiveStatus;
public final long lastUsed;
public int zoomLevel;
public int zoomWidth;

public LoyaltyCard(final int id, final String store, final String note, final Date expiry,
final BigDecimal balance, final Currency balanceType, final String cardId,
Expand All @@ -54,6 +55,29 @@ public LoyaltyCard(final int id, final String store, final String note, final Da
this.archiveStatus = archiveStatus;
}

// Another constructor, with zoomWidth as an extra parameter
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This comment makes no sense, this is the only constructor.

public LoyaltyCard(final int id, final String store, final String note, final Date expiry,
final BigDecimal balance, final Currency balanceType, final String cardId,
@Nullable final String barcodeId, @Nullable final CatimaBarcode barcodeType,
@Nullable final Integer headerColor, final int starStatus,
final long lastUsed, final int zoomLevel, final int zoomWidth, final int archiveStatus) {
this.id = id;
this.store = store;
this.note = note;
this.expiry = expiry;
this.balance = balance;
this.balanceType = balanceType;
this.cardId = cardId;
this.barcodeId = barcodeId;
this.barcodeType = barcodeType;
this.headerColor = headerColor;
this.starStatus = starStatus;
this.lastUsed = lastUsed;
this.zoomLevel = zoomLevel;
this.zoomWidth = zoomWidth;
this.archiveStatus = archiveStatus;
}

mn-0000 marked this conversation as resolved.
Show resolved Hide resolved
protected LoyaltyCard(Parcel in) {
id = in.readInt();
store = in.readString();
Expand All @@ -71,6 +95,7 @@ protected LoyaltyCard(Parcel in) {
starStatus = in.readInt();
lastUsed = in.readLong();
zoomLevel = in.readInt();
zoomWidth = in.readInt();
archiveStatus = in.readInt();
}

Expand All @@ -89,6 +114,7 @@ public void writeToParcel(Parcel parcel, int i) {
parcel.writeInt(starStatus);
parcel.writeLong(lastUsed);
parcel.writeInt(zoomLevel);
parcel.writeInt(zoomWidth);
parcel.writeInt(archiveStatus);
}

Expand All @@ -103,6 +129,7 @@ public static LoyaltyCard toLoyaltyCard(Cursor cursor) {
int starred = cursor.getInt(cursor.getColumnIndexOrThrow(DBHelper.LoyaltyCardDbIds.STAR_STATUS));
long lastUsed = cursor.getLong(cursor.getColumnIndexOrThrow(DBHelper.LoyaltyCardDbIds.LAST_USED));
int zoomLevel = cursor.getInt(cursor.getColumnIndexOrThrow(DBHelper.LoyaltyCardDbIds.ZOOM_LEVEL));
int zoomWidth = cursor.getInt(cursor.getColumnIndexOrThrow(DBHelper.LoyaltyCardDbIds.ZOOM_WIDTH));
int archived = cursor.getInt(cursor.getColumnIndexOrThrow(DBHelper.LoyaltyCardDbIds.ARCHIVE_STATUS));

int barcodeTypeColumn = cursor.getColumnIndexOrThrow(DBHelper.LoyaltyCardDbIds.BARCODE_TYPE);
Expand All @@ -129,8 +156,9 @@ public static LoyaltyCard toLoyaltyCard(Cursor cursor) {
if (cursor.isNull(headerColorColumn) == false) {
headerColor = cursor.getInt(headerColorColumn);
}
// return new LoyaltyCard(id, store, note, expiry, balance, balanceType, cardId, barcodeId, barcodeType, headerColor, starred, lastUsed, zoomLevel, archived);
mn-0000 marked this conversation as resolved.
Show resolved Hide resolved

return new LoyaltyCard(id, store, note, expiry, balance, balanceType, cardId, barcodeId, barcodeType, headerColor, starred, lastUsed, zoomLevel,archived);
return new LoyaltyCard(id, store, note, expiry, balance, balanceType, cardId, barcodeId, barcodeType, headerColor, starred, lastUsed, zoomLevel, zoomWidth, archived);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -215,6 +215,7 @@ private static LoyaltyCard updateTempState(LoyaltyCard loyaltyCard, LoyaltyCardF
(int) (fieldName == LoyaltyCardField.starStatus ? value : loyaltyCard.starStatus),
0, // Unimportant, always set to null in doSave so the DB updates it to the current timestamp
100, // Unimportant, not updated in doSave, defaults to 100 for new cards
100,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should have the same note as above

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These comments were actually from someone else (and they don't seem to be commenting out code, but rather just a reminder of what those values are for?), but I can remove them if you think they no longer need to be there.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The line that lacks the comment needs a comment so it's clear what the last 100 value is for.

(int) (fieldName == LoyaltyCardField.archiveStatus ? value : loyaltyCard.archiveStatus)
);
}
Expand Down Expand Up @@ -779,7 +780,7 @@ public void onResume() {
}
} else {
// New card, use default values
tempLoyaltyCard = new LoyaltyCard(-1, "", "", null, new BigDecimal("0"), null, "", null, null, null, 0, Utils.getUnixTime(), 100,0);
tempLoyaltyCard = new LoyaltyCard(-1, "", "", null, new BigDecimal("0"), null, "", null, null, null, 0, Utils.getUnixTime(), 100, 100, 0);

}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,11 @@ public class LoyaltyCardViewActivity extends CatimaAppCompatActivity implements

Guideline centerGuideline;
SeekBar barcodeScaler;
SeekBar barcodeWidthScaler;
TextView zoomHeightText;
TextView zoomWidthText;
LinearLayout widthScalerLayout;
LinearLayout heightScalerLayout;

Bitmap frontImageBitmap;
Bitmap backImageBitmap;
Expand Down Expand Up @@ -369,6 +374,8 @@ protected void onCreate(Bundle savedInstanceState) {
iconImage = binding.iconImage;
portraitToolbar = binding.toolbar;
landscapeToolbar = binding.toolbarLandscape;
zoomHeightText = binding.zoomHeightText;
zoomWidthText = binding.zoomWidthText;

bottomAppBarInfoButton = binding.buttonShowInfo;
bottomAppBarPreviousButton = binding.buttonPrevious;
Expand All @@ -388,8 +395,11 @@ protected void onCreate(Bundle savedInstanceState) {
}
};

widthScalerLayout = binding.widthScalerLayout;
heightScalerLayout = binding.heightScalerLayout;
centerGuideline = binding.centerGuideline;
barcodeScaler = binding.barcodeScaler;
zoomHeightText = binding.zoomHeightText;
barcodeScaler.setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener() {
mn-0000 marked this conversation as resolved.
Show resolved Hide resolved
@Override
public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) {
Expand Down Expand Up @@ -421,6 +431,41 @@ public void onStopTrackingTouch(SeekBar seekBar) {
}
});

// set zoom width of barcode
barcodeWidthScaler = binding.barcodeWidthScaler;
zoomWidthText = binding.zoomWidthText;
barcodeWidthScaler.setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener() {
@Override
public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) {
if (!fromUser) {
Log.d(TAG, "non user triggered onProgressChanged, ignoring, progress is " + progress);
return;
}
Log.d(TAG, "Progress is " + progress);
Log.d(TAG, "Max is " + barcodeWidthScaler.getMax());
float scale = (float) progress / (float) barcodeWidthScaler.getMax();
Log.d(TAG, "Scaling to " + scale);

loyaltyCard.zoomWidth = progress;
DBHelper.updateLoyaltyCardZoomWidth(database, loyaltyCardId, loyaltyCard.zoomWidth);

mainImage.getLayoutParams().width = mainLayout.getWidth() * loyaltyCard.zoomWidth / 100;
mainImage.requestLayout();

drawMainImage(mainImageIndex, true, isFullscreen);
}

@Override
public void onStartTrackingTouch(SeekBar seekBar) {

}

@Override
public void onStopTrackingTouch(SeekBar seekBar) {

}
});

mn-0000 marked this conversation as resolved.
Show resolved Hide resolved
rotationEnabled = true;

// Allow making barcode fullscreen on tap
Expand Down Expand Up @@ -1125,12 +1170,20 @@ private void setFullscreen(boolean enabled) {
drawMainImage(mainImageIndex, true, isFullscreen);

barcodeScaler.setProgress(loyaltyCard.zoomLevel);
barcodeWidthScaler.setProgress(loyaltyCard.zoomWidth);
setCenterGuideline(loyaltyCard.zoomLevel);

// Hide maximize and show minimize button and scaler
widthScalerLayout.setVisibility(View.VISIBLE);
heightScalerLayout.setVisibility(View.VISIBLE);
maximizeButton.setVisibility(View.GONE);
minimizeButton.setVisibility(View.VISIBLE);
barcodeScaler.setVisibility(View.VISIBLE);
barcodeWidthScaler.setVisibility(View.VISIBLE);
zoomWidthText.setText("Width");
zoomHeightText.setText("Height");
zoomWidthText.setVisibility(View.VISIBLE);
zoomHeightText.setVisibility(View.VISIBLE);

// Hide actionbar
if (actionBar != null) {
Expand Down Expand Up @@ -1170,7 +1223,16 @@ private void setFullscreen(boolean enabled) {
maximizeButton.setVisibility(imageTypes.isEmpty() ? View.GONE : View.VISIBLE);

minimizeButton.setVisibility(View.GONE);
widthScalerLayout.setVisibility(View.GONE);
heightScalerLayout.setVisibility(View.GONE);
barcodeScaler.setVisibility(View.GONE);
barcodeWidthScaler.setVisibility(View.GONE);
zoomWidthText.setVisibility(View.GONE);
zoomHeightText.setVisibility(View.GONE);

// reset displaying width after exiting maximize mode
mainImage.getLayoutParams().width = mainLayout.getWidth();
mainImage.requestLayout();

// Show actionbar
if (actionBar != null) {
Expand Down Expand Up @@ -1198,7 +1260,8 @@ private void setFullscreen(boolean enabled) {
}
}

Log.d("setFullScreen", "Is full screen enabled? " + enabled + " Zoom Level = " + barcodeScaler.getProgress());
Log.d("setFullScreen", "Is full screen enabled? " + enabled + " Zoom Level = " + barcodeScaler.getProgress() + ", Width level = " + barcodeWidthScaler.getProgress());

}

@SuppressWarnings("deprecation")
Expand Down
90 changes: 82 additions & 8 deletions app/src/main/res/layout/loyalty_card_view_layout.xml
Original file line number Diff line number Diff line change
Expand Up @@ -97,11 +97,25 @@
android:orientation="horizontal"
app:layout_constraintGuide_percent="0.5"/>

<androidx.constraintlayout.widget.Guideline
android:id="@+id/verticalGuideline"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical"
app:layout_constraintGuide_percent="0.25"/>

<androidx.constraintlayout.widget.Guideline
android:id="@+id/scalerGuideline"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="horizontal"
app:layout_constraintGuide_percent="0.8"/>

<androidx.constraintlayout.widget.Guideline
android:id="@+id/widthScalerGuideline"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="horizontal"
app:layout_constraintGuide_percent="0.75"/>

<ImageButton
Expand Down Expand Up @@ -171,20 +185,80 @@
app:layout_constraintTop_toBottomOf="@+id/minimizeButton"
tools:visibility="visible" />

<SeekBar
android:id="@+id/barcodeScaler"
<LinearLayout
android:id="@+id/widthScalerLayout"
app:layout_constraintBottom_toBottomOf="@+id/heightScalerLayout"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="@+id/widthScalerGuideline"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="@dimen/inputPadding"
android:layout_marginStart="15.0dip"
android:layout_marginEnd="15.0dip"
android:contentDescription="@string/set_scale"
android:max="100"
android:visibility="gone"
android:gravity="center"
android:orientation="horizontal" >

<TextView
android:id="@+id/zoomWidthText"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="15.0dip"
android:layout_marginEnd="4.8dip"
android:visibility="gone"
android:gravity="center|left"
/>

<SeekBar
android:id="@+id/barcodeWidthScaler"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="@dimen/inputPadding"
android:layout_marginEnd="15.0dip"
android:contentDescription="@string/set_scale"
android:max="100"
android:visibility="gone"
app:layout_constraintBottom_toBottomOf="@+id/barcodeScaler"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="@+id/verticalGuideline"
app:layout_constraintTop_toTopOf="@+id/scalerGuideline" />
mn-0000 marked this conversation as resolved.
Show resolved Hide resolved

</LinearLayout>

<LinearLayout
android:id="@+id/heightScalerLayout"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/scalerGuideline" />
app:layout_constraintTop_toBottomOf="@+id/scalerGuideline"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:visibility="gone"
android:gravity="center"
android:orientation="horizontal" >

<TextView
android:id="@+id/zoomHeightText"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="15.0dip"
android:visibility="gone"
android:gravity="center|left"
/>

<SeekBar
android:id="@+id/barcodeScaler"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="@dimen/inputPadding"
android:layout_marginEnd="15.0dip"
android:contentDescription="@string/set_scale"
android:max="100"
android:visibility="gone"
app:layout_constraintBottom_toBottomOf="@+id/barcodeScaler"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="@+id/verticalGuideline"
app:layout_constraintTop_toBottomOf="@+id/scalerGuideline" />

</LinearLayout>

<TextView
android:id="@+id/cardIdView"
Expand Down
Loading