Skip to content

Commit

Permalink
Merge pull request #280 from mateusz-bak/feat/amoled_theme
Browse files Browse the repository at this point in the history
Feat/amoled theme
  • Loading branch information
mateusz-bak authored Jul 9, 2023
2 parents 13d3e05 + 29ce1ff commit ad2df8a
Show file tree
Hide file tree
Showing 10 changed files with 1,663 additions and 1,412 deletions.
6 changes: 5 additions & 1 deletion assets/translations/en-US.json
Original file line number Diff line number Diff line change
Expand Up @@ -245,5 +245,9 @@
"migration_v1_to_v2_retrigger": "Run the v2.0 migration again",
"migration_v1_to_v2_retrigger_description": "Click if books are not showing up after update to v2.0.",
"click_here_to_restore_them" : "Click here to restore them",
"this_msg_will_only_be_displayed_three_times" : "This message will only be displayed three times."
"this_msg_will_only_be_displayed_three_times" : "This message will only be displayed three times.",

"dark_mode_style": "Dark mode style",
"dark_mode_natural": "Natural dark mode",
"dark_mode_amoled": "AMOLED dark mode"
}
3 changes: 3 additions & 0 deletions lib/generated/locale_keys.g.dart
Original file line number Diff line number Diff line change
Expand Up @@ -230,4 +230,7 @@ abstract class LocaleKeys {
static const click_here_to_restore_them = 'click_here_to_restore_them';
static const this_msg_will_only_be_displayed_three_times =
'this_msg_will_only_be_displayed_three_times';
static const dark_mode_style = 'dark_mode_style';
static const dark_mode_natural = 'dark_mode_natural';
static const dark_mode_amoled = 'dark_mode_amoled';
}
10 changes: 10 additions & 0 deletions lib/logic/bloc/theme_bloc/theme_bloc.dart
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ class ThemeBloc extends HydratedBloc<ThemeEvent, ThemeState> {
fontFamily: 'Nunito',
readTabFirst: true,
useMaterialYou: true,
amoledDark: false,
)) {
on<ChangeThemeEvent>((event, emit) {
fontFamily = event.fontFamily;
Expand All @@ -31,6 +32,7 @@ class ThemeBloc extends HydratedBloc<ThemeEvent, ThemeState> {
fontFamily: fontFamily,
readTabFirst: event.readTabFirst,
useMaterialYou: event.useMaterialYou,
amoledDark: event.amoledDark,
));
});
}
Expand All @@ -44,6 +46,7 @@ class ThemeBloc extends HydratedBloc<ThemeEvent, ThemeState> {
final fontFamily = json['font_family'] as String?;
final readTabFirst = json['read_tab_first'] as bool?;
final useMaterialYou = json['use_material_you'] as bool?;
final amoledDark = json['amoled_dark'] as bool?;

switch (themeState) {
case 1:
Expand All @@ -55,6 +58,7 @@ class ThemeBloc extends HydratedBloc<ThemeEvent, ThemeState> {
fontFamily: fontFamily ?? 'Nunito',
readTabFirst: readTabFirst ?? true,
useMaterialYou: useMaterialYou ?? true,
amoledDark: amoledDark ?? false,
);
case 2:
return SetThemeState(
Expand All @@ -65,6 +69,7 @@ class ThemeBloc extends HydratedBloc<ThemeEvent, ThemeState> {
fontFamily: fontFamily ?? 'Nunito',
readTabFirst: readTabFirst ?? true,
useMaterialYou: useMaterialYou ?? true,
amoledDark: amoledDark ?? false,
);
default:
return SetThemeState(
Expand All @@ -75,6 +80,7 @@ class ThemeBloc extends HydratedBloc<ThemeEvent, ThemeState> {
fontFamily: fontFamily ?? 'Nunito',
readTabFirst: readTabFirst ?? true,
useMaterialYou: useMaterialYou ?? true,
amoledDark: amoledDark ?? false,
);
}
}
Expand All @@ -92,6 +98,7 @@ class ThemeBloc extends HydratedBloc<ThemeEvent, ThemeState> {
'font_family': state.fontFamily,
'read_tab_first': state.readTabFirst,
'use_material_you': state.useMaterialYou,
'amoled_dark': state.amoledDark,
};
case ThemeMode.dark:
return {
Expand All @@ -102,6 +109,7 @@ class ThemeBloc extends HydratedBloc<ThemeEvent, ThemeState> {
'font_family': state.fontFamily,
'read_tab_first': state.readTabFirst,
'use_material_you': state.useMaterialYou,
'amoled_dark': state.amoledDark,
};
case ThemeMode.system:
return {
Expand All @@ -112,6 +120,7 @@ class ThemeBloc extends HydratedBloc<ThemeEvent, ThemeState> {
'font_family': state.fontFamily,
'read_tab_first': state.readTabFirst,
'use_material_you': state.useMaterialYou,
'amoled_dark': state.amoledDark,
};
}
} else {
Expand All @@ -124,6 +133,7 @@ class ThemeBloc extends HydratedBloc<ThemeEvent, ThemeState> {
'read_tab_first': null,
'use_material_you': null,
'locale': null,
'amoled_dark': false,
};
}
}
Expand Down
3 changes: 3 additions & 0 deletions lib/logic/bloc/theme_bloc/theme_event.dart
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ class ChangeThemeEvent extends ThemeEvent {
final String? fontFamily;
final bool readTabFirst;
final bool useMaterialYou;
final bool amoledDark;

const ChangeThemeEvent({
required this.themeMode,
Expand All @@ -21,6 +22,7 @@ class ChangeThemeEvent extends ThemeEvent {
required this.fontFamily,
required this.readTabFirst,
required this.useMaterialYou,
required this.amoledDark,
});

@override
Expand All @@ -32,5 +34,6 @@ class ChangeThemeEvent extends ThemeEvent {
fontFamily,
readTabFirst,
useMaterialYou,
amoledDark,
];
}
3 changes: 3 additions & 0 deletions lib/logic/bloc/theme_bloc/theme_state.dart
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ class SetThemeState extends ThemeState {
final String? fontFamily;
final bool readTabFirst;
final bool useMaterialYou;
final bool amoledDark;

const SetThemeState({
required this.themeMode,
Expand All @@ -28,6 +29,7 @@ class SetThemeState extends ThemeState {
required this.fontFamily,
required this.readTabFirst,
required this.useMaterialYou,
required this.amoledDark,
});

@override
Expand All @@ -39,5 +41,6 @@ class SetThemeState extends ThemeState {
fontFamily,
readTabFirst,
useMaterialYou,
amoledDark,
];
}
11 changes: 11 additions & 0 deletions lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,12 @@ class _OpenreadsAppState extends State<OpenreadsApp>
Widget build(BuildContext context) {
return DynamicColorBuilder(
builder: (ColorScheme? lightDynamic, ColorScheme? darkDynamic) {
if (widget.themeState.amoledDark) {
darkDynamic = darkDynamic?.copyWith(
background: Colors.black,
);
}

return MaterialApp(
title: 'Openreads',
builder: (context, child) => MediaQuery(
Expand All @@ -171,6 +177,11 @@ class _OpenreadsAppState extends State<OpenreadsApp>
colorScheme: widget.themeState.useMaterialYou ? darkDynamic : null,
brightness: Brightness.dark,
fontFamily: widget.themeState.fontFamily,
scaffoldBackgroundColor:
widget.themeState.amoledDark ? Colors.black : null,
appBarTheme: widget.themeState.amoledDark
? const AppBarTheme(backgroundColor: Colors.black)
: null,
),
themeMode: widget.themeState.themeMode,
home: welcomeMode
Expand Down
4 changes: 2 additions & 2 deletions lib/ui/books_screen/books_screen.dart
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import 'package:openreads/logic/bloc/theme_bloc/theme_bloc.dart';
import 'package:openreads/main.dart';
import 'package:openreads/model/book.dart';
import 'package:openreads/ui/add_book_screen/add_book_screen.dart';
import 'package:openreads/ui/backup_screen/backup_screen.dart';
import 'package:openreads/ui/settings_backup_screen/settings_backup_screen.dart';
import 'package:openreads/ui/books_screen/widgets/widgets.dart';
import 'package:openreads/ui/search_ol_screen/search_ol_screen.dart.dart';
import 'package:openreads/ui/search_page/search_page.dart';
Expand Down Expand Up @@ -411,7 +411,7 @@ class _BooksScreenState extends State<BooksScreen>
label: LocaleKeys.click_here_to_restore_them.tr(),
onPressed: () {
Navigator.push(context, MaterialPageRoute(builder: (_) {
return BackupScreen(autoMigrationV1ToV2: true);
return SettingsBackupScreen(autoMigrationV1ToV2: true);
}));
}),
),
Expand Down
Loading

0 comments on commit ad2df8a

Please sign in to comment.