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;
}
class UpdatedSetting implements PersistUI {}
class UpdateSettingsTemplate implements PersistUI {
UpdateSettingsTemplate({@required this.selectedTemplate});

View File

@ -113,4 +113,8 @@ Reducer<SettingsUIState> settingsUIReducer = combineReducers([
TypedReducer<SettingsUIState, UpdateSettingsTemplate>((state, action) {
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 =
'invoice_header_background_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
@memoized

View File

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

View File

@ -265,7 +265,7 @@ class _DeviceSettingsState extends State<DeviceSettings>
SizedBox(height: 16),
AppDropdownButton<String>(
showUseDefault: true,
labelText: localization.colorTheme,
labelText: localization.statusColorTheme,
value: state.prefState.colorTheme,
items: [
...colorThemesMap.keys
@ -318,13 +318,60 @@ class _DeviceSettingsState extends State<DeviceSettings>
]),
FormCard(
children: [
AppDropdownButton<String>(
labelText: localization.loadColorTheme,
value: '',
onChanged: (dynamic value) {
if (value == 'default') {
viewModel.onCustomColorsChanged(
context,
prefState.customColors
.rebuild((b) => b..clear()));
} else if (value == 'legacy') {
viewModel.onCustomColorsChanged(
context,
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_ALTERNATE_ROW_COLOR,
PrefState.THEME_TABLE_ALTERNATE_ROW_BACKGROUND_COLOR,
]
.map(
(selector) => FormColorPicker(
@ -338,7 +385,8 @@ class _DeviceSettingsState extends State<DeviceSettings>
},
),
)
.toList(),
.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/auth/auth_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/ui/app/app_builder.dart';
import 'package:invoiceninja_flutter/ui/settings/device_settings.dart';
@ -144,8 +145,8 @@ class DeviceSettingsVM {
},
),
onCustomColorsChanged: (context, customColors) {
print('## COOLRS: $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 = {
'en': {
// STARTER: lang key - do not remove comment
'default_clear_all': 'Default - Clear All',
'legacy': 'Legacy',
'custom_colors': 'Custom Colors',
'colors': 'Colors',
'sidebar_active_background_color': 'Sidebar Active Background Color',
'sidebar_active_font_color': 'Sidebar Active Font Color',
'sidebar_inactive_background_color': 'Sidebar Inactive Background 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_font_color': 'Invoice Header Font Color',
'net_subtotal': 'Net Subtotal',
@ -1837,7 +1840,8 @@ mixin LocalizationsProvider on LocaleCodeAware {
'tax_name2': 'Tax Name 2',
'tax_name3': 'Tax Name 3',
'transaction_id': 'Transaction ID',
'color_theme': 'Color Theme',
'status_color_theme': 'Status Color Theme',
'load_color_theme': 'Load Color Theme',
},
'sq': {
'import_data': 'Importo të dhëna',
@ -61835,8 +61839,6 @@ mixin LocalizationsProvider on LocaleCodeAware {
String get convertedTotal =>
_localizedValues[localeCode]['converted_total'] ?? '';
String get colorTheme => _localizedValues[localeCode]['color_theme'] ?? '';
String get emailSentToConfirmEmail =>
_localizedValues[localeCode]['email_sent_to_confirm_email'] ?? '';
@ -62393,9 +62395,9 @@ mixin LocalizationsProvider on LocaleCodeAware {
_localizedValues[localeCode]['sidebar_inactive_font_color'] ??
_localizedValues['en']['sidebar_inactive_font_color'];
String get alternateRowColor =>
_localizedValues[localeCode]['alternate_row_color'] ??
_localizedValues['en']['alternate_row_color'];
String get tableAlternateRowBackgroundColor =>
_localizedValues[localeCode]['table_alternate_row_background_color'] ??
_localizedValues['en']['table_alternate_row_background_color'];
String get invoiceHeaderBackgroundColor =>
_localizedValues[localeCode]['invoice_header_background_color'] ??
@ -62413,6 +62415,22 @@ mixin LocalizationsProvider on LocaleCodeAware {
_localizedValues[localeCode]['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) {
final lookupKey = toSnakeCase(key);