mirror of
https://github.com/zxing/zxing.git
synced 2025-03-05 20:48:51 -08:00
Show used prices if no new price is available, and search for expanded UPC-A value from UPC-E
git-svn-id: https://zxing.googlecode.com/svn/trunk@2817 59b500cc-1b3d-0410-9834-0bbf25fbcc57
This commit is contained in:
parent
3b6b62b06d
commit
d539107e47
|
@ -65,7 +65,8 @@ final class AmazonInfoRetriever extends SupplementalInfoRetriever {
|
||||||
String detailPageURL = null;
|
String detailPageURL = null;
|
||||||
Collection<String> authors = new ArrayList<String>();
|
Collection<String> authors = new ArrayList<String>();
|
||||||
String title = null;
|
String title = null;
|
||||||
String formattedPrice = null;
|
String formattedNewPrice = null;
|
||||||
|
String formattedUsedPrice = null;
|
||||||
boolean error = false;
|
boolean error = false;
|
||||||
|
|
||||||
try {
|
try {
|
||||||
|
@ -73,6 +74,8 @@ final class AmazonInfoRetriever extends SupplementalInfoRetriever {
|
||||||
|
|
||||||
boolean seenItem = false;
|
boolean seenItem = false;
|
||||||
boolean seenLowestNewPrice = false;
|
boolean seenLowestNewPrice = false;
|
||||||
|
boolean seenLowestUsedPrice = false;
|
||||||
|
|
||||||
for (int eventType = xpp.getEventType(); eventType != XmlPullParser.END_DOCUMENT; eventType = xpp.next()) {
|
for (int eventType = xpp.getEventType(); eventType != XmlPullParser.END_DOCUMENT; eventType = xpp.next()) {
|
||||||
if (eventType == XmlPullParser.START_TAG) {
|
if (eventType == XmlPullParser.START_TAG) {
|
||||||
String name = xpp.getName();
|
String name = xpp.getName();
|
||||||
|
@ -93,11 +96,21 @@ final class AmazonInfoRetriever extends SupplementalInfoRetriever {
|
||||||
title = xpp.getText();
|
title = xpp.getText();
|
||||||
} else if ("LowestNewPrice".equals(name)) {
|
} else if ("LowestNewPrice".equals(name)) {
|
||||||
seenLowestNewPrice = true;
|
seenLowestNewPrice = true;
|
||||||
} else if ("FormattedPrice".equals(name)) {
|
seenLowestUsedPrice = false;
|
||||||
if (seenLowestNewPrice) {
|
} else if ("LowestUsedPrice".equals(name)) {
|
||||||
assertTextNext(xpp);
|
|
||||||
formattedPrice = xpp.getText();
|
|
||||||
seenLowestNewPrice = false;
|
seenLowestNewPrice = false;
|
||||||
|
seenLowestUsedPrice = true;
|
||||||
|
} else if ("FormattedPrice".equals(name)) {
|
||||||
|
if (seenLowestNewPrice || seenLowestUsedPrice) {
|
||||||
|
assertTextNext(xpp);
|
||||||
|
String theText = xpp.getText();
|
||||||
|
if (seenLowestNewPrice) {
|
||||||
|
formattedNewPrice = theText;
|
||||||
|
} else {
|
||||||
|
formattedUsedPrice = theText;
|
||||||
|
}
|
||||||
|
seenLowestNewPrice = false;
|
||||||
|
seenLowestUsedPrice = false;
|
||||||
}
|
}
|
||||||
} else if ("Errors".equals(name)) {
|
} else if ("Errors".equals(name)) {
|
||||||
error = true;
|
error = true;
|
||||||
|
@ -117,7 +130,11 @@ final class AmazonInfoRetriever extends SupplementalInfoRetriever {
|
||||||
Collection<String> newTexts = new ArrayList<String>();
|
Collection<String> newTexts = new ArrayList<String>();
|
||||||
maybeAddText(title, newTexts);
|
maybeAddText(title, newTexts);
|
||||||
maybeAddTextSeries(authors, newTexts);
|
maybeAddTextSeries(authors, newTexts);
|
||||||
maybeAddText(formattedPrice, newTexts);
|
if (formattedNewPrice != null) {
|
||||||
|
maybeAddText(formattedNewPrice, newTexts);
|
||||||
|
} else if (formattedUsedPrice != null) {
|
||||||
|
maybeAddText(formattedUsedPrice, newTexts);
|
||||||
|
}
|
||||||
|
|
||||||
append(productID, "Amazon", newTexts.toArray(new String[newTexts.size()]), detailPageURL);
|
append(productID, "Amazon", newTexts.toArray(new String[newTexts.size()]), detailPageURL);
|
||||||
}
|
}
|
||||||
|
|
|
@ -53,14 +53,16 @@ public abstract class SupplementalInfoRetriever extends AsyncTask<Object,Object,
|
||||||
taskExec.execute(new URIResultInfoRetriever(textView, (URIParsedResult) result, historyManager, context));
|
taskExec.execute(new URIResultInfoRetriever(textView, (URIParsedResult) result, historyManager, context));
|
||||||
taskExec.execute(new TitleRetriever(textView, (URIParsedResult) result, historyManager));
|
taskExec.execute(new TitleRetriever(textView, (URIParsedResult) result, historyManager));
|
||||||
} else if (result instanceof ProductParsedResult) {
|
} else if (result instanceof ProductParsedResult) {
|
||||||
String productID = ((ProductParsedResult) result).getProductID();
|
ProductParsedResult productParsedResult = (ProductParsedResult) result;
|
||||||
|
String productID = productParsedResult.getProductID();
|
||||||
|
String normalizedProductID = productParsedResult.getNormalizedProductID();
|
||||||
taskExec.execute(new ProductResultInfoRetriever(textView, productID, historyManager, context));
|
taskExec.execute(new ProductResultInfoRetriever(textView, productID, historyManager, context));
|
||||||
switch (productID.length()) {
|
switch (productID.length()) {
|
||||||
case 12:
|
case 12:
|
||||||
taskExec.execute(new AmazonInfoRetriever(textView, "UPC", productID, historyManager, context));
|
taskExec.execute(new AmazonInfoRetriever(textView, "UPC", normalizedProductID, historyManager, context));
|
||||||
break;
|
break;
|
||||||
case 13:
|
case 13:
|
||||||
taskExec.execute(new AmazonInfoRetriever(textView, "EAN", productID, historyManager, context));
|
taskExec.execute(new AmazonInfoRetriever(textView, "EAN", normalizedProductID, historyManager, context));
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
} else if (result instanceof ISBNParsedResult) {
|
} else if (result instanceof ISBNParsedResult) {
|
||||||
|
|
Loading…
Reference in a new issue