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:
srowen@gmail.com 2013-06-15 13:08:17 +00:00
parent 3b6b62b06d
commit d539107e47
2 changed files with 26 additions and 7 deletions

View file

@ -65,7 +65,8 @@ final class AmazonInfoRetriever extends SupplementalInfoRetriever {
String detailPageURL = null;
Collection<String> authors = new ArrayList<String>();
String title = null;
String formattedPrice = null;
String formattedNewPrice = null;
String formattedUsedPrice = null;
boolean error = false;
try {
@ -73,6 +74,8 @@ final class AmazonInfoRetriever extends SupplementalInfoRetriever {
boolean seenItem = false;
boolean seenLowestNewPrice = false;
boolean seenLowestUsedPrice = false;
for (int eventType = xpp.getEventType(); eventType != XmlPullParser.END_DOCUMENT; eventType = xpp.next()) {
if (eventType == XmlPullParser.START_TAG) {
String name = xpp.getName();
@ -93,11 +96,21 @@ final class AmazonInfoRetriever extends SupplementalInfoRetriever {
title = xpp.getText();
} else if ("LowestNewPrice".equals(name)) {
seenLowestNewPrice = true;
seenLowestUsedPrice = false;
} else if ("LowestUsedPrice".equals(name)) {
seenLowestNewPrice = false;
seenLowestUsedPrice = true;
} else if ("FormattedPrice".equals(name)) {
if (seenLowestNewPrice) {
if (seenLowestNewPrice || seenLowestUsedPrice) {
assertTextNext(xpp);
formattedPrice = xpp.getText();
String theText = xpp.getText();
if (seenLowestNewPrice) {
formattedNewPrice = theText;
} else {
formattedUsedPrice = theText;
}
seenLowestNewPrice = false;
seenLowestUsedPrice = false;
}
} else if ("Errors".equals(name)) {
error = true;
@ -117,7 +130,11 @@ final class AmazonInfoRetriever extends SupplementalInfoRetriever {
Collection<String> newTexts = new ArrayList<String>();
maybeAddText(title, 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);
}

View file

@ -53,14 +53,16 @@ public abstract class SupplementalInfoRetriever extends AsyncTask<Object,Object,
taskExec.execute(new URIResultInfoRetriever(textView, (URIParsedResult) result, historyManager, context));
taskExec.execute(new TitleRetriever(textView, (URIParsedResult) result, historyManager));
} 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));
switch (productID.length()) {
case 12:
taskExec.execute(new AmazonInfoRetriever(textView, "UPC", productID, historyManager, context));
taskExec.execute(new AmazonInfoRetriever(textView, "UPC", normalizedProductID, historyManager, context));
break;
case 13:
taskExec.execute(new AmazonInfoRetriever(textView, "EAN", productID, historyManager, context));
taskExec.execute(new AmazonInfoRetriever(textView, "EAN", normalizedProductID, historyManager, context));
break;
}
} else if (result instanceof ISBNParsedResult) {