Custom colors

This commit is contained in:
Hillel Coren 2021-07-27 10:06:39 +03:00
parent ddc659a517
commit 265a905a0f
7 changed files with 105 additions and 30 deletions

View File

@ -49,6 +49,8 @@ class UpdateSettingsTab implements PersistUI {
final int tabIndex; final int tabIndex;
} }
class UpdatedSetting implements PersistUI {}
class UpdateSettingsTemplate implements PersistUI { class UpdateSettingsTemplate implements PersistUI {
UpdateSettingsTemplate({@required this.selectedTemplate}); UpdateSettingsTemplate({@required this.selectedTemplate});

View File

@ -113,4 +113,8 @@ Reducer<SettingsUIState> settingsUIReducer = combineReducers([
TypedReducer<SettingsUIState, UpdateSettingsTemplate>((state, action) { TypedReducer<SettingsUIState, UpdateSettingsTemplate>((state, action) {
return state.rebuild((b) => b..selectedTemplate = action.selectedTemplate); return state.rebuild((b) => b..selectedTemplate = action.selectedTemplate);
}), }),
TypedReducer<SettingsUIState, UpdatedSetting>((state, action) {
return state
.rebuild((b) => b..updatedAt = DateTime.now().millisecondsSinceEpoch);
}),
]); ]);

View File

@ -45,7 +45,8 @@ abstract class PrefState implements Built<PrefState, PrefStateBuilder> {
static const THEME_INVOICE_HEADER_BACKGROUND_COLOR = static const THEME_INVOICE_HEADER_BACKGROUND_COLOR =
'invoice_header_background_color'; 'invoice_header_background_color';
static const THEME_INVOICE_HEADER_FONT_COLOR = 'invoice_header_font_color'; static const THEME_INVOICE_HEADER_FONT_COLOR = 'invoice_header_font_color';
static const THEME_ALTERNATE_ROW_COLOR = 'alternate_row_color'; static const THEME_TABLE_ALTERNATE_ROW_BACKGROUND_COLOR =
'table_alternate_row_background_color';
@override @override
@memoized @memoized

View File

@ -75,8 +75,9 @@ class EntityDataTableSource extends AppDataTableSource {
} }
Color backgroundColor; Color backgroundColor;
final rowColor = final rowColor = state.prefState.customColors[
state.prefState.customColors[PrefState.THEME_ALTERNATE_ROW_COLOR] ?? ''; PrefState.THEME_TABLE_ALTERNATE_ROW_BACKGROUND_COLOR] ??
'';
if (isSelected && isDesktop(context)) { if (isSelected && isDesktop(context)) {
backgroundColor = convertHexStringToColor(state.prefState.enableDarkMode backgroundColor = convertHexStringToColor(state.prefState.enableDarkMode

View File

@ -265,7 +265,7 @@ class _DeviceSettingsState extends State<DeviceSettings>
SizedBox(height: 16), SizedBox(height: 16),
AppDropdownButton<String>( AppDropdownButton<String>(
showUseDefault: true, showUseDefault: true,
labelText: localization.colorTheme, labelText: localization.statusColorTheme,
value: state.prefState.colorTheme, value: state.prefState.colorTheme,
items: [ items: [
...colorThemesMap.keys ...colorThemesMap.keys
@ -318,27 +318,75 @@ class _DeviceSettingsState extends State<DeviceSettings>
]), ]),
FormCard( FormCard(
children: [ children: [
PrefState.THEME_SIDEBAR_ACTIVE_BACKGROUND_COLOR, AppDropdownButton<String>(
PrefState.THEME_SIDEBAR_ACTIVE_FONT_COLOR, labelText: localization.loadColorTheme,
PrefState.THEME_SIDEBAR_INACTIVE_BACKGROUND_COLOR, value: '',
PrefState.THEME_SIDEBAR_INACTIVE_FONT_COLOR, onChanged: (dynamic value) {
PrefState.THEME_INVOICE_HEADER_BACKGROUND_COLOR, if (value == 'default') {
PrefState.THEME_INVOICE_HEADER_FONT_COLOR,
PrefState.THEME_ALTERNATE_ROW_COLOR,
]
.map(
(selector) => FormColorPicker(
labelText: localization.lookup(selector),
initialValue: prefState.customColors[selector],
onSelected: (value) {
viewModel.onCustomColorsChanged( viewModel.onCustomColorsChanged(
context, context,
prefState.customColors prefState.customColors
.rebuild((b) => b[selector] = value ?? '')); .rebuild((b) => b..clear()));
}, } else if (value == 'legacy') {
), viewModel.onCustomColorsChanged(
) context,
.toList(), prefState.customColors.rebuild(
(b) => b.addAll(
<String, String>{
PrefState
.THEME_SIDEBAR_ACTIVE_BACKGROUND_COLOR:
'#444444',
PrefState.THEME_SIDEBAR_ACTIVE_FONT_COLOR:
'#FFFFFF',
PrefState
.THEME_SIDEBAR_INACTIVE_BACKGROUND_COLOR:
'#2F2F2F',
PrefState.THEME_SIDEBAR_INACTIVE_FONT_COLOR:
'#FFFFFF',
PrefState
.THEME_INVOICE_HEADER_BACKGROUND_COLOR:
'#777777',
PrefState.THEME_INVOICE_HEADER_FONT_COLOR:
'#FFFFFF',
PrefState
.THEME_TABLE_ALTERNATE_ROW_BACKGROUND_COLOR:
'#F9F9F9',
},
),
),
);
}
},
items: [
DropdownMenuItem(
child: Text(localization.defaultClearAll),
value: 'default'),
DropdownMenuItem(
child: Text(localization.legacy), value: 'legacy'),
]),
...[
PrefState.THEME_SIDEBAR_ACTIVE_BACKGROUND_COLOR,
PrefState.THEME_SIDEBAR_ACTIVE_FONT_COLOR,
PrefState.THEME_SIDEBAR_INACTIVE_BACKGROUND_COLOR,
PrefState.THEME_SIDEBAR_INACTIVE_FONT_COLOR,
PrefState.THEME_INVOICE_HEADER_BACKGROUND_COLOR,
PrefState.THEME_INVOICE_HEADER_FONT_COLOR,
PrefState.THEME_TABLE_ALTERNATE_ROW_BACKGROUND_COLOR,
]
.map(
(selector) => FormColorPicker(
labelText: localization.lookup(selector),
initialValue: prefState.customColors[selector],
onSelected: (value) {
viewModel.onCustomColorsChanged(
context,
prefState.customColors
.rebuild((b) => b[selector] = value ?? ''));
},
),
)
.toList()
],
) )
], ],
) )

