Browse Source

refactor(neon): cleanup usage of the spread operator.

Signed-off-by: Nikolas Rimikis <leptopoda@users.noreply.github.com>
pull/886/head
Nikolas Rimikis 1 year ago
parent
commit
0c79454e14
No known key found for this signature in database
GPG Key ID: 85ED1DE9786A4FF2
  1. 1
      packages/neon/neon/lib/l10n/en.arb
  2. 6
      packages/neon/neon/lib/l10n/localizations.dart
  3. 3
      packages/neon/neon/lib/l10n/localizations_en.dart
  4. 5
      packages/neon/neon/lib/src/utils/account_options.dart
  5. 42
      packages/neon/neon/lib/src/utils/global_options.dart
  6. 10
      packages/neon/neon/lib/src/utils/global_popups.dart
  7. 45
      packages/neon/neon/lib/src/widgets/account_tile.dart

1
packages/neon/neon/lib/l10n/en.arb

@ -152,7 +152,6 @@
"globalOptionsNavigationMode": "Navigation mode", "globalOptionsNavigationMode": "Navigation mode",
"globalOptionsNavigationModeDrawer": "Drawer", "globalOptionsNavigationModeDrawer": "Drawer",
"globalOptionsNavigationModeDrawerAlwaysVisible": "Drawer always visible", "globalOptionsNavigationModeDrawerAlwaysVisible": "Drawer always visible",
"globalOptionsNavigationModeQuickBar": "Quick bar",
"accountOptionsRemove": "Remove account", "accountOptionsRemove": "Remove account",
"accountOptionsRemoveConfirm": "Are you sure you want to remove the account {id}?", "accountOptionsRemoveConfirm": "Are you sure you want to remove the account {id}?",
"@accountOptionsRemoveConfirm": { "@accountOptionsRemoveConfirm": {

6
packages/neon/neon/lib/l10n/localizations.dart

@ -635,12 +635,6 @@ abstract class AppLocalizations {
/// **'Drawer always visible'** /// **'Drawer always visible'**
String get globalOptionsNavigationModeDrawerAlwaysVisible; String get globalOptionsNavigationModeDrawerAlwaysVisible;
/// No description provided for @globalOptionsNavigationModeQuickBar.
///
/// In en, this message translates to:
/// **'Quick bar'**
String get globalOptionsNavigationModeQuickBar;
/// No description provided for @accountOptionsRemove. /// No description provided for @accountOptionsRemove.
/// ///
/// In en, this message translates to: /// In en, this message translates to:

3
packages/neon/neon/lib/l10n/localizations_en.dart

@ -314,9 +314,6 @@ class AppLocalizationsEn extends AppLocalizations {
@override @override
String get globalOptionsNavigationModeDrawerAlwaysVisible => 'Drawer always visible'; String get globalOptionsNavigationModeDrawerAlwaysVisible => 'Drawer always visible';
@override
String get globalOptionsNavigationModeQuickBar => 'Quick bar';
@override @override
String get accountOptionsRemove => 'Remove account'; String get accountOptionsRemove => 'Remove account';

5
packages/neon/neon/lib/src/utils/account_options.dart

@ -19,10 +19,7 @@ class AccountSpecificOptions extends OptionsCollection {
initialApp.values = { initialApp.values = {
null: (final context) => AppLocalizations.of(context).accountOptionsAutomatic, null: (final context) => AppLocalizations.of(context).accountOptionsAutomatic,
for (final app in result.requireData) ...{ }..addEntries(result.requireData.map((final app) => MapEntry(app.id, app.name)));
app.id: app.name,
},
};
}); });
} }

42
packages/neon/neon/lib/src/utils/global_options.dart

