Поправил много неприятных косяков
This commit is contained in:
@@ -1,7 +1,7 @@
|
||||
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
package="com.dinect.checker"
|
||||
android:versionCode="1"
|
||||
android:versionName="0.0.3">
|
||||
android:versionName="0.0.4">
|
||||
|
||||
<uses-sdk android:minSdkVersion="16" android:targetSdkVersion="21" />
|
||||
|
||||
|
||||
@@ -56,7 +56,11 @@ import okhttp3.OkHttpClient;
|
||||
import okhttp3.Request;
|
||||
import okhttp3.Response;
|
||||
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<String> 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();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -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":
|
||||
|
||||
@@ -55,7 +55,7 @@ abstract class BaseState<T> extends State<T> {
|
||||
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: <Widget>[new Text(getHintText(), overflow: TextOverflow.ellipsis, textAlign: TextAlign.left,
|
||||
children: <Widget>[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<T> extends State<T> {
|
||||
onChanged: (text) => handleUserInput(text));
|
||||
}
|
||||
|
||||
/// Индикация ...
|
||||
Widget getProgressIndicator() {
|
||||
return new Center(child: loading ? new CircularProgressIndicator() : null);
|
||||
}
|
||||
@@ -121,7 +120,7 @@ abstract class BaseState<T> extends State<T> {
|
||||
return new Container(padding: new EdgeInsets.only(left: verticalMargin, right: verticalMargin, top: 18.0),
|
||||
child: new Column(children: <Widget>[
|
||||
new Row(crossAxisAlignment: CrossAxisAlignment.start, children: <Widget>[new Text(title, textAlign: TextAlign.left, style: new TextStyle(color: greyTextColor, fontSize: 14.0))]),
|
||||
new Row(crossAxisAlignment: CrossAxisAlignment.start, children: <Widget>[new Text(value, textAlign: TextAlign.left, style: new TextStyle(color: Colors.black, fontSize: 20.0))])
|
||||
new Row(crossAxisAlignment: CrossAxisAlignment.start, children: <Widget>[new Expanded(child: new Text(value, textAlign: TextAlign.left, style: new TextStyle(color: Colors.black, fontSize: 20.0)))])
|
||||
]));
|
||||
}
|
||||
|
||||
|
||||
@@ -31,8 +31,11 @@ logout(BuildContext context) {
|
||||
if (token != null) {
|
||||
deleteToken(token).then((response) {
|
||||
print(response.body);
|
||||
platform.invokeMethod('removeKeys');
|
||||
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');
|
||||
}
|
||||
|
||||
// Запуск диалога с двумя кнопками
|
||||
|
||||
@@ -33,7 +33,3 @@ deleteToken(String token) async {
|
||||
print(url);
|
||||
return httpClient.delete(url);
|
||||
}
|
||||
|
||||
// Удалить токены
|
||||
// 57e0d09aa935252d2a3463ebc1d61501608a6af9
|
||||
// f1355ea87375c173695b57afa72f78fedbe5b6c3
|
||||
@@ -35,17 +35,16 @@ class PurchaseScreenState<T> extends BaseState<PurchaseScreen> {
|
||||
String loyality = '';
|
||||
|
||||
@override Widget getScreenContent() {
|
||||
return new Container(height: 412.0,
|
||||
child: new ListView(reverse: true, children: <Widget>[
|
||||
new Column(children: <Widget>[
|
||||
getValueWithTitle('ФИО', user['first_name']),
|
||||
return new Column(
|
||||
children: <Widget>[new Expanded(child: new ListView(children: <Widget>[
|
||||
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<T> extends BaseState<PurchaseScreen> {
|
||||
@override handleUserInput(String tmpString) {
|
||||
setState(() {
|
||||
tmpString = tmpString.replaceAll('-', '');
|
||||
tmpString = tmpString.replaceAll(', ', '');
|
||||
tmpString = tmpString.replaceAll(',', '');
|
||||
print(tmpString);
|
||||
if (tmpString.contains('.')) {
|
||||
int dotIndex = tmpString.indexOf('.');
|
||||
@@ -88,6 +87,9 @@ class PurchaseScreenState<T> extends BaseState<PurchaseScreen> {
|
||||
|
||||
getLoyality(String url) {
|
||||
|
||||
print(url);
|
||||
print(token);
|
||||
|
||||
var headers = {
|
||||
'DM-Authorization': 'dmapptoken 9fec83cdca38c357e6b65dbb17514cdd36bf2a08',
|
||||
'Authorization': 'dmtoken ${token}'
|
||||
@@ -102,11 +104,15 @@ class PurchaseScreenState<T> extends BaseState<PurchaseScreen> {
|
||||
|
||||
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<T> extends BaseState<PurchaseScreen> {
|
||||
|
||||
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());
|
||||
|
||||
@@ -25,14 +25,14 @@ class _RegistrationScreenState extends BaseState<RegistrationScreen> {
|
||||
/// Высота контейнера задана для того, чтобы элементы располагались вверху экрана
|
||||
/// и список скроллился снизу вверх при открытии клавиатуры.
|
||||
@override Widget getScreenContent() {
|
||||
return new Container(height: 332.0,
|
||||
child: new ListView(reverse: true, children: <Widget>[
|
||||
return new Container(
|
||||
child: new ListView(children: <Widget>[
|
||||
new Center(child: new Column(children: <Widget>[
|
||||
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 символов.
|
||||
|
||||
@@ -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: <Widget>[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) {
|
||||
@@ -80,21 +77,21 @@ class SplashScreen extends StatelessWidget {
|
||||
|
||||
if (response.statusCode == 409) {
|
||||
pushRoute(context, new FinishRegistrationScreen());
|
||||
} else {
|
||||
deleteToken(token).then((response) {
|
||||
} 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);
|
||||
platform.invokeMethod('removeKeys');
|
||||
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()));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user