From 75c33370f18db34fd86b712e25dca317ba12420c Mon Sep 17 00:00:00 2001 From: Oleksandr Sobol Date: Fri, 6 Mar 2020 20:38:13 +0200 Subject: [PATCH 1/2] CWA-180 | fixed local date format in dashboard_page, date_section_raw, trade_details_page, transaction_details_page, added currentLocale parameter to settings store --- lib/src/screens/dashboard/dashboard_page.dart | 4 +++- lib/src/screens/dashboard/date_section_raw.dart | 4 +++- .../screens/trade_details/trade_details_page.dart | 7 +++++-- .../transaction_details_page.dart | 4 +++- lib/src/stores/settings/settings_store.dart | 12 ++++++++++-- 5 files changed, 24 insertions(+), 7 deletions(-) diff --git a/lib/src/screens/dashboard/dashboard_page.dart b/lib/src/screens/dashboard/dashboard_page.dart index d5037187e..7b29685f7 100644 --- a/lib/src/screens/dashboard/dashboard_page.dart +++ b/lib/src/screens/dashboard/dashboard_page.dart @@ -125,7 +125,9 @@ class DashboardPageBodyState extends State { final actionListStore = Provider.of(context); final syncStore = Provider.of(context); final settingsStore = Provider.of(context); - final transactionDateFormat = DateFormat("MMMM d, yyyy HH:mm", settingsStore.languageCode); + final transactionDateFormat = settingsStore.currentLocale == 'en_US' + ? DateFormat("MMMM d, yyyy, HH:mm", settingsStore.languageCode) + : DateFormat("d MMMM yyyy, HH:mm", settingsStore.languageCode); return Observer( key: _listObserverKey, diff --git a/lib/src/screens/dashboard/date_section_raw.dart b/lib/src/screens/dashboard/date_section_raw.dart index fb41f674f..f735278ba 100644 --- a/lib/src/screens/dashboard/date_section_raw.dart +++ b/lib/src/screens/dashboard/date_section_raw.dart @@ -19,7 +19,9 @@ class DateSectionRaw extends StatelessWidget { nowDate.year == date.year; final settingsStore = Provider.of(context); final currentLanguage = settingsStore.languageCode; - final dateSectionDateFormat = DateFormat("d MMM", currentLanguage); + final dateSectionDateFormat = settingsStore.currentLocale == 'en_US' + ? DateFormat("MMM d", settingsStore.languageCode) + : DateFormat("d MMM", settingsStore.languageCode); var title = ""; if (isToday) { diff --git a/lib/src/screens/trade_details/trade_details_page.dart b/lib/src/screens/trade_details/trade_details_page.dart index 8aaf1ced4..0d25254a0 100644 --- a/lib/src/screens/trade_details/trade_details_page.dart +++ b/lib/src/screens/trade_details/trade_details_page.dart @@ -5,6 +5,7 @@ import 'package:flutter/services.dart'; import 'package:flutter_mobx/flutter_mobx.dart'; import 'package:cake_wallet/generated/i18n.dart'; import 'package:cake_wallet/src/stores/exchange_trade/exchange_trade_store.dart'; +import 'package:cake_wallet/src/stores/settings/settings_store.dart'; import 'package:cake_wallet/src/screens/base_page.dart'; import 'package:cake_wallet/src/screens/transaction_details/standart_list_item.dart'; import 'package:cake_wallet/src/screens/transaction_details/standart_list_row.dart'; @@ -17,11 +18,13 @@ class TradeDetailsPage extends BasePage { @override bool get isModalBackButton => true; - final createdAtFormat = DateFormat('yyyy-MM-dd HH:mm:ss'); - @override Widget body(BuildContext context) { final exchangeStore = Provider.of(context); + final settingsStore = Provider.of(context); + final createdAtFormat = settingsStore.currentLocale == 'en_US' + ? DateFormat('yyyy.MM.dd, HH:mm') + : DateFormat('dd.MM.yyyy, HH:mm'); return Container( padding: EdgeInsets.only(top: 10.0, bottom: 10.0, left: 20, right: 15), diff --git a/lib/src/screens/transaction_details/transaction_details_page.dart b/lib/src/screens/transaction_details/transaction_details_page.dart index 670e6de6f..ec2b9a9f1 100644 --- a/lib/src/screens/transaction_details/transaction_details_page.dart +++ b/lib/src/screens/transaction_details/transaction_details_page.dart @@ -42,11 +42,13 @@ class TransactionDetailsForm extends StatefulWidget { } class TransactionDetailsFormState extends State { - final DateFormat _dateFormat = DateFormat('dd.MM.yyyy, HH:mm'); final _items = List(); @override void initState() { + final _dateFormat = widget.settingsStore.currentLocale == 'en_US' + ? DateFormat('yyyy.MM.dd, HH:mm') + : DateFormat('dd.MM.yyyy, HH:mm'); final items = [ StandartListItem( title: S.current.transaction_details_transaction_id, diff --git a/lib/src/stores/settings/settings_store.dart b/lib/src/stores/settings/settings_store.dart index 2faf106d0..7fce06e84 100644 --- a/lib/src/stores/settings/settings_store.dart +++ b/lib/src/stores/settings/settings_store.dart @@ -14,6 +14,7 @@ import 'package:cake_wallet/generated/i18n.dart'; import 'package:cake_wallet/src/domain/common/default_settings_migration.dart'; import 'package:package_info/package_info.dart'; import 'package:cake_wallet/src/domain/common/language.dart'; +import 'package:devicelocale/devicelocale.dart'; part 'settings_store.g.dart'; @@ -31,7 +32,8 @@ abstract class SettingsStoreBase with Store { @required bool initialDarkTheme, this.actionlistDisplayMode, @required int initialPinLength, - @required String initialLanguageCode}) { + @required String initialLanguageCode, + @required String initialCurrentLocale}) { fiatCurrency = initialFiatCurrency; transactionPriority = initialTransactionPriority; balanceDisplayMode = initialBalanceDisplayMode; @@ -42,6 +44,7 @@ abstract class SettingsStoreBase with Store { isDarkTheme = initialDarkTheme; defaultPinLength = initialPinLength; languageCode = initialLanguageCode; + currentLocale = initialCurrentLocale; itemHeaders = Map(); actionlistDisplayMode.observe( @@ -96,6 +99,7 @@ abstract class SettingsStoreBase with Store { sharedPreferences.getString(currentLanguageCode) == null ? await Language.localeDetection() : sharedPreferences.getString(currentLanguageCode); + final initialCurrentLocale = await Devicelocale.currentLocale; final store = SettingsStore( sharedPreferences: sharedPreferences, @@ -108,7 +112,8 @@ abstract class SettingsStoreBase with Store { initialDarkTheme: savedDarkTheme, actionlistDisplayMode: actionlistDisplayMode, initialPinLength: defaultPinLength, - initialLanguageCode: savedLanguageCode); + initialLanguageCode: savedLanguageCode, + initialCurrentLocale: initialCurrentLocale); await store.loadSettings(); @@ -141,8 +146,11 @@ abstract class SettingsStoreBase with Store { @observable int defaultPinLength; + String languageCode; + String currentLocale; + @observable Map itemHeaders; From 3d0d0521e4b162d6d8513eac2bf124d498622a4c Mon Sep 17 00:00:00 2001 From: Oleksandr Sobol Date: Mon, 9 Mar 2020 18:51:54 +0200 Subject: [PATCH 2/2] CWA-180 | added getCurrentDateFormat() to settings store, refactored date_section_raw, trade_details_page, transaction_details_page, dashboard_page --- lib/src/screens/dashboard/dashboard_page.dart | 7 +++---- lib/src/screens/dashboard/date_section_raw.dart | 6 +++--- lib/src/screens/trade_details/trade_details_page.dart | 7 +++---- .../transaction_details/transaction_details_page.dart | 7 +++---- lib/src/stores/settings/settings_store.dart | 7 +++++++ 5 files changed, 19 insertions(+), 15 deletions(-) diff --git a/lib/src/screens/dashboard/dashboard_page.dart b/lib/src/screens/dashboard/dashboard_page.dart index 7b29685f7..5a54eb204 100644 --- a/lib/src/screens/dashboard/dashboard_page.dart +++ b/lib/src/screens/dashboard/dashboard_page.dart @@ -1,5 +1,4 @@ import 'package:provider/provider.dart'; -import 'package:intl/intl.dart'; import 'package:date_range_picker/date_range_picker.dart' as date_rage_picker; import 'package:flutter/material.dart'; import 'package:flutter/cupertino.dart'; @@ -125,9 +124,9 @@ class DashboardPageBodyState extends State { final actionListStore = Provider.of(context); final syncStore = Provider.of(context); final settingsStore = Provider.of(context); - final transactionDateFormat = settingsStore.currentLocale == 'en_US' - ? DateFormat("MMMM d, yyyy, HH:mm", settingsStore.languageCode) - : DateFormat("d MMMM yyyy, HH:mm", settingsStore.languageCode); + final transactionDateFormat = settingsStore.getCurrentDateFormat( + formatUSA: "MMMM d, yyyy, HH:mm", + formatDefault: "d MMMM yyyy, HH:mm"); return Observer( key: _listObserverKey, diff --git a/lib/src/screens/dashboard/date_section_raw.dart b/lib/src/screens/dashboard/date_section_raw.dart index f735278ba..86fc3ff06 100644 --- a/lib/src/screens/dashboard/date_section_raw.dart +++ b/lib/src/screens/dashboard/date_section_raw.dart @@ -19,9 +19,9 @@ class DateSectionRaw extends StatelessWidget { nowDate.year == date.year; final settingsStore = Provider.of(context); final currentLanguage = settingsStore.languageCode; - final dateSectionDateFormat = settingsStore.currentLocale == 'en_US' - ? DateFormat("MMM d", settingsStore.languageCode) - : DateFormat("d MMM", settingsStore.languageCode); + final dateSectionDateFormat = settingsStore.getCurrentDateFormat( + formatUSA: "MMM d", + formatDefault: "d MMM"); var title = ""; if (isToday) { diff --git a/lib/src/screens/trade_details/trade_details_page.dart b/lib/src/screens/trade_details/trade_details_page.dart index 0d25254a0..508443e0d 100644 --- a/lib/src/screens/trade_details/trade_details_page.dart +++ b/lib/src/screens/trade_details/trade_details_page.dart @@ -9,7 +9,6 @@ import 'package:cake_wallet/src/stores/settings/settings_store.dart'; import 'package:cake_wallet/src/screens/base_page.dart'; import 'package:cake_wallet/src/screens/transaction_details/standart_list_item.dart'; import 'package:cake_wallet/src/screens/transaction_details/standart_list_row.dart'; -import 'package:intl/intl.dart'; class TradeDetailsPage extends BasePage { @override @@ -22,9 +21,9 @@ class TradeDetailsPage extends BasePage { Widget body(BuildContext context) { final exchangeStore = Provider.of(context); final settingsStore = Provider.of(context); - final createdAtFormat = settingsStore.currentLocale == 'en_US' - ? DateFormat('yyyy.MM.dd, HH:mm') - : DateFormat('dd.MM.yyyy, HH:mm'); + final createdAtFormat = settingsStore.getCurrentDateFormat( + formatUSA: "yyyy.MM.dd, HH:mm", + formatDefault: "dd.MM.yyyy, HH:mm"); return Container( padding: EdgeInsets.only(top: 10.0, bottom: 10.0, left: 20, right: 15), diff --git a/lib/src/screens/transaction_details/transaction_details_page.dart b/lib/src/screens/transaction_details/transaction_details_page.dart index ec2b9a9f1..c25dbaa1e 100644 --- a/lib/src/screens/transaction_details/transaction_details_page.dart +++ b/lib/src/screens/transaction_details/transaction_details_page.dart @@ -1,4 +1,3 @@ -import 'package:intl/intl.dart'; import 'package:provider/provider.dart'; import 'package:flutter/material.dart'; import 'package:flutter/cupertino.dart'; @@ -46,9 +45,9 @@ class TransactionDetailsFormState extends State { @override void initState() { - final _dateFormat = widget.settingsStore.currentLocale == 'en_US' - ? DateFormat('yyyy.MM.dd, HH:mm') - : DateFormat('dd.MM.yyyy, HH:mm'); + final _dateFormat = widget.settingsStore.getCurrentDateFormat( + formatUSA: "yyyy.MM.dd, HH:mm", + formatDefault: "dd.MM.yyyy, HH:mm"); final items = [ StandartListItem( title: S.current.transaction_details_transaction_id, diff --git a/lib/src/stores/settings/settings_store.dart b/lib/src/stores/settings/settings_store.dart index 7fce06e84..b3fe22e5a 100644 --- a/lib/src/stores/settings/settings_store.dart +++ b/lib/src/stores/settings/settings_store.dart @@ -15,6 +15,7 @@ import 'package:cake_wallet/src/domain/common/default_settings_migration.dart'; import 'package:package_info/package_info.dart'; import 'package:cake_wallet/src/domain/common/language.dart'; import 'package:devicelocale/devicelocale.dart'; +import 'package:intl/intl.dart'; part 'settings_store.g.dart'; @@ -287,4 +288,10 @@ abstract class SettingsStoreBase with Store { await changeCurrentNodeToDefault(sharedPreferences: _sharedPreferences, nodes: _nodes); await loadSettings(); } + + DateFormat getCurrentDateFormat({ + @required String formatUSA, + @required String formatDefault}) => currentLocale == 'en_US' + ? DateFormat(formatUSA, languageCode) + : DateFormat(formatDefault, languageCode); }