-
-
Notifications
You must be signed in to change notification settings - Fork 156
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
base: main
Are you sure you want to change the base?
Adjust width of barcode #1109
Changes from all commits
0558280
b1ab929
1e9879a
3b509b8
674c24c
b6a5c83
edb9fb5
becfb68
74e3eec
31427f3
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -21,7 +21,7 @@ | |
public class DBHelper extends SQLiteOpenHelper { | ||
public static final String DATABASE_NAME = "Catima.db"; | ||
public static final int ORIGINAL_DATABASE_VERSION = 1; | ||
public static final int DATABASE_VERSION = 15; | ||
public static final int DATABASE_VERSION = 16; | ||
|
||
public static class LoyaltyCardDbGroups { | ||
public static final String TABLE = "groups"; | ||
|
@@ -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"; | ||
} | ||
|
||
|
@@ -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 | ||
|
@@ -310,10 +312,17 @@ public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) { | |
db.execSQL("ALTER TABLE " + LoyaltyCardDbIds.TABLE | ||
+ " ADD COLUMN " + LoyaltyCardDbIds.ZOOM_LEVEL + " INTEGER DEFAULT '100' "); | ||
} | ||
|
||
if (oldVersion < 16 && newVersion >= 16) { | ||
db.execSQL("ALTER TABLE " + LoyaltyCardDbIds.TABLE | ||
+ " ADD COLUMN " + LoyaltyCardDbIds.ZOOM_WIDTH + " INTEGER DEFAULT '100' "); | ||
} | ||
|
||
if (oldVersion < 15 && newVersion >= 15) { | ||
db.execSQL("ALTER TABLE " + LoyaltyCardDbIds.TABLE | ||
+ " ADD COLUMN " + LoyaltyCardDbIds.ARCHIVE_STATUS + " INTEGER DEFAULT '0' "); | ||
} | ||
|
||
} | ||
|
||
private static ContentValues generateFTSContentValues(final int id, final String store, final String note) { | ||
|
@@ -494,6 +503,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()); | ||
|
@@ -899,4 +926,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
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This seems completely unused. |
||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -32,12 +32,14 @@ public class LoyaltyCard implements Parcelable { | |
public final int archiveStatus; | ||
public final long lastUsed; | ||
public int zoomLevel; | ||
public int zoomWidth; | ||
|
||
// Another constructor, with zoomWidth as an extra parameter | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 archiveStatus) { | ||
final long lastUsed, final int zoomLevel, final int zoomWidth, final int archiveStatus) { | ||
this.id = id; | ||
this.store = store; | ||
this.note = note; | ||
|
@@ -51,6 +53,7 @@ public LoyaltyCard(final int id, final String store, final String note, final Da | |
this.starStatus = starStatus; | ||
this.lastUsed = lastUsed; | ||
this.zoomLevel = zoomLevel; | ||
this.zoomWidth = zoomWidth; | ||
this.archiveStatus = archiveStatus; | ||
} | ||
|
||
|
@@ -71,6 +74,7 @@ protected LoyaltyCard(Parcel in) { | |
starStatus = in.readInt(); | ||
lastUsed = in.readLong(); | ||
zoomLevel = in.readInt(); | ||
zoomWidth = in.readInt(); | ||
archiveStatus = in.readInt(); | ||
} | ||
|
||
|
@@ -89,6 +93,7 @@ public void writeToParcel(Parcel parcel, int i) { | |
parcel.writeInt(starStatus); | ||
parcel.writeLong(lastUsed); | ||
parcel.writeInt(zoomLevel); | ||
parcel.writeInt(zoomWidth); | ||
parcel.writeInt(archiveStatus); | ||
} | ||
|
||
|
@@ -103,6 +108,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); | ||
|
@@ -130,7 +136,7 @@ public static LoyaltyCard toLoyaltyCard(Cursor cursor) { | |
headerColor = cursor.getInt(headerColorColumn); | ||
} | ||
|
||
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 | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Should have the same note as above There was a problem hiding this comment. Choose a reason for hiding this commentThe 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. There was a problem hiding this comment. Choose a reason for hiding this commentThe 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) | ||
); | ||
} | ||
|
@@ -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); | ||
|
||
} | ||
} | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,7 +2,6 @@ | |
|
||
import android.content.ActivityNotFoundException; | ||
import android.content.Context; | ||
import android.content.DialogInterface; | ||
import android.content.Intent; | ||
import android.content.pm.ActivityInfo; | ||
import android.content.res.ColorStateList; | ||
|
@@ -15,7 +14,6 @@ | |
import android.graphics.drawable.Drawable; | ||
import android.os.Build; | ||
import android.os.Bundle; | ||
import android.text.Editable; | ||
import android.text.InputType; | ||
import android.text.SpannableStringBuilder; | ||
import android.text.Spanned; | ||
|
@@ -58,7 +56,6 @@ | |
import androidx.core.graphics.BlendModeCompat; | ||
import androidx.core.graphics.ColorUtils; | ||
import androidx.core.graphics.drawable.DrawableCompat; | ||
import androidx.core.view.WindowCompat; | ||
import androidx.core.view.WindowInsetsControllerCompat; | ||
import androidx.core.widget.TextViewCompat; | ||
|
||
|
@@ -123,7 +120,12 @@ public class LoyaltyCardViewActivity extends CatimaAppCompatActivity implements | |
FloatingActionButton editButton; | ||
|
||
Guideline centerGuideline; | ||
SeekBar barcodeScaler; | ||
SeekBar barcodeHeightScaler; | ||
SeekBar barcodeWidthScaler; | ||
TextView zoomHeightText; | ||
TextView zoomWidthText; | ||
LinearLayout widthScalerLayout; | ||
LinearLayout heightScalerLayout; | ||
Comment on lines
+123
to
+128
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Please be consistent in order. Now it is: |
||
|
||
Bitmap frontImageBitmap; | ||
Bitmap backImageBitmap; | ||
|
@@ -369,6 +371,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; | ||
|
@@ -388,38 +392,19 @@ protected void onCreate(Bundle savedInstanceState) { | |
} | ||
}; | ||
|
||
widthScalerLayout = binding.widthScalerLayout; | ||
heightScalerLayout = binding.heightScalerLayout; | ||
centerGuideline = binding.centerGuideline; | ||
barcodeScaler = binding.barcodeScaler; | ||
barcodeScaler.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 " + barcodeScaler.getMax()); | ||
float scale = (float) progress / (float) barcodeScaler.getMax(); | ||
Log.d(TAG, "Scaling to " + scale); | ||
barcodeHeightScaler = binding.barcodeHeightScaler; | ||
|
||
loyaltyCard.zoomLevel = progress; | ||
DBHelper.updateLoyaltyCardZoomLevel(database, loyaltyCardId, loyaltyCard.zoomLevel); | ||
SeekBarListener heightScalerListener = new SeekBarListener(barcodeHeightScaler); | ||
barcodeHeightScaler.setOnSeekBarChangeListener(heightScalerListener); | ||
|
||
setCenterGuideline(loyaltyCard.zoomLevel); | ||
|
||
drawMainImage(mainImageIndex, true, isFullscreen); | ||
} | ||
|
||
@Override | ||
public void onStartTrackingTouch(SeekBar seekBar) { | ||
|
||
} | ||
|
||
@Override | ||
public void onStopTrackingTouch(SeekBar seekBar) { | ||
|
||
} | ||
}); | ||
// set zoom width of barcode | ||
barcodeWidthScaler = binding.barcodeWidthScaler; | ||
zoomWidthText = binding.zoomWidthText; | ||
SeekBarListener widthScalerListener = new SeekBarListener(barcodeWidthScaler); | ||
Comment on lines
+395
to
+406
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Again inconsistent ordering: Width And only the width has a comment and the height doesn't There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Also the extra |
||
barcodeWidthScaler.setOnSeekBarChangeListener(widthScalerListener); | ||
|
||
rotationEnabled = true; | ||
|
||
|
@@ -758,8 +743,10 @@ public void onResume() { | |
|
||
// Also apply colours to UI elements | ||
int darkenedColor = ColorUtils.blendARGB(backgroundHeaderColor, Color.BLACK, 0.1f); | ||
barcodeScaler.setProgressTintList(ColorStateList.valueOf(darkenedColor)); | ||
barcodeScaler.setThumbTintList(ColorStateList.valueOf(darkenedColor)); | ||
barcodeHeightScaler.setProgressTintList(ColorStateList.valueOf(darkenedColor)); | ||
barcodeHeightScaler.setThumbTintList(ColorStateList.valueOf(darkenedColor)); | ||
barcodeWidthScaler.setProgressTintList(ColorStateList.valueOf(darkenedColor)); | ||
barcodeWidthScaler.setThumbTintList(ColorStateList.valueOf(darkenedColor)); | ||
Comment on lines
+746
to
+749
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. And now it's suddenly Height These inconsistencies make things really hard to maintain and prone to future bugs. |
||
maximizeButton.setBackgroundColor(darkenedColor); | ||
minimizeButton.setBackgroundColor(darkenedColor); | ||
bottomAppBar.setBackgroundColor(darkenedColor); | ||
|
@@ -1124,13 +1111,21 @@ private void setFullscreen(boolean enabled) { | |
|
||
drawMainImage(mainImageIndex, true, isFullscreen); | ||
|
||
barcodeScaler.setProgress(loyaltyCard.zoomLevel); | ||
barcodeHeightScaler.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); | ||
barcodeHeightScaler.setVisibility(View.VISIBLE); | ||
barcodeWidthScaler.setVisibility(View.VISIBLE); | ||
zoomWidthText.setText("Width"); | ||
zoomHeightText.setText("Height"); | ||
zoomWidthText.setVisibility(View.VISIBLE); | ||
zoomHeightText.setVisibility(View.VISIBLE); | ||
Comment on lines
+1114
to
+1128
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Again inconsistent ordering: Height |
||
|
||
// Hide actionbar | ||
if (actionBar != null) { | ||
|
@@ -1170,7 +1165,16 @@ private void setFullscreen(boolean enabled) { | |
maximizeButton.setVisibility(imageTypes.isEmpty() ? View.GONE : View.VISIBLE); | ||
|
||
minimizeButton.setVisibility(View.GONE); | ||
barcodeScaler.setVisibility(View.GONE); | ||
widthScalerLayout.setVisibility(View.GONE); | ||
heightScalerLayout.setVisibility(View.GONE); | ||
barcodeHeightScaler.setVisibility(View.GONE); | ||
barcodeWidthScaler.setVisibility(View.GONE); | ||
zoomWidthText.setVisibility(View.GONE); | ||
zoomHeightText.setVisibility(View.GONE); | ||
Comment on lines
+1168
to
+1173
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Again inconsistent ordering |
||
|
||
// reset displaying width after exiting maximize mode | ||
mainImage.getLayoutParams().width = mainLayout.getWidth(); | ||
mainImage.requestLayout(); | ||
|
||
// Show actionbar | ||
if (actionBar != null) { | ||
|
@@ -1198,7 +1202,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 = " + barcodeHeightScaler.getProgress() + ", Width level = " + barcodeWidthScaler.getProgress()); | ||
|
||
} | ||
|
||
@SuppressWarnings("deprecation") | ||
|
@@ -1218,4 +1223,47 @@ private void setFullscreenModeSdkLessThan30() { | |
| View.SYSTEM_UI_FLAG_FULLSCREEN | ||
); | ||
} | ||
|
||
/** | ||
* Helper class for the barcode zoom scalers. | ||
*/ | ||
public class SeekBarListener implements SeekBar.OnSeekBarChangeListener { | ||
private SeekBar seekBar; | ||
|
||
public SeekBarListener(SeekBar sb) { | ||
seekBar = sb; | ||
} | ||
|
||
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 " + seekBar.getMax()); | ||
float scale = (float) progress / (float) seekBar.getMax(); | ||
Log.d(TAG, "Scaling to " + scale); | ||
|
||
if (seekBar == barcodeHeightScaler) { | ||
loyaltyCard.zoomLevel = progress; | ||
DBHelper.updateLoyaltyCardZoomLevel(database, loyaltyCardId, loyaltyCard.zoomLevel); | ||
setCenterGuideline(loyaltyCard.zoomLevel); | ||
} else if (seekBar == barcodeWidthScaler) { | ||
loyaltyCard.zoomWidth = progress; | ||
DBHelper.updateLoyaltyCardZoomWidth(database, loyaltyCardId, loyaltyCard.zoomWidth); | ||
mainImage.getLayoutParams().width = mainLayout.getWidth() * loyaltyCard.zoomWidth / 100; | ||
mainImage.requestLayout(); | ||
} | ||
Comment on lines
+1247
to
+1256
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It seems better to me if this class gets told with a separate parameter if it's working on height and width so it doesn't break in unexpected ways if and variable name changes and so it doesn't depend on variable names outside of itself. |
||
|
||
drawMainImage(mainImageIndex, true, isFullscreen); | ||
} | ||
|
||
public void onStartTrackingTouch(SeekBar seekBar) { | ||
|
||
} | ||
|
||
public void onStopTrackingTouch(SeekBar seekBar) { | ||
|
||
} | ||
} | ||
} |
There was a problem hiding this comment.
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.There was a problem hiding this comment.
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.