mirror of
https://github.com/CatimaLoyalty/Android.git
synced 2026-02-02 19:22:26 -05:00
Finish Stocard importing
This commit is contained in:
@@ -104,9 +104,6 @@ public class LoyaltyCardEditActivity extends AppCompatActivity
|
||||
ImageView cardImageFront;
|
||||
ImageView cardImageBack;
|
||||
|
||||
Bitmap frontImageBitmap;
|
||||
Bitmap backImageBitmap;
|
||||
|
||||
Button enterButton;
|
||||
|
||||
int loyaltyCardId;
|
||||
|
||||
@@ -89,6 +89,7 @@ public class LoyaltyCardViewActivity extends AppCompatActivity
|
||||
boolean starred;
|
||||
boolean backgroundNeedsDarkIcons;
|
||||
FullscreenType fullscreenType = FullscreenType.NONE;
|
||||
boolean isBarcodeSupported = true;
|
||||
|
||||
enum FullscreenType {
|
||||
NONE,
|
||||
@@ -406,7 +407,7 @@ public class LoyaltyCardViewActivity extends AppCompatActivity
|
||||
}
|
||||
expiryView.setTag(loyaltyCard.expiry);
|
||||
|
||||
if (fullscreenType != FullscreenType.NONE) {
|
||||
if (fullscreenType == FullscreenType.NONE) {
|
||||
makeBottomSheetVisibleIfUseful();
|
||||
}
|
||||
|
||||
@@ -459,8 +460,6 @@ public class LoyaltyCardViewActivity extends AppCompatActivity
|
||||
// Set shadow colour of store text so even same color on same color would be readable
|
||||
storeName.setShadowLayer(1, 1, 1, backgroundNeedsDarkIcons ? Color.BLACK : Color.WHITE);
|
||||
|
||||
Boolean isBarcodeSupported = true;
|
||||
|
||||
if (format != null && !BarcodeSelectorActivity.SUPPORTED_BARCODE_TYPES.contains(format.name())) {
|
||||
isBarcodeSupported = false;
|
||||
|
||||
@@ -682,14 +681,15 @@ public class LoyaltyCardViewActivity extends AppCompatActivity
|
||||
private void setFullscreen(FullscreenType fullscreenType)
|
||||
{
|
||||
ActionBar actionBar = getSupportActionBar();
|
||||
if (fullscreenType != FullscreenType.NONE)
|
||||
{
|
||||
Log.d(TAG, "Move into of fullscreen");
|
||||
if (fullscreenType != FullscreenType.NONE) {
|
||||
Log.d(TAG, "Move into fullscreen");
|
||||
|
||||
if (fullscreenType == FullscreenType.IMAGE_FRONT) {
|
||||
barcodeImage.setImageBitmap(frontImageBitmap);
|
||||
barcodeImage.setVisibility(View.VISIBLE);
|
||||
} else if (fullscreenType == FullscreenType.IMAGE_BACK) {
|
||||
barcodeImage.setImageBitmap(backImageBitmap);
|
||||
barcodeImage.setVisibility(View.VISIBLE);
|
||||
} else {
|
||||
// Prepare redraw after size change
|
||||
redrawBarcodeAfterResize();
|
||||
@@ -737,10 +737,16 @@ public class LoyaltyCardViewActivity extends AppCompatActivity
|
||||
barcodeScaler.setProgress(100);
|
||||
|
||||
// Prepare redraw after size change
|
||||
redrawBarcodeAfterResize();
|
||||
if (format != null && isBarcodeSupported) {
|
||||
redrawBarcodeAfterResize();
|
||||
} else {
|
||||
barcodeImage.setVisibility(View.GONE);
|
||||
}
|
||||
|
||||
// Show maximize and hide minimize button and scaler
|
||||
maximizeButton.setVisibility(View.VISIBLE);
|
||||
if (format != null && isBarcodeSupported) {
|
||||
maximizeButton.setVisibility(View.VISIBLE);
|
||||
}
|
||||
minimizeButton.setVisibility(View.GONE);
|
||||
barcodeScaler.setVisibility(View.GONE);
|
||||
|
||||
|
||||
@@ -2,6 +2,7 @@ package protect.card_locker.importexport;
|
||||
|
||||
import android.content.Context;
|
||||
import android.database.sqlite.SQLiteDatabase;
|
||||
import android.graphics.Bitmap;
|
||||
import android.graphics.BitmapFactory;
|
||||
|
||||
import com.google.zxing.BarcodeFormat;
|
||||
@@ -13,9 +14,13 @@ import org.json.JSONArray;
|
||||
import org.json.JSONException;
|
||||
import org.json.JSONObject;
|
||||
|
||||
import java.io.BufferedReader;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.io.InputStreamReader;
|
||||
import java.io.Reader;
|
||||
import java.math.BigDecimal;
|
||||
import java.nio.charset.Charset;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.text.ParseException;
|
||||
import java.util.ArrayList;
|
||||
@@ -118,14 +123,14 @@ public class StocardImporter implements Importer
|
||||
loyaltyCardHashMap,
|
||||
cardName,
|
||||
"frontImage",
|
||||
read(zipInputStream)
|
||||
readImage(zipInputStream)
|
||||
);
|
||||
} else if (fileName.endsWith("/images/back.png")) {
|
||||
loyaltyCardHashMap = appendToLoyaltyCardHashMap(
|
||||
loyaltyCardHashMap,
|
||||
cardName,
|
||||
"backImage",
|
||||
read(zipInputStream)
|
||||
readImage(zipInputStream)
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -155,12 +160,10 @@ public class StocardImporter implements Importer
|
||||
long loyaltyCardInternalId = db.insertLoyaltyCard(database, store, note, null, BigDecimal.valueOf(0), null, cardId, null, barcodeType, null, 0);
|
||||
|
||||
if (loyaltyCardData.containsKey("frontImage")) {
|
||||
byte[] byteArray = ((String) loyaltyCardData.get("frontImage")).getBytes();
|
||||
Utils.saveCardImage(context, BitmapFactory.decodeByteArray(byteArray, 0, byteArray.length), (int) loyaltyCardInternalId, true);
|
||||
Utils.saveCardImage(context, (Bitmap) loyaltyCardData.get("frontImage"), (int) loyaltyCardInternalId, true);
|
||||
}
|
||||
if (loyaltyCardData.containsKey("backImage")) {
|
||||
byte[] byteArray = ((String) loyaltyCardData.get("backImage")).getBytes();
|
||||
Utils.saveCardImage(context, BitmapFactory.decodeByteArray(byteArray, 0, byteArray.length), (int) loyaltyCardInternalId, false);
|
||||
Utils.saveCardImage(context, (Bitmap) loyaltyCardData.get("backImage"), (int) loyaltyCardInternalId, false);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -186,17 +189,19 @@ public class StocardImporter implements Importer
|
||||
}
|
||||
|
||||
private String read(ZipInputStream zipInputStream) throws IOException {
|
||||
int read;
|
||||
byte[] buffer = new byte[4096];
|
||||
|
||||
StringBuilder stringBuilder = new StringBuilder();
|
||||
while ((read = zipInputStream.read(buffer, 0, 4096)) >= 0) {
|
||||
stringBuilder.append(new String(buffer, 0, read, StandardCharsets.UTF_8));
|
||||
Reader reader = new BufferedReader(new InputStreamReader(zipInputStream, Charset.forName(StandardCharsets.UTF_8.name())));
|
||||
int c;
|
||||
while ((c = reader.read()) != -1) {
|
||||
stringBuilder.append((char) c);
|
||||
}
|
||||
|
||||
return stringBuilder.toString();
|
||||
}
|
||||
|
||||
private Bitmap readImage(ZipInputStream zipInputStream) {
|
||||
return BitmapFactory.decodeStream(zipInputStream);
|
||||
}
|
||||
|
||||
private JSONObject readJSON(ZipInputStream zipInputStream) throws IOException, JSONException {
|
||||
return new JSONObject(read(zipInputStream));
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user