diff --git a/android/app/src/main/AndroidManifest.xml b/android/app/src/main/AndroidManifest.xml index 66f6f5e..56be33f 100644 --- a/android/app/src/main/AndroidManifest.xml +++ b/android/app/src/main/AndroidManifest.xml @@ -1,7 +1,7 @@ + android:versionName="0.0.4"> diff --git a/android/app/src/main/java/com/dinect/checker/activity/CameraActivity.java b/android/app/src/main/java/com/dinect/checker/activity/CameraActivity.java index 4411cc0..6c7b770 100644 --- a/android/app/src/main/java/com/dinect/checker/activity/CameraActivity.java +++ b/android/app/src/main/java/com/dinect/checker/activity/CameraActivity.java @@ -55,8 +55,12 @@ import io.flutter.plugin.common.MethodChannel.Result; import okhttp3.OkHttpClient; import okhttp3.Request; import okhttp3.Response; -import org.json.*; - +import org.json.*; +import android.app.Dialog; +import android.app.DialogFragment; +import android.app.AlertDialog; +import android.app.AlertDialog.Builder; +import android.content.DialogInterface; import com.dinect.checker.R; public class CameraActivity extends AppCompatActivity implements SurfaceHolder.Callback { @@ -70,7 +74,7 @@ public class CameraActivity extends AppCompatActivity implements SurfaceHolder.C private boolean previewing = true; private Handler autoFocusHandler; private int mOffset; - private String mToken = "19305da6610a74504f8a462411199b5de0c93979"; + private String mToken; static { System.loadLibrary("iconv"); @@ -108,19 +112,17 @@ public class CameraActivity extends AppCompatActivity implements SurfaceHolder.C actionBar.setDisplayHomeAsUpEnabled(false); } + mToken = getIntent().getStringExtra(MainActivity.PREF_POS_TOKEN); + + if (mToken == null) { + Intent intent = new Intent(); + intent.putExtra("item", "logout"); + setResult(RESULT_OK, intent); + finish(); + } + mCamera = getCameraInstance(); mCamera.setPreviewCallback(previewCallback); - - Camera.Parameters params = mCamera.getParameters(); - List focusModes = params.getSupportedFocusModes(); - - if (focusModes.contains(Camera.Parameters.FOCUS_MODE_CONTINUOUS_PICTURE)) { - params.setFocusMode(Camera.Parameters.FOCUS_MODE_CONTINUOUS_PICTURE); - } else if (focusModes.contains(Camera.Parameters.FOCUS_MODE_AUTO)) { - params.setFocusMode(Camera.Parameters.FOCUS_MODE_AUTO); - } - mCamera.setParameters(params); - holder.addCallback(this); } @@ -221,13 +223,13 @@ public class CameraActivity extends AppCompatActivity implements SurfaceHolder.C @Override public boolean onOptionsItemSelected(MenuItem item) { - Intent intent = new Intent(); + if (item.getItemId() == R.id.logout) { - intent.putExtra("item", "logout"); - setResult(RESULT_OK, intent); - finish(); + LogoutDialogFragment newFragment = new LogoutDialogFragment(); + newFragment.show(getFragmentManager(), "logout"); return true; } else if (item.getItemId() == R.id.faq) { + Intent intent = new Intent(); intent.putExtra("item", "faq"); setResult(RESULT_OK, intent); finish(); @@ -287,9 +289,10 @@ public class CameraActivity extends AppCompatActivity implements SurfaceHolder.C } if (response.code() == 200) { try { - JSONArray users = new JSONArray(response.body().string()); + String s = response.body().string(); + JSONArray users = new JSONArray(s); + Log.d("kifio", s); if (users.length() > 0) { - Toast.makeText(this, "Чики-брики и в дамки", Toast.LENGTH_SHORT).show(); Intent intent = new Intent(); intent.putExtra("user", users.get(0).toString()); intent.putExtra("card", card); @@ -357,6 +360,9 @@ public class CameraActivity extends AppCompatActivity implements SurfaceHolder.C @Override public void run() { + Log.d("kifio", mUrl); + Log.d("kifio", mToken); + Request request = new Request.Builder() .addHeader("DM-Authorization", "dmapptoken 9fec83cdca38c357e6b65dbb17514cdd36bf2a08") .addHeader("Authorization", "dmtoken " + mToken) @@ -380,4 +386,30 @@ public class CameraActivity extends AppCompatActivity implements SurfaceHolder.C mActivity = null; } } + + public static class LogoutDialogFragment extends DialogFragment { + @Override + public Dialog onCreateDialog(Bundle savedInstanceState) { + // Use the Builder class for convenient dialog construction + AlertDialog.Builder builder = new AlertDialog.Builder(getActivity()); + builder.setTitle("Подтверждение"); + builder.setMessage("Вы действительно хотите выйти и ввести другой номер магазина?") + .setPositiveButton("Да", new DialogInterface.OnClickListener() { + public void onClick(DialogInterface dialog, int id) { + dialog.dismiss(); + Intent intent = new Intent(); + intent.putExtra("item", "logout"); + getActivity().setResult(RESULT_OK, intent); + getActivity().finish(); + } + }) + .setNegativeButton("Нет", new DialogInterface.OnClickListener() { + public void onClick(DialogInterface dialog, int id) { + dialog.dismiss(); + } + }); + // Create the AlertDialog object and return it + return builder.create(); + } + } } \ No newline at end of file diff --git a/android/app/src/main/java/com/dinect/checker/activity/MainActivity.java b/android/app/src/main/java/com/dinect/checker/activity/MainActivity.java index dec6647..5f19127 100644 --- a/android/app/src/main/java/com/dinect/checker/activity/MainActivity.java +++ b/android/app/src/main/java/com/dinect/checker/activity/MainActivity.java @@ -21,10 +21,10 @@ import java.lang.System; public class MainActivity extends FlutterActivity { private static final int START_SCANNER_REQUEST_CODE = 2017; - private static final String PREF_POS_TOKEN = "pref_pos_token"; private static final String PREF_POS_MERCHANT_ID = "pref_pos_merchant_id"; private static final String PREF_DOC_ID = "pref_doc_id"; private static final String PREF_POS_ID = "pref_pos_id"; + static final String PREF_POS_TOKEN = "pref_pos_token"; private MethodChannel mChannel; private SharedPreferences mPreferences; @@ -67,7 +67,9 @@ public class MainActivity extends FlutterActivity { result.success(mPreferences.getString(PREF_POS_MERCHANT_ID, null)); break; case "startScanner": + Map arguments = call.arguments(); Intent cameraIntent = new Intent(MainActivity.this, CameraActivity.class); + cameraIntent.putExtra(PREF_POS_TOKEN, (String) arguments.get("token")); startActivityForResult(cameraIntent, START_SCANNER_REQUEST_CODE); break; case "removeKeys": diff --git a/lib/base_state.dart b/lib/base_state.dart index ea95cfa..013d906 100644 --- a/lib/base_state.dart +++ b/lib/base_state.dart @@ -55,7 +55,7 @@ abstract class BaseState extends State { double horizontalMargin = 8.0; return new Container(margin: new EdgeInsets.only(top: horizontalMargin, bottom: horizontalMargin, left: verticalMargin, right: verticalMargin), child: new Row(crossAxisAlignment: CrossAxisAlignment.start, - children: [new Text(getHintText(), overflow: TextOverflow.ellipsis, textAlign: TextAlign.left, + children: [new Text(getHintText(), textAlign: TextAlign.left, style: new TextStyle(fontWeight: FontWeight.w300, color: error == null ? greyTextColor : primaryColor, fontSize: 14.0))])); } @@ -112,7 +112,6 @@ abstract class BaseState extends State { onChanged: (text) => handleUserInput(text)); } - /// Индикация ... Widget getProgressIndicator() { return new Center(child: loading ? new CircularProgressIndicator() : null); } @@ -121,7 +120,7 @@ abstract class BaseState extends State { return new Container(padding: new EdgeInsets.only(left: verticalMargin, right: verticalMargin, top: 18.0), child: new Column(children: [ new Row(crossAxisAlignment: CrossAxisAlignment.start, children: [new Text(title, textAlign: TextAlign.left, style: new TextStyle(color: greyTextColor, fontSize: 14.0))]), - new Row(crossAxisAlignment: CrossAxisAlignment.start, children: [new Text(value, textAlign: TextAlign.left, style: new TextStyle(color: Colors.black, fontSize: 20.0))]) + new Row(crossAxisAlignment: CrossAxisAlignment.start, children: [new Expanded(child: new Text(value, textAlign: TextAlign.left, style: new TextStyle(color: Colors.black, fontSize: 20.0)))]) ])); } diff --git a/lib/common.dart b/lib/common.dart index 3520066..5c66b17 100644 --- a/lib/common.dart +++ b/lib/common.dart @@ -31,8 +31,11 @@ logout(BuildContext context) { if (token != null) { deleteToken(token).then((response) { print(response.body); - platform.invokeMethod('removeKeys'); - pushRoute(context, new RegistrationScreen()); // Запускаем регистрацию + platform.invokeMethod('removeKeys').then((result) { + Navigator.of(context).pop(); + Navigator.of(context).pop(); + pushRoute(context, new RegistrationScreen()); // Запускаем регистрацию + }); }).catchError((error) { print(error.toString()); }); @@ -45,6 +48,19 @@ logout(BuildContext context) { showYesNoDialog(context, 'Подтверждение', 'Вы действительно хотите выйти и ввести другой номер магазина?', positiveCalback); } +forceLogout(BuildContext context) { + + deleteToken(token).then((response) { + print(response.body); + platform.invokeMethod('removeKeys').then((result) { + Navigator.of(context).pop(); + pushRoute(context, new RegistrationScreen()); // Запускаем регистрацию + }); + }).catchError((error) { + print(error.toString()); + }); +} + /// Запуск спецефичной для каждой платформы части приложения - сканера. /// Может производиться с нескольких экранов (splash, finish_registration). startScanner(BuildContext context) async { @@ -56,7 +72,7 @@ startScanner(BuildContext context) async { print('call.method: ${call.method}'); if (call.method == 'logout') { - logout(context); + forceLogout(context); } else if (call.method == 'faq') { faq(context, true); } else { @@ -68,9 +84,8 @@ startScanner(BuildContext context) async { Navigator.of(context).pushReplacement(route); } }); + await platform.invokeMethod('startScanner', {'token' : token}); } - - await platform.invokeMethod('startScanner'); } // Запуск диалога с двумя кнопками diff --git a/lib/network.dart b/lib/network.dart index 7e1d7a9..8a4a685 100644 --- a/lib/network.dart +++ b/lib/network.dart @@ -32,8 +32,4 @@ deleteToken(String token) async { String url = intUrl + 'tokens/' + token + '?_dmapptoken=' + intToken; print(url); return httpClient.delete(url); -} - -// Удалить токены -// 57e0d09aa935252d2a3463ebc1d61501608a6af9 -// f1355ea87375c173695b57afa72f78fedbe5b6c3 \ No newline at end of file +} \ No newline at end of file diff --git a/lib/purchase.dart b/lib/purchase.dart index c2e4864..696eeb9 100644 --- a/lib/purchase.dart +++ b/lib/purchase.dart @@ -35,17 +35,16 @@ class PurchaseScreenState extends BaseState { String loyality = ''; @override Widget getScreenContent() { - return new Container(height: 412.0, - child: new ListView(reverse: true, children: [ - new Column(children: [ - getValueWithTitle('ФИО', user['first_name']), + return new Column( + children: [new Expanded(child: new ListView(children: [ + getValueWithTitle('ФИО', user['first_name'] == null ? '' : user['first_name']), getValueWithTitle('Карта', card), getValueWithTitle('Вознаграждение', loyality), getHintLabel(), getDecoratedTextWidget(), buildButton(new EdgeInsets.only(top: 36.0, left: buttonVerticalMargin, right: buttonVerticalMargin), buildRaisedButton(context, 'ЗАВЕРШИТЬ ПОКУПКУ', () => onPurchaseClick(context))), - buildButton(new EdgeInsets.only(top: 24.0, left: buttonVerticalMargin, right: buttonVerticalMargin), buildFlatButton(context, 'СКАНИРОВАТЬ', primaryColor))]) - ].reversed.toList())); + buildButton(new EdgeInsets.only(top: 24.0, left: buttonVerticalMargin, right: buttonVerticalMargin), buildFlatButton(context, 'СКАНИРОВАТЬ', primaryColor)) + ]))]); } @override String getTitle() { @@ -68,7 +67,7 @@ class PurchaseScreenState extends BaseState { @override handleUserInput(String tmpString) { setState(() { tmpString = tmpString.replaceAll('-', ''); - tmpString = tmpString.replaceAll(', ', ''); + tmpString = tmpString.replaceAll(',', ''); print(tmpString); if (tmpString.contains('.')) { int dotIndex = tmpString.indexOf('.'); @@ -88,10 +87,13 @@ class PurchaseScreenState extends BaseState { getLoyality(String url) { - var headers = { - 'DM-Authorization': 'dmapptoken 9fec83cdca38c357e6b65dbb17514cdd36bf2a08', - 'Authorization': 'dmtoken ${token}' - }; + print(url); + print(token); + + var headers = { + 'DM-Authorization': 'dmapptoken 9fec83cdca38c357e6b65dbb17514cdd36bf2a08', + 'Authorization': 'dmtoken ${token}' + }; httpClient.get(url, headers: headers).then((response) { @@ -102,11 +104,15 @@ class PurchaseScreenState extends BaseState { setState(() { if (type == 'amount') { - this.loyality = user['discount']; + this.loyality = '${user['discount']}%'; } else { - List bonusToAmount = bonuses['bonus_to_amount']; - this.loyality = (bonusToAmount[1].toInt() / bonusToAmount[0].toInt() ).toString(); + List amountToBonus = bonuses['amount_to_bonus']; + // print(amountToBonus[0]); + // print(amountToBonus[1]); + this.loyality = '${(amountToBonus[0] / double.parse(amountToBonus[1])).toStringAsFixed(0)}%'; } + + }); }).catchError((error) { @@ -170,7 +176,7 @@ class PurchaseScreenState extends BaseState { print(response.body); Navigator.of(context).pop(); - pushRoute(context, new PurchaseSuccessScreen(sum_total, user['first_name'])); + pushRoute(context, new PurchaseSuccessScreen(sum_total, user['first_name'] == null ? '' : user['first_name'])); }).catchError((error) { print(error.toString()); diff --git a/lib/registration.dart b/lib/registration.dart index d972bea..d8d26ac 100644 --- a/lib/registration.dart +++ b/lib/registration.dart @@ -25,14 +25,14 @@ class _RegistrationScreenState extends BaseState { /// Высота контейнера задана для того, чтобы элементы располагались вверху экрана /// и список скроллился снизу вверх при открытии клавиатуры. @override Widget getScreenContent() { - return new Container(height: 332.0, - child: new ListView(reverse: true, children: [ + return new Container( + child: new ListView(children: [ new Center(child: new Column(children: [ getLogo(), getHintLabel(), getDecoratedTextWidget(), new Container(margin: new EdgeInsets.only(top: 36.0), child: buildRaisedButton(context, 'ЗАРЕГИСТРИРОВАТЬ', _isValidMerchantID() && !loading ? () => _registerShop(context) : null))])) - ].reversed.toList())); + ])); } /// Токен кассы - это DIN код. DIN код - это специальный код динекта, максимальная его длина - 25 символов. diff --git a/lib/splash.dart b/lib/splash.dart index ed41625..85b7f6c 100644 --- a/lib/splash.dart +++ b/lib/splash.dart @@ -16,8 +16,6 @@ class SplashScreen extends StatelessWidget { // Появляется splash screen, проверяется токен. new Future.delayed(const Duration(milliseconds: 500), () { showNextScreen(context); - // startScanner(context); - // pushRoute(context, new PurchaseScreen(null)); }); return new Stack(children: [getBackgroundContainer(), @@ -45,7 +43,6 @@ class SplashScreen extends StatelessWidget { if (token == null) { pushRoute(context, new RegistrationScreen()); } else { - checkTokenStatus(token).then((statusResponse) { handleStatusResponse(context, statusResponse); }).catchError((error) { @@ -77,23 +74,23 @@ class SplashScreen extends StatelessWidget { } else { createToken(await platform.invokeMethod('getMerchantID'), await platform.invokeMethod('getPosID')).then((response) { print('response.body: ${response.body}'); - + if (response.statusCode == 409) { pushRoute(context, new FinishRegistrationScreen()); - } else { - deleteToken(token).then((response) { - print(response.body); - platform.invokeMethod('removeKeys'); - Navigator.of(context).pop(); // Убираем текущий route - pushRoute(context, new RegistrationScreen()); // Запускаем регистрацию - }).catchError((error) { - print(error.toString()); + } else if (response.statusCode == 201) { + platform.invokeMethod('removeKeys').then((result) { + Map parsedMap = JSON.decode(result); + String t = parsedMap['token']; + deleteToken(t).then((response) { + print(response.body); + Navigator.of(context).pop(); // Убираем текущий route + pushRoute(context, new RegistrationScreen()); // Запускаем регистрацию + }).catchError((error) { + print(error.toString()); + }); }); } - - }).catchError((error) { - platform.invokeMethod('removeKeys').then((result) => pushRoute(context, new RegistrationScreen())); - }); + }).catchError((error) => print(error.toString())); } } }