diff --git a/packages/app/android/app/src/main/res/mipmap-hdpi/app_files.png b/packages/app/android/app/src/main/res/mipmap-hdpi/app_files.png deleted file mode 100644 index 8f8385c2..00000000 Binary files a/packages/app/android/app/src/main/res/mipmap-hdpi/app_files.png and /dev/null differ diff --git a/packages/app/android/app/src/main/res/mipmap-hdpi/app_news.png b/packages/app/android/app/src/main/res/mipmap-hdpi/app_news.png deleted file mode 100644 index aa9b7b35..00000000 Binary files a/packages/app/android/app/src/main/res/mipmap-hdpi/app_news.png and /dev/null differ diff --git a/packages/app/android/app/src/main/res/mipmap-hdpi/app_notes.png b/packages/app/android/app/src/main/res/mipmap-hdpi/app_notes.png deleted file mode 100644 index fb16e672..00000000 Binary files a/packages/app/android/app/src/main/res/mipmap-hdpi/app_notes.png and /dev/null differ diff --git a/packages/app/android/app/src/main/res/mipmap-hdpi/app_notifications.png b/packages/app/android/app/src/main/res/mipmap-hdpi/app_notifications.png deleted file mode 100644 index 52112ad9..00000000 Binary files a/packages/app/android/app/src/main/res/mipmap-hdpi/app_notifications.png and /dev/null differ diff --git a/packages/app/android/app/src/main/res/mipmap-mdpi/app_files.png b/packages/app/android/app/src/main/res/mipmap-mdpi/app_files.png deleted file mode 100644 index f1e6caa3..00000000 Binary files a/packages/app/android/app/src/main/res/mipmap-mdpi/app_files.png and /dev/null differ diff --git a/packages/app/android/app/src/main/res/mipmap-mdpi/app_news.png b/packages/app/android/app/src/main/res/mipmap-mdpi/app_news.png deleted file mode 100644 index 08aea4c3..00000000 Binary files a/packages/app/android/app/src/main/res/mipmap-mdpi/app_news.png and /dev/null differ diff --git a/packages/app/android/app/src/main/res/mipmap-mdpi/app_notes.png b/packages/app/android/app/src/main/res/mipmap-mdpi/app_notes.png deleted file mode 100644 index d372d23d..00000000 Binary files a/packages/app/android/app/src/main/res/mipmap-mdpi/app_notes.png and /dev/null differ diff --git a/packages/app/android/app/src/main/res/mipmap-mdpi/app_notifications.png b/packages/app/android/app/src/main/res/mipmap-mdpi/app_notifications.png deleted file mode 100644 index 83757de5..00000000 Binary files a/packages/app/android/app/src/main/res/mipmap-mdpi/app_notifications.png and /dev/null differ diff --git a/packages/app/android/app/src/main/res/mipmap-xhdpi/app_files.png b/packages/app/android/app/src/main/res/mipmap-xhdpi/app_files.png deleted file mode 100644 index 1d4d46d7..00000000 Binary files a/packages/app/android/app/src/main/res/mipmap-xhdpi/app_files.png and /dev/null differ diff --git a/packages/app/android/app/src/main/res/mipmap-xhdpi/app_news.png b/packages/app/android/app/src/main/res/mipmap-xhdpi/app_news.png deleted file mode 100644 index bdfb9c28..00000000 Binary files a/packages/app/android/app/src/main/res/mipmap-xhdpi/app_news.png and /dev/null differ diff --git a/packages/app/android/app/src/main/res/mipmap-xhdpi/app_notes.png b/packages/app/android/app/src/main/res/mipmap-xhdpi/app_notes.png deleted file mode 100644 index 1d310cba..00000000 Binary files a/packages/app/android/app/src/main/res/mipmap-xhdpi/app_notes.png and /dev/null differ diff --git a/packages/app/android/app/src/main/res/mipmap-xhdpi/app_notifications.png b/packages/app/android/app/src/main/res/mipmap-xhdpi/app_notifications.png deleted file mode 100644 index b117ac90..00000000 Binary files a/packages/app/android/app/src/main/res/mipmap-xhdpi/app_notifications.png and /dev/null differ diff --git a/packages/app/android/app/src/main/res/mipmap-xxhdpi/app_files.png b/packages/app/android/app/src/main/res/mipmap-xxhdpi/app_files.png deleted file mode 100644 index f00e483b..00000000 Binary files a/packages/app/android/app/src/main/res/mipmap-xxhdpi/app_files.png and /dev/null differ diff --git a/packages/app/android/app/src/main/res/mipmap-xxhdpi/app_news.png b/packages/app/android/app/src/main/res/mipmap-xxhdpi/app_news.png deleted file mode 100644 index de4c090e..00000000 Binary files a/packages/app/android/app/src/main/res/mipmap-xxhdpi/app_news.png and /dev/null differ diff --git a/packages/app/android/app/src/main/res/mipmap-xxhdpi/app_notes.png b/packages/app/android/app/src/main/res/mipmap-xxhdpi/app_notes.png deleted file mode 100644 index 5c02272e..00000000 Binary files a/packages/app/android/app/src/main/res/mipmap-xxhdpi/app_notes.png and /dev/null differ diff --git a/packages/app/android/app/src/main/res/mipmap-xxhdpi/app_notifications.png b/packages/app/android/app/src/main/res/mipmap-xxhdpi/app_notifications.png deleted file mode 100644 index c6cad23a..00000000 Binary files a/packages/app/android/app/src/main/res/mipmap-xxhdpi/app_notifications.png and /dev/null differ diff --git a/packages/app/android/app/src/main/res/mipmap-xxxhdpi/app_files.png b/packages/app/android/app/src/main/res/mipmap-xxxhdpi/app_files.png deleted file mode 100644 index 0b8e34b4..00000000 Binary files a/packages/app/android/app/src/main/res/mipmap-xxxhdpi/app_files.png and /dev/null differ diff --git a/packages/app/android/app/src/main/res/mipmap-xxxhdpi/app_news.png b/packages/app/android/app/src/main/res/mipmap-xxxhdpi/app_news.png deleted file mode 100644 index 57f72f48..00000000 Binary files a/packages/app/android/app/src/main/res/mipmap-xxxhdpi/app_news.png and /dev/null differ diff --git a/packages/app/android/app/src/main/res/mipmap-xxxhdpi/app_notes.png b/packages/app/android/app/src/main/res/mipmap-xxxhdpi/app_notes.png deleted file mode 100644 index 3a6f1ceb..00000000 Binary files a/packages/app/android/app/src/main/res/mipmap-xxxhdpi/app_notes.png and /dev/null differ diff --git a/packages/app/android/app/src/main/res/mipmap-xxxhdpi/app_notifications.png b/packages/app/android/app/src/main/res/mipmap-xxxhdpi/app_notifications.png deleted file mode 100644 index 6544a81c..00000000 Binary files a/packages/app/android/app/src/main/res/mipmap-xxxhdpi/app_notifications.png and /dev/null differ diff --git a/packages/neon/neon/lib/l10n/en.arb b/packages/neon/neon/lib/l10n/en.arb index ac4613e4..d15d03e6 100644 --- a/packages/neon/neon/lib/l10n/en.arb +++ b/packages/neon/neon/lib/l10n/en.arb @@ -1,6 +1,6 @@ { "@@locale": "en", - "appImplementationName": "{app, select, core{Server} files{Files} news{News} notes{Notes} notifications{Notifications} other{}}", + "appImplementationName": "{app, select, nextcloud{Nextcloud} core{Server} files{Files} news{News} notes{Notes} notifications{Notifications} other{}}", "@appImplementationName": { "placeholders": { "app": {} diff --git a/packages/neon/neon/lib/neon.dart b/packages/neon/neon/lib/neon.dart index 5a380332..0f19bedd 100644 --- a/packages/neon/neon/lib/neon.dart +++ b/packages/neon/neon/lib/neon.dart @@ -5,7 +5,6 @@ import 'dart:convert'; import 'dart:io'; import 'dart:math'; -import 'package:collection/collection.dart'; import 'package:crypto/crypto.dart'; import 'package:file_picker/file_picker.dart'; import 'package:filesize/filesize.dart'; diff --git a/packages/neon/neon/lib/src/blocs/accounts.dart b/packages/neon/neon/lib/src/blocs/accounts.dart index 457e09ec..fc12a79d 100644 --- a/packages/neon/neon/lib/src/blocs/accounts.dart +++ b/packages/neon/neon/lib/src/blocs/accounts.dart @@ -1,5 +1,7 @@ part of '../../neon.dart'; +const _keyAccounts = 'accounts'; + abstract class AccountsBlocEvents { void addAccount(final Account account); void removeAccount(final Account account); @@ -20,19 +22,12 @@ class AccountsBloc extends Bloc implements AccountsBlocEvents, AccountsBlocState this._globalOptions, this._allAppImplementations, ) { - accounts.listen((final as) async { - _globalOptions.updateAccounts(as); - await _storage.setStringList(_keyAccounts, as.map((final a) => json.encode(a.toJson())).toList()); - }); - - if (_storage.containsKey(_keyAccounts)) { - accounts.add( - _storage - .getStringList(_keyAccounts)! - .map((final a) => Account.fromJson(json.decode(a) as Map)) - .toList(), - ); - } + accounts + ..add(loadAccounts(_storage)) + ..listen((final as) async { + _globalOptions.updateAccounts(as); + await _storage.setStringList(_keyAccounts, as.map((final a) => json.encode(a.toJson())).toList()); + }); final as = accounts.value; if (_globalOptions.rememberLastUsedAccount.value && _storage.containsKey(_keyLastUsedAccount)) { @@ -56,7 +51,6 @@ class AccountsBloc extends Bloc implements AccountsBlocEvents, AccountsBlocState final SharedPreferences _sharedPreferences; final GlobalOptions _globalOptions; final List _allAppImplementations; - final _keyAccounts = 'accounts'; final _keyLastUsedAccount = 'last-used-account'; final _accountsOptions = {}; @@ -194,3 +188,13 @@ class AccountsBloc extends Bloc implements AccountsBlocEvents, AccountsBlocState ); } } + +List loadAccounts(final AppStorage storage) { + if (storage.containsKey(_keyAccounts)) { + return storage + .getStringList(_keyAccounts)! + .map((final a) => Account.fromJson(json.decode(a) as Map)) + .toList(); + } + return []; +} diff --git a/packages/neon/neon/lib/src/utils/push_utils.dart b/packages/neon/neon/lib/src/utils/push_utils.dart index 7a5a24c3..9797efbd 100644 --- a/packages/neon/neon/lib/src/utils/push_utils.dart +++ b/packages/neon/neon/lib/src/utils/push_utils.dart @@ -55,71 +55,71 @@ class PushUtils { for (final message in Uri(query: utf8.decode(messages)).queryParameters.values) { final data = json.decode(message) as Map; - final notification = PushNotification( + final pushNotification = PushNotification( accountID: instance, priority: data['priority']! as String, type: data['type']! as String, subject: decryptPushNotificationSubject(keypair.privateKey, data['subject']! as String), ); - if (notification.subject.delete ?? false) { - await localNotificationsPlugin.cancel(_getNotificationID(instance, notification)); - } else if (notification.subject.deleteAll ?? false) { + if (pushNotification.subject.delete ?? false) { + await localNotificationsPlugin.cancel(_getNotificationID(instance, pushNotification)); + } else if (pushNotification.subject.deleteAll ?? false) { await localNotificationsPlugin.cancelAll(); Global.onPushNotificationReceived?.call(instance); - } else if (notification.type == 'background') { - debugPrint('Got unknown background notification ${json.encode(notification.toJson())}'); + } else if (pushNotification.type == 'background') { + debugPrint('Got unknown background notification ${json.encode(pushNotification.toJson())}'); } else { final localizations = await appLocalizationsFromSystem(); final platform = await getNeonPlatform(); final cache = Cache(platform); await cache.init(); - //final requestManager = RequestManager(cache); - //final allAppImplementations = getAppImplementations(sharedPreferences, requestManager, platform); - final allAppImplementations = []; - final matchingAppImplementations = - allAppImplementations.where((final a) => a.id == notification.subject.app).toList(); - AppImplementation? app; - if (matchingAppImplementations.isNotEmpty) { - app = matchingAppImplementations.single; - } else { - app = allAppImplementations.firstWhereOrNull((final a) => a.id == 'notifications'); + NextcloudNotificationsNotification? notification; + var accounts = []; + Account? account; + try { + accounts = loadAccounts(AppStorage('accounts', sharedPreferences)); + account = accounts.find(instance); + if (account != null) { + notification = + (await account.client.notifications.getNotification(id: pushNotification.subject.nid!)).ocs.data; + } + } catch (e, s) { + debugPrint(e.toString()); + debugPrint(s.toString()); } - final appID = app?.id ?? notification.subject.app; - var appName = localizations.appImplementationName(appID ?? ''); + final appID = notification?.app ?? pushNotification.subject.app ?? 'nextcloud'; + var appName = localizations.appImplementationName(appID); if (appName == '') { - appName = appID ?? 'Nextcloud'; + debugPrint('Missing app name for $appID'); + appName = appID; } + final title = notification?.subject ?? pushNotification.subject.subject; + final message = notification != null && notification.message != '' ? notification.message : null; await localNotificationsPlugin.show( - _getNotificationID(instance, notification), - appName, - notification.subject.subject, + _getNotificationID(instance, pushNotification), + message != null ? '$appName: $title' : appName, + message ?? title, NotificationDetails( android: AndroidNotificationDetails( - notification.subject.app ?? 'nextcloud', + appID, appName, - groupKey: notification.subject.app != null ? 'app_${notification.subject.app}' : 'nextcloud', - icon: '@mipmap/${app != null ? 'app_${app.id}' : 'ic_launcher'}', + subText: accounts.length > 1 && account != null ? account.client.humanReadableID : null, + groupKey: 'app_$appID', + icon: '@mipmap/ic_launcher', color: themePrimaryColor, - category: notification.type == 'voip' ? AndroidNotificationCategory.call : null, + category: pushNotification.type == 'voip' ? AndroidNotificationCategory.call : null, importance: Importance.max, - priority: notification.priority == 'high' - ? (notification.type == 'voip' ? Priority.max : Priority.high) + priority: pushNotification.priority == 'high' + ? (pushNotification.type == 'voip' ? Priority.max : Priority.high) : Priority.defaultPriority, ), ), - payload: json.encode( - PushNotification( - accountID: instance, - priority: notification.priority, - type: notification.type, - subject: notification.subject, - ).toJson(), - ), + payload: json.encode(pushNotification.toJson()), ); } diff --git a/tool/generate-neon.sh b/tool/generate-neon.sh index f6ddce33..03fb5c92 100755 --- a/tool/generate-neon.sh +++ b/tool/generate-neon.sh @@ -70,10 +70,6 @@ copy_nextcloud_app_svg notifications external/nextcloud-notifications # Android launcher icons export_mipmap_icon_all "assets/logo.svg" "ic_launcher" & - for id in files news notes notifications; do - export_mipmap_icon_all "../neon/neon_$id/assets/app.svg" "app_$id" & - done - wait fvm dart run flutter_native_splash:create )