diff --git a/android/app/src/main/java/com/dinect/checker/AbstractScannerActivity.java b/android/app/src/main/java/com/dinect/checker/AbstractScannerActivity.java index c8bf444..d8c5003 100644 --- a/android/app/src/main/java/com/dinect/checker/AbstractScannerActivity.java +++ b/android/app/src/main/java/com/dinect/checker/AbstractScannerActivity.java @@ -136,6 +136,10 @@ public abstract class AbstractScannerActivity extends AppCompatActivity { private void initManualInput() { EditText manualInput = (EditText) findViewById(R.id.manual_input); + //if (BuildConfig.applicationId == "com.dinect.develop") { + // для удобства, чтоб не вводить постоянно руками при разработке + //manualInput.setText("4620011139016317023320337"); + //} manualInput.setOnEditorActionListener(new TextView.OnEditorActionListener() { @Override diff --git a/lib/base/base_state.dart b/lib/base/base_state.dart index b1a65a7..ab05916 100644 --- a/lib/base/base_state.dart +++ b/lib/base/base_state.dart @@ -143,6 +143,25 @@ abstract class BaseState extends State { ); } + /// Метод возвращает контейнер только с названием элемента + Widget getItemTitle(String title) { + return new Container( + padding: new EdgeInsets.only( + left: verticalMargin, + right: verticalMargin, + top: 18.0 + ), + child: new Column( + children: [ + new Row( + crossAxisAlignment: CrossAxisAlignment.start, + children: getDescriptionWidget(title) + ), + ] + ) + ); + } + /// Возвращает поле ввода. /// Переопределяется для использования на экранах регистрации и проведения покупки. Widget getTextWidget() { @@ -181,6 +200,8 @@ abstract class BaseState extends State { return new Container(height: containerHeight, child: new Image.asset(Resources.getLogo(app), width: imageWidth)); } + + /// Возвращает текстовое поле, с однострочным пояснением над ним. Widget getValueWithDescription(String title, String value) { return new Container(padding: new EdgeInsets.only(left: verticalMargin, right: verticalMargin, top: 18.0), diff --git a/lib/i18n/messages_en.dart b/lib/i18n/messages_en.dart index 5868bb2..c0f1cca 100644 --- a/lib/i18n/messages_en.dart +++ b/lib/i18n/messages_en.dart @@ -41,6 +41,7 @@ class MessageLookup extends MessageLookupByLibrary { "bonus_plus" : MessageLookupByLibrary.simpleMessage("Bonus points"), "bonus_minus" : MessageLookupByLibrary.simpleMessage("Bonus was charged"), "bonus_hint" : MessageLookupByLibrary.simpleMessage("Points to charge"), + "coupons_used" : MessageLookupByLibrary.simpleMessage("Coupons were used"), "bonus_explanation" : MessageLookupByLibrary.simpleMessage("If not set, points will be added"), "scan" : MessageLookupByLibrary.simpleMessage("Scan"), "sign_up" : MessageLookupByLibrary.simpleMessage("Sign Up"), diff --git a/lib/i18n/messages_ru.dart b/lib/i18n/messages_ru.dart index 989f96c..0d7390d 100644 --- a/lib/i18n/messages_ru.dart +++ b/lib/i18n/messages_ru.dart @@ -41,6 +41,7 @@ class MessageLookup extends MessageLookupByLibrary { "bonus_plus" : MessageLookupByLibrary.simpleMessage("Бонусов начислено"), "bonus_minus" : MessageLookupByLibrary.simpleMessage("Бонусов списано"), "bonus_hint" : MessageLookupByLibrary.simpleMessage("Сколько баллов списать?"), + "coupons_used" : MessageLookupByLibrary.simpleMessage("Были погашены купоны"), "bonus_explanation" : MessageLookupByLibrary.simpleMessage("Если не указано сколько баллов списать, баллы будут начислены"), "scan" : MessageLookupByLibrary.simpleMessage("Сканировать"), "sign_up" : MessageLookupByLibrary.simpleMessage("Зарегистрироваться"), diff --git a/lib/screens/purchase.dart b/lib/screens/purchase.dart index 9181c4f..f4097da 100644 --- a/lib/screens/purchase.dart +++ b/lib/screens/purchase.dart @@ -51,6 +51,7 @@ class PurchaseScreenState extends BaseState { bool purchaseInProgress = false; Map user; String card = ''; + String flavor = ''; String loyalty = ''; String bonus = ''; bool dataLoaded = false; @@ -74,8 +75,9 @@ class PurchaseScreenState extends BaseState { widgets.add(getInputField()); // Нельзя добавить еще одно поле таким же способом - widgets.add(getBonusInputField()); - + if (this.flavor != 'autobonus') { + widgets.add(getBonusInputField()); + } widgets.add(wrapButton(getScreenMargins(36.0), getCompleteButton())); widgets.add(wrapButton( @@ -155,6 +157,8 @@ class PurchaseScreenState extends BaseState { borderRadius: new BorderRadius.all(new Radius.circular(4.0)))); } + + @override String getTitle() { return StringsLocalization.carryingPurchase(); @@ -186,11 +190,13 @@ class PurchaseScreenState extends BaseState { requestLoyalty(String url) async { bool showBonus = await platform.invokeMethod('showBonus'); + String flavor = await platform.invokeMethod('getFlavor'); if (await platform.invokeMethod('isOnline') && !this.dataLoaded) { getLoyaltyRequest(url, helper).then((response) { print(response); this.dataLoaded = true; setState(() { + this.flavor = flavor; setBonuses(JSON.decode(response.body), showBonus ); }); }).catchError((error) { @@ -258,6 +264,7 @@ class PurchaseScreenState extends BaseState { new FlatButton( child: new Text(StringsLocalization.yes()), onPressed: () { + Navigator.of(context).pop(); purchase(val); }, ) @@ -303,32 +310,21 @@ class PurchaseScreenState extends BaseState { body['bonus_payment'] = bonusController.text; } - print(body['bonus_payment']); - var purchaseResponse; Map purchase; try { purchaseResponse = await getPurchaseRequest(user['purchases_url'], body, token); purchase = JSON.decode(purchaseResponse.body); - if (purchase['errors'] is List && purchase['errors'].length > 0) { - print(purchase['errors'][0]); - //Navigator.of(context).pop(); - apiErrorAlert(purchase['errors'][0]); - } } catch(error) { purchaseInProgress = false; print(error.toString()); - } - Navigator.of(context).pop(); - if (purchase.containsKey('errors')) { List errors = purchase['errors']; - Scaffold - .of(context) - .showSnackBar(new SnackBar(content: new Text(errors[0]))); + purchaseInProgress = false; + apiErrorAlert(errors[0]); } else { var couponsResponse; diff --git a/lib/screens/purchase_success.dart b/lib/screens/purchase_success.dart index 29c6098..e40b006 100644 --- a/lib/screens/purchase_success.dart +++ b/lib/screens/purchase_success.dart @@ -64,9 +64,7 @@ class PurchaseSuccessScreenState extends BaseState { platform.invokeMethod('getFlavor').then((flavor) { setState(() { this.flavor = flavor; -// if (showBonus == true) { -// -// } + if (this.details['sum_bonus'] is String) { String regexString = r'(\d+) начислено, (\d+).*'; RegExp regExp = new RegExp(regexString); @@ -80,7 +78,6 @@ class PurchaseSuccessScreenState extends BaseState { if (this.details['sum_bonus'] is int) { this.bonusPlus = this.details['sum_bonus']; - //bonusMinus = this.details['sum_bonus']; } }); }); @@ -108,11 +105,16 @@ class PurchaseSuccessScreenState extends BaseState { } // widgetList.add( new Expanded(child: new Center())); - this.coupons.forEach((couponItem) { - widgetList.add(getCoupons(couponItem)); - }); + if (this.coupons.length > 0) { + widgetList.add(getItemTitle(StringsLocalization.couponsUsed())); + this.coupons.forEach((couponItem) { + widgetList.add(getCoupons(couponItem)); + }); + } - widgetList.add(wrapButton(getScreenMargins(74.0), getScanButton())); + + + widgetList.add(wrapButton(getScreenMargins(174.0), getScanButton())); return new ListView.builder( itemBuilder: (BuildContext context, int index) => widgetList[index], @@ -139,12 +141,16 @@ class PurchaseSuccessScreenState extends BaseState { } getCoupons(couponItem) { + String title = couponItem['offer_name']; + if (title.length == 0) { + title = couponItem['coupon_condition'].substring(0,30) + " ..."; + } return new Container( margin: new EdgeInsets.only(left: 5.0, right: 5.0, top: 5.0), child: new Card( child: new ExpansionTile( title: new Text( - couponItem['offer_name'], + title, style: Theme.of(context).textTheme.button.copyWith( fontWeight: FontWeight.bold, color: faqTitlesColor diff --git a/lib/strings.dart b/lib/strings.dart index 8555bd2..8568df5 100644 --- a/lib/strings.dart +++ b/lib/strings.dart @@ -97,6 +97,7 @@ class StringsLocalization { static String reward() => Intl.message('reward', name: 'reward', locale: Intl.defaultLocale); static String sum() => Intl.message('sum', name: 'sum', locale: Intl.defaultLocale); static String bonus() => Intl.message('bonus', name: 'bonus', locale: Intl.defaultLocale); + static String couponsUsed() => Intl.message('coupons_used', name: 'coupons_used', locale: Intl.defaultLocale); static String carryingPurchase() => Intl.message('carry_purchase', name: 'carry_purchase', locale: Intl.defaultLocale); static String completePurchase() => Intl.message('complite_purchase', name: 'complite_purchase', locale: Intl.defaultLocale); static String scan() => Intl.message('scan', name: 'scan', locale: Intl.defaultLocale);