Browse Source

Merge pull request #517 from provokateurin/refactor/app-ids

refactor(neon,neon_files,neon_news,neon_notes,neon_notifications): Use shared constants for app ids
pull/508/head
Kate 1 year ago committed by GitHub
parent
commit
7c55196246
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 1
      packages/neon/neon/lib/models.dart
  2. 5
      packages/neon/neon/lib/src/app.dart
  3. 13
      packages/neon/neon/lib/src/blocs/apps.dart
  4. 3
      packages/neon/neon/lib/src/blocs/push_notifications.dart
  5. 6
      packages/neon/neon/lib/src/models/app_ids.dart
  6. 3
      packages/neon/neon/lib/src/utils/push_utils.dart
  7. 4
      packages/neon/neon_files/lib/neon_files.dart
  8. 5
      packages/neon/neon_files/lib/routes.dart
  9. 4
      packages/neon/neon_news/lib/neon_news.dart
  10. 5
      packages/neon/neon_news/lib/routes.dart
  11. 4
      packages/neon/neon_notes/lib/neon_notes.dart
  12. 5
      packages/neon/neon_notes/lib/routes.dart
  13. 4
      packages/neon/neon_notifications/lib/neon_notifications.dart
  14. 2
      packages/neon/neon_notifications/lib/pages/main.dart
  15. 5
      packages/neon/neon_notifications/lib/routes.dart

1
packages/neon/neon/lib/models.dart

@ -1,3 +1,4 @@
export 'package:neon/src/models/account.dart' hide Credentials, LoginQrcode;
export 'package:neon/src/models/app_ids.dart';
export 'package:neon/src/models/app_implementation.dart';
export 'package:neon/src/models/notifications_interface.dart';

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

