Android all done.

This commit is contained in:
Ivan Murashov
2018-03-12 21:41:41 +03:00
parent 3bc43724c6
commit 11640c0a16
15 changed files with 111 additions and 253 deletions

View File

@@ -165,8 +165,8 @@ public abstract class AbstractScannerActivity extends AppCompatActivity impleme
// для удобства, чтоб не вводить постоянно руками при разработке
// manualInput.setText("9990010009012057060904229");
manualInput.setText("4620011139016337050236302");
// manualInput.setText("9990010009012057060904229");
// manualInput.setText("4620011139016337050236302");
manualInput.setHint(getIntent().getStringExtra("enter_manual"));
manualInput.setOnEditorActionListener(new TextView.OnEditorActionListener() {

View File

@@ -15,6 +15,10 @@ import io.flutter.plugin.common.MethodChannel;
import io.flutter.plugin.common.MethodChannel.Result;
import io.flutter.plugins.GeneratedPluginRegistrant;
import android.support.v4.app.Fragment;
import android.Manifest;
import android.content.pm.PackageManager;
import android.support.v4.content.ContextCompat;
import android.support.v4.app.ActivityCompat;
import java.util.*;
@@ -127,7 +131,11 @@ public class MainActivity extends FlutterActivity {
}
private void startScannerActivity() {
final int idx = getSharedPreferences("scanner", Context.MODE_PRIVATE).getInt(SCANNER_BACKEND_KEY, 0);
if (ContextCompat.checkSelfPermission(this, Manifest.permission.CAMERA) != PackageManager.PERMISSION_GRANTED) {
ActivityCompat.requestPermissions(this, new String[] {Manifest.permission.CAMERA}, 101);
} else {
final int idx = getSharedPreferences("scanner", Context.MODE_PRIVATE).getInt(
SCANNER_BACKEND_KEY, 0);
Intent cameraIntent = new Intent(MainActivity.this, SCANNER_BACKEND[idx]);
for (Object key : mScannerArgs.keySet()) {
@@ -140,6 +148,18 @@ public class MainActivity extends FlutterActivity {
setLocale((String) mScannerArgs.get("localeCode"));
startActivityForResult(cameraIntent, START_SCANNER_REQUEST_CODE);
}
}
@Override
public void onRequestPermissionsResult(int requestCode,
String permissions[], int[] grantResults) {
if (requestCode == 101) {
if (grantResults.length > 0
&& grantResults[0] == PackageManager.PERMISSION_GRANTED) {
startScannerActivity();
}
}
}
@Override

View File

@@ -1,14 +0,0 @@
package com.kifio.checker.checker;
import android.os.Bundle;
import io.flutter.app.FlutterActivity;
import io.flutter.plugins.GeneratedPluginRegistrant;
public class MainActivity extends FlutterActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
GeneratedPluginRegistrant.registerWith(this);
}
}

View File

@@ -1,93 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<Scheme
LastUpgradeVersion = "0920"
version = "1.3">
<BuildAction
parallelizeBuildables = "YES"
buildImplicitDependencies = "YES">
<BuildActionEntries>
<BuildActionEntry
buildForTesting = "YES"
buildForRunning = "YES"
buildForProfiling = "YES"
buildForArchiving = "YES"
buildForAnalyzing = "YES">
<BuildableReference
BuildableIdentifier = "primary"
BlueprintIdentifier = "FB8CCC12204C8249002BBFDA"
BuildableName = "Dinect-INT.app"
BlueprintName = "Dinect-INT"
ReferencedContainer = "container:Runner.xcodeproj">
</BuildableReference>
</BuildActionEntry>
</BuildActionEntries>
</BuildAction>
<TestAction
buildConfiguration = "Debug"
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
language = ""
shouldUseLaunchSchemeArgsEnv = "YES">
<Testables>
</Testables>
<MacroExpansion>
<BuildableReference
BuildableIdentifier = "primary"
BlueprintIdentifier = "FB8CCC12204C8249002BBFDA"
BuildableName = "Dinect-INT.app"
BlueprintName = "Dinect-INT"
ReferencedContainer = "container:Runner.xcodeproj">
</BuildableReference>
</MacroExpansion>
<AdditionalOptions>
</AdditionalOptions>
</TestAction>
<LaunchAction
buildConfiguration = "Debug"
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
language = ""
launchStyle = "0"
useCustomWorkingDirectory = "NO"
ignoresPersistentStateOnLaunch = "NO"
debugDocumentVersioning = "YES"
debugServiceExtension = "internal"
allowLocationSimulation = "YES">
<BuildableProductRunnable
runnableDebuggingMode = "0">
<BuildableReference
BuildableIdentifier = "primary"
BlueprintIdentifier = "FB8CCC12204C8249002BBFDA"
BuildableName = "Dinect-INT.app"
BlueprintName = "Dinect-INT"
ReferencedContainer = "container:Runner.xcodeproj">
</BuildableReference>
</BuildableProductRunnable>
<AdditionalOptions>
</AdditionalOptions>
</LaunchAction>
<ProfileAction
buildConfiguration = "Release"
shouldUseLaunchSchemeArgsEnv = "YES"
savedToolIdentifier = ""
useCustomWorkingDirectory = "NO"
debugDocumentVersioning = "YES">
<BuildableProductRunnable
runnableDebuggingMode = "0">
<BuildableReference
BuildableIdentifier = "primary"
BlueprintIdentifier = "FB8CCC12204C8249002BBFDA"
BuildableName = "Dinect-INT.app"
BlueprintName = "Dinect-INT"
ReferencedContainer = "container:Runner.xcodeproj">
</BuildableReference>
</BuildableProductRunnable>
</ProfileAction>
<AnalyzeAction
buildConfiguration = "Debug">
</AnalyzeAction>
<ArchiveAction
buildConfiguration = "Release"
revealArchiveInOrganizer = "YES">
</ArchiveAction>
</Scheme>

View File

@@ -1,93 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<Scheme
LastUpgradeVersion = "0920"
version = "1.3">
<BuildAction
parallelizeBuildables = "YES"
buildImplicitDependencies = "YES">
<BuildActionEntries>
<BuildActionEntry
buildForTesting = "YES"
buildForRunning = "YES"
buildForProfiling = "YES"
buildForArchiving = "YES"
buildForAnalyzing = "YES">
<BuildableReference
BuildableIdentifier = "primary"
BlueprintIdentifier = "FB8CCC12204C8249002BBFDA"
BuildableName = "Debug-Dinect-INT.app"
BlueprintName = "Debug-Dinect-INT"
ReferencedContainer = "container:Runner.xcodeproj">
</BuildableReference>
</BuildActionEntry>
</BuildActionEntries>
</BuildAction>
<TestAction
buildConfiguration = "Debug"
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
language = ""
shouldUseLaunchSchemeArgsEnv = "YES">
<Testables>
</Testables>
<MacroExpansion>
<BuildableReference
BuildableIdentifier = "primary"
BlueprintIdentifier = "FB8CCC12204C8249002BBFDA"
BuildableName = "Debug-Dinect-INT.app"
BlueprintName = "Debug-Dinect-INT"
ReferencedContainer = "container:Runner.xcodeproj">
</BuildableReference>
</MacroExpansion>
<AdditionalOptions>
</AdditionalOptions>
</TestAction>
<LaunchAction
buildConfiguration = "Debug"
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
language = ""
launchStyle = "0"
useCustomWorkingDirectory = "NO"
ignoresPersistentStateOnLaunch = "NO"
debugDocumentVersioning = "YES"
debugServiceExtension = "internal"
allowLocationSimulation = "YES">
<BuildableProductRunnable
runnableDebuggingMode = "0">
<BuildableReference
BuildableIdentifier = "primary"
BlueprintIdentifier = "FB8CCC12204C8249002BBFDA"
BuildableName = "Debug-Dinect-INT.app"
BlueprintName = "Debug-Dinect-INT"
ReferencedContainer = "container:Runner.xcodeproj">
</BuildableReference>
</BuildableProductRunnable>
<AdditionalOptions>
</AdditionalOptions>
</LaunchAction>
<ProfileAction
buildConfiguration = "Release"
shouldUseLaunchSchemeArgsEnv = "YES"
savedToolIdentifier = ""
useCustomWorkingDirectory = "NO"
debugDocumentVersioning = "YES">
<BuildableProductRunnable
runnableDebuggingMode = "0">
<BuildableReference
BuildableIdentifier = "primary"
BlueprintIdentifier = "FB8CCC12204C8249002BBFDA"
BuildableName = "Debug-Dinect-INT.app"
BlueprintName = "Debug-Dinect-INT"
ReferencedContainer = "container:Runner.xcodeproj">
</BuildableReference>
</BuildableProductRunnable>
</ProfileAction>
<AnalyzeAction
buildConfiguration = "Debug">
</AnalyzeAction>
<ArchiveAction
buildConfiguration = "Release"
revealArchiveInOrganizer = "YES">
</ArchiveAction>
</Scheme>

View File

@@ -101,13 +101,18 @@ abstract class BaseState<T extends StatefulWidget> extends State<T> {
new Future.delayed(const Duration(milliseconds: 200), () {
var route = new MaterialPageRoute<String>(builder: (BuildContext context) => new SettingsScreen(helper, app, false), fullscreenDialog: true);
Navigator.of(context).push(route).then((token) {
Navigator.of(context).pop(token);
if (token != null) {
Navigator.of(context).pop(token);
}
});
});
break;
}
case 1: {
pushRoute(context, new FAQScreen(helper, app, false));
new Future.delayed(const Duration(milliseconds: 200), () {
var route = new MaterialPageRoute<String>(builder: (BuildContext context) => new FAQScreen(helper, app), fullscreenDialog: true);
Navigator.of(context).push(route);
});
break;
}
case 2: {

View File

@@ -3,6 +3,7 @@ import 'dart:async';
import 'package:checker/screens/faq.dart';
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:image_picker/image_picker.dart';
import 'db.dart';
import 'strings.dart';
@@ -10,6 +11,8 @@ import 'strings.dart';
// Канал для взаимодействия с кодом платформы.
const platform = const MethodChannel('com.dinect.checker/instance_id');
// TODO: Избавиться от следующих двух методов
pushRoute(BuildContext context, Widget widget) {
var route =
new MaterialPageRoute<Null>(builder: (BuildContext context) => widget, fullscreenDialog: true);
@@ -19,12 +22,6 @@ pushRoute(BuildContext context, Widget widget) {
});
}
// Добавление route, с возможностью вернуться к предыдущему экрану.
faq(SqliteHelper helper, String app, BuildContext context,
bool returnToScanner) {
pushRoute(context, new FAQScreen(helper, app, returnToScanner));
}
getCurrencyTitle(int code) {
switch (code) {
case 643:
@@ -52,3 +49,8 @@ getLocaleTitle(String code) {
return 'Español';
}
}
// Добавил вызов, что-бы AOT компилер не выкинул либу.
getImage() async {
return await ImagePicker.pickImage();
}

View File

@@ -68,19 +68,14 @@ class EntryItem extends StatelessWidget {
class FAQScreen extends BaseScreen {
FAQScreen(SqliteHelper helper, String app,
this.returnToScanner) : super(helper, app);
FAQScreen(SqliteHelper helper, String app) : super(helper, app);
final bool returnToScanner;
@override State createState() => new FAQScreenState<FAQScreen>(returnToScanner, helper, app);
@override State createState() => new FAQScreenState<FAQScreen>(helper, app);
}
class FAQScreenState<T> extends BaseState<FAQScreen> {
FAQScreenState(this.returnToScanner, SqliteHelper helper, String app) : super(helper, app);
bool returnToScanner;
FAQScreenState(SqliteHelper helper, String app) : super(helper, app);
List<Entry> data;
@@ -92,16 +87,14 @@ class FAQScreenState<T> extends BaseState<FAQScreen> {
return null;
}
@override
void initState() {
initPhoneAndUrl().then((_) {
super.initState();
});
}
@override Widget build(BuildContext context) {
if (data == null) {
platform.invokeMethod('getFlavor').then((flavor) {
initPhoneAndUrl().then((_) {
setState(() {
app = flavor;
});
});
});
}
return new Scaffold(appBar: getAppBar(), body: getScreenContent());
}

View File

@@ -73,7 +73,7 @@ class PurchaseScreenState<T> extends BaseState<PurchaseScreen> {
));
widgetList.add(getValueWithDescription(StringsLocalization.card(), card));
if (app != 'crypto') { // FIXME Заменить на crypto
if (app != 'crypto') {
widgetList.add(getValueWithDescription(StringsLocalization.reward(), loyalty));
}
@@ -186,7 +186,7 @@ class PurchaseScreenState<T> extends BaseState<PurchaseScreen> {
height: buttonHeight,
child: new FlatButton(
child: new Text(title, style: new TextStyle(color: textColor)),
onPressed: () => Navigator.of(context).pop()),
onPressed: () => restartScanner()),
decoration: new BoxDecoration(
border: new Border.all(
color: Resources.getButtonColor(app), width: 1.0),
@@ -437,4 +437,10 @@ class PurchaseScreenState<T> extends BaseState<PurchaseScreen> {
print('kifio ' + this.loyalty);
print('bonus ' + this.bonus);
}
restartScanner() {
helper.getToken().then((token) {
Navigator.of(context).pop(token);
});
}
}

View File

@@ -39,6 +39,7 @@ class PurchaseSuccessScreenState<T> extends BaseState<PurchaseSuccessScreen> {
int bonusPlus = 0;
int bonusMinus = 0;
int currency;
String token;
bool showBonus;
bool isAutomaticallyImplyLeading() => false;
@@ -51,15 +52,18 @@ class PurchaseSuccessScreenState<T> extends BaseState<PurchaseSuccessScreen> {
return null;
}
@override Widget build(BuildContext context) {
if (currency == null) {
helper.getCurrency().then((currency) {
setState(() {
this.currency = currency;
});
@override
void initState() {
helper.getCurrency().then((currency) {
helper.getToken().then((token) {
this.currency = currency;
this.token = token;
});
}
});
super.initState();
}
@override Widget build(BuildContext context) {
if (this.details['sum_bonus'] is String) {
String regexString = r'(\d+) начислено, (\d+).*';
@@ -122,9 +126,8 @@ class PurchaseSuccessScreenState<T> extends BaseState<PurchaseSuccessScreen> {
return new EdgeInsets.only(bottom: bottom, left: side, right: side);
}
getScanButton() async {
getScanButton() {
String title = StringsLocalization.scan();
String token = await helper.getToken();
return buildRaisedButton(title, () => Navigator.of(context).pop(token));
}

View File

@@ -29,7 +29,7 @@ class RegistrationScreenState extends BaseState<RegistrationScreen> {
@override
Widget build(BuildContext ctx) {
return getMainWidget();
return new WillPopScope(onWillPop: () => onWillPop(), child: getMainWidget());
}
@override
@@ -130,4 +130,10 @@ class RegistrationScreenState extends BaseState<RegistrationScreen> {
});
}
}
onWillPop() {
if (Theme.of(context).platform != TargetPlatform.iOS) {
platform.invokeMethod('finish');
}
}
}

View File

@@ -48,11 +48,11 @@ class SettingsState extends BaseState<SettingsScreen> {
@override
void initState() {
print('init state!');
super.initState();
}
@override Widget build(BuildContext ctx) {
// TODO: Перенести в initStater
helper.getSettings(true).then((info) {
setState(() {
menuItems[0].title = StringsLocalization.currency();
@@ -93,7 +93,6 @@ class SettingsState extends BaseState<SettingsScreen> {
List<Widget> widgets = new List();
for (int i = 0; i < menuItems.length; i++) {
if (menuItems[i].selectedValue.toString() != '') {
print('title : ${menuItems[i].title}');
widgets.add(
getSettingsItem(() => onPressed(menuItems.indexOf(menuItems[i])),
menuItems[i].title,
@@ -108,7 +107,6 @@ class SettingsState extends BaseState<SettingsScreen> {
case 0 :
return getCurrencyTitle(int.parse(menuItems[position].selectedValue));
case 1 :
print('val : ${menuItems[position].selectedValue}');
return getLocaleTitle(menuItems[position].selectedValue);
default :
return null;
@@ -188,11 +186,11 @@ class SettingsState extends BaseState<SettingsScreen> {
helper.getToken().then((token) {
getDeleteTokenRequest(token).then((response) {
helper.clear().then((result) {
Navigator.of(context).pop(null);
Navigator.of(context).pop('');
});
}).catchError((error) {
print(error.toString());
Navigator.of(context).pop(null);
Navigator.of(context).pop('');
});
});
}

View File

@@ -8,6 +8,7 @@ import 'package:checker/consts.dart';
import 'package:checker/db.dart';
import 'package:checker/network.dart';
import 'package:checker/resources.dart';
import 'package:checker/screens/faq.dart';
import 'package:checker/screens/finish_registration.dart';
import 'package:checker/screens/purchase.dart';
import 'package:checker/screens/registration.dart';
@@ -17,6 +18,7 @@ import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:http/http.dart';
// FIXME: Сделать запуск всех экранов из одной точки через метод showNextScreen()
class SplashScreen extends BaseScreen {
SplashScreen(SqliteHelper helper, String app) : super(helper, app);
@@ -40,7 +42,7 @@ class _SplashScreenState extends BaseState<SplashScreen> {
@override
Widget build(BuildContext ctx) {
return a ? new Container(
return !a ? new Container(
decoration: new BoxDecoration(
image: new DecorationImage(
image: new ExactAssetImage(Resources.getSplash(null)),
@@ -76,10 +78,15 @@ class _SplashScreenState extends BaseState<SplashScreen> {
var route = new MaterialPageRoute<String>(
builder: (BuildContext context) => screen, fullscreenDialog: true);
Navigator.of(context).push(route).then((token) {
if (token != null) {
if (token == '') {
showNextScreen(new RegistrationScreen(helper, app));
} else if (token != null) {
_initAndStartScanner(context, app, token, helper);
} else {
showNextScreen(new RegistrationScreen(helper, app));
print('Произошла непредусмотренная ошибка в логике приложения');
helper.getToken().then((token) {
_initAndStartScanner(context, app, token, helper);
});
}
});
});
@@ -209,13 +216,23 @@ class _SplashScreenState extends BaseState<SplashScreen> {
}
} else if (call.method == 'faq') {
faq(helper, app, context, true);
} else if (call.method == 'settings') {
new Future.delayed(const Duration(milliseconds: 200), () {
var route = new MaterialPageRoute<Null>(
builder: (BuildContext context) => new FAQScreen(helper, app), fullscreenDialog: true);
Navigator.of(context).push(route).then((_) {
_initAndStartScanner(context, app, token, helper);
});
});
} else if (call.method == 'settings') {
new Future.delayed(const Duration(milliseconds: 200), () {
var route = new MaterialPageRoute<String>(
builder: (BuildContext context) => new SettingsScreen(helper, app, true), fullscreenDialog: true);
Navigator.of(context).push(route).then((_) {
_initAndStartScanner(context, app, token, helper);
Navigator.of(context).push(route).then((result) {
if (result != null) {
showNextScreen(new RegistrationScreen(helper, app));
} else {
_initAndStartScanner(context, app, token, helper);
}
});
});
} else {

View File

@@ -41,6 +41,13 @@ packages:
url: "https://pub.dartlang.org"
source: hosted
version: "3.1.1"
image_picker:
dependency: "direct main"
description:
name: image_picker
url: "https://pub.dartlang.org"
source: hosted
version: "0.1.5"
matcher:
dependency: transitive
description:

View File

@@ -6,6 +6,7 @@ dependencies:
sprintf: "^3.0.2"
path_provider: "^0.2.1+1"
sqflite: any
image_picker: '^0.1.3' # use for ask permissions @ iOS
xml: "^2.6.0"
flutter:
sdk: flutter