Fix error when follow RSS product result to Google Shopper

git-svn-id: https://zxing.googlecode.com/svn/trunk@2793 59b500cc-1b3d-0410-9834-0bbf25fbcc57
This commit is contained in:
srowen@gmail.com 2013-05-14 11:24:41 +00:00
parent 556013145b
commit 061cdce0c3

View file

@ -42,8 +42,7 @@ public final class ProductResultHandler extends ResultHandler {
showGoogleShopperButton(new View.OnClickListener() {
@Override
public void onClick(View view) {
ProductParsedResult productResult = (ProductParsedResult) getResult();
openGoogleShopper(productResult.getNormalizedProductID());
openGoogleShopper(getProductIDFromResult(getResult()));
}
});
}
@ -60,15 +59,7 @@ public final class ProductResultHandler extends ResultHandler {
@Override
public void handleButtonPress(int index) {
ParsedResult rawResult = getResult();
String productID;
if (rawResult instanceof ProductParsedResult) {
productID = ((ProductParsedResult) rawResult).getNormalizedProductID();
} else if (rawResult instanceof ExpandedProductParsedResult) {
productID = ((ExpandedProductParsedResult) rawResult).getRawText();
} else {
throw new IllegalArgumentException(rawResult.getClass().toString());
}
String productID = getProductIDFromResult(getResult());
switch (index) {
case 0:
openProductSearch(productID);
@ -82,6 +73,16 @@ public final class ProductResultHandler extends ResultHandler {
}
}
private static String getProductIDFromResult(ParsedResult rawResult) {
if (rawResult instanceof ProductParsedResult) {
return ((ProductParsedResult) rawResult).getNormalizedProductID();
}
if (rawResult instanceof ExpandedProductParsedResult) {
return ((ExpandedProductParsedResult) rawResult).getRawText();
}
throw new IllegalArgumentException(rawResult.getClass().toString());
}
@Override
public int getDisplayTitle() {
return R.string.result_product;