@ -10,6 +10,7 @@ import 'package:neon/src/bloc/result_builder.dart';
import 'package:neon/src/blocs/accounts.dart';
import 'package:neon/src/blocs/capabilities.dart';
import 'package:neon/src/models/account.dart';
import 'package:neon/src/models/app_ids.dart';
import 'package:neon/src/models/app_implementation.dart';
import 'package:neon/src/models/notifications_interface.dart';
import 'package:neon/src/models/push_notification.dart';
@ -144,7 +145,7 @@ class _NeonAppState extends State<NeonApp> with WidgetsBindingObserver, tray.Tra
}
final allAppImplementations = Provider.of<Iterable<AppImplementation>>(context, listen: false);
final app = allAppImplementations.tryFind('notifications') as NotificationsAppInterface?;
final app = allAppImplementations.tryFind(AppIDs.notifications) as NotificationsAppInterface?;
if (app == null) {
return;
@ -161,7 +162,7 @@ class _NeonAppState extends State<NeonApp> with WidgetsBindingObserver, tray.Tra
final allAppImplementations = Provider.of<Iterable<AppImplementation>>(context, listen: false);
final notificationsApp = allAppImplementations.tryFind('notifications') as NotificationsAppInterface?;
final notificationsApp = allAppImplementations.tryFind(AppIDs.notifications) as NotificationsAppInterface?;
if (notificationsApp != null) {
_accountsBloc
.getAppsBlocFor(account)

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

@ -7,6 +7,7 @@ import 'package:neon/src/bloc/result.dart';
import 'package:neon/src/blocs/accounts.dart';
import 'package:neon/src/blocs/capabilities.dart';
import 'package:neon/src/models/account.dart';
import 'package:neon/src/models/app_ids.dart';
import 'package:neon/src/models/app_implementation.dart';
import 'package:neon/src/models/notifications_interface.dart';
import 'package:neon/src/settings/models/nextcloud_app_options.dart';
@ -66,7 +67,7 @@ class AppsBloc extends InteractiveBloc implements AppsBlocEvents, AppsBlocStates
_capabilitiesBloc.capabilities.listen((final result) {
notificationsAppImplementation.add(
result.transform(
(final data) => data.capabilities.notifications != null ? _findAppImplementation('notifications') : null,
(final data) => data.capabilities.notifications != null ? _findAppImplementation(AppIDs.notifications) : null,
),
);
@ -86,8 +87,8 @@ class AppsBloc extends InteractiveBloc implements AppsBlocEvents, AppsBlocStates
/// Returns null when no app is supported by the server.
String? _getInitialAppFallback() {
final supportedApps = appImplementations.value.requireData;
if (supportedApps.tryFind('files') != null) {
return 'files';
if (supportedApps.tryFind(AppIDs.files) != null) {
return AppIDs.files;
} else if (supportedApps.isNotEmpty) {
return supportedApps.first.id;
}
@ -115,8 +116,8 @@ class AppsBloc extends InteractiveBloc implements AppsBlocEvents, AppsBlocStates
try {
final (supported, minVersion) = switch (id) {
'core' => _account.client.core.isSupported(capabilities.requireData),
'news' => await _account.client.news.isSupported(),
'notes' => _account.client.notes.isSupported(capabilities.requireData),
AppIDs.news => await _account.client.news.isSupported(),
AppIDs.notes => _account.client.notes.isSupported(capabilities.requireData),
_ => (true, null),
};
@ -201,7 +202,7 @@ class AppsBloc extends InteractiveBloc implements AppsBlocEvents, AppsBlocStates
@override
Future setActiveApp(final String appID) async {
if (appID == 'notifications') {
if (appID == AppIDs.notifications) {
openNotifications.add(null);
return;
}

3
packages/neon/neon/lib/src/blocs/push_notifications.dart

@ -6,6 +6,7 @@ import 'package:meta/meta.dart';
import 'package:neon/src/bloc/bloc.dart';
import 'package:neon/src/blocs/accounts.dart';
import 'package:neon/src/models/account.dart';
import 'package:neon/src/models/app_ids.dart';
import 'package:neon/src/models/push_notification.dart';
import 'package:neon/src/platform/platform.dart';
import 'package:neon/src/settings/models/storage.dart';
@ -39,7 +40,7 @@ class PushNotificationsBloc extends Bloc implements PushNotificationsBlocEvents,
final AccountsBloc _accountsBloc;
final NeonPlatform _platform;
final SharedPreferences _sharedPreferences;
late final _storage = AppStorage('notifications', _sharedPreferences);
late final _storage = AppStorage(AppIDs.notifications, _sharedPreferences);
final GlobalOptions _globalOptions;
final _notificationsController = StreamController<PushNotification>();

6
packages/neon/neon/lib/src/models/app_ids.dart

@ -0,0 +1,6 @@
sealed class AppIDs {
static const files = 'files';
static const news = 'news';
static const notes = 'notes';
static const notifications = 'notifications';
}

3
packages/neon/neon/lib/src/utils/push_utils.dart

@ -11,6 +11,7 @@ import 'package:flutter_svg/flutter_svg.dart' show SvgFileLoader, vg;
import 'package:meta/meta.dart';
import 'package:neon/src/blocs/accounts.dart';
import 'package:neon/src/models/account.dart';
import 'package:neon/src/models/app_ids.dart';
import 'package:neon/src/models/push_notification.dart';
import 'package:neon/src/platform/platform.dart';
import 'package:neon/src/settings/models/storage.dart';
@ -74,7 +75,7 @@ class PushUtils {
);
final sharedPreferences = await SharedPreferences.getInstance();
final keypair = await loadRSAKeypair(AppStorage('notifications', sharedPreferences));
final keypair = await loadRSAKeypair(AppStorage(AppIDs.notifications, sharedPreferences));
for (final message in Uri(query: utf8.decode(messages)).queryParameters.values) {
final data = json.decode(message) as Map<String, dynamic>;

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

@ -49,9 +49,7 @@ class FilesApp extends AppImplementation<FilesBloc, FilesAppSpecificOptions> {
FilesApp(super.sharedPreferences, super.requestManager, super.platform);
@override
String id = appId;
static const String appId = 'files';
String id = AppIDs.files;
@override
LocalizationsDelegate localizationsDelegate = AppLocalizations.delegate;

5
packages/neon/neon_files/lib/routes.dart

@ -1,13 +1,14 @@
import 'package:flutter/widgets.dart';
import 'package:go_router/go_router.dart';
import 'package:neon/models.dart';
import 'package:neon/utils.dart';
import 'package:neon_files/neon_files.dart';
part 'routes.g.dart';
@TypedGoRoute<FilesAppRoute>(
path: '$appsRoutePrefix${FilesApp.appId}',
name: FilesApp.appId,
path: '$appsRoutePrefix${AppIDs.files}',
name: AppIDs.files,
)
@immutable
class FilesAppRoute extends NeonAppRoute {

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

@ -55,9 +55,7 @@ class NewsApp extends AppImplementation<NewsBloc, NewsAppSpecificOptions> {
NewsApp(super.sharedPreferences, super.requestManager, super.platform);
@override
String id = appId;
static const String appId = 'news';
String id = AppIDs.news;
@override
LocalizationsDelegate localizationsDelegate = AppLocalizations.delegate;

5
packages/neon/neon_news/lib/routes.dart

@ -1,13 +1,14 @@
import 'package:flutter/widgets.dart';
import 'package:go_router/go_router.dart';
import 'package:neon/models.dart';
import 'package:neon/utils.dart';
import 'package:neon_news/neon_news.dart';
part 'routes.g.dart';
@TypedGoRoute<NewsAppRoute>(
path: '$appsRoutePrefix${NewsApp.appId}',
name: NewsApp.appId,
path: '$appsRoutePrefix${AppIDs.news}',
name: AppIDs.news,
)
@immutable
class NewsAppRoute extends NeonAppRoute {

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

@ -45,9 +45,7 @@ class NotesApp extends AppImplementation<NotesBloc, NotesAppSpecificOptions> {
NotesApp(super.sharedPreferences, super.requestManager, super.platform);
@override
String id = appId;
static const String appId = 'notes';
String id = AppIDs.notes;
@override
List<Locale> supportedLocales = AppLocalizations.supportedLocales;

5
packages/neon/neon_notes/lib/routes.dart

@ -1,13 +1,14 @@
import 'package:flutter/widgets.dart';
import 'package:go_router/go_router.dart';
import 'package:neon/models.dart';
import 'package:neon/utils.dart';
import 'package:neon_notes/neon_notes.dart';
part 'routes.g.dart';
@TypedGoRoute<NotesAppRoute>(
path: '$appsRoutePrefix${NotesApp.appId}',
name: NotesApp.appId,
path: '$appsRoutePrefix${AppIDs.notes}',
name: AppIDs.notes,
)
@immutable
class NotesAppRoute extends NeonAppRoute {

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

@ -25,9 +25,7 @@ class NotificationsApp extends AppImplementation<NotificationsBloc, Notification
NotificationsApp(super.sharedPreferences, super.requestManager, super.platform);
@override
String id = appId;
static const String appId = 'notifications';
String id = AppIDs.notifications;
@override
LocalizationsDelegate localizationsDelegate = AppLocalizations.delegate;

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

@ -85,7 +85,7 @@ class _NotificationsMainPageState extends State<NotificationsMainPage> {
),
),
onTap: () async {
if (notification.app == 'notifications') {
if (notification.app == AppIDs.notifications) {
return;
}
if (app != null) {

5
packages/neon/neon_notifications/lib/routes.dart

@ -1,13 +1,14 @@
import 'package:flutter/widgets.dart';
import 'package:go_router/go_router.dart';
import 'package:neon/models.dart';
import 'package:neon/utils.dart';
import 'package:neon_notifications/neon_notifications.dart';
part 'routes.g.dart';
@TypedGoRoute<NotificationsAppRoute>(
path: '$appsRoutePrefix${NotificationsApp.appId}',
name: NotificationsApp.appId,
path: '$appsRoutePrefix${AppIDs.notifications}',
name: AppIDs.notifications,
)
@immutable
class NotificationsAppRoute extends NeonAppRoute {

Loading…
Cancel
Save