списание бонусов при покупке(часть)
This commit is contained in:
@@ -61,279 +61,278 @@ import okhttp3.ResponseBody;
|
||||
|
||||
public abstract class AbstractScannerActivity extends AppCompatActivity {
|
||||
|
||||
private final static String TAG = "Checker.ScannerActivity";
|
||||
private final static String TAG = "Checker.ScannerActivity";
|
||||
|
||||
private int counter;
|
||||
private int counter;
|
||||
|
||||
public static final String SCAN_MODES = "SCAN_MODES";
|
||||
public static final String ERROR_INFO = "ERROR_INFO";
|
||||
public static final String SCAN_MODES = "SCAN_MODES";
|
||||
public static final String ERROR_INFO = "ERROR_INFO";
|
||||
|
||||
protected LogoutDialogFragment logoutDialog;
|
||||
private ApiClient mClient;
|
||||
protected LogoutDialogFragment logoutDialog;
|
||||
private ApiClient mClient;
|
||||
|
||||
boolean isCameraAvailable() {
|
||||
Log.d(TAG, "isCameraAvailable");
|
||||
PackageManager pm = getPackageManager();
|
||||
return pm.hasSystemFeature(PackageManager.FEATURE_CAMERA);
|
||||
boolean isCameraAvailable() {
|
||||
Log.d(TAG, "isCameraAvailable");
|
||||
PackageManager pm = getPackageManager();
|
||||
return pm.hasSystemFeature(PackageManager.FEATURE_CAMERA);
|
||||
}
|
||||
|
||||
void cancelRequest(final @NonNull String message) {
|
||||
Log.d(TAG, "cancelRequest: " + message);
|
||||
final Intent response = new Intent();
|
||||
response.putExtra(ERROR_INFO, message);
|
||||
setResult(RESULT_CANCELED, response);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onCreate(@Nullable Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
final String appToken = getIntent().getStringExtra(MainActivity.PREF_APP_TOKEN);
|
||||
final String token = getIntent().getStringExtra(MainActivity.PREF_POS_TOKEN);
|
||||
final String url = getIntent().getStringExtra(MainActivity.PREF_API_URL) + "/users/";
|
||||
mClient = new ApiClient(url, appToken, token);
|
||||
}
|
||||
|
||||
/**
|
||||
* initialize activity
|
||||
* - removes windows title
|
||||
* - set content view to layout id
|
||||
*
|
||||
* @param layoutID layout to use
|
||||
*/
|
||||
protected final boolean init(final int layoutID) {
|
||||
Log.d(TAG, "init");
|
||||
if (!isCameraAvailable()) {
|
||||
// Cancel request if there is no rear-facing camera.
|
||||
cancelRequest("Camera unavailable");
|
||||
return false;
|
||||
}
|
||||
// Hide the window title.
|
||||
requestWindowFeature(Window.FEATURE_NO_TITLE);
|
||||
setContentView(layoutID);
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Configure toolbar of app
|
||||
*/
|
||||
protected final void initToolbar(Intent intent) {
|
||||
|
||||
final Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
|
||||
toolbar.setBackgroundColor((int) intent.getLongExtra(MainActivity.PREF_APP_BAR_COLOR, 0xffffff));
|
||||
setSupportActionBar(toolbar);
|
||||
|
||||
final ActionBar actionBar = getSupportActionBar();
|
||||
|
||||
if (actionBar != null) {
|
||||
actionBar.setTitle(null);
|
||||
actionBar.setDisplayHomeAsUpEnabled(false);
|
||||
}
|
||||
|
||||
void cancelRequest(final @NonNull String message) {
|
||||
Log.d(TAG, "cancelRequest: " + message);
|
||||
final Intent response = new Intent();
|
||||
response.putExtra(ERROR_INFO, message);
|
||||
setResult(RESULT_CANCELED, response);
|
||||
}
|
||||
initManualInput();
|
||||
setupSecretClickHandler(toolbar);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onCreate(@Nullable Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
final String appToken = getIntent().getStringExtra(MainActivity.PREF_APP_TOKEN);
|
||||
final String token = getIntent().getStringExtra(MainActivity.PREF_POS_TOKEN);
|
||||
final String url = getIntent().getStringExtra(MainActivity.PREF_API_URL) + "/users/";
|
||||
mClient = new ApiClient(url, appToken, token);
|
||||
}
|
||||
private void initManualInput() {
|
||||
EditText manualInput = (EditText) findViewById(R.id.manual_input);
|
||||
|
||||
/**
|
||||
* initialize activity
|
||||
* - removes windows title
|
||||
* - set content view to layout id
|
||||
*
|
||||
* @param layoutID layout to use
|
||||
*/
|
||||
protected final boolean init(final int layoutID) {
|
||||
Log.d(TAG, "init");
|
||||
if (!isCameraAvailable()) {
|
||||
// Cancel request if there is no rear-facing camera.
|
||||
cancelRequest("Camera unavailable");
|
||||
return false;
|
||||
|
||||
manualInput.setOnEditorActionListener(new TextView.OnEditorActionListener() {
|
||||
@Override
|
||||
public boolean onEditorAction(TextView v, int actionId, KeyEvent event) {
|
||||
handleBarcode(v.getText().toString());
|
||||
return false;
|
||||
}
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
private void setupSecretClickHandler(final @NonNull View toolbar) {
|
||||
// Configure increment handler
|
||||
toolbar.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View view) {
|
||||
if (counter == 15) {
|
||||
switchScanner();
|
||||
} else {
|
||||
counter++;
|
||||
}
|
||||
// Hide the window title.
|
||||
requestWindowFeature(Window.FEATURE_NO_TITLE);
|
||||
setContentView(layoutID);
|
||||
return true;
|
||||
}
|
||||
Log.d(TAG, "toolbar clicked " + counter + " times");
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Configure toolbar of app
|
||||
*/
|
||||
protected final void initToolbar(Intent intent) {
|
||||
private void switchScanner() {
|
||||
|
||||
final Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
|
||||
toolbar.setBackgroundColor((int) intent.getLongExtra(MainActivity.PREF_APP_BAR_COLOR, 0xffffff));
|
||||
setSupportActionBar(toolbar);
|
||||
final SharedPreferences prefs = getSharedPreferences("scanner", Context.MODE_PRIVATE);
|
||||
|
||||
final ActionBar actionBar = getSupportActionBar();
|
||||
int idx = (prefs.getInt(MainActivity.SCANNER_BACKEND_KEY, 0) == MainActivity.ZXING)
|
||||
? MainActivity.ZBAR
|
||||
: MainActivity.ZXING;
|
||||
|
||||
if (actionBar != null) {
|
||||
actionBar.setTitle(null);
|
||||
actionBar.setDisplayHomeAsUpEnabled(false);
|
||||
}
|
||||
Log.d(TAG, "switch to scanner backend " + idx + ", " + MainActivity.SCANNER_BACKEND[idx].toString());
|
||||
prefs.edit().putInt(MainActivity.SCANNER_BACKEND_KEY, idx).apply();
|
||||
|
||||
initManualInput();
|
||||
setupSecretClickHandler(toolbar);
|
||||
}
|
||||
|
||||
private void initManualInput() {
|
||||
EditText manualInput = (EditText) findViewById(R.id.manual_input);
|
||||
cancelRequest("Scanner backend changed");
|
||||
setResult(RESULT_OK);
|
||||
finish();
|
||||
}
|
||||
|
||||
|
||||
manualInput.setOnEditorActionListener(new TextView.OnEditorActionListener() {
|
||||
@Override
|
||||
public boolean onEditorAction(TextView v, int actionId, KeyEvent event) {
|
||||
handleBarcode(v.getText().toString());
|
||||
return false;
|
||||
}
|
||||
});
|
||||
/**
|
||||
* Adds scanner view to target frame layout
|
||||
*/
|
||||
protected final void addScanner(final @NonNull View view, final int targetFrameId) {
|
||||
Log.d(TAG, "addScanner");
|
||||
final FrameLayout root = (FrameLayout) findViewById(targetFrameId);
|
||||
root.addView(view, 0);
|
||||
}
|
||||
|
||||
}
|
||||
protected abstract View initScanner();
|
||||
|
||||
private void setupSecretClickHandler(final @NonNull View toolbar) {
|
||||
// Configure increment handler
|
||||
toolbar.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View view) {
|
||||
if (counter == 15) {
|
||||
switchScanner();
|
||||
public void handleBarcode(final @NonNull String card) {
|
||||
mClient.findUser(card, new Callback() {
|
||||
@Override
|
||||
public void onFailure(Call call, IOException e) {
|
||||
handleFail(card);
|
||||
}
|
||||
@Override
|
||||
public void onResponse(Call call, Response response) throws IOException {
|
||||
try {
|
||||
ResponseBody body = response.body();
|
||||
if (body != null) {
|
||||
switch (response.code()) {
|
||||
case 200:
|
||||
final JSONArray users = new JSONArray(body.string());
|
||||
if (users.length() > 0) {
|
||||
handleSuccess(card, users.get(0).toString());
|
||||
} else {
|
||||
counter++;
|
||||
handleFail(card);
|
||||
}
|
||||
Log.d(TAG, "toolbar clicked " + counter + " times");
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
private void switchScanner() {
|
||||
|
||||
final SharedPreferences prefs = getSharedPreferences("scanner", Context.MODE_PRIVATE);
|
||||
|
||||
int idx = (prefs.getInt(MainActivity.SCANNER_BACKEND_KEY, 0) == MainActivity.ZXING)
|
||||
? MainActivity.ZBAR
|
||||
: MainActivity.ZXING;
|
||||
|
||||
Log.d(TAG, "switch to scanner backend " + idx + ", " + MainActivity.SCANNER_BACKEND[idx].toString());
|
||||
prefs.edit().putInt(MainActivity.SCANNER_BACKEND_KEY, idx).apply();
|
||||
|
||||
cancelRequest("Scanner backend changed");
|
||||
setResult(RESULT_OK);
|
||||
finish();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Adds scanner view to target frame layout
|
||||
*/
|
||||
protected final void addScanner(final @NonNull View view, final int targetFrameId) {
|
||||
Log.d(TAG, "addScanner");
|
||||
final FrameLayout root = (FrameLayout) findViewById(targetFrameId);
|
||||
root.addView(view, 0);
|
||||
}
|
||||
|
||||
protected abstract View initScanner();
|
||||
|
||||
public void handleBarcode(final @NonNull String card) {
|
||||
mClient.findUser(card, new Callback() {
|
||||
@Override
|
||||
public void onFailure(Call call, IOException e) {
|
||||
break;
|
||||
case 204:
|
||||
handleFail(card);
|
||||
break;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onResponse(Call call, Response response) throws IOException {
|
||||
try {
|
||||
ResponseBody body = response.body();
|
||||
if (body != null) {
|
||||
switch (response.code()) {
|
||||
case 200:
|
||||
final JSONArray users = new JSONArray(body.string());
|
||||
if (users.length() > 0) {
|
||||
handleSuccess(card, users.get(0).toString());
|
||||
} else {
|
||||
handleFail(card);
|
||||
}
|
||||
break;
|
||||
case 204:
|
||||
handleFail(card);
|
||||
break;
|
||||
}
|
||||
}
|
||||
} catch (final IOException | JSONException e) {
|
||||
Log.e(TAG, e.getMessage(), e);
|
||||
handleFail(card);
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
protected final void handleSuccess(final String card, final String user) {
|
||||
runOnUiThread(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
setResult(RESULT_OK, new Intent().putExtra("user", user).putExtra("card", card));
|
||||
finish();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
protected final void handleFail(final String card) {
|
||||
runOnUiThread(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
String message = String.format(getString(R.string.identifier_not_found), card)
|
||||
+ ".\n"
|
||||
+ String.format(getString(R.string.error_contact_support), BuildConfig.supportPhone);
|
||||
Toast.makeText(AbstractScannerActivity.this, message, Toast.LENGTH_SHORT).show();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onCreateOptionsMenu(Menu menu) {
|
||||
getMenuInflater().inflate(R.menu.menu, menu);
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onPrepareOptionsMenu(Menu menu) {
|
||||
menu.findItem(R.id.settings).setIcon(getResources().getDrawable(R.drawable.settings));
|
||||
menu.findItem(R.id.faq).setIcon(getResources().getDrawable(R.drawable.help));
|
||||
menu.findItem(R.id.logout).setIcon(getResources().getDrawable(R.drawable.logout));
|
||||
return super.onPrepareOptionsMenu(menu);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onOptionsItemSelected(MenuItem item) {
|
||||
if (item.getItemId() == R.id.settings) {
|
||||
final Intent intent = new Intent();
|
||||
intent.putExtra("item", "settings");
|
||||
setResult(RESULT_OK, intent);
|
||||
finish();
|
||||
return true;
|
||||
} else if (item.getItemId() == R.id.logout) {
|
||||
int color = (int) getIntent().getLongExtra(MainActivity.PREF_APP_BAR_COLOR, 0xffffff);
|
||||
logoutDialog = LogoutDialogFragment.newInstance(color);
|
||||
logoutDialog.show(getFragmentManager(), "logout");
|
||||
return true;
|
||||
} else if (item.getItemId() == R.id.faq) {
|
||||
final Intent intent = new Intent();
|
||||
intent.putExtra("item", "faq");
|
||||
setResult(RESULT_OK, intent);
|
||||
finish();
|
||||
return true;
|
||||
}
|
||||
} catch (final IOException | JSONException e) {
|
||||
Log.e(TAG, e.getMessage(), e);
|
||||
handleFail(card);
|
||||
}
|
||||
return super.onOptionsItemSelected(item);
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
void dismissDialog() {
|
||||
if (logoutDialog != null) {
|
||||
logoutDialog.dismiss();
|
||||
logoutDialog = null;
|
||||
}
|
||||
}
|
||||
|
||||
void logout() {
|
||||
final Intent intent = new Intent();
|
||||
intent.putExtra("item", "logout");
|
||||
setResult(RESULT_OK, intent);
|
||||
protected final void handleSuccess(final String card, final String user) {
|
||||
runOnUiThread(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
setResult(RESULT_OK, new Intent().putExtra("user", user).putExtra("card", card));
|
||||
finish();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
protected final void handleFail(final String card) {
|
||||
runOnUiThread(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
String message = String.format(getString(R.string.identifier_not_found), card)
|
||||
+ ".\n"
|
||||
+ String.format(getString(R.string.error_contact_support), BuildConfig.supportPhone);
|
||||
Toast.makeText(AbstractScannerActivity.this, message, Toast.LENGTH_SHORT).show();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onCreateOptionsMenu(Menu menu) {
|
||||
getMenuInflater().inflate(R.menu.menu, menu);
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onPrepareOptionsMenu(Menu menu) {
|
||||
menu.findItem(R.id.settings).setIcon(getResources().getDrawable(R.drawable.settings));
|
||||
menu.findItem(R.id.faq).setIcon(getResources().getDrawable(R.drawable.help));
|
||||
menu.findItem(R.id.logout).setIcon(getResources().getDrawable(R.drawable.logout));
|
||||
return super.onPrepareOptionsMenu(menu);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onOptionsItemSelected(MenuItem item) {
|
||||
if (item.getItemId() == R.id.settings) {
|
||||
final Intent intent = new Intent();
|
||||
intent.putExtra("item", "settings");
|
||||
setResult(RESULT_OK, intent);
|
||||
finish();
|
||||
return true;
|
||||
} else if (item.getItemId() == R.id.logout) {
|
||||
int color = (int) getIntent().getLongExtra(MainActivity.PREF_APP_BAR_COLOR, 0xffffff);
|
||||
logoutDialog = LogoutDialogFragment.newInstance(color);
|
||||
logoutDialog.show(getFragmentManager(), "logout");
|
||||
return true;
|
||||
} else if (item.getItemId() == R.id.faq) {
|
||||
final Intent intent = new Intent();
|
||||
intent.putExtra("item", "faq");
|
||||
setResult(RESULT_OK, intent);
|
||||
finish();
|
||||
return true;
|
||||
}
|
||||
return super.onOptionsItemSelected(item);
|
||||
}
|
||||
|
||||
void dismissDialog() {
|
||||
if (logoutDialog != null) {
|
||||
logoutDialog.dismiss();
|
||||
logoutDialog = null;
|
||||
}
|
||||
}
|
||||
|
||||
void logout() {
|
||||
final Intent intent = new Intent();
|
||||
intent.putExtra("item", "logout");
|
||||
setResult(RESULT_OK, intent);
|
||||
finish();
|
||||
}
|
||||
|
||||
public static class LogoutDialogFragment extends DialogFragment {
|
||||
|
||||
static LogoutDialogFragment newInstance(int color) {
|
||||
LogoutDialogFragment f = new LogoutDialogFragment();
|
||||
Bundle bundle = new Bundle();
|
||||
bundle.putInt(MainActivity.PREF_APP_BAR_COLOR, color);
|
||||
f.setArguments(bundle);
|
||||
return f;
|
||||
}
|
||||
|
||||
public static class LogoutDialogFragment extends DialogFragment {
|
||||
|
||||
static LogoutDialogFragment newInstance(int color) {
|
||||
LogoutDialogFragment f = new LogoutDialogFragment();
|
||||
Bundle bundle = new Bundle();
|
||||
bundle.putInt(MainActivity.PREF_APP_BAR_COLOR, color);
|
||||
f.setArguments(bundle);
|
||||
return f;
|
||||
}
|
||||
@Override
|
||||
public Dialog onCreateDialog(Bundle savedInstanceState) {
|
||||
final AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());
|
||||
final LayoutInflater inflater = getActivity().getLayoutInflater();
|
||||
final View content = inflater.inflate(R.layout.f_logout_dialog, null);
|
||||
builder.setView(content);
|
||||
final TextView positiveButton = (TextView) content.findViewById(R.id.positiveButton);
|
||||
final TextView negativeButton = (TextView) content.findViewById(R.id.negativeButton);
|
||||
// Можно делать через стили, но я не уверен, что необходимо в нашем случае
|
||||
positiveButton.setTextColor(getArguments().getInt(MainActivity.PREF_APP_BAR_COLOR));
|
||||
negativeButton.setTextColor(getArguments().getInt(MainActivity.PREF_APP_BAR_COLOR));
|
||||
|
||||
negativeButton.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public Dialog onCreateDialog(Bundle savedInstanceState) {
|
||||
final AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());
|
||||
final LayoutInflater inflater = getActivity().getLayoutInflater();
|
||||
final View content = inflater.inflate(R.layout.f_logout_dialog, null);
|
||||
builder.setView(content);
|
||||
final TextView positiveButton = (TextView) content.findViewById(R.id.positiveButton);
|
||||
final TextView negativeButton = (TextView) content.findViewById(R.id.negativeButton);
|
||||
// Можно делать через стили, но я не уверен, что необходимо в нашем случае
|
||||
positiveButton.setTextColor(getArguments().getInt(MainActivity.PREF_APP_BAR_COLOR));
|
||||
negativeButton.setTextColor(getArguments().getInt(MainActivity.PREF_APP_BAR_COLOR));
|
||||
|
||||
negativeButton.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View view) {
|
||||
((AbstractScannerActivity) getActivity()).dismissDialog();
|
||||
}
|
||||
});
|
||||
|
||||
positiveButton.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View view) {
|
||||
((AbstractScannerActivity) getActivity()).logout();
|
||||
}
|
||||
});
|
||||
|
||||
return builder.create();
|
||||
public void onClick(View view) {
|
||||
((AbstractScannerActivity) getActivity()).dismissDialog();
|
||||
}
|
||||
});
|
||||
|
||||
positiveButton.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View view) {
|
||||
((AbstractScannerActivity) getActivity()).logout();
|
||||
}
|
||||
});
|
||||
|
||||
return builder.create();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -65,6 +65,7 @@ public class MainActivity extends FlutterActivity {
|
||||
break;
|
||||
case "startScanner":
|
||||
mScannerArgs = call.arguments();
|
||||
System.out.println(mScannerArgs.toString());
|
||||
startScannerActivity();
|
||||
break;
|
||||
case "isOnline":
|
||||
|
||||
@@ -139,7 +139,8 @@ abstract class BaseState<T extends StatefulWidget> extends State<T> {
|
||||
return new Container(margin: new EdgeInsets.only(left: verticalMargin, right: verticalMargin),
|
||||
padding: getInputFieldContainerPadding(),
|
||||
decoration: getInputFieldContainerDecoration(),
|
||||
child: getTextWidget());
|
||||
child: getTextWidget()
|
||||
);
|
||||
}
|
||||
|
||||
/// Возвращает поле ввода.
|
||||
|
||||
@@ -144,6 +144,7 @@ startScanner(BuildContext context, String app, SqliteHelper helper) async {
|
||||
String userString = call.arguments[0];
|
||||
print(userString);
|
||||
String card = call.arguments[1];
|
||||
print('$userString, $card');
|
||||
var route = new MaterialPageRoute<Null>(
|
||||
builder: (BuildContext context) =>
|
||||
new PurchaseScreen(helper, app, userString, card));
|
||||
@@ -155,7 +156,7 @@ startScanner(BuildContext context, String app, SqliteHelper helper) async {
|
||||
});
|
||||
|
||||
platform.invokeMethod('startScanner', {
|
||||
'token': await platform.invokeMethod('getAppToken'),
|
||||
'token': token,
|
||||
'url': await platform.invokeMethod('getEndpoint'),
|
||||
'appToken': await platform.invokeMethod('getAppToken'),
|
||||
'locale': Intl.defaultLocale,
|
||||
|
||||
@@ -40,6 +40,8 @@ class MessageLookup extends MessageLookupByLibrary {
|
||||
"discount_sum" : MessageLookupByLibrary.simpleMessage("Dicount Sum"),
|
||||
"bonus_plus" : MessageLookupByLibrary.simpleMessage("Bonus points"),
|
||||
"bonus_minus" : MessageLookupByLibrary.simpleMessage("Bonus was charged"),
|
||||
"bonus_hint" : MessageLookupByLibrary.simpleMessage("Points to charge"),
|
||||
"bonus_explanation" : MessageLookupByLibrary.simpleMessage("If not set, points will be added"),
|
||||
"scan" : MessageLookupByLibrary.simpleMessage("Scan"),
|
||||
"sign_up" : MessageLookupByLibrary.simpleMessage("Sign Up"),
|
||||
"specify_din_store" : MessageLookupByLibrary.simpleMessage("Specify the store ID"),
|
||||
|
||||
@@ -40,6 +40,8 @@ class MessageLookup extends MessageLookupByLibrary {
|
||||
"discount_sum" : MessageLookupByLibrary.simpleMessage("Сумма скидки"),
|
||||
"bonus_plus" : MessageLookupByLibrary.simpleMessage("Бонусов начислено"),
|
||||
"bonus_minus" : MessageLookupByLibrary.simpleMessage("Бонусов списано"),
|
||||
"bonus_hint" : MessageLookupByLibrary.simpleMessage("Сколько баллов списать?"),
|
||||
"bonus_explanation" : MessageLookupByLibrary.simpleMessage("Если не указано сколько баллов списать, баллы будут начислены"),
|
||||
"scan" : MessageLookupByLibrary.simpleMessage("Сканировать"),
|
||||
"sign_up" : MessageLookupByLibrary.simpleMessage("Зарегистрироваться"),
|
||||
"specify_din_store" : MessageLookupByLibrary.simpleMessage("Необходимо указать ID магазина"),
|
||||
|
||||
@@ -31,6 +31,8 @@ class PurchaseScreenState<T> extends BaseState<PurchaseScreen> {
|
||||
/// (удаляет запрещенные символы до их отображаения).
|
||||
TextEditingController controller = new TextEditingController();
|
||||
|
||||
TextEditingController bonusController = new TextEditingController();
|
||||
|
||||
PurchaseScreenState(SqliteHelper helper, String app, String userString, String card) {
|
||||
this.user = JSON.decode(userString);
|
||||
this.card = card;
|
||||
@@ -62,13 +64,19 @@ class PurchaseScreenState<T> extends BaseState<PurchaseScreen> {
|
||||
));
|
||||
widgets.add(getValueWithDescription(StringsLocalization.card(), card));
|
||||
|
||||
widgets.add(getValueWithDescription(StringsLocalization.reward(), loyalty));
|
||||
|
||||
if (bonus.length > 0) {
|
||||
widgets.add(getValueWithDescription(StringsLocalization.bonus(), bonus));
|
||||
}
|
||||
|
||||
widgets.add(getValueWithDescription(StringsLocalization.reward(), loyalty));
|
||||
widgets.add(getHintLabel());
|
||||
widgets.add(getInputField());
|
||||
|
||||
widgets.add(getInputField()); // Нельзя добавить еще одно поле таким же способом
|
||||
|
||||
widgets.add(getBonusInputField());
|
||||
|
||||
|
||||
widgets.add(wrapButton(getScreenMargins(36.0), getCompleteButton()));
|
||||
widgets.add(wrapButton(
|
||||
getScreenMargins(24.0),
|
||||
@@ -84,6 +92,47 @@ class PurchaseScreenState<T> extends BaseState<PurchaseScreen> {
|
||||
]);
|
||||
}
|
||||
|
||||
getBonusInputField() {
|
||||
return new Column(
|
||||
children: <Widget>[
|
||||
new Container(
|
||||
margin: new EdgeInsets.only(
|
||||
left: verticalMargin,
|
||||
right: verticalMargin,
|
||||
top: verticalMargin
|
||||
),
|
||||
padding: getInputFieldContainerPadding(),
|
||||
decoration: getInputFieldContainerDecoration(),
|
||||
child: new TextField(
|
||||
keyboardType: TextInputType.number,
|
||||
decoration: new InputDecoration.collapsed(
|
||||
hintText: StringsLocalization.bonusHint(),
|
||||
hintStyle: new TextStyle(color: greyTextColor, fontSize: 16.0)),
|
||||
controller: bonusController,
|
||||
onSubmitted: (String text) {
|
||||
setState(() {
|
||||
bonusController.text = text;
|
||||
});
|
||||
},
|
||||
textAlign: TextAlign.center,
|
||||
autofocus: true,
|
||||
)
|
||||
),
|
||||
new Container(
|
||||
margin: new EdgeInsets.only(
|
||||
top: 5.0
|
||||
),
|
||||
child: new Text(
|
||||
StringsLocalization.bonusExplanation(),
|
||||
textAlign: TextAlign.center,
|
||||
overflow: TextOverflow.ellipsis,
|
||||
style: new TextStyle(color: greyTextColor, fontSize: 11.0),
|
||||
)
|
||||
)
|
||||
],
|
||||
);
|
||||
}
|
||||
|
||||
getScreenMargins(double top) {
|
||||
double side = 42.0;
|
||||
return new EdgeInsets.only(top: top, left: side, right: side);
|
||||
@@ -118,6 +167,7 @@ class PurchaseScreenState<T> extends BaseState<PurchaseScreen> {
|
||||
|
||||
@override
|
||||
getTextWidget() {
|
||||
// ?? TODO переделать, т.к. позволяет иметь только одно поле ввода на странице
|
||||
return new TextField(
|
||||
keyboardType: TextInputType.number,
|
||||
decoration: new InputDecoration.collapsed(
|
||||
@@ -195,7 +245,9 @@ class PurchaseScreenState<T> extends BaseState<PurchaseScreen> {
|
||||
child: new AlertDialog(
|
||||
title: new Text(StringsLocalization.confirmation()),
|
||||
content:
|
||||
new Text(StringsLocalization.confirmPurchase(val, currency)),
|
||||
new Text(
|
||||
StringsLocalization.confirmPurchase(val, currency)
|
||||
),
|
||||
actions: <Widget>[
|
||||
new FlatButton(
|
||||
child: new Text(StringsLocalization.no()),
|
||||
@@ -213,6 +265,24 @@ class PurchaseScreenState<T> extends BaseState<PurchaseScreen> {
|
||||
});
|
||||
}
|
||||
|
||||
apiErrorAlert(String errorText) {
|
||||
showDialog(
|
||||
context: context,
|
||||
child: new AlertDialog(
|
||||
//title: new Text(StringsLocalization.()),
|
||||
content: new Text(errorText),
|
||||
actions: <Widget>[
|
||||
new FlatButton(
|
||||
child: new Text('Ok'),
|
||||
onPressed: () {
|
||||
Navigator.of(context).pop();
|
||||
},
|
||||
)
|
||||
]
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
purchase(String sumTotal) async {
|
||||
if (await platform.invokeMethod('isOnline')) {
|
||||
if (!purchaseInProgress) {
|
||||
@@ -229,17 +299,28 @@ class PurchaseScreenState<T> extends BaseState<PurchaseScreen> {
|
||||
'sum_total': sumTotal
|
||||
};
|
||||
|
||||
if (bonusController.text.length > 0) {
|
||||
body['bonus_payment'] = bonusController.text;
|
||||
}
|
||||
|
||||
print(body['bonus_payment']);
|
||||
|
||||
var purchaseResponse;
|
||||
Map purchase;
|
||||
|
||||
try {
|
||||
purchaseResponse = await getPurchaseRequest(user['purchases_url'], body, token);
|
||||
print(purchaseResponse.body);
|
||||
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());
|
||||
}
|
||||
|
||||
Map purchase = JSON.decode(purchaseResponse.body);
|
||||
}
|
||||
|
||||
Navigator.of(context).pop();
|
||||
|
||||
|
||||
@@ -101,6 +101,8 @@ class StringsLocalization {
|
||||
static String completePurchase() => Intl.message('complite_purchase', name: 'complite_purchase', locale: Intl.defaultLocale);
|
||||
static String scan() => Intl.message('scan', name: 'scan', locale: Intl.defaultLocale);
|
||||
static String buyer() => Intl.message('buyer', name: 'buyer', locale: Intl.defaultLocale);
|
||||
static String bonusHint() => Intl.message('bonus_hint', name: 'bonus_hint', locale: Intl.defaultLocale);
|
||||
static String bonusExplanation() => Intl.message('bonus_explanation', name: 'bonus_explanation', locale: Intl.defaultLocale);
|
||||
static String discountRate() => Intl.message('discount_rate', name: 'discount_rate', locale: Intl.defaultLocale);
|
||||
static String discountSum() => Intl.message('discount_sum', name: 'discount_sum', locale: Intl.defaultLocale);
|
||||
static String bonusPlus() => Intl.message('bonus_plus', name: 'bonus_plus', locale: Intl.defaultLocale);
|
||||
|
||||
Reference in New Issue
Block a user