Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
61 changes: 48 additions & 13 deletions app/src/main/java/protect/card_locker/LoyaltyCardEditActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -681,16 +681,17 @@ public void onUserDismissedSelector() {

if (bitmap != null) {
if (requestedFrontImage()) {
mFrontImageRemoved = false;
mFrontImageUnsaved = true;
setCardImage(cardImageFront, Utils.resizeBitmap(bitmap, Utils.BITMAP_SIZE_BIG), true);
} else if (requestedBackImage()) {
mBackImageRemoved = false;
mBackImageUnsaved = true;
setCardImage(cardImageBack, Utils.resizeBitmap(bitmap, Utils.BITMAP_SIZE_BIG), true);
} else {
mIconRemoved = false;
mIconUnsaved = true;
setCardImage(thumbnail, Utils.resizeBitmap(bitmap, Utils.BITMAP_SIZE_SMALL), false);
thumbnail.setBackgroundColor(Color.TRANSPARENT);
setColorFromIcon();
setThumbnailImage(Utils.resizeBitmap(bitmap, Utils.BITMAP_SIZE_SMALL));
}
Log.d("cropper", "mRequestedImage: " + mRequestedImage);
mCropperFinishedType = mRequestedImage;
Expand Down Expand Up @@ -834,7 +835,7 @@ protected void onResume() {
setCardImage(cardImageBack, Utils.retrieveCardImage(this, tempLoyaltyCard.id, ImageLocationType.back), true);
}
if (!mIconUnsaved && !croppedIcon() && !mIconRemoved) {
setCardImage(thumbnail, Utils.retrieveCardImage(this, tempLoyaltyCard.id, ImageLocationType.icon), false);
setThumbnailImage(Utils.retrieveCardImage(this, tempLoyaltyCard.id, ImageLocationType.icon));
}
} else {
setTitle(R.string.addCardTitle);
Expand All @@ -847,7 +848,7 @@ protected void onResume() {
setCardImage(cardImageBack, Utils.loadTempImage(this, TEMP_UNSAVED_BACK_IMAGE_NAME), true);
}
if (mIconUnsaved && !croppedIcon()) {
setCardImage(thumbnail, Utils.loadTempImage(this, TEMP_UNSAVED_ICON_NAME), false);
setThumbnailImage(Utils.loadTempImage(this, TEMP_UNSAVED_ICON_NAME));
}
}

Expand Down Expand Up @@ -998,6 +999,22 @@ protected void setColorFromIcon() {
}
}

protected void setThumbnailImage(@Nullable Bitmap bitmap) {
setCardImage(thumbnail, bitmap, false);

if (bitmap == null) {
generateIcon(storeFieldEdit.getText().toString().trim());
} else {
thumbnail.setBackgroundColor(Color.TRANSPARENT);
setColorFromIcon();
}

if (tempLoyaltyCard.headerColor != null) {
thumbnailEditIcon.setBackgroundColor(Utils.needsDarkForeground(tempLoyaltyCard.headerColor) ? Color.BLACK : Color.WHITE);
thumbnailEditIcon.setColorFilter(Utils.needsDarkForeground(tempLoyaltyCard.headerColor) ? Color.WHITE : Color.BLACK);
}
}

protected void setCardImage(ImageView imageView, Bitmap bitmap, boolean applyFallback) {
imageView.setTag(bitmap);

Expand Down Expand Up @@ -1325,6 +1342,28 @@ public void onClick(View v) throws NoSuchElementException {
return null;
});

if (v.getId() == R.id.thumbnail) {
if (cardImageFront.getTag() instanceof Bitmap) {
cardOptions.put(getString(R.string.useFrontImage), () -> {
mIconRemoved = false;
mIconUnsaved = true;
setThumbnailImage(Utils.resizeBitmap((Bitmap) cardImageFront.getTag(), Utils.BITMAP_SIZE_SMALL));

return null;
});
}

if (cardImageBack.getTag() instanceof Bitmap) {
cardOptions.put(getString(R.string.useBackImage), () -> {
mIconRemoved = false;
mIconUnsaved = true;
setThumbnailImage(Utils.resizeBitmap((Bitmap) cardImageBack.getTag(), Utils.BITMAP_SIZE_SMALL));

return null;
});
}
}

int titleResource;

if (v.getId() == R.id.frontImageHolder) {
Expand Down Expand Up @@ -1365,17 +1404,13 @@ public void onClick(View v) throws NoSuchElementException {
// We don't need to set or check the dialogId since it's only used for that single dialog
@Override
public void onColorSelected(int dialogId, int color) {
// Save new colour
updateTempState(LoyaltyCardField.headerColor, color);

// Unset image if set
setCardImage(thumbnail, null, false);
mIconRemoved = true;
mIconUnsaved = false;

updateTempState(LoyaltyCardField.headerColor, color);

thumbnailEditIcon.setBackgroundColor(Utils.needsDarkForeground(color) ? Color.BLACK : Color.WHITE);
thumbnailEditIcon.setColorFilter(Utils.needsDarkForeground(color) ? Color.WHITE : Color.BLACK);

generateIcon(storeFieldEdit.getText().toString().trim());
setThumbnailImage(null);
}

// ColorPickerDialogListener callback
Expand Down
2 changes: 2 additions & 0 deletions app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -349,4 +349,6 @@
<string name="noCameraFoundGuideText">Your device does not seem to have a camera. If it does, try rebooting the device. Otherwise, use the "More options" button below to add a barcode another way.</string>
<string name="importCancelled">Import cancelled</string>
<string name="exportCancelled">Export cancelled</string>
<string name="useFrontImage">Use front image</string>
<string name="useBackImage">Use back image</string>
</resources>