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. 7
      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. 14
      packages/neon/neon/lib/src/utils/global_popups.dart
  7. 45
      packages/neon/neon/lib/src/widgets/account_tile.dart

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

@ -51,7 +51,7 @@
"errorNoCompatibleNextcloudAppsFound": "No compatible Nextcloud apps could be found.\nWe are working hard to implement more and more apps!",
"errorServerInMaintenanceMode": "The server is in maintenance mode. Please try again later or contact the server admin.",
"errorMissingPermission": "Permission for {name} is missing",
"@errorMissingPermission" : {
"@errorMissingPermission": {
"placeholders": {
"name": {
"type": "String"
@ -59,7 +59,7 @@
}
},
"errorUnsupportedAppVersions": "Sorry, the version of the following apps on your Nextcloud instance are not supported. \n {names} \n Please contact your administrator to resolve the issues.",
"@errorUnsupportedAppVersions" : {
"@errorUnsupportedAppVersions": {
"placeholders": {
"names": {
"type": "String"
@ -70,7 +70,7 @@
"errorInvalidURL": "Invalid URL provided",
"errorInvalidQRcode": "Invalid QR-Code provided",
"errorRouteNotFound": "Route not found: {route}",
"@errorRouteNotFound" : {
"@errorRouteNotFound": {
"placeholders": {
"route": {
"type": "String"
@ -152,7 +152,6 @@
"globalOptionsNavigationMode": "Navigation mode",
"globalOptionsNavigationModeDrawer": "Drawer",
"globalOptionsNavigationModeDrawerAlwaysVisible": "Drawer always visible",
"globalOptionsNavigationModeQuickBar": "Quick bar",
"accountOptionsRemove": "Remove account",
"accountOptionsRemoveConfirm": "Are you sure you want to remove the account {id}?",
"@accountOptionsRemoveConfirm": {

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

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

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

@ -314,9 +314,6 @@ class AppLocalizationsEn extends AppLocalizations {
@override
String get globalOptionsNavigationModeDrawerAlwaysVisible => 'Drawer always visible';
@override
String get globalOptionsNavigationModeQuickBar => 'Quick bar';
@override
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 = {
null: (final context) => AppLocalizations.of(context).accountOptionsAutomatic,
for (final app in result.requireData) ...{
app.id: app.name,
},
};
}..addEntries(result.requireData.map((final app) => MapEntry(app.id, app.name)));
});
}

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

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

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

@ -34,6 +34,7 @@ class GlobalPopups {
}
_subscriptions.clear();
_registered = false;
instance = null;
}
void register(final BuildContext context) {
@ -42,12 +43,13 @@ class GlobalPopups {
return;
}
_registered = true;
final globalOptions = NeonProvider.of<GlobalOptions>(context);
final firstLaunchBloc = NeonProvider.of<FirstLaunchBloc>(context);
final nextPushBloc = NeonProvider.of<NextPushBloc>(context);
_subscriptions.addAll([
if (NeonPlatform.instance.canUsePushNotifications) ...[
if (NeonPlatform.instance.canUsePushNotifications) {
_subscriptions.addAll([
firstLaunchBloc.onFirstLaunch.listen((final _) {
assert(context.mounted, 'Context should be mounted');
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:intersperse/intersperse.dart';
import 'package:meta/meta.dart';
import 'package:neon/src/bloc/result_builder.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 {
const NeonAccountTile({
required this.account,
this.color,
this.trailing,
this.onTap,
this.textColor,
this.dense = false,
this.showStatus = true,
super.key,
});
final Account account;
final Color? color;
final Widget? trailing;
final GestureTapCallback? onTap;
final Color? textColor;
final bool dense;
final bool showStatus;
@override
@ -35,16 +30,7 @@ class NeonAccountTile extends StatelessWidget {
final userDetailsBloc = NeonProvider.of<AccountsBloc>(context).getUserDetailsBlocFor(account);
return ListTile(
textColor: textColor,
onTap: onTap,
dense: dense,
contentPadding: dense ? EdgeInsets.zero : null,
visualDensity: dense
? const VisualDensity(
horizontal: -4,
vertical: -4,
)
: null,
leading: NeonUserAvatar(
account: account,
showStatus: showStatus,
@ -54,46 +40,29 @@ class NeonAccountTile extends StatelessWidget {
stream: userDetailsBloc.userDetails,
builder: (final context, final userDetails) => Row(
children: [
if (userDetails.hasData) ...[
if (userDetails.hasData)
Flexible(
child: Text(
userDetails.requireData.displayname,
style: Theme.of(context).textTheme.bodyLarge!.copyWith(
color: textColor,
),
overflow: TextOverflow.ellipsis,
),
),
],
if (userDetails.isLoading) ...[
const SizedBox(
width: 5,
),
Expanded(
child: NeonLinearProgressIndicator(
color: textColor,
),
),
],
if (userDetails.hasError) ...[
const SizedBox(
width: 5,
if (userDetails.isLoading)
const Expanded(
child: NeonLinearProgressIndicator(),
),
if (userDetails.hasError)
NeonError(
userDetails.error,
onlyIcon: true,
iconSize: 24,
onRetry: userDetailsBloc.refresh,
),
],
],
].intersperse(const SizedBox(width: 5)).toList(),
),
),
subtitle: Text(
account.humanReadableID,
style: Theme.of(context).textTheme.bodySmall!.copyWith(
color: textColor,
),
overflow: TextOverflow.ellipsis,
),
);

Loading…
Cancel
Save