From b6f89ed793c025da12cb8f201de377c5bff89fcc Mon Sep 17 00:00:00 2001 From: mateusz-bak <32651935+mateusz-bak@users.noreply.github.com> Date: Sun, 9 Jul 2023 09:45:01 +0100 Subject: [PATCH 1/2] feat: Added AMOLED black theme --- assets/translations/en-US.json | 6 +- lib/generated/locale_keys.g.dart | 3 + lib/logic/bloc/theme_bloc/theme_bloc.dart | 10 + lib/logic/bloc/theme_bloc/theme_event.dart | 3 + lib/logic/bloc/theme_bloc/theme_state.dart | 3 + lib/main.dart | 11 + lib/ui/backup_screen/backup_screen.dart | 343 ++-- .../settings_apperance_screen.dart | 1280 +++++++++++++++ lib/ui/settings_screen/settings_screen.dart | 1400 ++--------------- 9 files changed, 1655 insertions(+), 1404 deletions(-) create mode 100644 lib/ui/settings_apperance_screen/settings_apperance_screen.dart diff --git a/assets/translations/en-US.json b/assets/translations/en-US.json index a79adcab6..c43d6f89d 100644 --- a/assets/translations/en-US.json +++ b/assets/translations/en-US.json @@ -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" } \ No newline at end of file diff --git a/lib/generated/locale_keys.g.dart b/lib/generated/locale_keys.g.dart index 812f13111..90893b573 100644 --- a/lib/generated/locale_keys.g.dart +++ b/lib/generated/locale_keys.g.dart @@ -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'; } diff --git a/lib/logic/bloc/theme_bloc/theme_bloc.dart b/lib/logic/bloc/theme_bloc/theme_bloc.dart index 26f0a1a2f..532a82d3b 100644 --- a/lib/logic/bloc/theme_bloc/theme_bloc.dart +++ b/lib/logic/bloc/theme_bloc/theme_bloc.dart @@ -17,6 +17,7 @@ class ThemeBloc extends HydratedBloc { fontFamily: 'Nunito', readTabFirst: true, useMaterialYou: true, + amoledDark: false, )) { on((event, emit) { fontFamily = event.fontFamily; @@ -31,6 +32,7 @@ class ThemeBloc extends HydratedBloc { fontFamily: fontFamily, readTabFirst: event.readTabFirst, useMaterialYou: event.useMaterialYou, + amoledDark: event.amoledDark, )); }); } @@ -44,6 +46,7 @@ class ThemeBloc extends HydratedBloc { 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: @@ -55,6 +58,7 @@ class ThemeBloc extends HydratedBloc { fontFamily: fontFamily ?? 'Nunito', readTabFirst: readTabFirst ?? true, useMaterialYou: useMaterialYou ?? true, + amoledDark: amoledDark ?? false, ); case 2: return SetThemeState( @@ -65,6 +69,7 @@ class ThemeBloc extends HydratedBloc { fontFamily: fontFamily ?? 'Nunito', readTabFirst: readTabFirst ?? true, useMaterialYou: useMaterialYou ?? true, + amoledDark: amoledDark ?? false, ); default: return SetThemeState( @@ -75,6 +80,7 @@ class ThemeBloc extends HydratedBloc { fontFamily: fontFamily ?? 'Nunito', readTabFirst: readTabFirst ?? true, useMaterialYou: useMaterialYou ?? true, + amoledDark: amoledDark ?? false, ); } } @@ -92,6 +98,7 @@ class ThemeBloc extends HydratedBloc { 'font_family': state.fontFamily, 'read_tab_first': state.readTabFirst, 'use_material_you': state.useMaterialYou, + 'amoled_dark': state.amoledDark, }; case ThemeMode.dark: return { @@ -102,6 +109,7 @@ class ThemeBloc extends HydratedBloc { 'font_family': state.fontFamily, 'read_tab_first': state.readTabFirst, 'use_material_you': state.useMaterialYou, + 'amoled_dark': state.amoledDark, }; case ThemeMode.system: return { @@ -112,6 +120,7 @@ class ThemeBloc extends HydratedBloc { 'font_family': state.fontFamily, 'read_tab_first': state.readTabFirst, 'use_material_you': state.useMaterialYou, + 'amoled_dark': state.amoledDark, }; } } else { @@ -124,6 +133,7 @@ class ThemeBloc extends HydratedBloc { 'read_tab_first': null, 'use_material_you': null, 'locale': null, + 'amoled_dark': false, }; } } diff --git a/lib/logic/bloc/theme_bloc/theme_event.dart b/lib/logic/bloc/theme_bloc/theme_event.dart index f1029b4b5..59861b81d 100644 --- a/lib/logic/bloc/theme_bloc/theme_event.dart +++ b/lib/logic/bloc/theme_bloc/theme_event.dart @@ -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, @@ -21,6 +22,7 @@ class ChangeThemeEvent extends ThemeEvent { required this.fontFamily, required this.readTabFirst, required this.useMaterialYou, + required this.amoledDark, }); @override @@ -32,5 +34,6 @@ class ChangeThemeEvent extends ThemeEvent { fontFamily, readTabFirst, useMaterialYou, + amoledDark, ]; } diff --git a/lib/logic/bloc/theme_bloc/theme_state.dart b/lib/logic/bloc/theme_bloc/theme_state.dart index 6cda2c9d9..df5eda3eb 100644 --- a/lib/logic/bloc/theme_bloc/theme_state.dart +++ b/lib/logic/bloc/theme_bloc/theme_state.dart @@ -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, @@ -28,6 +29,7 @@ class SetThemeState extends ThemeState { required this.fontFamily, required this.readTabFirst, required this.useMaterialYou, + required this.amoledDark, }); @override @@ -39,5 +41,6 @@ class SetThemeState extends ThemeState { fontFamily, readTabFirst, useMaterialYou, + amoledDark, ]; } diff --git a/lib/main.dart b/lib/main.dart index bbe72e377..1aada4c7d 100644 --- a/lib/main.dart +++ b/lib/main.dart @@ -145,6 +145,12 @@ class _OpenreadsAppState extends State 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( @@ -171,6 +177,11 @@ class _OpenreadsAppState extends State 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 diff --git a/lib/ui/backup_screen/backup_screen.dart b/lib/ui/backup_screen/backup_screen.dart index 2bd3e2b90..fa961c0db 100644 --- a/lib/ui/backup_screen/backup_screen.dart +++ b/lib/ui/backup_screen/backup_screen.dart @@ -12,6 +12,7 @@ import 'package:font_awesome_flutter/font_awesome_flutter.dart'; import 'package:openreads/logic/bloc/migration_v1_to_v2_bloc/migration_v1_to_v2_bloc.dart'; import 'package:openreads/generated/locale_keys.g.dart'; import 'package:openreads/logic/bloc/challenge_bloc/challenge_bloc.dart'; +import 'package:openreads/logic/bloc/theme_bloc/theme_bloc.dart'; import 'package:openreads/main.dart'; import 'package:openreads/model/book.dart'; import 'package:openreads/model/book_from_backup_v3.dart'; @@ -725,177 +726,197 @@ class _BackupScreenState extends State { body: Column( children: [ Expanded( - child: SettingsList( - contentPadding: const EdgeInsets.only(top: 10), - lightTheme: SettingsThemeData( - settingsListBackground: Theme.of(context).colorScheme.surface, - ), - darkTheme: SettingsThemeData( - settingsListBackground: Theme.of(context).colorScheme.surface, - ), - sections: [ - SettingsSection( - tiles: [ - SettingsTile( - title: Text( - LocaleKeys.create_local_backup.tr(), - style: const TextStyle( - fontSize: 16, - ), - ), - leading: (_creatingLocal) - ? const SizedBox( - width: 24, - height: 24, - child: CircularProgressIndicator(), - ) - : const Icon(FontAwesomeIcons.solidFloppyDisk), - description: Text( - LocaleKeys.create_local_backup_description.tr(), - ), - onPressed: _startLocalBackup, - ), - SettingsTile( - title: Text( - LocaleKeys.create_cloud_backup.tr(), - style: const TextStyle( - fontSize: 16, + child: BlocBuilder( + builder: (context, state) { + late final bool amoledDark; + + if (state is SetThemeState) { + amoledDark = state.amoledDark; + } else { + amoledDark = false; + } + + return SettingsList( + contentPadding: const EdgeInsets.only(top: 10), + darkTheme: SettingsThemeData( + settingsListBackground: amoledDark + ? Colors.black + : Theme.of(context).colorScheme.surface, + ), + lightTheme: SettingsThemeData( + settingsListBackground: amoledDark + ? Colors.black + : Theme.of(context).colorScheme.surface, + ), + sections: [ + SettingsSection( + tiles: [ + SettingsTile( + title: Text( + LocaleKeys.create_local_backup.tr(), + style: const TextStyle( + fontSize: 16, + ), + ), + leading: (_creatingLocal) + ? const SizedBox( + width: 24, + height: 24, + child: CircularProgressIndicator(), + ) + : const Icon(FontAwesomeIcons.solidFloppyDisk), + description: Text( + LocaleKeys.create_local_backup_description.tr(), + ), + onPressed: _startLocalBackup, ), - ), - leading: (_creatingCloud) - ? const SizedBox( - width: 24, - height: 24, - child: CircularProgressIndicator(), - ) - : const Icon(FontAwesomeIcons.cloudArrowUp), - description: Text( - LocaleKeys.create_cloud_backup_description.tr(), - ), - onPressed: _startCloudBackup, - ), - SettingsTile( - title: Text( - LocaleKeys.restore_backup.tr(), - style: const TextStyle( - fontSize: 16, + SettingsTile( + title: Text( + LocaleKeys.create_cloud_backup.tr(), + style: const TextStyle( + fontSize: 16, + ), + ), + leading: (_creatingCloud) + ? const SizedBox( + width: 24, + height: 24, + child: CircularProgressIndicator(), + ) + : const Icon(FontAwesomeIcons.cloudArrowUp), + description: Text( + LocaleKeys.create_cloud_backup_description.tr(), + ), + onPressed: _startCloudBackup, ), - ), - leading: (_restoringLocal) - ? const SizedBox( - width: 24, - height: 24, - child: CircularProgressIndicator(), - ) - : const Icon(FontAwesomeIcons.arrowUpFromBracket), - description: Column( - crossAxisAlignment: CrossAxisAlignment.start, - children: [ - restoredCounterText.isNotEmpty - ? Text( - restoredCounterText, - style: const TextStyle( - fontWeight: FontWeight.bold, - ), + SettingsTile( + title: Text( + LocaleKeys.restore_backup.tr(), + style: const TextStyle( + fontSize: 16, + ), + ), + leading: (_restoringLocal) + ? const SizedBox( + width: 24, + height: 24, + child: CircularProgressIndicator(), ) - : const SizedBox(), - Text( - '${LocaleKeys.restore_backup_description_1.tr()}\n${LocaleKeys.restore_backup_description_2.tr()}', + : const Icon(FontAwesomeIcons.arrowUpFromBracket), + description: Column( + crossAxisAlignment: CrossAxisAlignment.start, + children: [ + restoredCounterText.isNotEmpty + ? Text( + restoredCounterText, + style: const TextStyle( + fontWeight: FontWeight.bold, + ), + ) + : const SizedBox(), + Text( + '${LocaleKeys.restore_backup_description_1.tr()}\n${LocaleKeys.restore_backup_description_2.tr()}', + ), + ], ), - ], - ), - onPressed: (context) { - showDialog( - context: context, - builder: (context) { - return Builder(builder: (context) { - return AlertDialog( - title: Text( - LocaleKeys.are_you_sure.tr(), - ), - content: Text( - LocaleKeys.restore_backup_alert_content.tr(), - ), - actionsAlignment: - MainAxisAlignment.spaceBetween, - actions: [ - FilledButton.tonal( - onPressed: () { - _startLocalRestore(context); - Navigator.of(context).pop(); - }, - child: Text(LocaleKeys.yes.tr()), - ), - FilledButton.tonal( - onPressed: () => - Navigator.of(context).pop(), - child: Text(LocaleKeys.no.tr()), - ), - ], - ); - }); + onPressed: (context) { + showDialog( + context: context, + builder: (context) { + return Builder(builder: (context) { + return AlertDialog( + title: Text( + LocaleKeys.are_you_sure.tr(), + ), + content: Text( + LocaleKeys.restore_backup_alert_content + .tr(), + ), + actionsAlignment: + MainAxisAlignment.spaceBetween, + actions: [ + FilledButton.tonal( + onPressed: () { + _startLocalRestore(context); + Navigator.of(context).pop(); + }, + child: Text(LocaleKeys.yes.tr()), + ), + FilledButton.tonal( + onPressed: () => + Navigator.of(context).pop(), + child: Text(LocaleKeys.no.tr()), + ), + ], + ); + }); + }, + ); }, - ); - }, - ), - SettingsTile( - title: Text( - LocaleKeys.migration_v1_to_v2_retrigger.tr(), - style: TextStyle( - fontSize: 16, - color: widget.autoMigrationV1ToV2 - ? Theme.of(context).colorScheme.primary - : null, - ), - ), - leading: Icon( - FontAwesomeIcons.wrench, - color: widget.autoMigrationV1ToV2 - ? Theme.of(context).colorScheme.primary - : null, - ), - description: Text( - LocaleKeys.migration_v1_to_v2_retrigger_description - .tr(), - style: TextStyle( - color: widget.autoMigrationV1ToV2 - ? Theme.of(context).colorScheme.primary - : null, ), - ), - onPressed: (context) { - showDialog( - context: context, - builder: (context) { - return AlertDialog( - title: Text( - LocaleKeys.are_you_sure.tr(), - ), - content: Text( - LocaleKeys.restore_backup_alert_content.tr(), - ), - actionsAlignment: MainAxisAlignment.spaceBetween, - actions: [ - FilledButton.tonal( - onPressed: () { - _startMigrationV1ToV2(); - Navigator.of(context).pop(); - }, - child: Text(LocaleKeys.yes.tr()), - ), - FilledButton.tonal( - onPressed: () => Navigator.of(context).pop(), - child: Text(LocaleKeys.no.tr()), - ), - ], + SettingsTile( + title: Text( + LocaleKeys.migration_v1_to_v2_retrigger.tr(), + style: TextStyle( + fontSize: 16, + color: widget.autoMigrationV1ToV2 + ? Theme.of(context).colorScheme.primary + : null, + ), + ), + leading: Icon( + FontAwesomeIcons.wrench, + color: widget.autoMigrationV1ToV2 + ? Theme.of(context).colorScheme.primary + : null, + ), + description: Text( + LocaleKeys.migration_v1_to_v2_retrigger_description + .tr(), + style: TextStyle( + color: widget.autoMigrationV1ToV2 + ? Theme.of(context).colorScheme.primary + : null, + ), + ), + onPressed: (context) { + showDialog( + context: context, + builder: (context) { + return AlertDialog( + title: Text( + LocaleKeys.are_you_sure.tr(), + ), + content: Text( + LocaleKeys.restore_backup_alert_content + .tr(), + ), + actionsAlignment: + MainAxisAlignment.spaceBetween, + actions: [ + FilledButton.tonal( + onPressed: () { + _startMigrationV1ToV2(); + Navigator.of(context).pop(); + }, + child: Text(LocaleKeys.yes.tr()), + ), + FilledButton.tonal( + onPressed: () => + Navigator.of(context).pop(), + child: Text(LocaleKeys.no.tr()), + ), + ], + ); + }, ); }, - ); - }, + ), + ], ), ], - ), - ], + ); + }, ), ), BlocBuilder( diff --git a/lib/ui/settings_apperance_screen/settings_apperance_screen.dart b/lib/ui/settings_apperance_screen/settings_apperance_screen.dart new file mode 100644 index 000000000..c7a9104bd --- /dev/null +++ b/lib/ui/settings_apperance_screen/settings_apperance_screen.dart @@ -0,0 +1,1280 @@ +import 'package:easy_localization/easy_localization.dart'; +import 'package:flutter/material.dart'; +import 'package:flutter_bloc/flutter_bloc.dart'; +import 'package:font_awesome_flutter/font_awesome_flutter.dart'; +import 'package:openreads/core/constants.dart/enums.dart'; +import 'package:openreads/core/themes/app_theme.dart'; +import 'package:openreads/generated/locale_keys.g.dart'; +import 'package:openreads/logic/bloc/rating_type_bloc/rating_type_bloc.dart'; +import 'package:openreads/logic/bloc/theme_bloc/theme_bloc.dart'; +import 'package:openreads/ui/settings_screen/widgets/widgets.dart'; +import 'package:settings_ui/settings_ui.dart'; + +class SettingsApperanceScreen extends StatelessWidget { + const SettingsApperanceScreen({super.key}); + + _showThemeModeDialog(BuildContext context) { + showDialog( + context: context, + builder: (BuildContext context) { + return Dialog( + shape: RoundedRectangleBorder( + borderRadius: BorderRadius.circular(cornerRadius), + ), + backgroundColor: Theme.of(context).colorScheme.surface, + child: Padding( + padding: const EdgeInsets.symmetric(horizontal: 10, vertical: 20), + child: BlocBuilder( + builder: (context, state) { + if (state is SetThemeState) { + return Column( + crossAxisAlignment: CrossAxisAlignment.start, + mainAxisSize: MainAxisSize.min, + children: [ + Padding( + padding: const EdgeInsets.only(left: 10), + child: Text( + LocaleKeys.select_theme_mode.tr(), + style: const TextStyle( + fontSize: 18, + fontWeight: FontWeight.bold, + ), + ), + ), + const SizedBox(height: 15), + SettingsDialogButton( + text: LocaleKeys.theme_mode_system.tr(), + onPressed: () => _setThemeModeAuto(context, state), + ), + const SizedBox(height: 5), + SettingsDialogButton( + text: LocaleKeys.theme_mode_light.tr(), + onPressed: () => _setThemeModeLight(context, state), + ), + const SizedBox(height: 5), + SettingsDialogButton( + text: LocaleKeys.theme_mode_dark.tr(), + onPressed: () => _setThemeModeDark(context, state), + ), + ], + ); + } else { + return const SizedBox(); + } + }, + ), + ), + ); + }, + ); + } + + _showDarkModeDialog(BuildContext context) { + showDialog( + context: context, + builder: (BuildContext context) { + return Dialog( + shape: RoundedRectangleBorder( + borderRadius: BorderRadius.circular(cornerRadius), + ), + backgroundColor: Theme.of(context).colorScheme.surface, + child: Padding( + padding: const EdgeInsets.symmetric(horizontal: 10, vertical: 20), + child: BlocBuilder( + builder: (context, state) { + if (state is SetThemeState) { + return Column( + crossAxisAlignment: CrossAxisAlignment.start, + mainAxisSize: MainAxisSize.min, + children: [ + Padding( + padding: const EdgeInsets.only(left: 10), + child: Text( + LocaleKeys.dark_mode_style.tr(), + style: const TextStyle( + fontSize: 18, + fontWeight: FontWeight.bold, + ), + ), + ), + const SizedBox(height: 15), + SettingsDialogButton( + text: LocaleKeys.dark_mode_natural.tr(), + onPressed: () => _setDarkMode(context, state, false), + ), + const SizedBox(height: 5), + SettingsDialogButton( + text: LocaleKeys.dark_mode_amoled.tr(), + onPressed: () => _setDarkMode(context, state, true), + ), + ], + ); + } else { + return const SizedBox(); + } + }, + ), + ), + ); + }, + ); + } + + _showFontDialog(BuildContext context) { + showDialog( + context: context, + builder: (BuildContext context) { + return Dialog( + shape: RoundedRectangleBorder( + borderRadius: BorderRadius.circular(cornerRadius), + ), + backgroundColor: Theme.of(context).colorScheme.surface, + child: Padding( + padding: const EdgeInsets.symmetric(horizontal: 10, vertical: 20), + child: BlocBuilder( + builder: (context, state) { + if (state is SetThemeState) { + return Column( + crossAxisAlignment: CrossAxisAlignment.start, + children: [ + Padding( + padding: const EdgeInsets.only(left: 10), + child: Text( + LocaleKeys.select_font.tr(), + style: const TextStyle( + fontSize: 18, + fontWeight: FontWeight.bold, + ), + ), + ), + const SizedBox(height: 15), + Expanded( + child: Scrollbar( + thumbVisibility: true, + child: SingleChildScrollView( + child: Column( + crossAxisAlignment: CrossAxisAlignment.start, + mainAxisSize: MainAxisSize.min, + children: [ + SettingsDialogButton( + text: LocaleKeys.font_default.tr(), + onPressed: () => _setFont( + context, + state, + Font.system, + ), + ), + const SizedBox(height: 5), + SettingsDialogButton( + text: 'Nunito', + onPressed: () => _setFont( + context, + state, + Font.nunito, + ), + ), + const SizedBox(height: 5), + SettingsDialogButton( + text: 'Jost', + onPressed: () => _setFont( + context, + state, + Font.jost, + ), + ), + const SizedBox(height: 5), + SettingsDialogButton( + text: 'Barlow', + onPressed: () => _setFont( + context, + state, + Font.barlow, + ), + ), + const SizedBox(height: 5), + SettingsDialogButton( + text: 'Kanit', + onPressed: () => _setFont( + context, + state, + Font.kanit, + ), + ), + const SizedBox(height: 5), + SettingsDialogButton( + text: 'Lato', + onPressed: () => _setFont( + context, + state, + Font.lato, + ), + ), + const SizedBox(height: 5), + SettingsDialogButton( + text: 'Lora', + onPressed: () => _setFont( + context, + state, + Font.lora, + ), + ), + const SizedBox(height: 5), + SettingsDialogButton( + text: 'Montserrat', + onPressed: () => _setFont( + context, + state, + Font.montserrat, + ), + ), + const SizedBox(height: 5), + SettingsDialogButton( + text: 'Playfair Display', + onPressed: () => _setFont( + context, + state, + Font.playfairDisplay, + ), + ), + const SizedBox(height: 5), + SettingsDialogButton( + text: 'Poppins', + onPressed: () => _setFont( + context, + state, + Font.poppins, + ), + ), + const SizedBox(height: 5), + SettingsDialogButton( + text: 'Raleway', + onPressed: () => _setFont( + context, + state, + Font.raleway, + ), + ), + const SizedBox(height: 5), + SettingsDialogButton( + text: 'Sofia Sans', + onPressed: () => _setFont( + context, + state, + Font.sofiaSans, + ), + ), + const SizedBox(height: 5), + SettingsDialogButton( + text: 'Quicksand', + onPressed: () => _setFont( + context, + state, + Font.quicksand, + ), + ), + ], + ), + ), + ), + ), + ], + ); + } else { + return const SizedBox(); + } + }, + ), + ), + ); + }, + ); + } + + _showOutlinesDialog(BuildContext context) { + showDialog( + context: context, + builder: (BuildContext context) { + return Dialog( + shape: RoundedRectangleBorder( + borderRadius: BorderRadius.circular(cornerRadius), + ), + backgroundColor: Theme.of(context).colorScheme.surface, + child: Padding( + padding: const EdgeInsets.symmetric(horizontal: 10, vertical: 20), + child: BlocBuilder( + builder: (context, state) { + if (state is SetThemeState) { + return Column( + crossAxisAlignment: CrossAxisAlignment.start, + mainAxisSize: MainAxisSize.min, + children: [ + Padding( + padding: const EdgeInsets.only(left: 10), + child: Text( + LocaleKeys.display_outlines.tr(), + style: const TextStyle( + fontSize: 18, + fontWeight: FontWeight.bold, + ), + ), + ), + const SizedBox(height: 15), + SettingsDialogButton( + text: LocaleKeys.show_outlines.tr(), + onPressed: () => _showOutlines(context, state), + ), + const SizedBox(height: 5), + SettingsDialogButton( + text: LocaleKeys.hide_outlines.tr(), + onPressed: () => _hideOutlines(context, state), + ), + ], + ); + } else { + return const SizedBox(); + } + }, + ), + ), + ); + }, + ); + } + + _showCornerRadiusDialog(BuildContext context) { + showDialog( + context: context, + builder: (BuildContext context) { + return Dialog( + shape: RoundedRectangleBorder( + borderRadius: BorderRadius.circular(cornerRadius), + ), + backgroundColor: Theme.of(context).colorScheme.surface, + child: Padding( + padding: const EdgeInsets.symmetric(horizontal: 10, vertical: 20), + child: BlocBuilder( + builder: (context, state) { + if (state is SetThemeState) { + return Column( + crossAxisAlignment: CrossAxisAlignment.start, + mainAxisSize: MainAxisSize.min, + children: [ + Padding( + padding: const EdgeInsets.only(left: 10), + child: Text( + LocaleKeys.select_corner_radius.tr(), + style: const TextStyle( + fontSize: 18, + fontWeight: FontWeight.bold, + ), + ), + ), + const SizedBox(height: 15), + SettingsDialogButton( + text: LocaleKeys.no_rounded_corners.tr(), + onPressed: () => _changeCornerRadius(context, state, 0), + ), + const SizedBox(height: 5), + SettingsDialogButton( + text: LocaleKeys.small_rounded_corners.tr(), + onPressed: () => _changeCornerRadius(context, state, 5), + ), + const SizedBox(height: 5), + SettingsDialogButton( + text: LocaleKeys.medium_rounded_corners.tr(), + onPressed: () => + _changeCornerRadius(context, state, 10), + ), + const SizedBox(height: 5), + SettingsDialogButton( + text: LocaleKeys.big_rounded_corners.tr(), + onPressed: () => + _changeCornerRadius(context, state, 20), + ), + ], + ); + } else { + return const SizedBox(); + } + }, + ), + ), + ); + }, + ); + } + + _showTabsOrderDialog(BuildContext context) { + showDialog( + context: context, + builder: (BuildContext context) { + return Dialog( + shape: RoundedRectangleBorder( + borderRadius: BorderRadius.circular(cornerRadius), + ), + backgroundColor: Theme.of(context).colorScheme.surface, + child: Padding( + padding: const EdgeInsets.symmetric(horizontal: 10, vertical: 20), + child: BlocBuilder( + builder: (context, state) { + if (state is SetThemeState) { + return Column( + crossAxisAlignment: CrossAxisAlignment.start, + mainAxisSize: MainAxisSize.min, + children: [ + Padding( + padding: const EdgeInsets.only(left: 10), + child: Text( + LocaleKeys.select_tabs_order.tr(), + style: const TextStyle( + fontSize: 18, + fontWeight: FontWeight.bold, + ), + ), + ), + const SizedBox(height: 15), + SettingsDialogButton( + text: LocaleKeys.tabs_order_read_first.tr(), + onPressed: () { + BlocProvider.of(context).add( + ChangeThemeEvent( + themeMode: state.themeMode, + showOutlines: state.showOutlines, + cornerRadius: state.cornerRadius, + primaryColor: state.primaryColor, + fontFamily: state.fontFamily, + readTabFirst: true, + useMaterialYou: state.useMaterialYou, + amoledDark: state.amoledDark, + ), + ); + + Navigator.of(context).pop(); + }, + ), + const SizedBox(height: 5), + SettingsDialogButton( + text: LocaleKeys.tabs_order_in_progress_first.tr(), + onPressed: () { + BlocProvider.of(context).add( + ChangeThemeEvent( + themeMode: state.themeMode, + showOutlines: state.showOutlines, + cornerRadius: state.cornerRadius, + primaryColor: state.primaryColor, + fontFamily: state.fontFamily, + readTabFirst: false, + useMaterialYou: state.useMaterialYou, + amoledDark: state.amoledDark, + ), + ); + + Navigator.of(context).pop(); + }, + ), + ], + ); + } else { + return const SizedBox(); + } + }, + ), + ), + ); + }, + ); + } + + _setThemeModeAuto(BuildContext context, SetThemeState state) { + BlocProvider.of(context).add(ChangeThemeEvent( + themeMode: ThemeMode.system, + showOutlines: state.showOutlines, + cornerRadius: state.cornerRadius, + primaryColor: state.primaryColor, + fontFamily: state.fontFamily, + readTabFirst: state.readTabFirst, + useMaterialYou: state.useMaterialYou, + amoledDark: state.amoledDark, + )); + + Navigator.of(context).pop(); + } + + _setThemeModeLight(BuildContext context, SetThemeState state) { + BlocProvider.of(context).add(ChangeThemeEvent( + themeMode: ThemeMode.light, + showOutlines: state.showOutlines, + cornerRadius: state.cornerRadius, + primaryColor: state.primaryColor, + fontFamily: state.fontFamily, + readTabFirst: state.readTabFirst, + useMaterialYou: state.useMaterialYou, + amoledDark: state.amoledDark, + )); + + Navigator.of(context).pop(); + } + + _setThemeModeDark(BuildContext context, SetThemeState state) { + BlocProvider.of(context).add(ChangeThemeEvent( + themeMode: ThemeMode.dark, + showOutlines: state.showOutlines, + cornerRadius: state.cornerRadius, + primaryColor: state.primaryColor, + fontFamily: state.fontFamily, + readTabFirst: state.readTabFirst, + useMaterialYou: state.useMaterialYou, + amoledDark: state.amoledDark, + )); + + Navigator.of(context).pop(); + } + + _setDarkMode(BuildContext context, SetThemeState state, bool amoledDark) { + BlocProvider.of(context).add(ChangeThemeEvent( + themeMode: ThemeMode.dark, + showOutlines: state.showOutlines, + cornerRadius: state.cornerRadius, + primaryColor: state.primaryColor, + fontFamily: state.fontFamily, + readTabFirst: state.readTabFirst, + useMaterialYou: state.useMaterialYou, + amoledDark: amoledDark, + )); + + Navigator.of(context).pop(); + } + + _setFont( + BuildContext context, + SetThemeState state, + Font font, + ) { + String? fontFamily; + + switch (font) { + case Font.system: + fontFamily = null; + break; + case Font.montserrat: + fontFamily = 'Montserrat'; + break; + case Font.lato: + fontFamily = 'Lato'; + break; + case Font.sofiaSans: + fontFamily = 'SofiaSans'; + break; + case Font.poppins: + fontFamily = 'Poppins'; + break; + case Font.raleway: + fontFamily = 'Raleway'; + break; + case Font.nunito: + fontFamily = 'Nunito'; + break; + case Font.playfairDisplay: + fontFamily = 'PlayfairDisplay'; + break; + case Font.kanit: + fontFamily = 'Kanit'; + break; + case Font.lora: + fontFamily = 'Lora'; + break; + case Font.quicksand: + fontFamily = 'Quicksand'; + break; + case Font.barlow: + fontFamily = 'Barlow'; + break; + case Font.jost: + fontFamily = 'Jost'; + break; + default: + fontFamily = 'Nunito'; + break; + } + + BlocProvider.of(context).add(ChangeThemeEvent( + themeMode: state.themeMode, + showOutlines: state.showOutlines, + cornerRadius: state.cornerRadius, + primaryColor: state.primaryColor, + fontFamily: fontFamily, + readTabFirst: state.readTabFirst, + useMaterialYou: state.useMaterialYou, + amoledDark: state.amoledDark, + )); + + Navigator.of(context).pop(); + } + + _showOutlines(BuildContext context, SetThemeState state) { + BlocProvider.of(context).add(ChangeThemeEvent( + themeMode: state.themeMode, + showOutlines: true, + cornerRadius: state.cornerRadius, + primaryColor: state.primaryColor, + fontFamily: state.fontFamily, + readTabFirst: state.readTabFirst, + useMaterialYou: state.useMaterialYou, + amoledDark: state.amoledDark, + )); + + Navigator.of(context).pop(); + } + + _hideOutlines(BuildContext context, SetThemeState state) { + BlocProvider.of(context).add(ChangeThemeEvent( + themeMode: state.themeMode, + showOutlines: false, + cornerRadius: state.cornerRadius, + primaryColor: state.primaryColor, + fontFamily: state.fontFamily, + readTabFirst: state.readTabFirst, + useMaterialYou: state.useMaterialYou, + amoledDark: state.amoledDark, + )); + + Navigator.of(context).pop(); + } + + _changeCornerRadius( + BuildContext context, SetThemeState state, double radius) { + BlocProvider.of(context).add(ChangeThemeEvent( + themeMode: state.themeMode, + showOutlines: state.showOutlines, + cornerRadius: radius, + primaryColor: state.primaryColor, + fontFamily: state.fontFamily, + readTabFirst: state.readTabFirst, + useMaterialYou: state.useMaterialYou, + amoledDark: state.amoledDark, + )); + + Navigator.of(context).pop(); + } + + _setAccentColor(BuildContext context, SetThemeState state, Color color) { + BlocProvider.of(context).add(ChangeThemeEvent( + themeMode: state.themeMode, + showOutlines: state.showOutlines, + cornerRadius: state.cornerRadius, + primaryColor: color, + fontFamily: state.fontFamily, + readTabFirst: state.readTabFirst, + useMaterialYou: false, + amoledDark: state.amoledDark, + )); + + Navigator.of(context).pop(); + } + + _setMaterialYou(BuildContext context, SetThemeState state) { + BlocProvider.of(context).add(ChangeThemeEvent( + themeMode: state.themeMode, + showOutlines: state.showOutlines, + cornerRadius: state.cornerRadius, + primaryColor: state.primaryColor, + fontFamily: state.fontFamily, + readTabFirst: state.readTabFirst, + useMaterialYou: true, + amoledDark: state.amoledDark, + )); + + Navigator.of(context).pop(); + } + + _showAccentColorDialog(BuildContext context) { + showDialog( + context: context, + builder: (BuildContext context) { + return Dialog( + shape: RoundedRectangleBorder( + borderRadius: BorderRadius.circular(cornerRadius), + ), + backgroundColor: Theme.of(context).colorScheme.surface, + child: Padding( + padding: const EdgeInsets.symmetric(horizontal: 10, vertical: 20), + child: BlocBuilder( + builder: (context, state) { + if (state is SetThemeState) { + return Column( + crossAxisAlignment: CrossAxisAlignment.start, + mainAxisSize: MainAxisSize.min, + children: [ + Padding( + padding: const EdgeInsets.only(left: 10), + child: Text( + LocaleKeys.select_accent_color.tr(), + style: const TextStyle( + fontSize: 18, + fontWeight: FontWeight.bold, + ), + ), + ), + const SizedBox(height: 15), + Scrollbar( + child: SingleChildScrollView( + child: Column( + children: [ + GestureDetector( + onTap: () => _setMaterialYou( + context, + state, + ), + child: Container( + padding: const EdgeInsets.all(10), + decoration: BoxDecoration( + borderRadius: + BorderRadius.circular(cornerRadius), + color: Theme.of(context) + .colorScheme + .surfaceVariant, + border: Border.all(color: dividerColor), + ), + child: Row( + children: [ + Text( + LocaleKeys.material_you.tr(), + style: const TextStyle( + fontSize: 16, + fontWeight: FontWeight.bold, + ), + ), + ], + ), + ), + ), + const SizedBox(height: 5), + _buildAccentButton( + context, + state, + primaryGreen, + LocaleKeys.green_color.tr(), + ), + _buildAccentButton( + context, + state, + primaryBlue, + LocaleKeys.blue_color.tr(), + ), + _buildAccentButton( + context, + state, + primaryRed, + LocaleKeys.red_color.tr(), + ), + _buildAccentButton( + context, + state, + primaryYellow, + LocaleKeys.yellow_color.tr(), + ), + _buildAccentButton( + context, + state, + primaryOrange, + LocaleKeys.orange_color.tr(), + ), + _buildAccentButton( + context, + state, + primaryPurple, + LocaleKeys.purple_color.tr(), + ), + _buildAccentButton( + context, + state, + primaryPink, + LocaleKeys.pink_color.tr(), + ), + _buildAccentButton( + context, + state, + primaryTeal, + LocaleKeys.teal_color.tr(), + ), + ], + ), + ), + ), + ], + ); + } else { + return const SizedBox(); + } + }, + ), + ), + ); + }, + ); + } + + _showRatingBarDialog(BuildContext context) { + showDialog( + context: context, + builder: (BuildContext context) { + return Dialog( + shape: RoundedRectangleBorder( + borderRadius: BorderRadius.circular(cornerRadius), + ), + backgroundColor: Theme.of(context).colorScheme.surface, + child: Padding( + padding: const EdgeInsets.symmetric(horizontal: 10, vertical: 20), + child: Column( + crossAxisAlignment: CrossAxisAlignment.start, + mainAxisSize: MainAxisSize.min, + children: [ + Padding( + padding: const EdgeInsets.only(left: 10), + child: Text( + LocaleKeys.seletct_rating_type.tr(), + style: const TextStyle( + fontSize: 18, + fontWeight: FontWeight.bold, + ), + ), + ), + const SizedBox(height: 15), + SettingsDialogButton( + text: LocaleKeys.rating_as_bar.tr(), + onPressed: () { + BlocProvider.of(context).add( + const RatingTypeChange(ratingType: RatingType.bar), + ); + + Navigator.of(context).pop(); + }, + ), + const SizedBox(height: 5), + SettingsDialogButton( + text: LocaleKeys.rating_as_number.tr(), + onPressed: () { + BlocProvider.of(context).add( + const RatingTypeChange(ratingType: RatingType.number), + ); + + Navigator.of(context).pop(); + }, + ), + ], + ), + ), + ); + }, + ); + } + + @override + Widget build(BuildContext context) { + return Scaffold( + appBar: AppBar( + title: Text( + LocaleKeys.apperance.tr(), + style: const TextStyle(fontSize: 18), + ), + ), + body: BlocBuilder( + builder: (context, state) { + late final bool amoledDark; + + if (state is SetThemeState) { + amoledDark = state.amoledDark; + } else { + amoledDark = false; + } + + return SettingsList( + contentPadding: const EdgeInsets.only(top: 10), + darkTheme: SettingsThemeData( + settingsListBackground: amoledDark + ? Colors.black + : Theme.of(context).colorScheme.surface, + ), + lightTheme: SettingsThemeData( + settingsListBackground: amoledDark + ? Colors.black + : Theme.of(context).colorScheme.surface, + ), + sections: [ + SettingsSection( + tiles: [ + _buildAccentSetting(context), + _buildThemeModeSetting(context), + _buildDarkModeSetting(context), + _buildFontSetting(context), + _buildRatingTypeSetting(context), + _buildTabOrderSetting(context), + _buildOutlinesSetting(context), + _buildCornersSetting(context), + ], + ), + ], + ); + }, + ), + ); + } + + Widget _buildAccentButton( + BuildContext context, + SetThemeState state, + Color color, + String colorName, + ) { + return Padding( + padding: const EdgeInsets.symmetric(vertical: 5), + child: Container( + decoration: BoxDecoration( + borderRadius: BorderRadius.circular(cornerRadius), + color: Theme.of(context).colorScheme.surfaceVariant, + border: Border.all(color: dividerColor), + ), + child: Row( + crossAxisAlignment: CrossAxisAlignment.center, + children: [ + Padding( + padding: const EdgeInsets.symmetric(horizontal: 10), + child: Container( + width: 50, + height: 25, + decoration: BoxDecoration( + borderRadius: BorderRadius.circular(cornerRadius), + color: color, + ), + ), + ), + Expanded( + child: SettingsDialogButton( + text: colorName, + onPressed: () => _setAccentColor( + context, + state, + color, + ), + ), + ), + ], + ), + ), + ); + } + + SettingsTile _buildThemeModeSetting(BuildContext context) { + return SettingsTile( + title: Text( + LocaleKeys.theme_mode.tr(), + style: const TextStyle( + fontSize: 16, + ), + ), + leading: const Icon(Icons.sunny), + description: BlocBuilder( + builder: (_, themeState) { + if (themeState is SetThemeState) { + switch (themeState.themeMode) { + case ThemeMode.light: + return Text( + LocaleKeys.theme_mode_light.tr(), + style: const TextStyle(), + ); + case ThemeMode.dark: + return Text( + LocaleKeys.theme_mode_dark.tr(), + style: const TextStyle(), + ); + default: + return Text( + LocaleKeys.theme_mode_system.tr(), + style: const TextStyle(), + ); + } + } else { + return const SizedBox(); + } + }, + ), + onPressed: (context) => _showThemeModeDialog(context), + ); + } + + SettingsTile _buildDarkModeSetting(BuildContext context) { + return SettingsTile( + title: Text( + LocaleKeys.dark_mode_style.tr(), + style: const TextStyle( + fontSize: 16, + ), + ), + leading: const Icon(Icons.contrast), + description: BlocBuilder( + builder: (_, themeState) { + if (themeState is SetThemeState) { + if (themeState.amoledDark) { + return Text( + LocaleKeys.dark_mode_amoled.tr(), + style: const TextStyle(), + ); + } else { + return Text( + LocaleKeys.dark_mode_natural.tr(), + style: const TextStyle(), + ); + } + } else { + return const SizedBox(); + } + }, + ), + onPressed: (context) => _showDarkModeDialog(context), + ); + } + + SettingsTile _buildFontSetting(BuildContext context) { + return SettingsTile( + title: Text( + LocaleKeys.font.tr(), + style: const TextStyle( + fontSize: 16, + ), + ), + leading: const Icon( + Icons.font_download, + size: 22, + ), + description: BlocBuilder( + builder: (_, state) { + if (state is SetThemeState) { + if (state.fontFamily != null) { + return Text( + state.fontFamily!, + style: const TextStyle(), + ); + } else { + return Text( + LocaleKeys.font_default.tr(), + style: const TextStyle(), + ); + } + } else { + return const SizedBox(); + } + }, + ), + onPressed: (context) => _showFontDialog(context), + ); + } + + SettingsTile _buildRatingTypeSetting(BuildContext context) { + return SettingsTile( + title: Text( + LocaleKeys.rating_type.tr(), + style: const TextStyle( + fontSize: 16, + ), + ), + leading: const Icon(Icons.star_rounded), + description: BlocBuilder( + builder: (_, state) { + if (state is RatingTypeNumber) { + return Text( + LocaleKeys.rating_as_number.tr(), + style: const TextStyle(), + ); + } else if (state is RatingTypeBar) { + return Text( + LocaleKeys.rating_as_bar.tr(), + style: const TextStyle(), + ); + } else { + return const SizedBox(); + } + }, + ), + onPressed: (context) => _showRatingBarDialog(context), + ); + } + + SettingsTile _buildTabOrderSetting(BuildContext context) { + return SettingsTile( + title: Text( + LocaleKeys.tabs_order.tr(), + style: const TextStyle( + fontSize: 16, + ), + ), + leading: const FaIcon( + FontAwesomeIcons.tableColumns, + size: 22, + ), + description: BlocBuilder( + builder: (_, state) { + if (state is SetThemeState) { + if (state.readTabFirst) { + return Text( + LocaleKeys.tabs_order_read_first.tr(), + style: const TextStyle(), + ); + } else { + return Text( + LocaleKeys.tabs_order_in_progress_first.tr(), + style: const TextStyle(), + ); + } + } else { + return const SizedBox(); + } + }, + ), + onPressed: (context) => _showTabsOrderDialog(context), + ); + } + + SettingsTile _buildAccentSetting(BuildContext context) { + return SettingsTile( + title: Text( + LocaleKeys.accent_color.tr(), + style: const TextStyle( + fontSize: 16, + ), + ), + leading: const Icon(Icons.color_lens), + description: BlocBuilder( + builder: (_, themeState) { + if (themeState is SetThemeState) { + if (themeState.useMaterialYou) { + return Text( + LocaleKeys.material_you.tr(), + style: const TextStyle(), + ); + } + + switch (themeState.primaryColor.value) { + case 0xffB73E3E: + return Text( + LocaleKeys.red_color.tr(), + style: const TextStyle(), + ); + case 0xff2146C7: + return Text( + LocaleKeys.blue_color.tr(), + style: const TextStyle(), + ); + case 0xff285430: + return Text( + LocaleKeys.green_color.tr(), + style: const TextStyle(), + ); + case 0xffE14D2A: + return Text( + LocaleKeys.orange_color.tr(), + style: const TextStyle(), + ); + case 0xff9F73AB: + return Text( + LocaleKeys.purple_color.tr(), + style: const TextStyle(), + ); + case 0xffFF577F: + return Text( + LocaleKeys.pink_color.tr(), + style: const TextStyle(), + ); + case 0xff3FA796: + return Text( + LocaleKeys.teal_color.tr(), + style: const TextStyle(), + ); + default: + return Text( + LocaleKeys.yellow_color.tr(), + style: const TextStyle(), + ); + } + } else { + return const SizedBox(); + } + }, + ), + onPressed: (context) => _showAccentColorDialog(context), + ); + } + + SettingsTile _buildCornersSetting(BuildContext context) { + return SettingsTile( + title: Text( + LocaleKeys.rounded_corners.tr(), + style: const TextStyle( + fontSize: 16, + ), + ), + leading: const Icon(Icons.rounded_corner_rounded), + description: BlocBuilder( + builder: (_, themeState) { + if (themeState is SetThemeState) { + if (themeState.cornerRadius == 5) { + return Text( + LocaleKeys.small_rounded_corners.tr(), + style: const TextStyle(), + ); + } else if (themeState.cornerRadius == 10) { + return Text( + LocaleKeys.medium_rounded_corners.tr(), + style: const TextStyle(), + ); + } else if (themeState.cornerRadius == 20) { + return Text( + LocaleKeys.big_rounded_corners.tr(), + style: const TextStyle(), + ); + } else { + return Text( + LocaleKeys.no_rounded_corners.tr(), + style: const TextStyle(), + ); + } + } else { + return const SizedBox(); + } + }, + ), + onPressed: (context) => _showCornerRadiusDialog(context), + ); + } + + SettingsTile _buildOutlinesSetting(BuildContext context) { + return SettingsTile( + title: Text( + LocaleKeys.display_outlines.tr(), + style: const TextStyle( + fontSize: 16, + ), + ), + leading: const Icon(Icons.check_box_outline_blank_rounded), + description: BlocBuilder( + builder: (_, themeState) { + if (themeState is SetThemeState) { + if (themeState.showOutlines) { + return Text( + LocaleKeys.show_outlines.tr(), + style: const TextStyle(), + ); + } else { + return Text( + LocaleKeys.hide_outlines.tr(), + style: const TextStyle(), + ); + } + } else { + return const SizedBox(); + } + }, + ), + onPressed: (context) => _showOutlinesDialog(context), + ); + } +} diff --git a/lib/ui/settings_screen/settings_screen.dart b/lib/ui/settings_screen/settings_screen.dart index c3a00106e..e846a4f5a 100644 --- a/lib/ui/settings_screen/settings_screen.dart +++ b/lib/ui/settings_screen/settings_screen.dart @@ -5,13 +5,12 @@ import 'package:flutter/material.dart'; import 'package:flutter_bloc/flutter_bloc.dart'; import 'package:flutter_email_sender/flutter_email_sender.dart'; import 'package:font_awesome_flutter/font_awesome_flutter.dart'; -import 'package:openreads/core/constants.dart/enums.dart'; import 'package:openreads/core/constants.dart/locale.dart'; import 'package:openreads/core/themes/app_theme.dart'; import 'package:openreads/generated/locale_keys.g.dart'; -import 'package:openreads/logic/bloc/rating_type_bloc/rating_type_bloc.dart'; import 'package:openreads/logic/bloc/theme_bloc/theme_bloc.dart'; import 'package:openreads/ui/backup_screen/backup_screen.dart'; +import 'package:openreads/ui/settings_apperance_screen/settings_apperance_screen.dart'; import 'package:openreads/ui/settings_screen/widgets/widgets.dart'; import 'package:openreads/ui/trash_screen/trash_screen.dart'; import 'package:openreads/ui/unfinished_screen/unfinished_screen.dart'; @@ -114,311 +113,6 @@ class SettingsScreen extends StatelessWidget { } } - _setThemeModeAuto(BuildContext context, SetThemeState state) { - BlocProvider.of(context).add(ChangeThemeEvent( - themeMode: ThemeMode.system, - showOutlines: state.showOutlines, - cornerRadius: state.cornerRadius, - primaryColor: state.primaryColor, - fontFamily: state.fontFamily, - readTabFirst: state.readTabFirst, - useMaterialYou: state.useMaterialYou, - )); - - Navigator.of(context).pop(); - } - - _setThemeModeLight(BuildContext context, SetThemeState state) { - BlocProvider.of(context).add(ChangeThemeEvent( - themeMode: ThemeMode.light, - showOutlines: state.showOutlines, - cornerRadius: state.cornerRadius, - primaryColor: state.primaryColor, - fontFamily: state.fontFamily, - readTabFirst: state.readTabFirst, - useMaterialYou: state.useMaterialYou, - )); - - Navigator.of(context).pop(); - } - - _setThemeModeDark(BuildContext context, SetThemeState state) { - BlocProvider.of(context).add(ChangeThemeEvent( - themeMode: ThemeMode.dark, - showOutlines: state.showOutlines, - cornerRadius: state.cornerRadius, - primaryColor: state.primaryColor, - fontFamily: state.fontFamily, - readTabFirst: state.readTabFirst, - useMaterialYou: state.useMaterialYou, - )); - - Navigator.of(context).pop(); - } - - _setFont( - BuildContext context, - SetThemeState state, - Font font, - ) { - String? fontFamily; - - switch (font) { - case Font.system: - fontFamily = null; - break; - case Font.montserrat: - fontFamily = 'Montserrat'; - break; - case Font.lato: - fontFamily = 'Lato'; - break; - case Font.sofiaSans: - fontFamily = 'SofiaSans'; - break; - case Font.poppins: - fontFamily = 'Poppins'; - break; - case Font.raleway: - fontFamily = 'Raleway'; - break; - case Font.nunito: - fontFamily = 'Nunito'; - break; - case Font.playfairDisplay: - fontFamily = 'PlayfairDisplay'; - break; - case Font.kanit: - fontFamily = 'Kanit'; - break; - case Font.lora: - fontFamily = 'Lora'; - break; - case Font.quicksand: - fontFamily = 'Quicksand'; - break; - case Font.barlow: - fontFamily = 'Barlow'; - break; - case Font.jost: - fontFamily = 'Jost'; - break; - default: - fontFamily = 'Nunito'; - break; - } - - BlocProvider.of(context).add(ChangeThemeEvent( - themeMode: state.themeMode, - showOutlines: state.showOutlines, - cornerRadius: state.cornerRadius, - primaryColor: state.primaryColor, - fontFamily: fontFamily, - readTabFirst: state.readTabFirst, - useMaterialYou: state.useMaterialYou, - )); - - Navigator.of(context).pop(); - } - - _showOutlines(BuildContext context, SetThemeState state) { - BlocProvider.of(context).add(ChangeThemeEvent( - themeMode: state.themeMode, - showOutlines: true, - cornerRadius: state.cornerRadius, - primaryColor: state.primaryColor, - fontFamily: state.fontFamily, - readTabFirst: state.readTabFirst, - useMaterialYou: state.useMaterialYou, - )); - - Navigator.of(context).pop(); - } - - _hideOutlines(BuildContext context, SetThemeState state) { - BlocProvider.of(context).add(ChangeThemeEvent( - themeMode: state.themeMode, - showOutlines: false, - cornerRadius: state.cornerRadius, - primaryColor: state.primaryColor, - fontFamily: state.fontFamily, - readTabFirst: state.readTabFirst, - useMaterialYou: state.useMaterialYou, - )); - - Navigator.of(context).pop(); - } - - _changeCornerRadius( - BuildContext context, SetThemeState state, double radius) { - BlocProvider.of(context).add(ChangeThemeEvent( - themeMode: state.themeMode, - showOutlines: state.showOutlines, - cornerRadius: radius, - primaryColor: state.primaryColor, - fontFamily: state.fontFamily, - readTabFirst: state.readTabFirst, - useMaterialYou: state.useMaterialYou, - )); - - Navigator.of(context).pop(); - } - - _setAccentColor(BuildContext context, SetThemeState state, Color color) { - BlocProvider.of(context).add(ChangeThemeEvent( - themeMode: state.themeMode, - showOutlines: state.showOutlines, - cornerRadius: state.cornerRadius, - primaryColor: color, - fontFamily: state.fontFamily, - readTabFirst: state.readTabFirst, - useMaterialYou: false, - )); - - Navigator.of(context).pop(); - } - - _setMaterialYou(BuildContext context, SetThemeState state) { - BlocProvider.of(context).add(ChangeThemeEvent( - themeMode: state.themeMode, - showOutlines: state.showOutlines, - cornerRadius: state.cornerRadius, - primaryColor: state.primaryColor, - fontFamily: state.fontFamily, - readTabFirst: state.readTabFirst, - useMaterialYou: true, - )); - - Navigator.of(context).pop(); - } - - _showAccentColorDialog(BuildContext context) { - showDialog( - context: context, - builder: (BuildContext context) { - return Dialog( - shape: RoundedRectangleBorder( - borderRadius: BorderRadius.circular(cornerRadius), - ), - backgroundColor: Theme.of(context).colorScheme.surface, - child: Padding( - padding: const EdgeInsets.symmetric(horizontal: 10, vertical: 20), - child: BlocBuilder( - builder: (context, state) { - if (state is SetThemeState) { - return Column( - crossAxisAlignment: CrossAxisAlignment.start, - mainAxisSize: MainAxisSize.min, - children: [ - Padding( - padding: const EdgeInsets.only(left: 10), - child: Text( - LocaleKeys.select_accent_color.tr(), - style: const TextStyle( - fontSize: 18, - fontWeight: FontWeight.bold, - ), - ), - ), - const SizedBox(height: 15), - Scrollbar( - child: SingleChildScrollView( - child: Column( - children: [ - GestureDetector( - onTap: () => _setMaterialYou( - context, - state, - ), - child: Container( - padding: const EdgeInsets.all(10), - decoration: BoxDecoration( - borderRadius: - BorderRadius.circular(cornerRadius), - color: Theme.of(context) - .colorScheme - .surfaceVariant, - border: Border.all(color: dividerColor), - ), - child: Row( - children: [ - Text( - LocaleKeys.material_you.tr(), - style: const TextStyle( - fontSize: 16, - fontWeight: FontWeight.bold, - ), - ), - ], - ), - ), - ), - const SizedBox(height: 5), - _buildAccentButton( - context, - state, - primaryGreen, - LocaleKeys.green_color.tr(), - ), - _buildAccentButton( - context, - state, - primaryBlue, - LocaleKeys.blue_color.tr(), - ), - _buildAccentButton( - context, - state, - primaryRed, - LocaleKeys.red_color.tr(), - ), - _buildAccentButton( - context, - state, - primaryYellow, - LocaleKeys.yellow_color.tr(), - ), - _buildAccentButton( - context, - state, - primaryOrange, - LocaleKeys.orange_color.tr(), - ), - _buildAccentButton( - context, - state, - primaryPurple, - LocaleKeys.purple_color.tr(), - ), - _buildAccentButton( - context, - state, - primaryPink, - LocaleKeys.pink_color.tr(), - ), - _buildAccentButton( - context, - state, - primaryTeal, - LocaleKeys.teal_color.tr(), - ), - ], - ), - ), - ), - ], - ); - } else { - return const SizedBox(); - } - }, - ), - ), - ); - }, - ); - } - _showLanguageDialog(BuildContext context) { showDialog( context: context, @@ -487,565 +181,48 @@ class SettingsScreen extends StatelessWidget { state, null, ), - ), - ); - - for (var language in supportedLocales) { - widgets.add( - LanguageButton( - language: language.fullName, - onPressed: () => _setLanguage( - context, - state, - language.locale, - ), - ), - ); - } - - return widgets; - } - - _setLanguage(BuildContext context, SetThemeState state, Locale? locale) { - if (locale == null) { - if (context.supportedLocales.contains(context.deviceLocale)) { - context.resetLocale(); - } else { - context.setLocale(context.fallbackLocale!); - } - } else { - context.setLocale(locale); - } - - BlocProvider.of(context).add(ChangeThemeEvent( - themeMode: state.themeMode, - showOutlines: state.showOutlines, - cornerRadius: state.cornerRadius, - primaryColor: state.primaryColor, - fontFamily: state.fontFamily, - readTabFirst: state.readTabFirst, - useMaterialYou: state.useMaterialYou, - )); - - Navigator.of(context).pop(); - } - - Widget _buildAccentButton( - BuildContext context, - SetThemeState state, - Color color, - String colorName, - ) { - return Padding( - padding: const EdgeInsets.symmetric(vertical: 5), - child: Container( - decoration: BoxDecoration( - borderRadius: BorderRadius.circular(cornerRadius), - color: Theme.of(context).colorScheme.surfaceVariant, - border: Border.all(color: dividerColor), - ), - child: Row( - crossAxisAlignment: CrossAxisAlignment.center, - children: [ - Padding( - padding: const EdgeInsets.symmetric(horizontal: 10), - child: Container( - width: 50, - height: 25, - decoration: BoxDecoration( - borderRadius: BorderRadius.circular(cornerRadius), - color: color, - ), - ), - ), - Expanded( - child: SettingsDialogButton( - text: colorName, - onPressed: () => _setAccentColor( - context, - state, - color, - ), - ), - ), - ], - ), - ), - ); - } - - _showRatingBarDialog(BuildContext context) { - showDialog( - context: context, - builder: (BuildContext context) { - return Dialog( - shape: RoundedRectangleBorder( - borderRadius: BorderRadius.circular(cornerRadius), - ), - backgroundColor: Theme.of(context).colorScheme.surface, - child: Padding( - padding: const EdgeInsets.symmetric(horizontal: 10, vertical: 20), - child: Column( - crossAxisAlignment: CrossAxisAlignment.start, - mainAxisSize: MainAxisSize.min, - children: [ - Padding( - padding: const EdgeInsets.only(left: 10), - child: Text( - LocaleKeys.seletct_rating_type.tr(), - style: const TextStyle( - fontSize: 18, - fontWeight: FontWeight.bold, - ), - ), - ), - const SizedBox(height: 15), - SettingsDialogButton( - text: LocaleKeys.rating_as_bar.tr(), - onPressed: () { - BlocProvider.of(context).add( - const RatingTypeChange(ratingType: RatingType.bar), - ); - - Navigator.of(context).pop(); - }, - ), - const SizedBox(height: 5), - SettingsDialogButton( - text: LocaleKeys.rating_as_number.tr(), - onPressed: () { - BlocProvider.of(context).add( - const RatingTypeChange(ratingType: RatingType.number), - ); - - Navigator.of(context).pop(); - }, - ), - ], - ), - ), - ); - }, - ); - } - - _showThemeModeDialog(BuildContext context) { - showDialog( - context: context, - builder: (BuildContext context) { - return Dialog( - shape: RoundedRectangleBorder( - borderRadius: BorderRadius.circular(cornerRadius), - ), - backgroundColor: Theme.of(context).colorScheme.surface, - child: Padding( - padding: const EdgeInsets.symmetric(horizontal: 10, vertical: 20), - child: BlocBuilder( - builder: (context, state) { - if (state is SetThemeState) { - return Column( - crossAxisAlignment: CrossAxisAlignment.start, - mainAxisSize: MainAxisSize.min, - children: [ - Padding( - padding: const EdgeInsets.only(left: 10), - child: Text( - LocaleKeys.select_theme_mode.tr(), - style: const TextStyle( - fontSize: 18, - fontWeight: FontWeight.bold, - ), - ), - ), - const SizedBox(height: 15), - SettingsDialogButton( - text: LocaleKeys.theme_mode_system.tr(), - onPressed: () => _setThemeModeAuto(context, state), - ), - const SizedBox(height: 5), - SettingsDialogButton( - text: LocaleKeys.theme_mode_light.tr(), - onPressed: () => _setThemeModeLight(context, state), - ), - const SizedBox(height: 5), - SettingsDialogButton( - text: LocaleKeys.theme_mode_dark.tr(), - onPressed: () => _setThemeModeDark(context, state), - ), - ], - ); - } else { - return const SizedBox(); - } - }, - ), - ), - ); - }, - ); - } - - _showFontDialog(BuildContext context) { - showDialog( - context: context, - builder: (BuildContext context) { - return Dialog( - shape: RoundedRectangleBorder( - borderRadius: BorderRadius.circular(cornerRadius), - ), - backgroundColor: Theme.of(context).colorScheme.surface, - child: Padding( - padding: const EdgeInsets.symmetric(horizontal: 10, vertical: 20), - child: BlocBuilder( - builder: (context, state) { - if (state is SetThemeState) { - return Column( - crossAxisAlignment: CrossAxisAlignment.start, - children: [ - Padding( - padding: const EdgeInsets.only(left: 10), - child: Text( - LocaleKeys.select_font.tr(), - style: const TextStyle( - fontSize: 18, - fontWeight: FontWeight.bold, - ), - ), - ), - const SizedBox(height: 15), - Expanded( - child: Scrollbar( - thumbVisibility: true, - child: SingleChildScrollView( - child: Column( - crossAxisAlignment: CrossAxisAlignment.start, - mainAxisSize: MainAxisSize.min, - children: [ - SettingsDialogButton( - text: LocaleKeys.font_default.tr(), - onPressed: () => _setFont( - context, - state, - Font.system, - ), - ), - const SizedBox(height: 5), - SettingsDialogButton( - text: 'Nunito', - onPressed: () => _setFont( - context, - state, - Font.nunito, - ), - ), - const SizedBox(height: 5), - SettingsDialogButton( - text: 'Jost', - onPressed: () => _setFont( - context, - state, - Font.jost, - ), - ), - const SizedBox(height: 5), - SettingsDialogButton( - text: 'Barlow', - onPressed: () => _setFont( - context, - state, - Font.barlow, - ), - ), - const SizedBox(height: 5), - SettingsDialogButton( - text: 'Kanit', - onPressed: () => _setFont( - context, - state, - Font.kanit, - ), - ), - const SizedBox(height: 5), - SettingsDialogButton( - text: 'Lato', - onPressed: () => _setFont( - context, - state, - Font.lato, - ), - ), - const SizedBox(height: 5), - SettingsDialogButton( - text: 'Lora', - onPressed: () => _setFont( - context, - state, - Font.lora, - ), - ), - const SizedBox(height: 5), - SettingsDialogButton( - text: 'Montserrat', - onPressed: () => _setFont( - context, - state, - Font.montserrat, - ), - ), - const SizedBox(height: 5), - SettingsDialogButton( - text: 'Playfair Display', - onPressed: () => _setFont( - context, - state, - Font.playfairDisplay, - ), - ), - const SizedBox(height: 5), - SettingsDialogButton( - text: 'Poppins', - onPressed: () => _setFont( - context, - state, - Font.poppins, - ), - ), - const SizedBox(height: 5), - SettingsDialogButton( - text: 'Raleway', - onPressed: () => _setFont( - context, - state, - Font.raleway, - ), - ), - const SizedBox(height: 5), - SettingsDialogButton( - text: 'Sofia Sans', - onPressed: () => _setFont( - context, - state, - Font.sofiaSans, - ), - ), - const SizedBox(height: 5), - SettingsDialogButton( - text: 'Quicksand', - onPressed: () => _setFont( - context, - state, - Font.quicksand, - ), - ), - ], - ), - ), - ), - ), - ], - ); - } else { - return const SizedBox(); - } - }, - ), - ), - ); - }, - ); - } - - _showOutlinesDialog(BuildContext context) { - showDialog( - context: context, - builder: (BuildContext context) { - return Dialog( - shape: RoundedRectangleBorder( - borderRadius: BorderRadius.circular(cornerRadius), - ), - backgroundColor: Theme.of(context).colorScheme.surface, - child: Padding( - padding: const EdgeInsets.symmetric(horizontal: 10, vertical: 20), - child: BlocBuilder( - builder: (context, state) { - if (state is SetThemeState) { - return Column( - crossAxisAlignment: CrossAxisAlignment.start, - mainAxisSize: MainAxisSize.min, - children: [ - Padding( - padding: const EdgeInsets.only(left: 10), - child: Text( - LocaleKeys.display_outlines.tr(), - style: const TextStyle( - fontSize: 18, - fontWeight: FontWeight.bold, - ), - ), - ), - const SizedBox(height: 15), - SettingsDialogButton( - text: LocaleKeys.show_outlines.tr(), - onPressed: () => _showOutlines(context, state), - ), - const SizedBox(height: 5), - SettingsDialogButton( - text: LocaleKeys.hide_outlines.tr(), - onPressed: () => _hideOutlines(context, state), - ), - ], - ); - } else { - return const SizedBox(); - } - }, - ), - ), - ); - }, - ); - } - - _showCornerRadiusDialog(BuildContext context) { - showDialog( - context: context, - builder: (BuildContext context) { - return Dialog( - shape: RoundedRectangleBorder( - borderRadius: BorderRadius.circular(cornerRadius), - ), - backgroundColor: Theme.of(context).colorScheme.surface, - child: Padding( - padding: const EdgeInsets.symmetric(horizontal: 10, vertical: 20), - child: BlocBuilder( - builder: (context, state) { - if (state is SetThemeState) { - return Column( - crossAxisAlignment: CrossAxisAlignment.start, - mainAxisSize: MainAxisSize.min, - children: [ - Padding( - padding: const EdgeInsets.only(left: 10), - child: Text( - LocaleKeys.select_corner_radius.tr(), - style: const TextStyle( - fontSize: 18, - fontWeight: FontWeight.bold, - ), - ), - ), - const SizedBox(height: 15), - SettingsDialogButton( - text: LocaleKeys.no_rounded_corners.tr(), - onPressed: () => _changeCornerRadius(context, state, 0), - ), - const SizedBox(height: 5), - SettingsDialogButton( - text: LocaleKeys.small_rounded_corners.tr(), - onPressed: () => _changeCornerRadius(context, state, 5), - ), - const SizedBox(height: 5), - SettingsDialogButton( - text: LocaleKeys.medium_rounded_corners.tr(), - onPressed: () => - _changeCornerRadius(context, state, 10), - ), - const SizedBox(height: 5), - SettingsDialogButton( - text: LocaleKeys.big_rounded_corners.tr(), - onPressed: () => - _changeCornerRadius(context, state, 20), - ), - ], - ); - } else { - return const SizedBox(); - } - }, - ), - ), - ); - }, - ); - } - - _showTabsOrderDialog(BuildContext context) { - showDialog( - context: context, - builder: (BuildContext context) { - return Dialog( - shape: RoundedRectangleBorder( - borderRadius: BorderRadius.circular(cornerRadius), - ), - backgroundColor: Theme.of(context).colorScheme.surface, - child: Padding( - padding: const EdgeInsets.symmetric(horizontal: 10, vertical: 20), - child: BlocBuilder( - builder: (context, state) { - if (state is SetThemeState) { - return Column( - crossAxisAlignment: CrossAxisAlignment.start, - mainAxisSize: MainAxisSize.min, - children: [ - Padding( - padding: const EdgeInsets.only(left: 10), - child: Text( - LocaleKeys.select_tabs_order.tr(), - style: const TextStyle( - fontSize: 18, - fontWeight: FontWeight.bold, - ), - ), - ), - const SizedBox(height: 15), - SettingsDialogButton( - text: LocaleKeys.tabs_order_read_first.tr(), - onPressed: () { - BlocProvider.of(context).add( - ChangeThemeEvent( - themeMode: state.themeMode, - showOutlines: state.showOutlines, - cornerRadius: state.cornerRadius, - primaryColor: state.primaryColor, - fontFamily: state.fontFamily, - readTabFirst: true, - useMaterialYou: state.useMaterialYou, - ), - ); - - Navigator.of(context).pop(); - }, - ), - const SizedBox(height: 5), - SettingsDialogButton( - text: LocaleKeys.tabs_order_in_progress_first.tr(), - onPressed: () { - BlocProvider.of(context).add( - ChangeThemeEvent( - themeMode: state.themeMode, - showOutlines: state.showOutlines, - cornerRadius: state.cornerRadius, - primaryColor: state.primaryColor, - fontFamily: state.fontFamily, - readTabFirst: false, - useMaterialYou: state.useMaterialYou, - ), - ); + ), + ); - Navigator.of(context).pop(); - }, - ), - ], - ); - } else { - return const SizedBox(); - } - }, - ), + for (var language in supportedLocales) { + widgets.add( + LanguageButton( + language: language.fullName, + onPressed: () => _setLanguage( + context, + state, + language.locale, ), - ); - }, - ); + ), + ); + } + + return widgets; + } + + _setLanguage(BuildContext context, SetThemeState state, Locale? locale) { + if (locale == null) { + if (context.supportedLocales.contains(context.deviceLocale)) { + context.resetLocale(); + } else { + context.setLocale(context.fallbackLocale!); + } + } else { + context.setLocale(locale); + } + + BlocProvider.of(context).add(ChangeThemeEvent( + themeMode: state.themeMode, + showOutlines: state.showOutlines, + cornerRadius: state.cornerRadius, + primaryColor: state.primaryColor, + fontFamily: state.fontFamily, + readTabFirst: state.readTabFirst, + useMaterialYou: state.useMaterialYou, + amoledDark: state.amoledDark, + )); + + Navigator.of(context).pop(); } SettingsTile _buildURLSetting({ @@ -1297,73 +474,23 @@ class SettingsScreen extends StatelessWidget { ); } - SettingsTile _buildAccentSetting(BuildContext context) { + SettingsTile _buildAppearanceSetting(BuildContext context) { return SettingsTile( title: Text( - LocaleKeys.accent_color.tr(), + LocaleKeys.apperance.tr(), style: const TextStyle( fontSize: 16, ), ), leading: const Icon(Icons.color_lens), - description: BlocBuilder( - builder: (_, themeState) { - if (themeState is SetThemeState) { - if (themeState.useMaterialYou) { - return Text( - LocaleKeys.material_you.tr(), - style: const TextStyle(), - ); - } - - switch (themeState.primaryColor.value) { - case 0xffB73E3E: - return Text( - LocaleKeys.red_color.tr(), - style: const TextStyle(), - ); - case 0xff2146C7: - return Text( - LocaleKeys.blue_color.tr(), - style: const TextStyle(), - ); - case 0xff285430: - return Text( - LocaleKeys.green_color.tr(), - style: const TextStyle(), - ); - case 0xffE14D2A: - return Text( - LocaleKeys.orange_color.tr(), - style: const TextStyle(), - ); - case 0xff9F73AB: - return Text( - LocaleKeys.purple_color.tr(), - style: const TextStyle(), - ); - case 0xffFF577F: - return Text( - LocaleKeys.pink_color.tr(), - style: const TextStyle(), - ); - case 0xff3FA796: - return Text( - LocaleKeys.teal_color.tr(), - style: const TextStyle(), - ); - default: - return Text( - LocaleKeys.yellow_color.tr(), - style: const TextStyle(), - ); - } - } else { - return const SizedBox(); - } - }, - ), - onPressed: (context) => _showAccentColorDialog(context), + onPressed: (context) { + Navigator.push( + context, + MaterialPageRoute( + builder: (context) => const SettingsApperanceScreen(), + ), + ); + }, ); } @@ -1403,218 +530,6 @@ class SettingsScreen extends StatelessWidget { ); } - SettingsTile _buildCornersSetting(BuildContext context) { - return SettingsTile( - title: Text( - LocaleKeys.rounded_corners.tr(), - style: const TextStyle( - fontSize: 16, - ), - ), - leading: const Icon(Icons.rounded_corner_rounded), - description: BlocBuilder( - builder: (_, themeState) { - if (themeState is SetThemeState) { - if (themeState.cornerRadius == 5) { - return Text( - LocaleKeys.small_rounded_corners.tr(), - style: const TextStyle(), - ); - } else if (themeState.cornerRadius == 10) { - return Text( - LocaleKeys.medium_rounded_corners.tr(), - style: const TextStyle(), - ); - } else if (themeState.cornerRadius == 20) { - return Text( - LocaleKeys.big_rounded_corners.tr(), - style: const TextStyle(), - ); - } else { - return Text( - LocaleKeys.no_rounded_corners.tr(), - style: const TextStyle(), - ); - } - } else { - return const SizedBox(); - } - }, - ), - onPressed: (context) => _showCornerRadiusDialog(context), - ); - } - - SettingsTile _buildOutlinesSetting(BuildContext context) { - return SettingsTile( - title: Text( - LocaleKeys.display_outlines.tr(), - style: const TextStyle( - fontSize: 16, - ), - ), - leading: const Icon(Icons.check_box_outline_blank_rounded), - description: BlocBuilder( - builder: (_, themeState) { - if (themeState is SetThemeState) { - if (themeState.showOutlines) { - return Text( - LocaleKeys.show_outlines.tr(), - style: const TextStyle(), - ); - } else { - return Text( - LocaleKeys.hide_outlines.tr(), - style: const TextStyle(), - ); - } - } else { - return const SizedBox(); - } - }, - ), - onPressed: (context) => _showOutlinesDialog(context), - ); - } - - SettingsTile _buildThemeModeSetting(BuildContext context) { - return SettingsTile( - title: Text( - LocaleKeys.theme_mode.tr(), - style: const TextStyle( - fontSize: 16, - ), - ), - leading: const Icon(Icons.sunny), - description: BlocBuilder( - builder: (_, themeState) { - if (themeState is SetThemeState) { - switch (themeState.themeMode) { - case ThemeMode.light: - return Text( - LocaleKeys.theme_mode_light.tr(), - style: const TextStyle(), - ); - case ThemeMode.dark: - return Text( - LocaleKeys.theme_mode_dark.tr(), - style: const TextStyle(), - ); - default: - return Text( - LocaleKeys.theme_mode_system.tr(), - style: const TextStyle(), - ); - } - } else { - return const SizedBox(); - } - }, - ), - onPressed: (context) => _showThemeModeDialog(context), - ); - } - - SettingsTile _buildFontSetting(BuildContext context) { - return SettingsTile( - title: Text( - LocaleKeys.font.tr(), - style: const TextStyle( - fontSize: 16, - ), - ), - leading: const Icon( - Icons.font_download, - size: 22, - ), - description: BlocBuilder( - builder: (_, state) { - if (state is SetThemeState) { - if (state.fontFamily != null) { - return Text( - state.fontFamily!, - style: const TextStyle(), - ); - } else { - return Text( - LocaleKeys.font_default.tr(), - style: const TextStyle(), - ); - } - } else { - return const SizedBox(); - } - }, - ), - onPressed: (context) => _showFontDialog(context), - ); - } - - SettingsTile _buildRatingTypeSetting(BuildContext context) { - return SettingsTile( - title: Text( - LocaleKeys.rating_type.tr(), - style: const TextStyle( - fontSize: 16, - ), - ), - leading: const Icon(Icons.star_rounded), - description: BlocBuilder( - builder: (_, state) { - if (state is RatingTypeNumber) { - return Text( - LocaleKeys.rating_as_number.tr(), - style: const TextStyle(), - ); - } else if (state is RatingTypeBar) { - return Text( - LocaleKeys.rating_as_bar.tr(), - style: const TextStyle(), - ); - } else { - return const SizedBox(); - } - }, - ), - onPressed: (context) => _showRatingBarDialog(context), - ); - } - - SettingsTile _buildTabOrderSetting(BuildContext context) { - return SettingsTile( - title: Text( - LocaleKeys.tabs_order.tr(), - style: const TextStyle( - fontSize: 16, - ), - ), - leading: const FaIcon( - FontAwesomeIcons.tableColumns, - size: 22, - ), - description: BlocBuilder( - builder: (_, state) { - if (state is SetThemeState) { - if (state.readTabFirst) { - return Text( - LocaleKeys.tabs_order_read_first.tr(), - style: const TextStyle(), - ); - } else { - return Text( - LocaleKeys.tabs_order_in_progress_first.tr(), - style: const TextStyle(), - ); - } - } else { - return const SizedBox(); - } - }, - ), - onPressed: (context) => _showTabsOrderDialog(context), - ); - } - Future _getAppVersion() async { PackageInfo packageInfo = await PackageInfo.fromPlatform(); @@ -1638,118 +553,119 @@ class SettingsScreen extends StatelessWidget { if (snapshot.hasData) { version = snapshot.data; - return SettingsList( - contentPadding: const EdgeInsets.only(top: 10), - darkTheme: SettingsThemeData( - settingsListBackground: Theme.of(context).colorScheme.surface, - ), - lightTheme: SettingsThemeData( - settingsListBackground: Theme.of(context).colorScheme.surface, - ), - sections: [ - SettingsSection( - tiles: [ - _buildSupportSetting(context), - _buildURLSetting( - title: LocaleKeys.join_community.tr(), - description: LocaleKeys.join_community_description.tr(), - url: communityUrl, - iconData: FontAwesomeIcons.peopleGroup, - context: context, - ), - // TODO: Show only on GPlay variant - _buildURLSetting( - title: LocaleKeys.rate_app.tr(), - description: LocaleKeys.rate_app_description.tr(), - url: rateUrl, - iconData: Icons.star_rounded, - context: context, - ), - _buildFeedbackSetting(context), - _buildURLSetting( - title: LocaleKeys.translate_app.tr(), - description: LocaleKeys.translate_app_description.tr(), - url: translationUrl, - iconData: Icons.translate_rounded, - context: context, - ), - ], - ), - SettingsSection( - title: Text( - LocaleKeys.app.tr(), - style: TextStyle( - fontSize: 16, - fontWeight: FontWeight.bold, - color: Theme.of(context).colorScheme.primary, - ), - ), - tiles: [ - _buildLanguageSetting(context), - _buildTrashSetting(context), - _buildUnfinishedSetting(context), - _buildBackupSetting(context), - ], - ), - SettingsSection( - title: Text( - LocaleKeys.apperance.tr(), - style: TextStyle( - fontSize: 16, - fontWeight: FontWeight.bold, - color: Theme.of(context).colorScheme.primary, - ), + return BlocBuilder( + builder: (context, state) { + late final bool amoledDark; + + if (state is SetThemeState) { + amoledDark = state.amoledDark; + } else { + amoledDark = false; + } + + return SettingsList( + contentPadding: const EdgeInsets.only(top: 10), + darkTheme: SettingsThemeData( + settingsListBackground: amoledDark + ? Colors.black + : Theme.of(context).colorScheme.surface, ), - tiles: [ - _buildAccentSetting(context), - _buildThemeModeSetting(context), - _buildFontSetting(context), - _buildRatingTypeSetting(context), - _buildTabOrderSetting(context), - _buildOutlinesSetting(context), - _buildCornersSetting(context), - ], - ), - SettingsSection( - title: Text( - LocaleKeys.about.tr(), - style: TextStyle( - fontSize: 16, - fontWeight: FontWeight.bold, - color: Theme.of(context).colorScheme.primary, - ), + lightTheme: SettingsThemeData( + settingsListBackground: amoledDark + ? Colors.black + : Theme.of(context).colorScheme.surface, ), - tiles: [ - _buildURLSetting( - title: LocaleKeys.version.tr(), - description: version, - iconData: FontAwesomeIcons.rocket, - context: context, - ), - _buildURLSetting( - title: LocaleKeys.changelog.tr(), - description: LocaleKeys.changelog_description.tr(), - url: releasesUrl, - iconData: Icons.auto_awesome_rounded, - context: context, + sections: [ + SettingsSection( + tiles: [ + _buildSupportSetting(context), + _buildURLSetting( + title: LocaleKeys.join_community.tr(), + description: + LocaleKeys.join_community_description.tr(), + url: communityUrl, + iconData: FontAwesomeIcons.peopleGroup, + context: context, + ), + // TODO: Show only on GPlay variant + _buildURLSetting( + title: LocaleKeys.rate_app.tr(), + description: LocaleKeys.rate_app_description.tr(), + url: rateUrl, + iconData: Icons.star_rounded, + context: context, + ), + _buildFeedbackSetting(context), + _buildURLSetting( + title: LocaleKeys.translate_app.tr(), + description: + LocaleKeys.translate_app_description.tr(), + url: translationUrl, + iconData: Icons.translate_rounded, + context: context, + ), + ], ), - _buildURLSetting( - title: LocaleKeys.source_code.tr(), - description: LocaleKeys.source_code_description.tr(), - url: repoUrl, - iconData: FontAwesomeIcons.code, - context: context, + SettingsSection( + title: Text( + LocaleKeys.app.tr(), + style: TextStyle( + fontSize: 16, + fontWeight: FontWeight.bold, + color: Theme.of(context).colorScheme.primary, + ), + ), + tiles: [ + _buildLanguageSetting(context), + _buildTrashSetting(context), + _buildUnfinishedSetting(context), + _buildBackupSetting(context), + _buildAppearanceSetting(context), + ], ), - _buildURLSetting( - title: LocaleKeys.licence.tr(), - description: licence, - url: licenceUrl, - iconData: Icons.copyright_rounded, - context: context, + SettingsSection( + title: Text( + LocaleKeys.about.tr(), + style: TextStyle( + fontSize: 16, + fontWeight: FontWeight.bold, + color: Theme.of(context).colorScheme.primary, + ), + ), + tiles: [ + _buildURLSetting( + title: LocaleKeys.version.tr(), + description: version, + iconData: FontAwesomeIcons.rocket, + context: context, + ), + _buildURLSetting( + title: LocaleKeys.changelog.tr(), + description: LocaleKeys.changelog_description.tr(), + url: releasesUrl, + iconData: Icons.auto_awesome_rounded, + context: context, + ), + _buildURLSetting( + title: LocaleKeys.source_code.tr(), + description: + LocaleKeys.source_code_description.tr(), + url: repoUrl, + iconData: FontAwesomeIcons.code, + context: context, + ), + _buildURLSetting( + title: LocaleKeys.licence.tr(), + description: licence, + url: licenceUrl, + iconData: Icons.copyright_rounded, + context: context, + ), + ], ), ], - ), - ], + ); + }, ); } else { return const SizedBox(); From 29ce1ffae575f7a8d9891817195a7006250cda25 Mon Sep 17 00:00:00 2001 From: mateusz-bak <32651935+mateusz-bak@users.noreply.github.com> Date: Sun, 9 Jul 2023 09:50:56 +0100 Subject: [PATCH 2/2] refactor: Renamed backup screen files --- lib/ui/books_screen/books_screen.dart | 4 ++-- .../settings_backup_screen.dart} | 8 ++++---- lib/ui/settings_screen/settings_screen.dart | 4 ++-- 3 files changed, 8 insertions(+), 8 deletions(-) rename lib/ui/{backup_screen/backup_screen.dart => settings_backup_screen/settings_backup_screen.dart} (99%) diff --git a/lib/ui/books_screen/books_screen.dart b/lib/ui/books_screen/books_screen.dart index fa4182da5..9251aff85 100644 --- a/lib/ui/books_screen/books_screen.dart +++ b/lib/ui/books_screen/books_screen.dart @@ -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'; @@ -411,7 +411,7 @@ class _BooksScreenState extends State label: LocaleKeys.click_here_to_restore_them.tr(), onPressed: () { Navigator.push(context, MaterialPageRoute(builder: (_) { - return BackupScreen(autoMigrationV1ToV2: true); + return SettingsBackupScreen(autoMigrationV1ToV2: true); })); }), ), diff --git a/lib/ui/backup_screen/backup_screen.dart b/lib/ui/settings_backup_screen/settings_backup_screen.dart similarity index 99% rename from lib/ui/backup_screen/backup_screen.dart rename to lib/ui/settings_backup_screen/settings_backup_screen.dart index fa961c0db..5b0cf6269 100644 --- a/lib/ui/backup_screen/backup_screen.dart +++ b/lib/ui/settings_backup_screen/settings_backup_screen.dart @@ -30,8 +30,8 @@ import 'package:sqflite/sqflite.dart'; import 'package:blurhash_dart/blurhash_dart.dart' as blurhash_dart; import 'package:image/image.dart' as img; -class BackupScreen extends StatefulWidget { - BackupScreen({ +class SettingsBackupScreen extends StatefulWidget { + SettingsBackupScreen({ super.key, this.autoMigrationV1ToV2 = false, }); @@ -39,10 +39,10 @@ class BackupScreen extends StatefulWidget { bool autoMigrationV1ToV2; @override - State createState() => _BackupScreenState(); + State createState() => _SettingsBackupScreenState(); } -class _BackupScreenState extends State { +class _SettingsBackupScreenState extends State { bool _creatingLocal = false; bool _creatingCloud = false; bool _restoringLocal = false; diff --git a/lib/ui/settings_screen/settings_screen.dart b/lib/ui/settings_screen/settings_screen.dart index e846a4f5a..a5f4ebebf 100644 --- a/lib/ui/settings_screen/settings_screen.dart +++ b/lib/ui/settings_screen/settings_screen.dart @@ -9,7 +9,7 @@ import 'package:openreads/core/constants.dart/locale.dart'; import 'package:openreads/core/themes/app_theme.dart'; import 'package:openreads/generated/locale_keys.g.dart'; import 'package:openreads/logic/bloc/theme_bloc/theme_bloc.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/settings_apperance_screen/settings_apperance_screen.dart'; import 'package:openreads/ui/settings_screen/widgets/widgets.dart'; import 'package:openreads/ui/trash_screen/trash_screen.dart'; @@ -467,7 +467,7 @@ class SettingsScreen extends StatelessWidget { Navigator.push( context, MaterialPageRoute( - builder: (context) => BackupScreen(), + builder: (context) => SettingsBackupScreen(), ), ); },