Panagiotis Triantafyllou

minor fix

...@@ -653,34 +653,36 @@ public class CouponInfoActivity extends Activity implements View.OnClickListener ...@@ -653,34 +653,36 @@ public class CouponInfoActivity extends Activity implements View.OnClickListener
653 653
654 String tempCoupon = ""; 654 String tempCoupon = "";
655 int result = 0; 655 int result = 0;
656 - if (mCoupon.getCoupon().length() == 13) { 656 + if (mCoupon != null) {
657 - tempCoupon = mCoupon.getCoupon(); 657 + if (!TextUtils.isEmpty(mCoupon.getCoupon()) && mCoupon.getCoupon().length() == 13) {
658 + tempCoupon = mCoupon.getCoupon();
658 659
659 - try { 660 + try {
660 - for (int i = mCoupon.getCoupon().length() - 1; i >= 0; i--) { 661 + for (int i = mCoupon.getCoupon().length() - 1; i >= 0; i--) {
661 - result = result + Integer.parseInt(String.valueOf((mCoupon.getCoupon()).charAt(i))) * (1 + (2 * (i % 2))); 662 + result = result + Integer.parseInt(String.valueOf((mCoupon.getCoupon()).charAt(i))) * (1 + (2 * (i % 2)));
663 + }
664 + } catch (Exception e) {
665 + e.printStackTrace();
662 } 666 }
663 - } catch (Exception e) { 667 + } else if (!TextUtils.isEmpty(mCoupon.getCoupon()) && mCoupon.getCoupon().length() != 13) {
664 - e.printStackTrace(); 668 + try {
665 - } 669 + tempCoupon = mCoupon.getCoupon();
666 - } else { 670 + for (int i = 0; i < (12 - mCoupon.getCoupon().length()); i++) {
667 - try { 671 + tempCoupon += "0";
668 - tempCoupon = mCoupon.getCoupon(); 672 + }
669 - for (int i = 0; i < (12 - mCoupon.getCoupon().length()); i++) { 673 + } catch (Exception e) {
670 - tempCoupon += "0"; 674 + e.printStackTrace();
671 } 675 }
672 - } catch (Exception e) {
673 - e.printStackTrace();
674 - }
675 676
676 - try { 677 + try {
677 - for (int i = mCoupon.getCoupon().length() - 1; i >= 0; i--) { 678 + for (int i = mCoupon.getCoupon().length() - 1; i >= 0; i--) {
678 - result = result + Integer.parseInt(String.valueOf((mCoupon.getCoupon()).charAt(i))) * (1 + (2 * (i % 2))); 679 + result = result + Integer.parseInt(String.valueOf((mCoupon.getCoupon()).charAt(i))) * (1 + (2 * (i % 2)));
679 - } 680 + }
680 681
681 - tempCoupon = tempCoupon + (10 - (result % 10)) % 10; 682 + tempCoupon = tempCoupon + (10 - (result % 10)) % 10;
682 - } catch (Exception e) { 683 + } catch (Exception e) {
683 - e.printStackTrace(); 684 + e.printStackTrace();
685 + }
684 } 686 }
685 } 687 }
686 688
......
...@@ -160,7 +160,7 @@ public class Coupon implements Parcelable, Serializable { ...@@ -160,7 +160,7 @@ public class Coupon implements Parcelable, Serializable {
160 if (json != null) { 160 if (json != null) {
161 this.barcode = json.optString(BARCODE); 161 this.barcode = json.optString(BARCODE);
162 this.category = json.optString(CATEGORY); 162 this.category = json.optString(CATEGORY);
163 - this.coupon = json.optString(COUPON); 163 + this.coupon = json.optString(COUPON, "");
164 this.created = json.optString(CREATED); 164 this.created = json.optString(CREATED);
165 this.description = json.optString(DESCRIPTION); 165 this.description = json.optString(DESCRIPTION);
166 this.discount = json.optString(DISCOUNT); 166 this.discount = json.optString(DISCOUNT);
...@@ -214,7 +214,7 @@ public class Coupon implements Parcelable, Serializable { ...@@ -214,7 +214,7 @@ public class Coupon implements Parcelable, Serializable {
214 e.printStackTrace(); 214 e.printStackTrace();
215 } 215 }
216 } 216 }
217 - this.coupon = json.optString(COUPON); 217 + this.coupon = json.optString(COUPON, "");
218 this.couponsetUuid = json.optString(COUPONSET_UUID); 218 this.couponsetUuid = json.optString(COUPONSET_UUID);
219 this.discount = json.optString(DISCOUNT); 219 this.discount = json.optString(DISCOUNT);
220 if (this.discount.contains(",")) { 220 if (this.discount.contains(",")) {
......