Browse Source

Merge pull request #845 from nextcloud/refactor/neon/settings-switches

Refactor/neon/settings switches
pull/840/head
Kate 1 year ago committed by GitHub
parent
commit
6609be85b9
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 2
      packages/app/integration_test/screenshot_test.dart
  2. 4
      packages/neon/neon/lib/src/pages/account_settings.dart
  3. 28
      packages/neon/neon/lib/src/pages/settings.dart
  4. 8
      packages/neon/neon/lib/src/settings/widgets/option_settings_tile.dart
  5. 4
      packages/neon/neon/lib/src/settings/widgets/select_settings_tile.dart
  6. 11
      packages/neon/neon/lib/src/settings/widgets/toggle_settings_tile.dart

2
packages/app/integration_test/screenshot_test.dart

@ -346,7 +346,7 @@ Future<void> main() async {
await binding.takeScreenshot('settings_dark'); await binding.takeScreenshot('settings_dark');
// Enable OLED theme // Enable OLED theme
await tester.tap(find.byType(CheckboxListTile).first); await tester.tap(find.byType(SwitchListTile).first);
await tester.pumpAndSettle(); await tester.pumpAndSettle();
await binding.takeScreenshot('settings_oled'); await binding.takeScreenshot('settings_oled');

4
packages/neon/neon/lib/src/pages/account_settings.dart

@ -8,7 +8,7 @@ import 'package:neon/src/blocs/accounts.dart';
import 'package:neon/src/models/account.dart'; import 'package:neon/src/models/account.dart';
import 'package:neon/src/router.dart'; import 'package:neon/src/router.dart';
import 'package:neon/src/settings/widgets/custom_settings_tile.dart'; import 'package:neon/src/settings/widgets/custom_settings_tile.dart';
import 'package:neon/src/settings/widgets/dropdown_button_settings_tile.dart'; import 'package:neon/src/settings/widgets/select_settings_tile.dart';
import 'package:neon/src/settings/widgets/settings_category.dart'; import 'package:neon/src/settings/widgets/settings_category.dart';
import 'package:neon/src/settings/widgets/settings_list.dart'; import 'package:neon/src/settings/widgets/settings_list.dart';
import 'package:neon/src/theme/dialog.dart'; import 'package:neon/src/theme/dialog.dart';
@ -119,7 +119,7 @@ class AccountSettingsPage extends StatelessWidget {
SettingsCategory( SettingsCategory(
title: Text(AppLocalizations.of(context).optionsCategoryGeneral), title: Text(AppLocalizations.of(context).optionsCategoryGeneral),
tiles: [ tiles: [
DropdownButtonSettingsTile( SelectSettingsTile(
option: options.initialApp, option: options.initialApp,
), ),
], ],

28
packages/neon/neon/lib/src/pages/settings.dart

@ -10,13 +10,13 @@ import 'package:neon/src/platform/platform.dart';
import 'package:neon/src/router.dart'; import 'package:neon/src/router.dart';
import 'package:neon/src/settings/utils/settings_export_helper.dart'; import 'package:neon/src/settings/utils/settings_export_helper.dart';
import 'package:neon/src/settings/widgets/account_settings_tile.dart'; import 'package:neon/src/settings/widgets/account_settings_tile.dart';
import 'package:neon/src/settings/widgets/checkbox_settings_tile.dart';
import 'package:neon/src/settings/widgets/custom_settings_tile.dart'; import 'package:neon/src/settings/widgets/custom_settings_tile.dart';
import 'package:neon/src/settings/widgets/dropdown_button_settings_tile.dart'; import 'package:neon/src/settings/widgets/select_settings_tile.dart';
import 'package:neon/src/settings/widgets/settings_category.dart'; import 'package:neon/src/settings/widgets/settings_category.dart';
import 'package:neon/src/settings/widgets/settings_list.dart'; import 'package:neon/src/settings/widgets/settings_list.dart';
import 'package:neon/src/settings/widgets/settings_tile.dart'; import 'package:neon/src/settings/widgets/settings_tile.dart';
import 'package:neon/src/settings/widgets/text_settings_tile.dart'; import 'package:neon/src/settings/widgets/text_settings_tile.dart';
import 'package:neon/src/settings/widgets/toggle_settings_tile.dart';
import 'package:neon/src/theme/branding.dart'; import 'package:neon/src/theme/branding.dart';
import 'package:neon/src/theme/dialog.dart'; import 'package:neon/src/theme/dialog.dart';
import 'package:neon/src/utils/confirmation_dialog.dart'; import 'package:neon/src/utils/confirmation_dialog.dart';
@ -120,13 +120,13 @@ class _SettingsPageState extends State<SettingsPage> {
title: Text(AppLocalizations.of(context).optionsCategoryTheme), title: Text(AppLocalizations.of(context).optionsCategoryTheme),
key: ValueKey(SettingsCategories.theme.name), key: ValueKey(SettingsCategories.theme.name),
tiles: [ tiles: [
DropdownButtonSettingsTile( SelectSettingsTile(
option: globalOptions.themeMode, option: globalOptions.themeMode,
), ),
CheckBoxSettingsTile( ToggleSettingsTile(
option: globalOptions.themeOLEDAsDark, option: globalOptions.themeOLEDAsDark,
), ),
CheckBoxSettingsTile( ToggleSettingsTile(
option: globalOptions.themeKeepOriginalAccentColor, option: globalOptions.themeKeepOriginalAccentColor,
), ),
], ],
@ -135,7 +135,7 @@ class _SettingsPageState extends State<SettingsPage> {
title: Text(AppLocalizations.of(context).optionsCategoryNavigation), title: Text(AppLocalizations.of(context).optionsCategoryNavigation),
key: ValueKey(SettingsCategories.navigation.name), key: ValueKey(SettingsCategories.navigation.name),
tiles: [ tiles: [
DropdownButtonSettingsTile( SelectSettingsTile(
option: globalOptions.navigationMode, option: globalOptions.navigationMode,
), ),
], ],
@ -155,10 +155,10 @@ class _SettingsPageState extends State<SettingsPage> {
), ),
), ),
], ],
CheckBoxSettingsTile( ToggleSettingsTile(
option: globalOptions.pushNotificationsEnabled, option: globalOptions.pushNotificationsEnabled,
), ),
DropdownButtonSettingsTile( SelectSettingsTile(
option: globalOptions.pushNotificationsDistributor, option: globalOptions.pushNotificationsDistributor,
), ),
], ],
@ -169,10 +169,10 @@ class _SettingsPageState extends State<SettingsPage> {
title: Text(AppLocalizations.of(context).optionsCategoryStartup), title: Text(AppLocalizations.of(context).optionsCategoryStartup),
key: ValueKey(SettingsCategories.startup.name), key: ValueKey(SettingsCategories.startup.name),
tiles: [ tiles: [
CheckBoxSettingsTile( ToggleSettingsTile(
option: globalOptions.startupMinimized, option: globalOptions.startupMinimized,
), ),
CheckBoxSettingsTile( ToggleSettingsTile(
option: globalOptions.startupMinimizeInsteadOfExit, option: globalOptions.startupMinimizeInsteadOfExit,
), ),
], ],
@ -183,10 +183,10 @@ class _SettingsPageState extends State<SettingsPage> {
title: Text(AppLocalizations.of(context).optionsCategorySystemTray), title: Text(AppLocalizations.of(context).optionsCategorySystemTray),
key: ValueKey(SettingsCategories.systemTray.name), key: ValueKey(SettingsCategories.systemTray.name),
tiles: [ tiles: [
CheckBoxSettingsTile( ToggleSettingsTile(
option: globalOptions.systemTrayEnabled, option: globalOptions.systemTrayEnabled,
), ),
CheckBoxSettingsTile( ToggleSettingsTile(
option: globalOptions.systemTrayHideToTrayWhenMinimized, option: globalOptions.systemTrayHideToTrayWhenMinimized,
), ),
], ],
@ -197,10 +197,10 @@ class _SettingsPageState extends State<SettingsPage> {
key: ValueKey(SettingsCategories.accounts.name), key: ValueKey(SettingsCategories.accounts.name),
tiles: [ tiles: [
if (accountsSnapshot.requireData.length > 1) ...[ if (accountsSnapshot.requireData.length > 1) ...[
CheckBoxSettingsTile( ToggleSettingsTile(
option: globalOptions.rememberLastUsedAccount, option: globalOptions.rememberLastUsedAccount,
), ),
DropdownButtonSettingsTile( SelectSettingsTile(
option: globalOptions.initialAccount, option: globalOptions.initialAccount,
), ),
], ],

8
packages/neon/neon/lib/src/settings/widgets/option_settings_tile.dart

@ -1,9 +1,9 @@
import 'package:flutter/widgets.dart'; import 'package:flutter/widgets.dart';
import 'package:meta/meta.dart'; import 'package:meta/meta.dart';
import 'package:neon/settings.dart'; import 'package:neon/settings.dart';
import 'package:neon/src/settings/widgets/checkbox_settings_tile.dart'; import 'package:neon/src/settings/widgets/select_settings_tile.dart';
import 'package:neon/src/settings/widgets/dropdown_button_settings_tile.dart';
import 'package:neon/src/settings/widgets/settings_tile.dart'; import 'package:neon/src/settings/widgets/settings_tile.dart';
import 'package:neon/src/settings/widgets/toggle_settings_tile.dart';
@internal @internal
class OptionSettingsTile extends InputSettingsTile { class OptionSettingsTile extends InputSettingsTile {
@ -14,7 +14,7 @@ class OptionSettingsTile extends InputSettingsTile {
@override @override
Widget build(final BuildContext context) => switch (option) { Widget build(final BuildContext context) => switch (option) {
ToggleOption() => CheckBoxSettingsTile(option: option as ToggleOption), ToggleOption() => ToggleSettingsTile(option: option as ToggleOption),
SelectOption() => DropdownButtonSettingsTile(option: option as SelectOption), SelectOption() => SelectSettingsTile(option: option as SelectOption),
}; };
} }

4
packages/neon/neon/lib/src/settings/widgets/dropdown_button_settings_tile.dart → packages/neon/neon/lib/src/settings/widgets/select_settings_tile.dart

@ -4,8 +4,8 @@ import 'package:neon/src/settings/models/option.dart';
import 'package:neon/src/settings/widgets/settings_tile.dart'; import 'package:neon/src/settings/widgets/settings_tile.dart';
@internal @internal
class DropdownButtonSettingsTile<T> extends InputSettingsTile<SelectOption<T>> { class SelectSettingsTile<T> extends InputSettingsTile<SelectOption<T>> {
const DropdownButtonSettingsTile({ const SelectSettingsTile({
required super.option, required super.option,
super.key, super.key,
}); });

11
packages/neon/neon/lib/src/settings/widgets/checkbox_settings_tile.dart → packages/neon/neon/lib/src/settings/widgets/toggle_settings_tile.dart

@ -4,8 +4,8 @@ import 'package:neon/src/settings/models/option.dart';
import 'package:neon/src/settings/widgets/settings_tile.dart'; import 'package:neon/src/settings/widgets/settings_tile.dart';
@internal @internal
class CheckBoxSettingsTile extends InputSettingsTile<ToggleOption> { class ToggleSettingsTile extends InputSettingsTile<ToggleOption> {
const CheckBoxSettingsTile({ const ToggleSettingsTile({
required super.option, required super.option,
super.key, super.key,
}); });
@ -13,13 +13,10 @@ class CheckBoxSettingsTile extends InputSettingsTile<ToggleOption> {
@override @override
Widget build(final BuildContext context) => ValueListenableBuilder( Widget build(final BuildContext context) => ValueListenableBuilder(
valueListenable: option, valueListenable: option,
builder: (final context, final value, final child) => CheckboxListTile.adaptive( builder: (final context, final value, final child) => SwitchListTile.adaptive(
enabled: option.enabled,
title: child, title: child,
value: value, value: value,
onChanged: (final value) { onChanged: option.enabled ? (final value) => option.value = value : null,
option.value = value!;
},
), ),
child: Text(option.label(context)), child: Text(option.label(context)),
); );
Loading…
Cancel
Save