View File

@ -8,6 +8,7 @@ import 'package:invoiceninja_flutter/redux/app/app_actions.dart';
import 'package:invoiceninja_flutter/redux/app/app_state.dart'; import 'package:invoiceninja_flutter/redux/app/app_state.dart';
import 'package:invoiceninja_flutter/redux/auth/auth_actions.dart'; import 'package:invoiceninja_flutter/redux/auth/auth_actions.dart';
import 'package:invoiceninja_flutter/redux/dashboard/dashboard_actions.dart'; import 'package:invoiceninja_flutter/redux/dashboard/dashboard_actions.dart';
import 'package:invoiceninja_flutter/redux/settings/settings_actions.dart';
import 'package:invoiceninja_flutter/redux/ui/pref_state.dart'; import 'package:invoiceninja_flutter/redux/ui/pref_state.dart';
import 'package:invoiceninja_flutter/ui/app/app_builder.dart'; import 'package:invoiceninja_flutter/ui/app/app_builder.dart';
import 'package:invoiceninja_flutter/ui/settings/device_settings.dart'; import 'package:invoiceninja_flutter/ui/settings/device_settings.dart';
@ -144,8 +145,8 @@ class DeviceSettingsVM {
}, },
), ),
onCustomColorsChanged: (context, customColors) { onCustomColorsChanged: (context, customColors) {
print('## COOLRS: $customColors');
store.dispatch(UpdateUserPreferences(customColors: customColors)); store.dispatch(UpdateUserPreferences(customColors: customColors));
store.dispatch(UpdatedSetting());
}); });
} }

View File

