Skip to content

Commit

Permalink
Merge pull request nextcloud#845 from nextcloud/refactor/neon/setting…
Browse files Browse the repository at this point in the history
…s-switches

Refactor/neon/settings switches
  • Loading branch information
provokateurin authored Sep 24, 2023
2 parents 1047f53 + 240dd27 commit 6609be8
Show file tree
Hide file tree
Showing 6 changed files with 27 additions and 30 deletions.
2 changes: 1 addition & 1 deletion packages/app/integration_test/screenshot_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -346,7 +346,7 @@ Future<void> main() async {
await binding.takeScreenshot('settings_dark');

// Enable OLED theme
await tester.tap(find.byType(CheckboxListTile).first);
await tester.tap(find.byType(SwitchListTile).first);
await tester.pumpAndSettle();

await binding.takeScreenshot('settings_oled');
Expand Down
4 changes: 2 additions & 2 deletions packages/neon/neon/lib/src/pages/account_settings.dart
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import 'package:neon/src/blocs/accounts.dart';
import 'package:neon/src/models/account.dart';
import 'package:neon/src/router.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_list.dart';
import 'package:neon/src/theme/dialog.dart';
Expand Down Expand Up @@ -119,7 +119,7 @@ class AccountSettingsPage extends StatelessWidget {
SettingsCategory(
title: Text(AppLocalizations.of(context).optionsCategoryGeneral),
tiles: [
DropdownButtonSettingsTile(
SelectSettingsTile(
option: options.initialApp,
),
],
Expand Down
28 changes: 14 additions & 14 deletions packages/neon/neon/lib/src/pages/settings.dart
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,13 @@ import 'package:neon/src/platform/platform.dart';
import 'package:neon/src/router.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/checkbox_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_list.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/toggle_settings_tile.dart';
import 'package:neon/src/theme/branding.dart';
import 'package:neon/src/theme/dialog.dart';
import 'package:neon/src/utils/confirmation_dialog.dart';
Expand Down Expand Up @@ -120,13 +120,13 @@ class _SettingsPageState extends State<SettingsPage> {
title: Text(AppLocalizations.of(context).optionsCategoryTheme),
key: ValueKey(SettingsCategories.theme.name),
tiles: [
DropdownButtonSettingsTile(
SelectSettingsTile(
option: globalOptions.themeMode,
),
CheckBoxSettingsTile(
ToggleSettingsTile(
option: globalOptions.themeOLEDAsDark,
),
CheckBoxSettingsTile(
ToggleSettingsTile(
option: globalOptions.themeKeepOriginalAccentColor,
),
],
Expand All @@ -135,7 +135,7 @@ class _SettingsPageState extends State<SettingsPage> {
title: Text(AppLocalizations.of(context).optionsCategoryNavigation),
key: ValueKey(SettingsCategories.navigation.name),
tiles: [
DropdownButtonSettingsTile(
SelectSettingsTile(
option: globalOptions.navigationMode,
),
],
Expand All @@ -155,10 +155,10 @@ class _SettingsPageState extends State<SettingsPage> {
),
),
],
CheckBoxSettingsTile(
ToggleSettingsTile(
option: globalOptions.pushNotificationsEnabled,
),
DropdownButtonSettingsTile(
SelectSettingsTile(
option: globalOptions.pushNotificationsDistributor,
),
],
Expand All @@ -169,10 +169,10 @@ class _SettingsPageState extends State<SettingsPage> {
title: Text(AppLocalizations.of(context).optionsCategoryStartup),
key: ValueKey(SettingsCategories.startup.name),
tiles: [
CheckBoxSettingsTile(
ToggleSettingsTile(
option: globalOptions.startupMinimized,
),
CheckBoxSettingsTile(
ToggleSettingsTile(
option: globalOptions.startupMinimizeInsteadOfExit,
),
],
Expand All @@ -183,10 +183,10 @@ class _SettingsPageState extends State<SettingsPage> {
title: Text(AppLocalizations.of(context).optionsCategorySystemTray),
key: ValueKey(SettingsCategories.systemTray.name),
tiles: [
CheckBoxSettingsTile(
ToggleSettingsTile(
option: globalOptions.systemTrayEnabled,
),
CheckBoxSettingsTile(
ToggleSettingsTile(
option: globalOptions.systemTrayHideToTrayWhenMinimized,
),
],
Expand All @@ -197,10 +197,10 @@ class _SettingsPageState extends State<SettingsPage> {
key: ValueKey(SettingsCategories.accounts.name),
tiles: [
if (accountsSnapshot.requireData.length > 1) ...[
CheckBoxSettingsTile(
ToggleSettingsTile(
option: globalOptions.rememberLastUsedAccount,
),
DropdownButtonSettingsTile(
SelectSettingsTile(
option: globalOptions.initialAccount,
),
],
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import 'package:flutter/widgets.dart';
import 'package:meta/meta.dart';
import 'package:neon/settings.dart';
import 'package:neon/src/settings/widgets/checkbox_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_tile.dart';
import 'package:neon/src/settings/widgets/toggle_settings_tile.dart';

@internal
class OptionSettingsTile extends InputSettingsTile {
Expand All @@ -14,7 +14,7 @@ class OptionSettingsTile extends InputSettingsTile {

@override
Widget build(final BuildContext context) => switch (option) {
ToggleOption() => CheckBoxSettingsTile(option: option as ToggleOption),
SelectOption() => DropdownButtonSettingsTile(option: option as SelectOption),
ToggleOption() => ToggleSettingsTile(option: option as ToggleOption),
SelectOption() => SelectSettingsTile(option: option as SelectOption),
};
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ import 'package:neon/src/settings/models/option.dart';
import 'package:neon/src/settings/widgets/settings_tile.dart';

@internal
class DropdownButtonSettingsTile<T> extends InputSettingsTile<SelectOption<T>> {
const DropdownButtonSettingsTile({
class SelectSettingsTile<T> extends InputSettingsTile<SelectOption<T>> {
const SelectSettingsTile({
required super.option,
super.key,
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,22 +4,19 @@ import 'package:neon/src/settings/models/option.dart';
import 'package:neon/src/settings/widgets/settings_tile.dart';

@internal
class CheckBoxSettingsTile extends InputSettingsTile<ToggleOption> {
const CheckBoxSettingsTile({
class ToggleSettingsTile extends InputSettingsTile<ToggleOption> {
const ToggleSettingsTile({
required super.option,
super.key,
});

@override
Widget build(final BuildContext context) => ValueListenableBuilder(
valueListenable: option,
builder: (final context, final value, final child) => CheckboxListTile.adaptive(
enabled: option.enabled,
builder: (final context, final value, final child) => SwitchListTile.adaptive(
title: child,
value: value,
onChanged: (final value) {
option.value = value!;
},
onChanged: option.enabled ? (final value) => option.value = value : null,
),
child: Text(option.label(context)),
);
Expand Down

0 comments on commit 6609be8

Please sign in to comment.