Browse Source

Merge pull request #374 from Leptopoda/refactor/iterable

Refactor/iterable
pull/378/head
Nikolas Rimikis 1 year ago committed by GitHub
parent
commit
4a49d4a419
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 2
      packages/app/integration_test/screenshot_test.dart
  2. 2
      packages/app/lib/main.dart
  3. 7
      packages/neon/neon/lib/neon.dart
  4. 8
      packages/neon/neon/lib/src/app.dart
  5. 2
      packages/neon/neon/lib/src/blocs/accounts.dart
  6. 16
      packages/neon/neon/lib/src/blocs/apps.dart
  7. 2
      packages/neon/neon/lib/src/models/account.dart
  8. 2
      packages/neon/neon/lib/src/pages/home.dart
  9. 2
      packages/neon/neon/lib/src/pages/settings.dart
  10. 2
      packages/neon/neon/lib/src/router.dart
  11. 2
      packages/neon/neon/lib/src/utils/app_implementation.dart
  12. 2
      packages/neon/neon/lib/src/utils/settings_export_helper.dart
  13. 2
      packages/neon/neon_notifications/lib/pages/main.dart

2
packages/app/integration_test/screenshot_test.dart

@ -93,9 +93,9 @@ Future runTestApp(
final Account? account,
}) async {
await runNeon(
binding: binding,
getAppImplementations: getAppImplementations,
branding: getNeonBranding(),
bindingOverride: binding,
sharedPreferencesOverride: MemorySharedPreferences(),
account: account,
firstLaunchDisabled: true,

2
packages/app/lib/main.dart

@ -1,11 +1,9 @@
import 'package:app/apps.dart';
import 'package:app/branding.dart';
import 'package:flutter/material.dart';
import 'package:neon/neon.dart';
Future main() async {
await runNeon(
binding: WidgetsFlutterBinding.ensureInitialized(),
getAppImplementations: getAppImplementations,
branding: getNeonBranding(),
);

7
packages/neon/neon/lib/neon.dart

@ -102,15 +102,16 @@ part 'src/widgets/text_settings_tile.dart';
part 'src/widgets/user_avatar.dart';
Future runNeon({
required final WidgetsBinding binding,
required final List<AppImplementation> Function(SharedPreferences, RequestManager, NeonPlatform)
required final Iterable<AppImplementation> Function(SharedPreferences, RequestManager, NeonPlatform)
getAppImplementations,
required final Branding branding,
final WidgetsBinding? bindingOverride,
final SharedPreferences? sharedPreferencesOverride,
final Account? account,
final bool firstLaunchDisabled = false,
final bool nextPushDisabled = false,
}) async {
final binding = bindingOverride ?? WidgetsFlutterBinding.ensureInitialized();
FlutterNativeSplash.preserve(widgetsBinding: binding);
final sharedPreferences = sharedPreferencesOverride ?? await SharedPreferences.getInstance();
@ -183,7 +184,7 @@ Future runNeon({
Provider<NextPushBloc>(
create: (final _) => nextPushBloc,
),
Provider<List<AppImplementation>>(
Provider<Iterable<AppImplementation>>(
create: (final _) => allAppImplementations,
),
Provider<PackageInfo>(

8
packages/neon/neon/lib/src/app.dart

@ -22,7 +22,7 @@ class NeonApp extends StatefulWidget {
class _NeonAppState extends State<NeonApp> with WidgetsBindingObserver, tray.TrayListener, WindowListener {
final _appRegex = RegExp(r'^app_([a-z]+)$', multiLine: true);
final _navigatorKey = GlobalKey<NavigatorState>();
late final List<AppImplementation> _appImplementations;
late final Iterable<AppImplementation> _appImplementations;
late final NeonPlatform _platform;
late final GlobalOptions _globalOptions;
late final AccountsBloc _accountsBloc;
@ -37,7 +37,7 @@ class _NeonAppState extends State<NeonApp> with WidgetsBindingObserver, tray.Tra
void initState() {
super.initState();
_appImplementations = Provider.of<List<AppImplementation>>(context, listen: false);
_appImplementations = Provider.of<Iterable<AppImplementation>>(context, listen: false);
_platform = Provider.of<NeonPlatform>(context, listen: false);
_globalOptions = Provider.of<GlobalOptions>(context, listen: false);
_accountsBloc = Provider.of<AccountsBloc>(context, listen: false);
@ -122,13 +122,13 @@ class _NeonAppState extends State<NeonApp> with WidgetsBindingObserver, tray.Tra
if (account == null) {
return;
}
final app = Provider.of<List<AppImplementation>>(context, listen: false).find('notifications');
final app = Provider.of<Iterable<AppImplementation>>(context, listen: false).find('notifications');
if (app != null) {
await _accountsBloc.getAppsBlocFor(account).getAppBloc<NotificationsBlocInterface>(app).refresh();
}
};
Global.onPushNotificationClicked = (final pushNotificationWithAccountID) async {
final allAppImplementations = Provider.of<List<AppImplementation>>(context, listen: false);
final allAppImplementations = Provider.of<Iterable<AppImplementation>>(context, listen: false);
final app = (pushNotificationWithAccountID.subject.app != null
? allAppImplementations.find(pushNotificationWithAccountID.subject.app!)

2
packages/neon/neon/lib/src/blocs/accounts.dart

@ -91,7 +91,7 @@ class AccountsBloc extends Bloc implements AccountsBlocEvents, AccountsBlocState
late final AppStorage _storage = AppStorage('accounts', _sharedPreferences);
final SharedPreferences _sharedPreferences;
final GlobalOptions _globalOptions;
final List<AppImplementation> _allAppImplementations;
final Iterable<AppImplementation> _allAppImplementations;
final _keyLastUsedAccount = 'last-used-account';
final _accountsOptions = <String, AccountSpecificOptions>{};

16
packages/neon/neon/lib/src/blocs/apps.dart

@ -9,7 +9,7 @@ abstract class AppsBlocEvents {
abstract class AppsBlocStates {
BehaviorSubject<Result<List<NextcloudApp>>> get apps;
BehaviorSubject<Result<List<AppImplementation>>> get appImplementations;
BehaviorSubject<Result<Iterable<AppImplementation>>> get appImplementations;
BehaviorSubject<Result<NotificationsAppInterface?>> get notificationsAppImplementation;
@ -28,7 +28,7 @@ class AppsBloc extends InteractiveBloc implements AppsBlocEvents, AppsBlocStates
) {
apps.listen((final result) {
appImplementations
.add(result.transform((final data) => _filteredAppImplementations(data.map((final a) => a.id).toList())));
.add(result.transform((final data) => _filteredAppImplementations(data.map((final a) => a.id))));
});
appImplementations.listen((final result) {
@ -42,7 +42,7 @@ class AppsBloc extends InteractiveBloc implements AppsBlocEvents, AppsBlocStates
} else if (result.data!.isNotEmpty) {
// This should never happen, because the files app is always installed and can not be removed, but just in
// case this changes at a later point.
initialApp = result.data![0].id;
initialApp = result.data!.first.id;
}
}
if (!activeAppID.hasValue) {
@ -73,14 +73,14 @@ class AppsBloc extends InteractiveBloc implements AppsBlocEvents, AppsBlocStates
return null;
}
List<AppImplementation> _filteredAppImplementations(final List<String> appIds) =>
_allAppImplementations.where((final a) => appIds.contains(a.id)).toList();
Iterable<AppImplementation> _filteredAppImplementations(final Iterable<String> appIds) =>
_allAppImplementations.where((final a) => appIds.contains(a.id));
final RequestManager _requestManager;
final CapabilitiesBloc _capabilitiesBloc;
final AccountsBloc _accountsBloc;
final Account _account;
final List<AppImplementation> _allAppImplementations;
final Iterable<AppImplementation> _allAppImplementations;
final Map<String, Bloc> _blocs = {};
@ -100,8 +100,8 @@ class AppsBloc extends InteractiveBloc implements AppsBlocEvents, AppsBlocStates
BehaviorSubject<String?> activeAppID = BehaviorSubject<String?>();
@override
BehaviorSubject<Result<List<AppImplementation<Bloc, NextcloudAppSpecificOptions>>>> appImplementations =
BehaviorSubject<Result<List<AppImplementation>>>();
BehaviorSubject<Result<Iterable<AppImplementation<Bloc, NextcloudAppSpecificOptions>>>> appImplementations =
BehaviorSubject<Result<Iterable<AppImplementation>>>();
@override
BehaviorSubject<Result<List<NextcloudApp>>> apps = BehaviorSubject<Result<List<NextcloudApp>>>();

2
packages/neon/neon/lib/src/models/account.dart

@ -103,7 +103,7 @@ extension NextcloudClientHelpers on NextcloudClient {
}
}
extension AccountFind on List<Account> {
extension AccountFind on Iterable<Account> {
Account? find(final String accountID) {
for (final account in this) {
if (account.id == accountID) {

2
packages/neon/neon/lib/src/pages/home.dart

@ -165,7 +165,7 @@ class _HomePageState extends State<HomePage> {
@override
Widget build(final BuildContext context) => ResultBuilder<Capabilities>(
stream: _capabilitiesBloc.capabilities,
builder: (final context, final capabilities) => ResultBuilder<List<AppImplementation>>(
builder: (final context, final capabilities) => ResultBuilder<Iterable<AppImplementation>>(
stream: _appsBloc.appImplementations,
builder: (final context, final appImplementations) => ResultBuilder<NotificationsAppInterface?>(
stream: _appsBloc.notificationsAppImplementation,

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

@ -14,7 +14,7 @@ class _SettingsPageState extends State<SettingsPage> {
Widget build(final BuildContext context) {
final globalOptions = Provider.of<GlobalOptions>(context);
final accountsBloc = Provider.of<AccountsBloc>(context, listen: false);
final appImplementations = Provider.of<List<AppImplementation>>(context);
final appImplementations = Provider.of<Iterable<AppImplementation>>(context);
return Scaffold(
resizeToAvoidBottomInset: false,
appBar: AppBar(

2
packages/neon/neon/lib/src/router.dart

@ -119,7 +119,7 @@ class NextcloudAppSettingsRoute extends GoRouteData {
@override
Widget build(final BuildContext context, final GoRouterState state) {
final appImplementations = Provider.of<List<AppImplementation>>(context, listen: false);
final appImplementations = Provider.of<Iterable<AppImplementation>>(context, listen: false);
final appImplementation = appImplementations.find(appid)!;
return NextcloudAppSettingsPage(appImplementation: appImplementation);

2
packages/neon/neon/lib/src/utils/app_implementation.dart

@ -51,7 +51,7 @@ abstract class AppImplementation<T extends Bloc, R extends NextcloudAppSpecificO
}
}
extension AppImplementationFind on List<AppImplementation> {
extension AppImplementationFind on Iterable<AppImplementation> {
AppImplementation? find(final String appID) {
for (final app in this) {
if (app.id == appID) {

2
packages/neon/neon/lib/src/utils/settings_export_helper.dart

@ -8,7 +8,7 @@ class SettingsExportHelper {
});
final GlobalOptions globalOptions;
final List<AppImplementation> appImplementations;
final Iterable<AppImplementation> appImplementations;
final Map<Account, List<Option>> accountSpecificOptions;
Future applyFromJson(final Map<String, dynamic> data) async {

2
packages/neon/neon_notifications/lib/pages/main.dart

@ -51,7 +51,7 @@ class _NotificationsMainPageState extends State<NotificationsMainPage> {
final BuildContext context,
final NextcloudNotificationsNotification notification,
) {
final app = Provider.of<List<AppImplementation>>(context, listen: false).find(notification.app);
final app = Provider.of<Iterable<AppImplementation>>(context, listen: false).find(notification.app);
return ListTile(
title: Text(notification.subject),

Loading…
Cancel
Save