Skip to content

Commit

Permalink
Merge pull request #53 from enrique-lozano/amoled-mode
Browse files Browse the repository at this point in the history
Optional AMOLED mode
  • Loading branch information
enrique-lozano authored Oct 11, 2023
2 parents 877e7f3 + c98709d commit 2bead1c
Show file tree
Hide file tree
Showing 9 changed files with 61 additions and 7 deletions.
1 change: 1 addition & 0 deletions assets/sql/initial_data.sql
Original file line number Diff line number Diff line change
Expand Up @@ -314,4 +314,5 @@ INSERT INTO userSettings VALUES
('userName', 'User'),
('appLanguage', null),
('accentColor', 'auto'),
('amoledMode', '0'),
('themeMode', 'system');
3 changes: 2 additions & 1 deletion assets/sql/migrations/v5.sql
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
INSERT INTO userSettings VALUES ('accentColor', 'auto');
INSERT INTO userSettings VALUES ('accentColor', 'auto'),
('amoledMode', '0');
20 changes: 20 additions & 0 deletions lib/app/settings/appearance_settings_page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,26 @@ class _AdvancedSettingsPageState extends State<AdvancedSettingsPage> {
},
);
}),
StreamBuilder(
stream: UserSettingService.instance
.getSetting(SettingKey.amoledMode)
.map((event) => event == '1'),
initialData: true,
builder: (context, snapshot) {
return SwitchListTile(
title: Text(t.settings.general.amoled_mode),
subtitle: Text(t.settings.general.amoled_mode_descr),
value: snapshot.data!,
onChanged: Theme.of(context).brightness == Brightness.light
? null
: (bool value) {
setState(() {
UserSettingService.instance.setSetting(
SettingKey.amoledMode, value ? '1' : '0');
});
},
);
}),
StreamBuilder(
stream: UserSettingService.instance
.getSetting(SettingKey.accentColor)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,9 @@ enum SettingKey {
/// Key to storage the app accentColor. It's a string representing the color in HEX format (without the `#`) or the string 'auto' to apply dynamic colors if possible (if not possible will default to the Monekin blue brand color)
accentColor,

/// Key to storage if the user have the AMOLED mode activated. Could be '1' (true) or '0' (false)
amoledMode,

/// Key to storage if we should display a calculator in the transaction-form page. Could be '1' (true) or '0' (false)
transactionMobileMode,
}
Expand Down
13 changes: 10 additions & 3 deletions lib/core/presentation/theme.dart
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ class CustomColors extends ThemeExtension<CustomColors> {
ThemeData getThemeData(
BuildContext context, {
required bool isDark,
required bool amoledMode,
required ColorScheme? lightDynamic,
required ColorScheme? darkDynamic,
required String accentColor,
Expand All @@ -90,6 +91,11 @@ ThemeData getThemeData(

// Repeat for the dark color scheme.
darkColorScheme = darkDynamic.harmonized();

if (amoledMode) {
darkColorScheme = darkColorScheme.copyWith(background: Colors.black);
}

darkCustomColors = darkCustomColors.harmonized(darkColorScheme);

isAppUsingDynamicColors = true; // ignore, only for demo purposes
Expand All @@ -99,9 +105,10 @@ ThemeData getThemeData(
seedColor: accentColor == 'auto' ? _brandBlue : ColorHex.get(accentColor),
);
darkColorScheme = ColorScheme.fromSeed(
seedColor: accentColor == 'auto' ? _brandBlue : ColorHex.get(accentColor),
brightness: Brightness.dark,
);
seedColor:
accentColor == 'auto' ? _brandBlue : ColorHex.get(accentColor),
brightness: Brightness.dark,
background: amoledMode ? Colors.black : null);
}

theme = ThemeData(
Expand Down
2 changes: 2 additions & 0 deletions lib/i18n/strings_en.json
Original file line number Diff line number Diff line change
Expand Up @@ -522,6 +522,8 @@
"theme.auto": "Defined by the system",
"theme.light": "Light",
"theme.dark": "Dark",
"amoled-mode": "AMOLED mode",
"amoled-mode.descr": "Use a pure black wallpaper when possible. This will slightly help the battery of devices with AMOLED screens",
"dynamic-colors": "Dynamic colors",
"dynamic-colors.descr": "Use your system accent color whenever possible",
"accent-color": "Accent color",
Expand Down
2 changes: 2 additions & 0 deletions lib/i18n/strings_es.json
Original file line number Diff line number Diff line change
Expand Up @@ -524,6 +524,8 @@
"theme.auto": "Definido por el sistema",
"theme.light": "Claro",
"theme.dark": "Oscuro",
"amoled-mode": "Modo AMOLED",
"amoled-mode.descr": "Usa un fondo de pantalla negro puro cuando sea posible. Esto ayudará ligeramente a la bateria de dispositivos con pantallas AMOLED",
"dynamic-colors": "Colores dinámicos",
"dynamic-colors.descr": "Usa el color de acentuación de su sistema siempre que sea posible",
"accent-color": "Color de acentuación",
Expand Down
12 changes: 10 additions & 2 deletions lib/i18n/translations.g.dart
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@
/// To regenerate, run: `dart run slang`
///
/// Locales: 2
/// Strings: 884 (442 per locale)
/// Strings: 888 (444 per locale)
///
/// Built on 2023-10-10 at 22:44 UTC
/// Built on 2023-10-11 at 10:27 UTC
// coverage:ignore-file
// ignore_for_file: type=lint
Expand Down Expand Up @@ -914,6 +914,8 @@ class _TranslationsSettingsGeneralEn {
String get theme_auto => 'Defined by the system';
String get theme_light => 'Light';
String get theme_dark => 'Dark';
String get amoled_mode => 'AMOLED mode';
String get amoled_mode_descr => 'Use a pure black wallpaper when possible. This will slightly help the battery of devices with AMOLED screens';
String get dynamic_colors => 'Dynamic colors';
String get dynamic_colors_descr => 'Use your system accent color whenever possible';
String get accent_color => 'Accent color';
Expand Down Expand Up @@ -1955,6 +1957,8 @@ class _TranslationsSettingsGeneralEs implements _TranslationsSettingsGeneralEn {
@override String get theme_auto => 'Definido por el sistema';
@override String get theme_light => 'Claro';
@override String get theme_dark => 'Oscuro';
@override String get amoled_mode => 'Modo AMOLED';
@override String get amoled_mode_descr => 'Usa un fondo de pantalla negro puro cuando sea posible. Esto ayudará ligeramente a la bateria de dispositivos con pantallas AMOLED';
@override String get dynamic_colors => 'Colores dinámicos';
@override String get dynamic_colors_descr => 'Usa el color de acentuación de su sistema siempre que sea posible';
@override String get accent_color => 'Color de acentuación';
Expand Down Expand Up @@ -2635,6 +2639,8 @@ extension on _TranslationsEn {
case 'settings.general.theme_auto': return 'Defined by the system';
case 'settings.general.theme_light': return 'Light';
case 'settings.general.theme_dark': return 'Dark';
case 'settings.general.amoled_mode': return 'AMOLED mode';
case 'settings.general.amoled_mode_descr': return 'Use a pure black wallpaper when possible. This will slightly help the battery of devices with AMOLED screens';
case 'settings.general.dynamic_colors': return 'Dynamic colors';
case 'settings.general.dynamic_colors_descr': return 'Use your system accent color whenever possible';
case 'settings.general.accent_color': return 'Accent color';
Expand Down Expand Up @@ -3104,6 +3110,8 @@ extension on _TranslationsEs {
case 'settings.general.theme_auto': return 'Definido por el sistema';
case 'settings.general.theme_light': return 'Claro';
case 'settings.general.theme_dark': return 'Oscuro';
case 'settings.general.amoled_mode': return 'Modo AMOLED';
case 'settings.general.amoled_mode_descr': return 'Usa un fondo de pantalla negro puro cuando sea posible. Esto ayudará ligeramente a la bateria de dispositivos con pantallas AMOLED';
case 'settings.general.dynamic_colors': return 'Colores dinámicos';
case 'settings.general.dynamic_colors_descr': return 'Usa el color de acentuación de su sistema siempre que sea posible';
case 'settings.general.accent_color': return 'Color de acentuación';
Expand Down
12 changes: 11 additions & 1 deletion lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ class MonekinAppEntryPoint extends StatelessWidget {
UserSettingService.instance.getSettings((p0) =>
p0.settingKey.equalsValue(SettingKey.appLanguage) |
p0.settingKey.equalsValue(SettingKey.themeMode) |
p0.settingKey.equalsValue(SettingKey.amoledMode) |
p0.settingKey.equalsValue(SettingKey.accentColor)),
AppDataService.instance
.getAppDataItems((p0) => AppDB.instance.buildExpr([])),
Expand Down Expand Up @@ -76,6 +77,11 @@ class MonekinAppEntryPoint extends StatelessWidget {
return TranslationProvider(
child: MaterialAppContainer(
goToIntro: userHasSeenIntro != '1',
amoledMode: userSettings
.firstWhere((element) =>
element.settingKey == SettingKey.amoledMode)
.settingValue! ==
'1',
accentColor: userSettings
.firstWhere((element) =>
element.settingKey == SettingKey.accentColor)
Expand All @@ -96,11 +102,13 @@ class MaterialAppContainer extends StatelessWidget {
{super.key,
required this.themeMode,
required this.goToIntro,
required this.accentColor});
required this.accentColor,
required this.amoledMode});

final ThemeMode themeMode;
final bool goToIntro;
final String accentColor;
final bool amoledMode;

@override
Widget build(BuildContext context) {
Expand All @@ -117,11 +125,13 @@ class MaterialAppContainer extends StatelessWidget {
localizationsDelegates: GlobalMaterialLocalizations.delegates,
theme: getThemeData(context,
isDark: false,
amoledMode: amoledMode,
lightDynamic: lightDynamic,
darkDynamic: darkDynamic,
accentColor: accentColor),
darkTheme: getThemeData(context,
isDark: true,
amoledMode: amoledMode,
lightDynamic: lightDynamic,
darkDynamic: darkDynamic,
accentColor: accentColor),
Expand Down

0 comments on commit 2bead1c

Please sign in to comment.