Исправлено переключение локали на экране сканера

This commit is contained in:
Ivan Murashov
2017-09-21 13:09:38 +03:00
parent eba8c9e642
commit afc9cde20d
12 changed files with 85 additions and 49 deletions

View File

@@ -2,7 +2,7 @@
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.dinect.checker"
android:versionCode="1"
android:versionName="1.0.5">
android:versionName="1.1.0">
<uses-sdk
android:minSdkVersion="16"

View File

@@ -210,8 +210,10 @@ public abstract class AbstractScannerActivity extends AppCompatActivity {
} else {
handleFail(card);
}
break;
case 204:
handleFail(card);
break;
}
}
} catch (final IOException | JSONException e) {

View File

@@ -111,6 +111,14 @@ public class MainActivity extends FlutterActivity {
result.success(connected);
}
private void setLocale(String locale) {
Resources res = getResources();
Configuration configuration = new Configuration(res.getConfiguration());
configuration.locale = new Locale(locale);
Locale.setDefault(configuration.locale);
res.updateConfiguration(configuration, res.getDisplayMetrics());
}
private void startScannerActivity() {
final int idx = getSharedPreferences("scanner", Context.MODE_PRIVATE).getInt(SCANNER_BACKEND_KEY, 0);
Intent cameraIntent = new Intent(MainActivity.this, SCANNER_BACKEND[idx]);
@@ -118,6 +126,7 @@ public class MainActivity extends FlutterActivity {
cameraIntent.putExtra(PREF_APP_TOKEN, (String) mScannerArgs.get("appToken"));
cameraIntent.putExtra(PREF_POS_TOKEN, (String) mScannerArgs.get("token"));
cameraIntent.putExtra(PREF_APP_BAR_COLOR, (Long) mScannerArgs.get("color"));
setLocale((String) mScannerArgs.get("locale"));
startActivityForResult(cameraIntent, START_SCANNER_REQUEST_CODE);
}
@@ -161,6 +170,10 @@ public class MainActivity extends FlutterActivity {
}
public void setUserLocale() {
}
public void startScanner() {
}

View File

@@ -51,9 +51,6 @@ public class ScannerActivity extends AbstractScannerActivity
initToolbar(getIntent());
scannerView = (ZXingScannerView) initScanner();
ArrayList<BarcodeFormat> formats = new ArrayList<>();
formats.add(BarcodeFormat.UPC_EAN_EXTENSION);
scannerView.setFormats(formats);
addScanner(scannerView, R.id.zxingRoot);
}

View File

@@ -14,15 +14,13 @@ abstract class SettingsBaseState<T extends StatefulWidget> extends BaseState<T>
int selectedItem;
@override Widget build(BuildContext context) {
return getMainWidget();
return new Scaffold(appBar: getAppBar(),
body: getScreenContent());
}
@override
Widget getScreenContent() {
getSelectedValue();
List<Widget> widgets = new List();
for (String option in getOptions()) {

View File

@@ -87,6 +87,7 @@ startScanner(BuildContext context, String app, SqliteHelper helper) async {
});
} else {
String token = await helper.getToken();
String locale = await helper.getLocale();
helper.close();
// Канал ловит вызовы методов из "нативной" части приложения.
// Могут быть вызваны либо logout либо faq, либо purchase.
@@ -119,6 +120,7 @@ startScanner(BuildContext context, String app, SqliteHelper helper) async {
'token': token,
'url': url,
'appToken': appToken,
'locale': locale,
'color': Resources
.getPrimaryColor(app)
.value

View File

@@ -3,11 +3,11 @@ import 'package:flutter/material.dart';
// Serious constants
const String appName = "Autobonus";
//const String url = 'https://pos-api-autoclub.dinect.com/20130701/';
//const String appToken = 'bdea0f3ba9034b688019a7cac753d1209e2b227f';
const String url = 'https://pos-api-autoclub.dinect.com/20130701/';
const String appToken = 'bdea0f3ba9034b688019a7cac753d1209e2b227f';
const String url = 'https://pos-api-int.dinect.com/20130701/';
const String appToken = '9fec83cdca38c357e6b65dbb17514cdd36bf2a08';
//const String url = 'https://pos-api-int.dinect.com/20130701/';
//const String appToken = '9fec83cdca38c357e6b65dbb17514cdd36bf2a08';
// Assets
const String logout_png = 'assets/logout.png';

View File

@@ -70,7 +70,6 @@ class SqliteHelper {
return null;
} else {
return db.insert(tableSettings, {
columnLocale: locale,
columnCurrency: currency
});
}

View File

@@ -77,7 +77,7 @@ class MessageLookup extends MessageLookupByLibrary {
"usage_guide": MessageLookupByLibrary.simpleMessage('''
Шаг 1:
Запустите прилодение для сканирования карты участника системы лояльности.
Запустите приложение для сканирования карты участника системы лояльности.
При успешном сканировании на вашем экране появятся данные покупателя.

View File

@@ -40,19 +40,23 @@ class LanguagesState extends SettingsBaseState<LanguagesScreen> {
saveOption() async {
await helper.saveLocale(languages[selectedItem]);
Intl.defaultLocale = languages[selectedItem];
StringsLocalization.load(languages[selectedItem]).then((_) {
setState(() {
});
});
await StringsLocalization.load(languages[selectedItem]);
}
@override
void getSelectedValue() {
helper.getLocale().then((locale) {
if (locale == null) {
platform.invokeMethod('getLocale').then((locale) {
setState(() {
selectedItem == locale;
});
});
} else {
setState(() {
selectedItem = getOptions().indexOf(getLocaleTitle(locale));
});
}
});
}
}

View File

@@ -7,6 +7,7 @@ import 'package:checker/screens/currencies.dart';
import 'package:checker/screens/languages.dart';
import 'package:checker/strings.dart';
import 'package:flutter/material.dart';
import 'package:intl/intl.dart';
class SettingsScreen extends BaseScreen {
@@ -28,8 +29,8 @@ class MenuItem {
class SettingsState extends BaseState<SettingsScreen> {
List<MenuItem> menuItems = [
new MenuItem(StringsLocalization.currency(), ''),
new MenuItem(StringsLocalization.locale(), '')
new MenuItem('', ''),
new MenuItem('', '')
];
bool returnToScanner;
@@ -42,23 +43,24 @@ class SettingsState extends BaseState<SettingsScreen> {
@override Widget build(BuildContext ctx) {
helper.getSettings().then((info) {
if (menuItems != null) {
if (menuItems[0].selectedValue != info['currency'].toString()) {
setState(() {
menuItems[0].title = StringsLocalization.currency();
menuItems[1].title = StringsLocalization.locale();
menuItems[0].selectedValue = info['currency'].toString();
menuItems[1].selectedValue = info['locale'].toString();
menuItems[1].selectedValue = info['locale'] == null ? Intl.defaultLocale : info['locale'].toString();
});
}
}
});
return new WillPopScope(onWillPop: onWillPop, child: getMainWidget());
}
Widget getMainWidget() {
return new Scaffold(appBar: getAppBar(),
body: getScreenContent());
}
@override
Widget getScreenContent() {
return menuItems == null
? getBackground()
: new Container(
return new Container(
margin: new EdgeInsets.only(top: 16.0),
child: new ListView(children: getSettings()));
}

View File

@@ -38,24 +38,43 @@ class _SplashScreenState extends BaseState<SplashScreen> {
}
void onStart() {
helper.getSettings().then((info) {
if (info == null) {
platform.invokeMethod('getCurrency').then((currency) {
helper.getLocale().then((locale) {
if (locale == null) {
initWithSystemValue();
} else {
initWithSavedValue();
}
});
}
void initWithSystemValue() {
platform.invokeMethod('getLocale').then((locale) {
helper.getSettings().then((settings) {
if (settings == null) {
createSettingsTable(locale);
} else {
initLocale(locale, () {
helper.createAppInfo(locale, currency).then((_) {
showNext();
});
}
});
});
});
} else {
}
void initWithSavedValue() {
helper.getLocale().then((locale) {
initLocale(locale, () {
showNext();
});
});
}
void createSettingsTable(String locale) {
platform.invokeMethod('getCurrency').then((currency) {
helper.createAppInfo(locale, currency);
initLocale(locale, () {
showNext();
});
});
}