This commit is contained in:
Ivan Murashov
2018-03-10 02:41:53 +03:00
parent bd1e0ec17f
commit 60f506a08d
6 changed files with 31 additions and 35 deletions

View File

@@ -64,28 +64,33 @@ class SqliteHelper {
} }
/// Создается запись в таблице, содержащая данные, которые не зависят от сессии. /// Создается запись в таблице, содержащая данные, которые не зависят от сессии.
Future createAppInfo(int currency) async { Future createAppInfo(int currency, String locale) async {
List<Map> appInfo = await db.query(tableSettings); List<Map> appInfo = await db.query(tableSettings);
if (appInfo.length > 0) { if (appInfo.length > 0) {
return null; return null;
} else { } else {
return db.insert(tableSettings, { return db.insert(tableSettings, {
columnCurrency: currency columnCurrency: currency,
columnLocale: locale
}); });
} }
} }
Future<Map> getSettings(bool withSession) async { Future<Map> getSettings(bool withSession) async {
Map results = new Map();
Map settings = await selectAll(tableSettings); Map settings = await selectAll(tableSettings);
results.addAll(settings);
if (withSession) { if (withSession) {
Map session = await selectAll(tableSession); Map session = await selectAll(tableSession);
if (settings != null && session != null) { if (settings != null && session != null) {
settings.addAll(session); results.addAll(session);
} }
} }
return settings; return results;
} }
Future<String> getToken() async { Future<String> getToken() async {

View File

@@ -30,52 +30,43 @@ main() {
} }
initWithSystemValue(String app, String name, SqliteHelper helper) { initWithSystemValue(String app, String name, SqliteHelper helper) {
platform.invokeMethod('getLocale').then((locale) {
helper.getSettings(false).then((settings) { helper.getSettings(false).then((settings) {
if (settings == null) { if (settings == null) {
createSettingsTable(app, name, locale, helper); createSettingsTable(app, name, helper);
} else { } else {
start(app, name, locale, helper); start(app, name, locale, helper);
} }
}); });
});
} }
createSettingsTable(String app, String name, String locale, SqliteHelper helper) { createSettingsTable(String app, String name, SqliteHelper helper) {
platform.invokeMethod('getLocale').then((locale) {
platform.invokeMethod('getCurrency').then((currency) { platform.invokeMethod('getCurrency').then((currency) {
helper.createAppInfo(currency).then(() { helper.createAppInfo(currency, locale).then((_) {
start(app, name, locale, helper); start(app, name, locale, helper);
}); });
}); });
});
} }
start(String app, String name, String locale, SqliteHelper helper) { start(String app, String name, String locale, SqliteHelper helper) {
StringsLocalization.load(locale).then((_) { StringsLocalization.load(locale).then((_) {
runApp(new Checker(app, name, locale, helper)); runApp(new Checker(app, name, helper));
}); });
} }
class Checker extends StatefulWidget { class Checker extends StatefulWidget {
/// Класс для работы с бд
final SqliteHelper helper; final SqliteHelper helper;
/// Тип сборки. Определяет, какие брать ресурсы (цвета, картинки)
final String app; final String app;
/// Отображаемое в заголовке приложения названия (когда показывается список запущенных приложений)
final String appName; final String appName;
/// Локаль приложения Checker(this.app, this.appName, this.helper);
final String locale;
Checker(this.app, this.appName, this.locale, this.helper);
@override @override
State<StatefulWidget> createState() => new CheckerState( State<StatefulWidget> createState() => new CheckerState(
this.app, this.app,
this.appName, this.appName,
this.locale,
this.helper); this.helper);
} }
@@ -84,11 +75,8 @@ class CheckerState extends State<Checker> {
SqliteHelper helper; SqliteHelper helper;
String app; String app;
String appName; String appName;
String locale;
String token; CheckerState(this.app, this.appName, this.helper);
CheckerState(this.app, this.appName, this.locale, this.helper);
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {

View File

@@ -188,7 +188,6 @@ class PurchaseScreenState<T> extends BaseState<PurchaseScreen> {
height: buttonHeight, height: buttonHeight,
child: new FlatButton( child: new FlatButton(
child: new Text(title, style: new TextStyle(color: textColor)), child: new Text(title, style: new TextStyle(color: textColor)),
// FIXME: onPressed: () => startScanner(context, app, helper)),
onPressed: () => Navigator.of(context).pop(true)), onPressed: () => Navigator.of(context).pop(true)),
decoration: new BoxDecoration( decoration: new BoxDecoration(
border: new Border.all( border: new Border.all(

View File

@@ -122,8 +122,7 @@ class PurchaseSuccessScreenState<T> extends BaseState<PurchaseSuccessScreen> {
getScanButton() { getScanButton() {
String title = StringsLocalization.scan(); String title = StringsLocalization.scan();
// FIXME: return buildRaisedButton(title, () => startScanner(context, app, helper)); return buildRaisedButton(title, () => Navigator.of(context).pop(true));
return buildRaisedButton(title, () => print('startScanner'));
} }
@@ -149,7 +148,8 @@ class PurchaseSuccessScreenState<T> extends BaseState<PurchaseSuccessScreen> {
) )
) )
)) ))
]); ]
);
} }
getMessageTitle() { getMessageTitle() {

View File

@@ -43,6 +43,9 @@ class SettingsState extends BaseState<SettingsScreen> {
@override Widget build(BuildContext ctx) { @override Widget build(BuildContext ctx) {
helper.getSettings(true).then((info) { helper.getSettings(true).then((info) {
setState(() { setState(() {
print('currency: ${info['currency']}');
print('locale: ${info['locale']}');
print('token: ${info['token']}');
menuItems[0].title = StringsLocalization.currency(); menuItems[0].title = StringsLocalization.currency();
menuItems[1].title = StringsLocalization.locale(); menuItems[1].title = StringsLocalization.locale();
menuItems[2].title = StringsLocalization.logout(); menuItems[2].title = StringsLocalization.logout();

View File

@@ -78,6 +78,7 @@ class _SplashScreenState extends BaseState<SplashScreen> {
/// Запуск следующего экрана приложения. /// Запуск следующего экрана приложения.
showNextScreen() async { showNextScreen() async {
String token = await helper.getToken(); String token = await helper.getToken();
// В случае, если в приложении отсутствует токен, // В случае, если в приложении отсутствует токен,