Browse Source

neon,neon_notifications: Cleanup finding app implementation

pull/257/head
jld3103 2 years ago
parent
commit
fe068ee385
No known key found for this signature in database
GPG Key ID: 9062417B9E8EB7B3
  1. 28
      packages/neon/neon/lib/src/app.dart
  2. 7
      packages/neon/neon/lib/src/blocs/apps.dart
  3. 4
      packages/neon/neon/lib/src/pages/home.dart
  4. 12
      packages/neon/neon/lib/src/utils/app_implementation.dart
  5. 6
      packages/neon/neon/lib/src/utils/settings_export_helper.dart
  6. 14
      packages/neon/neon_notifications/lib/pages/main.dart

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

@ -171,22 +171,18 @@ class _NeonAppState extends State<NeonApp> with WidgetsBindingObserver, tray.Tra
if (account == null) {
return;
}
final appImplementation = Provider.of<List<AppImplementation>>(context, listen: false)
.singleWhere((final a) => a.id == 'notifications');
await _accountsBloc.getAppsBloc(account).getAppBloc<NotificationsBlocInterface>(appImplementation).refresh();
final app = Provider.of<List<AppImplementation>>(context, listen: false).find('notifications');
if (app != null) {
await _accountsBloc.getAppsBloc(account).getAppBloc<NotificationsBlocInterface>(app).refresh();
}
};
Global.onPushNotificationClicked = (final pushNotificationWithAccountID) async {
final allAppImplementations = Provider.of<List<AppImplementation>>(context, listen: false);
final matchingAppImplementations =
allAppImplementations.where((final a) => a.id == pushNotificationWithAccountID.subject.app);
late AppImplementation appImplementation;
if (matchingAppImplementations.isNotEmpty) {
appImplementation = matchingAppImplementations.single;
} else {
appImplementation = allAppImplementations.singleWhere((final a) => a.id == 'notifications');
}
final app = (pushNotificationWithAccountID.subject.app != null
? allAppImplementations.find(pushNotificationWithAccountID.subject.app!)
: null) ??
allAppImplementations.find('notifications');
final account = _accountsBloc.accounts.value.find(pushNotificationWithAccountID.accountID);
if (account == null) {
@ -194,13 +190,15 @@ class _NeonAppState extends State<NeonApp> with WidgetsBindingObserver, tray.Tra
}
_accountsBloc.setActiveAccount(account);
if (appImplementation.id != 'notifications') {
if (app != null) {
if (app.id != 'notifications') {
_accountsBloc
.getAppsBloc(account)
.getAppBloc<NotificationsBlocInterface>(appImplementation)
.getAppBloc<NotificationsBlocInterface>(app)
.deleteNotification(pushNotificationWithAccountID.subject.nid!);
}
await _openAppFromExternal(account, appImplementation.id);
await _openAppFromExternal(account, app.id);
}
};
final details = await localNotificationsPlugin.getNotificationAppLaunchDetails();

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

@ -37,7 +37,7 @@ class AppsBloc extends InteractiveBloc implements AppsBlocEvents, AppsBlocStates
unawaited(
options.initialApp.stream.first.then((var initialApp) async {
if (initialApp == null) {
if (result.data!.where((final a) => a.id == 'files').isNotEmpty) {
if (result.data!.find('files') != null) {
initialApp = 'files';
} else if (result.data!.isNotEmpty) {
// This should never happen, because the files app is always installed and can not be removed, but just in
@ -126,10 +126,7 @@ class AppsBloc extends InteractiveBloc implements AppsBlocEvents, AppsBlocStates
@override
Future setActiveApp(final String? appID) async {
if ((await appImplementations.firstWhere((final a) => a.data != null))
.data!
.where((final app) => app.id == appID)
.isNotEmpty) {
if (appID != null && (await appImplementations.firstWhere((final a) => a.data != null)).data!.find(appID) != null) {
if (activeAppID.valueOrNull != appID) {
activeAppID.add(appID);
}

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

@ -474,7 +474,7 @@ class _HomePageState extends State<HomePage> {
Flexible(
child: Text(
appImplementations.data!
.singleWhere((final a) => a.id == activeAppIDSnapshot.data!)
.find(activeAppIDSnapshot.data!)!
.name(context),
),
),
@ -583,7 +583,7 @@ class _HomePageState extends State<HomePage> {
if (activeAppIDSnapshot.hasData) ...[
Expanded(
child: appImplementations.data!
.singleWhere((final a) => a.id == activeAppIDSnapshot.data!)
.find(activeAppIDSnapshot.data!)!
.buildPage(context, _appsBloc),
),
],

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

@ -46,3 +46,15 @@ abstract class AppImplementation<T extends Bloc, R extends NextcloudAppSpecificO
options.dispose();
}
}
extension AppImplementationFind on List<AppImplementation> {
AppImplementation? find(final String appID) {
for (final app in this) {
if (app.id == appID) {
return app;
}
}
return null;
}
}

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

@ -20,13 +20,13 @@ class SettingsExportHelper {
final appImplementationsData = data['apps'] as Map<String, dynamic>;
for (final appId in appImplementationsData.keys) {
final matchingAppImplementations = appImplementations.where((final app) => app.id == appId).toList();
if (matchingAppImplementations.length != 1) {
final app = appImplementations.find(appId);
if (app == null) {
return;
}
final appImplementationData = appImplementationsData[appId]! as Map<String, dynamic>;
await _applyOptionsMapToOptions(
matchingAppImplementations[0].options.options,
app.options.options,
appImplementationData,
);
}

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

@ -50,9 +50,7 @@ class _NotificationsMainPageState extends State<NotificationsMainPage> {
final BuildContext context,
final NextcloudNotificationsNotification notification,
) {
final matchingAppImplementations = Provider.of<List<AppImplementation>>(context, listen: false)
.where((final a) => a.id == notification.app)
.toList();
final app = Provider.of<List<AppImplementation>>(context, listen: false).find(notification.app);
return ListTile(
title: Text(notification.subject),
@ -73,8 +71,8 @@ class _NotificationsMainPageState extends State<NotificationsMainPage> {
),
],
),
leading: matchingAppImplementations.isNotEmpty
? matchingAppImplementations.single.buildIcon(
leading: app != null
? app.buildIcon(
context,
width: 40,
height: 40,
@ -93,11 +91,9 @@ class _NotificationsMainPageState extends State<NotificationsMainPage> {
if (notification.app == 'notifications') {
return;
}
final allAppImplementations = Provider.of<List<AppImplementation>>(context, listen: false);
final matchingAppImplementations = allAppImplementations.where((final a) => a.id == notification.app);
if (matchingAppImplementations.isNotEmpty) {
if (app != null) {
final accountsBloc = Provider.of<AccountsBloc>(context, listen: false);
await accountsBloc.getAppsBloc(accountsBloc.activeAccount.value!).setActiveApp(notification.app);
await accountsBloc.getAppsBloc(accountsBloc.activeAccount.value!).setActiveApp(app.id);
} else {
await showDialog(
context: context,

Loading…
Cancel
Save