@ -15,13 +15,16 @@ mixin LocalizationsProvider on LocaleCodeAware {
static final Map<String, Map<String, String>> _localizedValues = { static final Map<String, Map<String, String>> _localizedValues = {
'en': { 'en': {
// STARTER: lang key - do not remove comment // STARTER: lang key - do not remove comment
'default_clear_all': 'Default - Clear All',
'legacy': 'Legacy',
'custom_colors': 'Custom Colors', 'custom_colors': 'Custom Colors',
'colors': 'Colors', 'colors': 'Colors',
'sidebar_active_background_color': 'Sidebar Active Background Color', 'sidebar_active_background_color': 'Sidebar Active Background Color',
'sidebar_active_font_color': 'Sidebar Active Font Color', 'sidebar_active_font_color': 'Sidebar Active Font Color',
'sidebar_inactive_background_color': 'Sidebar Inactive Background Color', 'sidebar_inactive_background_color': 'Sidebar Inactive Background Color',
'sidebar_inactive_font_color': 'Sidebar Inactive Font Color', 'sidebar_inactive_font_color': 'Sidebar Inactive Font Color',
'alternate_row_color': 'Alternate Row Color', 'table_alternate_row_background_color':
'Table Alternate Row Background Color',
'invoice_header_background_color': 'Invoice Header Background Color', 'invoice_header_background_color': 'Invoice Header Background Color',
'invoice_header_font_color': 'Invoice Header Font Color', 'invoice_header_font_color': 'Invoice Header Font Color',
'net_subtotal': 'Net Subtotal', 'net_subtotal': 'Net Subtotal',
@ -1837,7 +1840,8 @@ mixin LocalizationsProvider on LocaleCodeAware {
'tax_name2': 'Tax Name 2', 'tax_name2': 'Tax Name 2',
'tax_name3': 'Tax Name 3', 'tax_name3': 'Tax Name 3',
'transaction_id': 'Transaction ID', 'transaction_id': 'Transaction ID',
'color_theme': 'Color Theme', 'status_color_theme': 'Status Color Theme',
'load_color_theme': 'Load Color Theme',
}, },
'sq': { 'sq': {
'import_data': 'Importo të dhëna', 'import_data': 'Importo të dhëna',
@ -61835,8 +61839,6 @@ mixin LocalizationsProvider on LocaleCodeAware {
String get convertedTotal => String get convertedTotal =>
_localizedValues[localeCode]['converted_total'] ?? ''; _localizedValues[localeCode]['converted_total'] ?? '';
String get colorTheme => _localizedValues[localeCode]['color_theme'] ?? '';
String get emailSentToConfirmEmail => String get emailSentToConfirmEmail =>
_localizedValues[localeCode]['email_sent_to_confirm_email'] ?? ''; _localizedValues[localeCode]['email_sent_to_confirm_email'] ?? '';
@ -62393,9 +62395,9 @@ mixin LocalizationsProvider on LocaleCodeAware {
_localizedValues[localeCode]['sidebar_inactive_font_color'] ?? _localizedValues[localeCode]['sidebar_inactive_font_color'] ??
_localizedValues['en']['sidebar_inactive_font_color']; _localizedValues['en']['sidebar_inactive_font_color'];
String get alternateRowColor => String get tableAlternateRowBackgroundColor =>
_localizedValues[localeCode]['alternate_row_color'] ?? _localizedValues[localeCode]['table_alternate_row_background_color'] ??
_localizedValues['en']['alternate_row_color']; _localizedValues['en']['table_alternate_row_background_color'];
String get invoiceHeaderBackgroundColor => String get invoiceHeaderBackgroundColor =>
_localizedValues[localeCode]['invoice_header_background_color'] ?? _localizedValues[localeCode]['invoice_header_background_color'] ??
@ -62413,6 +62415,22 @@ mixin LocalizationsProvider on LocaleCodeAware {
_localizedValues[localeCode]['custom_colors'] ?? _localizedValues[localeCode]['custom_colors'] ??
_localizedValues['en']['custom_colors']; _localizedValues['en']['custom_colors'];
String get statusColorTheme =>
_localizedValues[localeCode]['status_color_theme'] ??
_localizedValues['en']['status_color_theme'];
String get loadColorTheme =>
_localizedValues[localeCode]['load_color_theme'] ??
_localizedValues['en']['load_color_theme'];
String get defaultClearAll =>
_localizedValues[localeCode]['default_clear_all'] ??
_localizedValues['en']['default_clear_all'];
String get legacy =>
_localizedValues[localeCode]['legacy'] ??
_localizedValues['en']['legacy'];
String lookup(String key) { String lookup(String key) {
final lookupKey = toSnakeCase(key); final lookupKey = toSnakeCase(key);