@ -26,7 +26,7 @@ class GlobalOptions extends OptionsCollection {
void _rememberLastUsedAccountListener() { void _rememberLastUsedAccountListener() {
initialAccount.enabled = !rememberLastUsedAccount.value; initialAccount.enabled = !rememberLastUsedAccount.value;
if (rememberLastUsedAccount.value) { if (rememberLastUsedAccount.value) {
initialAccount.value = null; initialAccount.reset();
} else { } else {
// Only override the initial account if there already has been a value, // Only override the initial account if there already has been a value,
// which means it's not the initial emit from rememberLastUsedAccount // which means it's not the initial emit from rememberLastUsedAccount
@ -44,7 +44,7 @@ class GlobalOptions extends OptionsCollection {
pushNotificationsEnabled.value = false; pushNotificationsEnabled.value = false;
} }
} else { } else {
pushNotificationsDistributor.value = null; pushNotificationsDistributor.reset();
} }
} }
@ -91,26 +91,29 @@ class GlobalOptions extends OptionsCollection {
} }
void updateAccounts(final List<Account> accounts) { void updateAccounts(final List<Account> accounts) {
initialAccount.values = { initialAccount.values = Map.fromEntries(
for (final account in accounts) account.id: (final context) => account.humanReadableID, accounts.map(
}; (final account) => MapEntry(account.id, (final context) => account.humanReadableID),
),
);
if (accounts.tryFind(initialAccount.value) == null) { if (!initialAccount.values.containsKey(initialAccount.value)) {
initialAccount.reset(); initialAccount.reset();
} }
} }
Future<void> updateDistributors(final List<String> distributors) async { void updateDistributors(final List<String> distributors) {
pushNotificationsDistributor.values = { pushNotificationsDistributor.values = Map.fromEntries(
for (final distributor in distributors) ...{ distributors.map(
distributor: _distributorsMap[distributor] ?? (final _) => distributor, (final distributor) => MapEntry(distributor, _distributorsMap[distributor] ?? (final _) => distributor),
}, ),
}; );
final allowed = distributors.isNotEmpty; final allowed = pushNotificationsDistributor.values.containsKey(pushNotificationsDistributor.value);
pushNotificationsEnabled.enabled = allowed; pushNotificationsEnabled.enabled = allowed;
if (!allowed) { if (!allowed) {
pushNotificationsEnabled.value = false; pushNotificationsDistributor.reset();
pushNotificationsEnabled.reset();
} }
} }
@ -128,7 +131,7 @@ class GlobalOptions extends OptionsCollection {
late final themeOLEDAsDark = ToggleOption( late final themeOLEDAsDark = ToggleOption(
storage: storage, storage: storage,
key: GlobalOptionKeys.themeOledAsDark, key: GlobalOptionKeys.themeOLEDAsDark,
label: (final context) => AppLocalizations.of(context).globalOptionsThemeOLEDAsDark, label: (final context) => AppLocalizations.of(context).globalOptionsThemeOLEDAsDark,
defaultValue: false, defaultValue: false,
); );
@ -209,20 +212,17 @@ class GlobalOptions extends OptionsCollection {
defaultValue: Platform.isAndroid || Platform.isIOS ? NavigationMode.drawer : NavigationMode.drawerAlwaysVisible, defaultValue: Platform.isAndroid || Platform.isIOS ? NavigationMode.drawer : NavigationMode.drawerAlwaysVisible,
values: { values: {
NavigationMode.drawer: (final context) => AppLocalizations.of(context).globalOptionsNavigationModeDrawer, NavigationMode.drawer: (final context) => AppLocalizations.of(context).globalOptionsNavigationModeDrawer,
if (!Platform.isAndroid && !Platform.isIOS) ...{ if (!Platform.isAndroid && !Platform.isIOS)
NavigationMode.drawerAlwaysVisible: (final context) => NavigationMode.drawerAlwaysVisible: (final context) =>
AppLocalizations.of(context).globalOptionsNavigationModeDrawerAlwaysVisible, AppLocalizations.of(context).globalOptionsNavigationModeDrawerAlwaysVisible,
}, },
// ignore: deprecated_member_use_from_same_package
NavigationMode.quickBar: (final context) => AppLocalizations.of(context).globalOptionsNavigationModeQuickBar,
},
); );
} }
@internal @internal
enum GlobalOptionKeys implements Storable { enum GlobalOptionKeys implements Storable {
themeMode._('theme-mode'), themeMode._('theme-mode'),
themeOledAsDark._('theme-oled-as-dark'), themeOLEDAsDark._('theme-oled-as-dark'),
themeKeepOriginalAccentColor._('theme-keep-original-accent-color'), themeKeepOriginalAccentColor._('theme-keep-original-accent-color'),
pushNotificationsEnabled._('push-notifications-enabled'), pushNotificationsEnabled._('push-notifications-enabled'),
pushNotificationsDistributor._('push-notifications-distributor'), pushNotificationsDistributor._('push-notifications-distributor'),
@ -244,6 +244,4 @@ enum GlobalOptionKeys implements Storable {
enum NavigationMode { enum NavigationMode {
drawer, drawer,
drawerAlwaysVisible, drawerAlwaysVisible,
@Deprecated("The new design won't use this anymore")
quickBar,
} }

10
packages/neon/neon/lib/src/utils/global_popups.dart

@ -34,6 +34,7 @@ class GlobalPopups {
} }
_subscriptions.clear(); _subscriptions.clear();
_registered = false; _registered = false;
instance = null;
} }
void register(final BuildContext context) { void register(final BuildContext context) {
@ -42,12 +43,13 @@ class GlobalPopups {
return; return;
} }
_registered = true;
final globalOptions = NeonProvider.of<GlobalOptions>(context); final globalOptions = NeonProvider.of<GlobalOptions>(context);
final firstLaunchBloc = NeonProvider.of<FirstLaunchBloc>(context); final firstLaunchBloc = NeonProvider.of<FirstLaunchBloc>(context);
final nextPushBloc = NeonProvider.of<NextPushBloc>(context); final nextPushBloc = NeonProvider.of<NextPushBloc>(context);
if (NeonPlatform.instance.canUsePushNotifications) {
_subscriptions.addAll([ _subscriptions.addAll([
if (NeonPlatform.instance.canUsePushNotifications) ...[
firstLaunchBloc.onFirstLaunch.listen((final _) { firstLaunchBloc.onFirstLaunch.listen((final _) {
assert(context.mounted, 'Context should be mounted'); assert(context.mounted, 'Context should be mounted');
if (!globalOptions.pushNotificationsEnabled.enabled) { if (!globalOptions.pushNotificationsEnabled.enabled) {
@ -98,9 +100,7 @@ class GlobalPopups {
), ),
); );
}), }),
],
]); ]);
}
_registered = true;
} }
} }

