mirror of
https://github.com/CatimaLoyalty/Android.git
synced 2026-05-02 21:23:02 -04:00
Add page number to barcode selector for PDF scan results
This commit is contained in:
@@ -3,12 +3,17 @@ package protect.card_locker;
|
||||
public class BarcodeValues {
|
||||
private final String mFormat;
|
||||
private final String mContent;
|
||||
private String mNote;
|
||||
|
||||
public BarcodeValues(String format, String content) {
|
||||
mFormat = format;
|
||||
mContent = content;
|
||||
}
|
||||
|
||||
public void setNote(String note) {
|
||||
mNote = note;
|
||||
}
|
||||
|
||||
public String format() {
|
||||
return mFormat;
|
||||
}
|
||||
@@ -17,7 +22,5 @@ public class BarcodeValues {
|
||||
return mContent;
|
||||
}
|
||||
|
||||
public boolean isEmpty() {
|
||||
return mFormat == null && mContent == null;
|
||||
}
|
||||
}
|
||||
public String note() { return mNote; }
|
||||
}
|
||||
@@ -187,7 +187,7 @@ public class Utils {
|
||||
return new ArrayList<>();
|
||||
}
|
||||
|
||||
// Loop over all pages to find a barcode
|
||||
// Loop over all pages to find barcodes
|
||||
List<BarcodeValues> barcodesFromPdfPages = new ArrayList<>();
|
||||
Bitmap renderedPage;
|
||||
for (int i = 0; i < renderer.getPageCount(); i++) {
|
||||
@@ -196,7 +196,11 @@ public class Utils {
|
||||
page.render(renderedPage, null, null, PdfRenderer.Page.RENDER_MODE_FOR_DISPLAY);
|
||||
page.close();
|
||||
|
||||
barcodesFromPdfPages.addAll(getBarcodesFromBitmap(renderedPage));
|
||||
List<BarcodeValues> barcodesFromPage = getBarcodesFromBitmap(renderedPage);
|
||||
for (BarcodeValues barcodeValues : barcodesFromPage) {
|
||||
barcodeValues.setNote(String.format(context.getString(R.string.pageWithNumber), i+1));
|
||||
barcodesFromPdfPages.add(barcodeValues);
|
||||
}
|
||||
}
|
||||
renderer.close();
|
||||
|
||||
@@ -323,12 +327,24 @@ public class Utils {
|
||||
// TODO: This should contain an image of the barcode in question to help users understand the choice they're making
|
||||
CharSequence[] barcodeDescriptions = new CharSequence[barcodeValuesList.size()];
|
||||
for (int i = 0; i < barcodeValuesList.size(); i++) {
|
||||
CatimaBarcode catimaBarcode = CatimaBarcode.fromName(barcodeValuesList.get(i).format());
|
||||
barcodeDescriptions[i] = catimaBarcode.prettyName() + ": " + barcodeValuesList.get(i).content();
|
||||
BarcodeValues barcodeValues = barcodeValuesList.get(i);
|
||||
CatimaBarcode catimaBarcode = CatimaBarcode.fromName(barcodeValues.format());
|
||||
|
||||
String barcodeContent = barcodeValues.content();
|
||||
// Shorten overly long barcodes
|
||||
if (barcodeContent.length() > 22) {
|
||||
barcodeContent = barcodeContent.substring(0, 20) + "…";
|
||||
}
|
||||
|
||||
if (barcodeValues.note() != null) {
|
||||
barcodeDescriptions[i] = String.format("%s: %s (%s)", barcodeValues.note(), catimaBarcode.prettyName(), barcodeContent);
|
||||
} else {
|
||||
barcodeDescriptions[i] = String.format("%s (%s)", catimaBarcode.prettyName(), barcodeContent);
|
||||
}
|
||||
}
|
||||
|
||||
MaterialAlertDialogBuilder builder = new MaterialAlertDialogBuilder(context);
|
||||
builder.setTitle(context.getString(R.string.multiple_barcodes_found_choose_one));
|
||||
builder.setTitle(context.getString(R.string.multipleBarcodesFoundPleaseChooseOne));
|
||||
builder.setItems(
|
||||
barcodeDescriptions,
|
||||
(dialogInterface, i) -> callback.onUserChoseBarcode(barcodeValuesList.get(i))
|
||||
|
||||
@@ -344,5 +344,6 @@
|
||||
<string name="addFromPdfFile">Select a PDF file</string>
|
||||
<string name="errorReadingFile">Could not read the file</string>
|
||||
<string name="failedLaunchingFileManager">Could not find a supported file manager</string>
|
||||
<string name="multiple_barcodes_found_choose_one">Which of the found barcodes do you want to use?</string>
|
||||
<string name="multipleBarcodesFoundPleaseChooseOne">Which of the found barcodes do you want to use?</string>
|
||||
<string name="pageWithNumber">Page <xliff:g>%d</xliff:g></string>
|
||||
</resources>
|
||||
|
||||
Reference in New Issue
Block a user