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, final Account? account,
}) async { }) async {
await runNeon( await runNeon(
binding: binding,
getAppImplementations: getAppImplementations, getAppImplementations: getAppImplementations,
branding: getNeonBranding(), branding: getNeonBranding(),
bindingOverride: binding,
sharedPreferencesOverride: MemorySharedPreferences(), sharedPreferencesOverride: MemorySharedPreferences(),
account: account, account: account,
firstLaunchDisabled: true, firstLaunchDisabled: true,

2
packages/app/lib/main.dart

@ -1,11 +1,9 @@
import 'package:app/apps.dart'; import 'package:app/apps.dart';
import 'package:app/branding.dart'; import 'package:app/branding.dart';
import 'package:flutter/material.dart';
import 'package:neon/neon.dart'; import 'package:neon/neon.dart';
Future main() async { Future main() async {
await runNeon( await runNeon(
binding: WidgetsFlutterBinding.ensureInitialized(),
getAppImplementations: getAppImplementations, getAppImplementations: getAppImplementations,
branding: getNeonBranding(), 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'; part 'src/widgets/user_avatar.dart';
Future runNeon({ Future runNeon({
required final WidgetsBinding binding, required final Iterable<AppImplementation> Function(SharedPreferences, RequestManager, NeonPlatform)
required final List<AppImplementation> Function(SharedPreferences, RequestManager, NeonPlatform)
getAppImplementations, getAppImplementations,
required final Branding branding, required final Branding branding,
final WidgetsBinding? bindingOverride,
final SharedPreferences? sharedPreferencesOverride, final SharedPreferences? sharedPreferencesOverride,
final Account? account, final Account? account,
final bool firstLaunchDisabled = false, final bool firstLaunchDisabled = false,
final bool nextPushDisabled = false, final bool nextPushDisabled = false,
}) async { }) async {
final binding = bindingOverride ?? WidgetsFlutterBinding.ensureInitialized();
FlutterNativeSplash.preserve(widgetsBinding: binding); FlutterNativeSplash.preserve(widgetsBinding: binding);
final sharedPreferences = sharedPreferencesOverride ?? await SharedPreferences.getInstance(); final sharedPreferences = sharedPreferencesOverride ?? await SharedPreferences.getInstance();
@ -183,7 +184,7 @@ Future runNeon({
Provider<NextPushBloc>( Provider<NextPushBloc>(
create: (final _) => nextPushBloc, create: (final _) => nextPushBloc,
), ),
Provider<List<AppImplementation>>( Provider<Iterable<AppImplementation>>(
create: (final _) => allAppImplementations, create: (final _) => allAppImplementations,
), ),
Provider<PackageInfo>( 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 { class _NeonAppState extends State<NeonApp> with WidgetsBindingObserver, tray.TrayListener, WindowListener {
final _appRegex = RegExp(r'^app_([a-z]+)$', multiLine: true); final _appRegex = RegExp(r'^app_([a-z]+)$', multiLine: true);
final _navigatorKey = GlobalKey<NavigatorState>(); final _navigatorKey = GlobalKey<NavigatorState>();
late final List<AppImplementation> _appImplementations; late final Iterable<AppImplementation> _appImplementations;
late final NeonPlatform _platform; late final NeonPlatform _platform;
late final GlobalOptions _globalOptions; late final GlobalOptions _globalOptions;
late final AccountsBloc _accountsBloc; late final AccountsBloc _accountsBloc;
@ -37,7 +37,7 @@ class _NeonAppState extends State<NeonApp> with WidgetsBindingObserver, tray.Tra
void initState() { void initState() {
super.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); _platform = Provider.of<NeonPlatform>(context, listen: false);
_globalOptions = Provider.of<GlobalOptions>(context, listen: false); _globalOptions = Provider.of<GlobalOptions>(context, listen: false);
_accountsBloc = Provider.of<AccountsBloc>(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) { if (account == null) {
return; 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) { if (app != null) {
await _accountsBloc.getAppsBlocFor(account).getAppBloc<NotificationsBlocInterface>(app).refresh(); await _accountsBloc.getAppsBlocFor(account).getAppBloc<NotificationsBlocInterface>(app).refresh();
} }
}; };
Global.onPushNotificationClicked = (final pushNotificationWithAccountID) async { 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 final app = (pushNotificationWithAccountID.subject.app != null
? allAppImplementations.find(pushNotificationWithAccountID.subject.app!) ? 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); late final AppStorage _storage = AppStorage('accounts', _sharedPreferences);
final SharedPreferences _sharedPreferences; final SharedPreferences _sharedPreferences;
final GlobalOptions _globalOptions; final GlobalOptions _globalOptions;
final List<AppImplementation> _allAppImplementations; final Iterable<AppImplementation> _allAppImplementations;
final _keyLastUsedAccount = 'last-used-account'; final _keyLastUsedAccount = 'last-used-account';
final _accountsOptions = <String, AccountSpecificOptions>{}; final _accountsOptions = <String, AccountSpecificOptions>{};

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

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

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

@ -165,7 +165,7 @@ class _HomePageState extends State<HomePage> {
@override @override
Widget build(final BuildContext context) => ResultBuilder<Capabilities>( Widget build(final BuildContext context) => ResultBuilder<Capabilities>(
stream: _capabilitiesBloc.capabilities, stream: _capabilitiesBloc.capabilities,
builder: (final context, final capabilities) => ResultBuilder<List<AppImplementation>>( builder: (final context, final capabilities) => ResultBuilder<Iterable<AppImplementation>>(
stream: _appsBloc.appImplementations, stream: _appsBloc.appImplementations,
builder: (final context, final appImplementations) => ResultBuilder<NotificationsAppInterface?>( builder: (final context, final appImplementations) => ResultBuilder<NotificationsAppInterface?>(
stream: _appsBloc.notificationsAppImplementation, 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) { Widget build(final BuildContext context) {
final globalOptions = Provider.of<GlobalOptions>(context); final globalOptions = Provider.of<GlobalOptions>(context);
final accountsBloc = Provider.of<AccountsBloc>(context, listen: false); final accountsBloc = Provider.of<AccountsBloc>(context, listen: false);
final appImplementations = Provider.of<List<AppImplementation>>(context); final appImplementations = Provider.of<Iterable<AppImplementation>>(context);
return Scaffold( return Scaffold(
resizeToAvoidBottomInset: false, resizeToAvoidBottomInset: false,
appBar: AppBar( appBar: AppBar(

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

@ -119,7 +119,7 @@ class NextcloudAppSettingsRoute extends GoRouteData {
@override @override
Widget build(final BuildContext context, final GoRouterState state) { 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)!; final appImplementation = appImplementations.find(appid)!;
return NextcloudAppSettingsPage(appImplementation: appImplementation); 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) { AppImplementation? find(final String appID) {
for (final app in this) { for (final app in this) {
if (app.id == appID) { 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 GlobalOptions globalOptions;
final List<AppImplementation> appImplementations; final Iterable<AppImplementation> appImplementations;
final Map<Account, List<Option>> accountSpecificOptions; final Map<Account, List<Option>> accountSpecificOptions;
Future applyFromJson(final Map<String, dynamic> data) async { 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 BuildContext context,
final NextcloudNotificationsNotification notification, 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( return ListTile(
title: Text(notification.subject), title: Text(notification.subject),

Loading…
Cancel
Save