Browse Source

app, neon, neon_notifications: allow iterable in appImplementations

pull/374/head
Nikolas Rimikis 1 year ago
parent
commit
4565832790
No known key found for this signature in database
GPG Key ID: 85ED1DE9786A4FF2
  1. 4
      packages/neon/neon/lib/neon.dart
  2. 8
      packages/neon/neon/lib/src/app.dart
  3. 2
      packages/neon/neon/lib/src/blocs/accounts.dart
  4. 16
      packages/neon/neon/lib/src/blocs/apps.dart
  5. 2
      packages/neon/neon/lib/src/models/account.dart
  6. 2
      packages/neon/neon/lib/src/pages/home.dart
  7. 2
      packages/neon/neon/lib/src/pages/settings.dart
  8. 2
      packages/neon/neon/lib/src/router.dart
  9. 2
      packages/neon/neon/lib/src/utils/app_implementation.dart
  10. 2
      packages/neon/neon/lib/src/utils/settings_export_helper.dart
  11. 2
      packages/neon/neon_notifications/lib/pages/main.dart

4
packages/neon/neon/lib/neon.dart

@ -103,7 +103,7 @@ 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 SharedPreferences? sharedPreferencesOverride,
@ -183,7 +183,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