Регистрация кассы, авторизация, сканнер готовы к демонстрации
This commit is contained in:
@@ -72,17 +72,18 @@ public class CameraActivity extends AppCompatActivity {
|
|||||||
actionBar.setDisplayHomeAsUpEnabled(true);
|
actionBar.setDisplayHomeAsUpEnabled(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
mCamera = getCameraInstance();
|
||||||
|
mCamera.setDisplayOrientation(90);
|
||||||
|
|
||||||
holder.addCallback(new SurfaceHolder.Callback() {
|
holder.addCallback(new SurfaceHolder.Callback() {
|
||||||
@Override
|
@Override
|
||||||
public void surfaceCreated(SurfaceHolder holder) {
|
public void surfaceCreated(SurfaceHolder holder) {
|
||||||
try {
|
try {
|
||||||
mCamera = getCameraInstance();
|
|
||||||
mCamera.setPreviewDisplay(holder);
|
mCamera.setPreviewDisplay(holder);
|
||||||
mCamera.startPreview();
|
mCamera.startPreview();
|
||||||
mCamera.setPreviewCallback(previewCallback);
|
mCamera.setPreviewCallback(previewCallback);
|
||||||
mCamera.autoFocus(autoFocusCB);
|
mCamera.autoFocus(autoFocusCB);
|
||||||
mCamera.setDisplayOrientation(90);
|
|
||||||
initCountours();
|
initCountours();
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
@@ -95,7 +96,7 @@ public class CameraActivity extends AppCompatActivity {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void surfaceDestroyed(SurfaceHolder holder) {
|
public void surfaceDestroyed(SurfaceHolder holder) {
|
||||||
mCamera = null;
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
@@ -116,6 +117,12 @@ public class CameraActivity extends AppCompatActivity {
|
|||||||
return super.onOptionsItemSelected(item);
|
return super.onOptionsItemSelected(item);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onDestroy() {
|
||||||
|
super.onDestroy();
|
||||||
|
mCamera = null;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
private void initCountours() {
|
private void initCountours() {
|
||||||
|
|
||||||
|
|||||||
@@ -10,38 +10,6 @@
|
|||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="match_parent"/>
|
android:layout_height="match_parent"/>
|
||||||
|
|
||||||
<LinearLayout android:orientation="vertical"
|
|
||||||
android:layout_width="match_parent"
|
|
||||||
android:layout_height="match_parent"
|
|
||||||
android:layout_marginTop="?attr/actionBarSize">
|
|
||||||
|
|
||||||
<View android:layout_height="0dp"
|
|
||||||
android:layout_weight="0.42"
|
|
||||||
android:layout_width="match_parent"
|
|
||||||
android:background="#с0000000"/>
|
|
||||||
|
|
||||||
<FrameLayout android:layout_height="0dp"
|
|
||||||
android:layout_weight="0.16"
|
|
||||||
android:layout_width="match_parent">
|
|
||||||
|
|
||||||
<View android:layout_height="match_parent"
|
|
||||||
android:layout_width="24dp"
|
|
||||||
android:layout_gravity="left"
|
|
||||||
android:background="#с0000000"/>
|
|
||||||
|
|
||||||
<View android:layout_height="match_parent"
|
|
||||||
android:layout_width="24dp"
|
|
||||||
android:layout_gravity="right"
|
|
||||||
android:background="#с0000000"/>
|
|
||||||
|
|
||||||
</FrameLayout>
|
|
||||||
|
|
||||||
<View android:layout_height="0dp"
|
|
||||||
android:layout_weight="0.42"
|
|
||||||
android:layout_width="match_parent"
|
|
||||||
android:background="#с0000000"/>
|
|
||||||
</LinearLayout>
|
|
||||||
|
|
||||||
<android.support.v7.widget.Toolbar
|
<android.support.v7.widget.Toolbar
|
||||||
android:id="@+id/toolbar"
|
android:id="@+id/toolbar"
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
|
|||||||
@@ -7,7 +7,7 @@ class FinishRegistrationScreen extends StatefulWidget {
|
|||||||
@override State createState() => new _RegistrationScreenState();
|
@override State createState() => new _RegistrationScreenState();
|
||||||
}
|
}
|
||||||
|
|
||||||
class _RegistrationScreenState extends BaseState<FinishRegistrationScreen> {
|
class _RegistrationScreenState extends State<FinishRegistrationScreen> {
|
||||||
|
|
||||||
@override Widget build(BuildContext context) {
|
@override Widget build(BuildContext context) {
|
||||||
return new Scaffold(appBar: _getAppBar(), body: _getScreen(context));
|
return new Scaffold(appBar: _getAppBar(), body: _getScreen(context));
|
||||||
@@ -18,22 +18,14 @@ class _RegistrationScreenState extends BaseState<FinishRegistrationScreen> {
|
|||||||
backgroundColor: primaryColor, actions: <Widget>[
|
backgroundColor: primaryColor, actions: <Widget>[
|
||||||
new IconButton(
|
new IconButton(
|
||||||
icon: new Icon(Icons.help_outline),
|
icon: new Icon(Icons.help_outline),
|
||||||
tooltip: 'Air it',
|
onPressed: () {}
|
||||||
onPressed: faq,
|
)]);
|
||||||
),
|
|
||||||
new IconButton(
|
|
||||||
icon: new Image(height: 24.0, width: 24.0, image: new AssetImage(logout_png)),
|
|
||||||
tooltip: 'Restitch it',
|
|
||||||
onPressed: logout,
|
|
||||||
)
|
|
||||||
]);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
Widget _getScreen(BuildContext context) {
|
Widget _getScreen(BuildContext context) {
|
||||||
return new Center(child: new Column(children: <Widget>[
|
return new Center(child: new Column(children: <Widget>[
|
||||||
_getLogo(),
|
_getLogo(),
|
||||||
_getDecoratedInputField(merchantIDHint),
|
_getDecoratedText(),
|
||||||
_getDecoratedInputField(posIDHint),
|
|
||||||
_getMessage(),
|
_getMessage(),
|
||||||
_getButton(context)
|
_getButton(context)
|
||||||
]));
|
]));
|
||||||
@@ -44,27 +36,22 @@ class _RegistrationScreenState extends BaseState<FinishRegistrationScreen> {
|
|||||||
child: new Image.asset(logo_png, height: 24.0, width: 156.0));
|
child: new Image.asset(logo_png, height: 24.0, width: 156.0));
|
||||||
}
|
}
|
||||||
|
|
||||||
Container _getDecoratedInputField(String hint) {
|
Container _getDecoratedText() {
|
||||||
return new Container(
|
return new Container(margin: new EdgeInsets.only(left: 28.0, right: 28.0),
|
||||||
padding: new EdgeInsets.only(left: 28.0, right: 28.0, top: 8.0),
|
padding: new EdgeInsets.only(top: 12.0, bottom: 12.0, left: 16.0, right: 16.0),
|
||||||
child: new Container(height: 48.0,
|
decoration: _getDecoraionForMerchantId(),
|
||||||
padding: new EdgeInsets.only(left: 16.0, right: 16.0),
|
child: _getMerchantIDText());
|
||||||
decoration: _getDecoraionForInputField(),
|
|
||||||
child: _getInputField(hint))) ;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
TextField _getInputField(String hint) {
|
Text _getMerchantIDText() {
|
||||||
return new TextField(decoration: new InputDecoration(hintText: hint,
|
return new Text(merchantID, style: new TextStyle(color: const Color(0xffa5a5a5), fontSize: 16.0));
|
||||||
hideDivider: true,
|
|
||||||
hintStyle: new TextStyle(color: const Color(0xffa5a5a5),
|
|
||||||
fontSize: 16.0)), onChanged: null);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
Container _getMessage() {
|
Container _getMessage() {
|
||||||
return new Container(padding: new EdgeInsets.only(top: 20.0, left: 26.0, right: 26.0),
|
return new Container(padding: new EdgeInsets.only(top: 20.0, left: 26.0, right: 26.0),
|
||||||
child: new Container(height: 128.0, decoration: _getDecoraionForMessageField(),
|
child: new Container(height: 128.0, decoration: _getDecoraionForMessageField(),
|
||||||
padding: new EdgeInsets.only(top: 16.0, bottom: 8.0, left: 28.0, right: 28.0),
|
padding: new EdgeInsets.only(top: 16.0, bottom: 8.0, left: 28.0, right: 28.0),
|
||||||
child: new Text('Запрос на активацию программы отправлен, дождитесь подтверждения активации администратором',
|
child: new Text('Запрос на активацию программы отправлен, дождrитесь подтверждения активации администратором',
|
||||||
textAlign: TextAlign.center, style: new TextStyle(fontWeight: FontWeight.bold, color: const Color(0xff4e3a19)))));
|
textAlign: TextAlign.center, style: new TextStyle(fontWeight: FontWeight.bold, color: const Color(0xff4e3a19)))));
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -73,7 +60,7 @@ class _RegistrationScreenState extends BaseState<FinishRegistrationScreen> {
|
|||||||
image: new ExactAssetImage(activate_token_bg_png), fit: BoxFit.fill));
|
image: new ExactAssetImage(activate_token_bg_png), fit: BoxFit.fill));
|
||||||
}
|
}
|
||||||
|
|
||||||
Decoration _getDecoraionForInputField() {
|
Decoration _getDecoraionForMerchantId() {
|
||||||
return new BoxDecoration(color: Colors.white,
|
return new BoxDecoration(color: Colors.white,
|
||||||
border: new Border.all(color: const Color(0xffcfd8dc), width: 1.0),
|
border: new Border.all(color: const Color(0xffcfd8dc), width: 1.0),
|
||||||
borderRadius: new BorderRadius.all(new Radius.circular(4.0)));
|
borderRadius: new BorderRadius.all(new Radius.circular(4.0)));
|
||||||
@@ -84,9 +71,9 @@ class _RegistrationScreenState extends BaseState<FinishRegistrationScreen> {
|
|||||||
child: new Container(height: 64.0, padding: new EdgeInsets.all(8.0),
|
child: new Container(height: 64.0, padding: new EdgeInsets.all(8.0),
|
||||||
child: new RaisedButton(child: new Text('Обновить статус активации',
|
child: new RaisedButton(child: new Text('Обновить статус активации',
|
||||||
style: new TextStyle(color: Colors.white)),
|
style: new TextStyle(color: Colors.white)),
|
||||||
onPressed: _checkToken(context),
|
onPressed: () {
|
||||||
disabledColor: const Color(0xffbfbfbf),
|
startScanner(context);
|
||||||
color: const Color(0xff3078c0))));
|
})));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
import 'package:flutter/services.dart';
|
import 'package:flutter/services.dart';
|
||||||
import 'splash.dart';
|
import 'splash.dart';
|
||||||
|
import 'registration.dart';
|
||||||
import 'dart:async';
|
import 'dart:async';
|
||||||
import 'dart:convert';
|
import 'dart:convert';
|
||||||
|
|
||||||
@@ -34,6 +35,7 @@ void main() {
|
|||||||
|
|
||||||
/// Токен кассы. Инициализируется при регистрации.
|
/// Токен кассы. Инициализируется при регистрации.
|
||||||
String token;
|
String token;
|
||||||
|
String merchantID = "";
|
||||||
|
|
||||||
/// Проверка статуса токена. Токен может быть активирован, либо не активирован.
|
/// Проверка статуса токена. Токен может быть активирован, либо не активирован.
|
||||||
void checkToken(BuildContext context, Callback callback) {
|
void checkToken(BuildContext context, Callback callback) {
|
||||||
@@ -62,21 +64,16 @@ void checkToken(BuildContext context, Callback callback) {
|
|||||||
/// Запуск спецефичной для каждой платформы части приложения - сканера.
|
/// Запуск спецефичной для каждой платформы части приложения - сканера.
|
||||||
/// Может производиться с нескольких экранов (splash, finish_registration).
|
/// Может производиться с нескольких экранов (splash, finish_registration).
|
||||||
startScanner(BuildContext context) async{
|
startScanner(BuildContext context) async{
|
||||||
|
|
||||||
const platform = const MethodChannel('com.dinect.checker/instance_id');
|
const platform = const MethodChannel('com.dinect.checker/instance_id');
|
||||||
platform.setMethodCallHandler((MethodCall call) async {
|
platform.setMethodCallHandler((MethodCall call) async {
|
||||||
logout();
|
pushRoute(context, new RegistrationScreen());
|
||||||
print(call.method);
|
|
||||||
// dynamic arguments = call.arguments;
|
|
||||||
// handle call then
|
|
||||||
return result;
|
return result;
|
||||||
// or
|
// or
|
||||||
// throw new PlatformException(errorCode, anErrorMessage, someDetails);
|
// throw new PlatformException(errorCode, anErrorMessage, someDetails);
|
||||||
});
|
});
|
||||||
await platform.invokeMethod('startScanner');
|
|
||||||
}
|
|
||||||
|
|
||||||
logout() {
|
await platform.invokeMethod('startScanner');
|
||||||
pushRute(_context, new RegistrationScreen());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Навигация по приложению.
|
/// Навигация по приложению.
|
||||||
@@ -99,14 +96,6 @@ class Checker extends StatelessWidget {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
abstract class BaseState<T> extends State<StatefulWidget> {
|
|
||||||
|
|
||||||
void faq() {
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
abstract class Callback {
|
abstract class Callback {
|
||||||
void call(BuildContext context);
|
void call(BuildContext context);
|
||||||
}
|
}
|
||||||
@@ -2,6 +2,7 @@ import 'dart:convert';
|
|||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
import 'package:flutter/services.dart';
|
import 'package:flutter/services.dart';
|
||||||
import 'main.dart';
|
import 'main.dart';
|
||||||
|
import 'dart:async';
|
||||||
import 'activate_token.dart';
|
import 'activate_token.dart';
|
||||||
|
|
||||||
/// Экран регистрации магазина и кассы.
|
/// Экран регистрации магазина и кассы.
|
||||||
@@ -9,7 +10,7 @@ class RegistrationScreen extends StatefulWidget {
|
|||||||
@override State createState() => new _RegistrationScreenState();
|
@override State createState() => new _RegistrationScreenState();
|
||||||
}
|
}
|
||||||
|
|
||||||
class _RegistrationScreenState extends BaseState<RegistrationScreen> {
|
class _RegistrationScreenState extends State<RegistrationScreen> {
|
||||||
|
|
||||||
String _merchantID = "";
|
String _merchantID = "";
|
||||||
bool _loading = false;
|
bool _loading = false;
|
||||||
@@ -20,7 +21,7 @@ class _RegistrationScreenState extends BaseState<RegistrationScreen> {
|
|||||||
|
|
||||||
AppBar _getAppBar() {
|
AppBar _getAppBar() {
|
||||||
return new AppBar(title: new Text("Регистрация"),
|
return new AppBar(title: new Text("Регистрация"),
|
||||||
actions: <Widget>[new IconButton(icon: new Icon(Icons.help_outline), onPressed: faq)]);
|
actions: <Widget>[new IconButton(icon: new Icon(Icons.help_outline), onPressed: () {})]);
|
||||||
}
|
}
|
||||||
|
|
||||||
Widget _getScreen(BuildContext context) {
|
Widget _getScreen(BuildContext context) {
|
||||||
@@ -70,7 +71,7 @@ class _RegistrationScreenState extends BaseState<RegistrationScreen> {
|
|||||||
padding: new EdgeInsets.only(left: 40.0, right: 40.0),
|
padding: new EdgeInsets.only(left: 40.0, right: 40.0),
|
||||||
child: new RaisedButton(child: new Text('ЗАРЕГИСТРИРОВАТЬ',
|
child: new RaisedButton(child: new Text('ЗАРЕГИСТРИРОВАТЬ',
|
||||||
style: new TextStyle(color: Colors.white)),
|
style: new TextStyle(color: Colors.white)),
|
||||||
onPressed: _isValidMerchantID() ? () => _registerShop(context, _merchantID) : null,
|
onPressed: _isValidMerchantID() ? () => _registerShop(context) : null,
|
||||||
color: primaryColor));
|
color: primaryColor));
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -79,57 +80,63 @@ class _RegistrationScreenState extends BaseState<RegistrationScreen> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
_isValidMerchantID() {
|
_isValidMerchantID() {
|
||||||
return _merchantID.length == 5;
|
return merchantID.length == 5;
|
||||||
}
|
}
|
||||||
|
|
||||||
_handleUserInput(String text) {
|
_handleUserInput(String text) {
|
||||||
if (text.length > 0) {
|
if (text.length > 0) {
|
||||||
setState(() {
|
setState(() {
|
||||||
_merchantID = text;
|
merchantID = text;
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
_registerShop(BuildContext context, String merchantShop) {
|
_registerShop(BuildContext context) {
|
||||||
setState(() {
|
setState(() {
|
||||||
loading = true;
|
_loading = true;
|
||||||
_register(context, merchantShop);
|
_registerDemo(context);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
_register(BuildContext context, String merchantShop) async {
|
_registerDemo(BuildContext context) {
|
||||||
|
new Future.delayed(const Duration(milliseconds: 1000), () {
|
||||||
const platform = const MethodChannel('com.dinect.checker/instance_id');
|
_loading = false;
|
||||||
String url = intUrl + 'tokens/?_dmapptoken=' + intToken;
|
|
||||||
String pos = await platform.invokeMethod('getInstanceID');
|
|
||||||
print(pos);
|
|
||||||
String userAgent = 'dm-checker-test v1.0.1';
|
|
||||||
|
|
||||||
var body = {
|
|
||||||
'merchant_shop': merchantShop,
|
|
||||||
'pos': pos,
|
|
||||||
'description': userAgent + '-' + pos
|
|
||||||
};
|
|
||||||
|
|
||||||
print(url);
|
|
||||||
|
|
||||||
for (var value in body.values) {
|
|
||||||
print(value);
|
|
||||||
}
|
|
||||||
|
|
||||||
httpClient.post(url, body: body).then((response) {
|
|
||||||
print(response.body);
|
|
||||||
Map parsedMap = JSON.decode(response.body);
|
|
||||||
token = parsedMap['token'];
|
|
||||||
platform.invokeMethod('saveToken', {'token' : token}).then((value) {
|
|
||||||
print(value.toString());
|
|
||||||
});
|
|
||||||
setState(() {
|
|
||||||
loading = false;
|
|
||||||
});
|
|
||||||
pushRoute(context, new FinishRegistrationScreen());
|
pushRoute(context, new FinishRegistrationScreen());
|
||||||
}).catchError((error) {
|
|
||||||
print(error.toString());
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
_register(BuildContext context) async {
|
||||||
|
// const platform = const MethodChannel('com.dinect.checker/instance_id');
|
||||||
|
// String url = intUrl + 'tokens/?_dmapptoken=' + intToken;
|
||||||
|
// String pos = await platform.invokeMethod('getInstanceID');
|
||||||
|
// print(pos);
|
||||||
|
// String userAgent = 'dm-checker-test v1.0.1';
|
||||||
|
|
||||||
|
// var body = {
|
||||||
|
// 'merchant_shop': merchantShop,
|
||||||
|
// 'pos': pos,
|
||||||
|
// 'description': userAgent + '-' + pos
|
||||||
|
// };
|
||||||
|
|
||||||
|
// print(url);
|
||||||
|
|
||||||
|
// for (var value in body.values) {
|
||||||
|
// print(value);
|
||||||
|
// }
|
||||||
|
|
||||||
|
// httpClient.post(url, body: body).then((response) {
|
||||||
|
// print(response.body);
|
||||||
|
// Map parsedMap = JSON.decode(response.body);
|
||||||
|
// token = parsedMap['token'];
|
||||||
|
// platform.invokeMethod('saveToken', {'token' : token}).then((value) {
|
||||||
|
// print(value.toString());
|
||||||
|
// });
|
||||||
|
// setState(() {
|
||||||
|
// loading = false;
|
||||||
|
// });
|
||||||
|
// pushRoute(context, new FinishRegistrationScreen());
|
||||||
|
// }).catchError((error) {
|
||||||
|
// print(error.toString());
|
||||||
|
// });
|
||||||
|
}
|
||||||
}
|
}
|
||||||
@@ -28,11 +28,10 @@ class SplashScreen extends StatelessWidget {
|
|||||||
// В случае, если в приложении отсутствует токен,
|
// В случае, если в приложении отсутствует токен,
|
||||||
// необходимо запустить регистрацию кассы.
|
// необходимо запустить регистрацию кассы.
|
||||||
// if (token == null) {
|
// if (token == null) {
|
||||||
// pushRoute(context, new RegistrationScreen());
|
pushRoute(context, new RegistrationScreen());
|
||||||
// } else {
|
// } else {
|
||||||
// checkToken(context, new CheckTokenCallback());
|
// checkToken(context, new CheckTokenCallback());
|
||||||
// }
|
// }
|
||||||
startScanner(context);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user