45
packages/neon/neon/lib/src/widgets/account_tile.dart

@ -1,4 +1,5 @@
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
import 'package:intersperse/intersperse.dart';
import 'package:meta/meta.dart'; import 'package:meta/meta.dart';
import 'package:neon/src/bloc/result_builder.dart'; import 'package:neon/src/bloc/result_builder.dart';
import 'package:neon/src/blocs/accounts.dart'; import 'package:neon/src/blocs/accounts.dart';
@ -13,21 +14,15 @@ import 'package:nextcloud/provisioning_api.dart' as provisioning_api;
class NeonAccountTile extends StatelessWidget { class NeonAccountTile extends StatelessWidget {
const NeonAccountTile({ const NeonAccountTile({
required this.account, required this.account,
this.color,
this.trailing, this.trailing,
this.onTap, this.onTap,
this.textColor,
this.dense = false,
this.showStatus = true, this.showStatus = true,
super.key, super.key,
}); });
final Account account; final Account account;
final Color? color;
final Widget? trailing; final Widget? trailing;
final GestureTapCallback? onTap; final GestureTapCallback? onTap;
final Color? textColor;
final bool dense;
final bool showStatus; final bool showStatus;
@override @override
@ -35,16 +30,7 @@ class NeonAccountTile extends StatelessWidget {
final userDetailsBloc = NeonProvider.of<AccountsBloc>(context).getUserDetailsBlocFor(account); final userDetailsBloc = NeonProvider.of<AccountsBloc>(context).getUserDetailsBlocFor(account);
return ListTile( return ListTile(
textColor: textColor,
onTap: onTap, onTap: onTap,
dense: dense,
contentPadding: dense ? EdgeInsets.zero : null,
visualDensity: dense
? const VisualDensity(
horizontal: -4,
vertical: -4,
)
: null,
leading: NeonUserAvatar( leading: NeonUserAvatar(
account: account, account: account,
showStatus: showStatus, showStatus: showStatus,
@ -54,46 +40,29 @@ class NeonAccountTile extends StatelessWidget {
stream: userDetailsBloc.userDetails, stream: userDetailsBloc.userDetails,
builder: (final context, final userDetails) => Row( builder: (final context, final userDetails) => Row(
children: [ children: [
if (userDetails.hasData) ...[ if (userDetails.hasData)
Flexible( Flexible(
child: Text( child: Text(
userDetails.requireData.displayname, userDetails.requireData.displayname,
style: Theme.of(context).textTheme.bodyLarge!.copyWith(
color: textColor,
),
overflow: TextOverflow.ellipsis, overflow: TextOverflow.ellipsis,
), ),
), ),
], if (userDetails.isLoading)
if (userDetails.isLoading) ...[ const Expanded(
const SizedBox( child: NeonLinearProgressIndicator(),
width: 5,
),
Expanded(
child: NeonLinearProgressIndicator(
color: textColor,
),
),
],
if (userDetails.hasError) ...[
const SizedBox(
width: 5,
), ),
if (userDetails.hasError)
NeonError( NeonError(
userDetails.error, userDetails.error,
onlyIcon: true, onlyIcon: true,
iconSize: 24, iconSize: 24,
onRetry: userDetailsBloc.refresh, onRetry: userDetailsBloc.refresh,
), ),
], ].intersperse(const SizedBox(width: 5)).toList(),
],
), ),
), ),
subtitle: Text( subtitle: Text(
account.humanReadableID, account.humanReadableID,
style: Theme.of(context).textTheme.bodySmall!.copyWith(
color: textColor,
),
overflow: TextOverflow.ellipsis, overflow: TextOverflow.ellipsis,
), ),
); );

Loading…
Cancel
Save