Начал добавлять запросы на регистрацию, валидацию, удаление токена кассы

This commit is contained in:
Ivan Murashov
2017-07-17 19:02:50 +03:00
parent a14f521b1f
commit 79a16fb81f
11 changed files with 163 additions and 52 deletions

View File

@@ -47,6 +47,7 @@ flutter {
dependencies { dependencies {
compile fileTree(dir: 'libs', include: ['*.jar']) compile fileTree(dir: 'libs', include: ['*.jar'])
compile "com.google.android.gms:play-services-gcm:11.0.1"
androidTestCompile 'com.android.support:support-annotations:21.0.0' androidTestCompile 'com.android.support:support-annotations:21.0.0'
androidTestCompile 'com.android.support.test:runner:0.5' androidTestCompile 'com.android.support.test:runner:0.5'
androidTestCompile 'com.android.support.test:rules:0.5' androidTestCompile 'com.android.support.test:rules:0.5'

View File

@@ -18,7 +18,7 @@
additional functionality it is fine to subclass or reimplement additional functionality it is fine to subclass or reimplement
FlutterApplication and put your custom class here. --> FlutterApplication and put your custom class here. -->
<application android:name="io.flutter.app.FlutterApplication" android:label="checker" android:icon="@mipmap/ic_launcher"> <application android:name="io.flutter.app.FlutterApplication" android:label="checker" android:icon="@mipmap/ic_launcher">
<activity android:name=".MainActivity" <activity android:name="com.dinnect.checker.activity.MainActivity"
android:launchMode="singleTop" android:launchMode="singleTop"
android:theme="@android:style/Theme.Black.NoTitleBar" android:theme="@android:style/Theme.Black.NoTitleBar"
android:configChanges="orientation|keyboardHidden|keyboard|screenSize|locale|layoutDirection" android:configChanges="orientation|keyboardHidden|keyboard|screenSize|locale|layoutDirection"
@@ -30,7 +30,12 @@
</intent-filter> </intent-filter>
</activity> </activity>
<activity android:name=".CameraActivity" <activity android:name="com.dinnect.checker.activity.CameraActivity"
android:theme="@android:style/Theme.Black.NoTitleBar"/> android:theme="@android:style/Theme.Black.NoTitleBar"/>
<service
android:name="com.dinnect.checker.service.RegistrationIntentService"
android:exported="false"/>
</application> </application>
</manifest> </manifest>

View File

@@ -1,4 +1,4 @@
package com.dinnect.checker; package com.dinnect.checker.activity;
import android.app.Activity; import android.app.Activity;
import android.content.pm.ActivityInfo; import android.content.pm.ActivityInfo;

View File

@@ -0,0 +1,61 @@
package com.dinnect.checker.activity;
import android.os.Bundle;
import android.content.Intent;
import android.util.Log;
import com.dinnect.checker.activity.CameraActivity;
import com.dinnect.checker.service.RegistrationIntentService;
import io.flutter.app.FlutterActivity;
import io.flutter.plugins.GeneratedPluginRegistrant;
import io.flutter.plugin.common.MethodCall;
import io.flutter.plugin.common.MethodChannel;
import io.flutter.plugin.common.MethodChannel.MethodCallHandler;
import io.flutter.plugin.common.MethodChannel.Result;
import com.google.android.gms.iid.InstanceID;
public class MainActivity extends FlutterActivity {
private static final String SCANNER_CHANNEL = "com.dinnect.checker";
// private static final String INSTANCE_ID_CHANNEL = "com.dinnect.checker/instance_id";
private String mInstanceID = null;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
GeneratedPluginRegistrant.registerWith(this);
// new MethodChannel(getFlutterView(), INSTANCE_ID_CHANNEL).setMethodCallHandler(
// new MethodCallHandler() {
// @Override
// public void onMethodCall(MethodCall call, Result result) {
//
// }
// });
new MethodChannel(getFlutterView(), SCANNER_CHANNEL).setMethodCallHandler(
new MethodCallHandler() {
@Override
public void onMethodCall(MethodCall call, Result result) {
}
});
}
public void startScanner() {
startActivity(new Intent(MainActivity.this, CameraActivity.class));
}
public String getInstanceID() {
if (mInstanceID == null) {
InstanceID instanceID = InstanceID.getInstance(this);
mInstanceID = instanceID.getId();
}
Log.d()
return mInstanceID;
}
}

View File

@@ -0,0 +1,24 @@
package com.dinnect.checker.service;
import android.app.IntentService;
import android.content.Intent;
import android.util.Log;
import android.support.annotation.Nullable;
import android.widget.Toast;
import com.google.android.gms.iid.InstanceID;
import java.io.IOException;
public class RegistrationIntentService extends IntentService {
public RegistrationIntentService() {
super(RegistrationIntentService.class.getName());
}
@Override
protected void onHandleIntent(@Nullable Intent intent) {
InstanceID instanceID = InstanceID.getInstance(this);
String token = instanceID.getId();
Log.d("kifio", token);
}
}

View File

@@ -1,38 +0,0 @@
package com.dinnect.checker;
import android.os.Bundle;
import android.content.Intent;
import android.util.Log;
import com.dinnect.checker.CameraActivity;
import io.flutter.app.FlutterActivity;
import io.flutter.plugins.GeneratedPluginRegistrant;
import io.flutter.plugin.common.MethodCall;
import io.flutter.plugin.common.MethodChannel;
import io.flutter.plugin.common.MethodChannel.MethodCallHandler;
import io.flutter.plugin.common.MethodChannel.Result;
public class MainActivity extends FlutterActivity {
private static final String CHANNEL = "com.dinnect.checker/scanner";
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
GeneratedPluginRegistrant.registerWith(this);
new MethodChannel(getFlutterView(), CHANNEL).setMethodCallHandler(
new MethodCallHandler() {
@Override
public void onMethodCall(MethodCall call, Result result) {
Log.d("kifio", "onMethodCall");
startActivity(new Intent(MainActivity.this, CameraActivity.class));
}
});
}
public void startScanner() {
}
}

16
checker.iml Normal file
View File

@@ -0,0 +1,16 @@
<?xml version="1.0" encoding="UTF-8"?>
<module external.linked.project.id="checker" external.linked.project.path="$MODULE_DIR$" external.root.project.path="$MODULE_DIR$" external.system.id="GRADLE" external.system.module.group="" external.system.module.version="unspecified" type="FLUTTER_MODULE_TYPE" version="4">
<component name="NewModuleRootManager" inherit-compiler-output="true">
<exclude-output />
<content url="file://$MODULE_DIR$">
<excludeFolder url="file://$MODULE_DIR$/.gradle" />
<excludeFolder url="file://$MODULE_DIR$/.pub" />
<excludeFolder url="file://$MODULE_DIR$/build" />
<excludeFolder url="file://$MODULE_DIR$/packages" />
</content>
<orderEntry type="inheritedJdk" />
<orderEntry type="sourceFolder" forTests="false" />
<orderEntry type="library" name="Dart SDK" level="project" />
<orderEntry type="library" name="Dart Packages" level="project" />
</component>
</module>

View File

@@ -1,7 +1,12 @@
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'splash.dart'; import 'splash.dart';
const String _name = "Ivan Murashov"; const String _name = 'Ivan Murashov';
const String intUrl = 'https://pos-api.dinect.com/20130701/';
const String intToken = '9fec83cdca38c357e6b65dbb17514cdd36bf2a08';
final httpClient = createHttpClient();
void main() { void main() {
runApp(new Checker()); runApp(new Checker());
@@ -23,3 +28,6 @@ abstract class BaseState<T> extends State<StatefulWidget> {
} }
} }
//DMUrl := 'http://pos-api-int.dinect.com/20130701/';
//DMAToken := '9fec83cdca38c357e6b65dbb17514cdd36bf2a08';

