Skip to content

Commit

Permalink
Show used prices if no new price is available, and search for expande…
Browse files Browse the repository at this point in the history
…d UPC-A value from UPC-E

git-svn-id: https://zxing.googlecode.com/svn/trunk@2817 59b500cc-1b3d-0410-9834-0bbf25fbcc57
  • Loading branch information
[email protected] committed Jun 15, 2013
1 parent 3b6b62b commit d539107
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -65,14 +65,17 @@ void retrieveSupplementalInfo() throws IOException {
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 {
XmlPullParser xpp = buildParser(contents);

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();
Expand All @@ -93,11 +96,21 @@ void retrieveSupplementalInfo() throws IOException {
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;
Expand All @@ -117,7 +130,11 @@ void retrieveSupplementalInfo() throws IOException {
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);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,14 +53,16 @@ public static void maybeInvokeRetrieval(TextView textView,
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) {
Expand Down

0 comments on commit d539107

Please sign in to comment.