View File

@@ -10,14 +10,15 @@ class RegistrationScreen extends StatefulWidget {
class _RegistrationScreenState extends BaseState<RegistrationScreen> { class _RegistrationScreenState extends BaseState<RegistrationScreen> {
static const platform = const MethodChannel('com.dinnect.checker/scanner'); static const platform = const MethodChannel('com.dinnect.checker');
String _merchantID = "";
String _posNumber = "";
@override Widget build(BuildContext context) { @override Widget build(BuildContext context) {
return new Scaffold(appBar: _getAppBar(), body: _getScreen()); return new Scaffold(appBar: _getAppBar(), body: _getScreen());
} }
faq() {}
AppBar _getAppBar() { AppBar _getAppBar() {
return new AppBar(title: new Text("Регистрация магазина"), return new AppBar(title: new Text("Регистрация магазина"),
backgroundColor: const Color(0xff4272e7), actions: <Widget>[ backgroundColor: const Color(0xff4272e7), actions: <Widget>[
@@ -77,7 +78,15 @@ class _RegistrationScreenState extends BaseState<RegistrationScreen> {
return new TextField(decoration: new InputDecoration(hintText: hint, return new TextField(decoration: new InputDecoration(hintText: hint,
hideDivider: true, hideDivider: true,
hintStyle: new TextStyle(color: const Color(0xffa5a5a5), hintStyle: new TextStyle(color: const Color(0xffa5a5a5),
fontSize: 16.0))); fontSize: 16.0)), onChanged: (text) => _handleUserInput(text) );
}
void _handleUserInput(String text) {
if (text.length > 0) {
setState(() { //new
_merchantID = text;
});
}
} }
Decoration _getDecoraionForInputField() { Decoration _getDecoraionForInputField() {
@@ -92,9 +101,31 @@ class _RegistrationScreenState extends BaseState<RegistrationScreen> {
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: null, disabledColor: const Color(0xffbfbfbf)))); onPressed: _merchantID.length == 0
? null
: () => _register(_merchantID),
disabledColor: const Color(0xffbfbfbf))));
} }
doStuff() {} void _register(String merchantShop) {
_registerToken(merchantShop);
}
Future<Null> _registerToken(String merchantShop) async {
String pos = await platform.invokeMethod('getInstanceID');
String userAgent = 'dm-checker-test v1.0.1';
var body = {
'merchant_shop' : merchantShop,
'pos' : pos,
'description' : userAgent + '-' + pos
};
httpClient.post(intUrl, body: body).then((response) {
print(response);
}).catchError((error) {
print(error);
});
}
} }

View File

@@ -2,18 +2,21 @@ import 'dart:async';
import 'registration.dart'; import 'registration.dart';
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
class SplashScreen extends StatelessWidget { class SplashScreen extends StatelessWidget {
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
new Future.delayed(const Duration(milliseconds: 1000), () { new Future.delayed(const Duration(milliseconds: 1000), () {
_goToNextScreen(context); _goToNextScreen(context);
}); });
return new Image.asset('assets/splash.png', fit: BoxFit.cover); return new Image.asset('assets/splash.png', fit: BoxFit.cover);
} }
_goToNextScreen(BuildContext context) { _goToNextScreen(BuildContext context) async {
Navigator.of(context).push(new MaterialPageRoute<Null>( Navigator.of(context).push(new MaterialPageRoute<Null>(
builder: (BuildContext context) { builder: (BuildContext context) {
return new RegistrationScreen(); return new RegistrationScreen();