Browse Source

neon,neon_notifications: Use interfaces for app implementations

pull/240/head
jld3103 2 years ago
parent
commit
7153739d20
No known key found for this signature in database
GPG Key ID: 9062417B9E8EB7B3
  1. 2
      packages/neon/neon/lib/neon.dart
  2. 4
      packages/neon/neon/lib/src/app.dart
  3. 6
      packages/neon/neon/lib/src/blocs/apps.dart
  4. 21
      packages/neon/neon/lib/src/interfaces/notifications.dart
  5. 4
      packages/neon/neon/lib/src/pages/home.dart
  6. 2
      packages/neon/neon/pubspec.yaml
  7. 5
      packages/neon/neon_notifications/lib/blocs/notifications.dart
  8. 2
      packages/neon/neon_notifications/lib/neon_notifications.dart
  9. 2
      packages/neon/neon_notifications/lib/options.dart

2
packages/neon/neon/lib/neon.dart

@ -23,7 +23,6 @@ import 'package:material_design_icons_flutter/material_design_icons_flutter.dart
import 'package:neon/l10n/localizations.dart';
import 'package:neon/src/models/account.dart';
import 'package:neon/src/models/push_notification.dart';
import 'package:neon_notifications/neon_notifications.dart';
import 'package:nextcloud/nextcloud.dart';
import 'package:package_info_plus/package_info_plus.dart';
import 'package:path/path.dart' as p;
@ -58,6 +57,7 @@ part 'src/blocs/next_push.dart';
part 'src/blocs/push_notifications.dart';
part 'src/blocs/user_details.dart';
part 'src/blocs/user_status.dart';
part 'src/interfaces/notifications.dart';
part 'src/pages/account_settings.dart';
part 'src/pages/home.dart';
part 'src/pages/login.dart';

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

@ -173,7 +173,7 @@ class _NeonAppState extends State<NeonApp> with WidgetsBindingObserver, tray.Tra
}
final appImplementation = Provider.of<List<AppImplementation>>(context, listen: false)
.singleWhere((final a) => a.id == 'notifications');
await _accountsBloc.getAppsBloc(account).getAppBloc<NotificationsBloc>(appImplementation).refresh();
await _accountsBloc.getAppsBloc(account).getAppBloc<NotificationsBlocInterface>(appImplementation).refresh();
};
Global.onPushNotificationClicked = (final pushNotificationWithAccountID) async {
final allAppImplementations = Provider.of<List<AppImplementation>>(context, listen: false);
@ -197,7 +197,7 @@ class _NeonAppState extends State<NeonApp> with WidgetsBindingObserver, tray.Tra
if (appImplementation.id != 'notifications') {
_accountsBloc
.getAppsBloc(account)
.getAppBloc<NotificationsBloc>(appImplementation)
.getAppBloc<NotificationsBlocInterface>(appImplementation)
.deleteNotification(pushNotificationWithAccountID.subject.nid!);
}
await _openAppFromExternal(account, appImplementation.id);

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

@ -11,7 +11,7 @@ abstract class AppsBlocStates {
BehaviorSubject<Result<List<AppImplementation>>> get appImplementations;
BehaviorSubject<Result<NotificationsApp?>> get notificationsAppImplementation;
BehaviorSubject<Result<NotificationsAppInterface?>> get notificationsAppImplementation;
BehaviorSubject<String?> get activeAppID;
@ -107,8 +107,8 @@ class AppsBloc extends InteractiveBloc implements AppsBlocEvents, AppsBlocStates
BehaviorSubject<Result<List<NextcloudApp>>> apps = BehaviorSubject<Result<List<NextcloudApp>>>();
@override
BehaviorSubject<Result<NotificationsApp?>> notificationsAppImplementation =
BehaviorSubject<Result<NotificationsApp?>>();
BehaviorSubject<Result<NotificationsAppInterface?>> notificationsAppImplementation =
BehaviorSubject<Result<NotificationsAppInterface?>>();
@override
BehaviorSubject openNotifications = BehaviorSubject();

21
packages/neon/neon/lib/src/interfaces/notifications.dart

@ -0,0 +1,21 @@
part of '../../neon.dart';
abstract class NotificationsAppInterface
extends AppImplementation<NotificationsBlocInterface, NotificationsOptionsInterface> {
NotificationsAppInterface(
super.sharedPreferences,
super.requestManager,
super.platform,
);
}
abstract class NotificationsBlocInterface extends InteractiveBloc {
NotificationsBlocInterface(this.options);
final NotificationsOptionsInterface options;
void deleteNotification(final int id);
}
abstract class NotificationsOptionsInterface extends NextcloudAppSpecificOptions {
NotificationsOptionsInterface(super.storage);
}

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

@ -147,7 +147,7 @@ class _HomePageState extends State<HomePage> {
}
Future _openNotifications(
final NotificationsApp app,
final NotificationsAppInterface app,
final List<Account> accounts,
final Account account,
) async {
@ -186,7 +186,7 @@ class _HomePageState extends State<HomePage> {
stream: _capabilitiesBloc.capabilities,
builder: (final context, final capabilities) => ResultBuilder<AppsBloc, List<AppImplementation>>(
stream: _appsBloc.appImplementations,
builder: (final context, final appImplementations) => ResultBuilder<AppsBloc, NotificationsApp?>(
builder: (final context, final appImplementations) => ResultBuilder<AppsBloc, NotificationsAppInterface?>(
stream: _appsBloc.notificationsAppImplementation,
builder: (final context, final notificationsAppImplementation) => StreamBuilder<String?>(
stream: _appsBloc.activeAppID,

2
packages/neon/neon/pubspec.yaml

@ -24,8 +24,6 @@ dependencies:
intl: ^0.17.0
json_annotation: ^4.7.0
material_design_icons_flutter: ^6.0.7096
neon_notifications:
path: ../neon_notifications
nextcloud:
path: ../../nextcloud
package_info_plus: ^1.4.2

5
packages/neon/neon_notifications/lib/blocs/notifications.dart

@ -12,9 +12,9 @@ abstract class NotificationsBlocStates {
BehaviorSubject<int> get unreadCounter;
}
class NotificationsBloc extends InteractiveBloc implements NotificationsBlocEvents, NotificationsBlocStates {
class NotificationsBloc extends NotificationsBlocInterface implements NotificationsBlocEvents, NotificationsBlocStates {
NotificationsBloc(
this.options,
super.options,
this._requestManager,
this._client,
) {
@ -27,7 +27,6 @@ class NotificationsBloc extends InteractiveBloc implements NotificationsBlocEven
unawaited(refresh());
}
final NotificationsAppSpecificOptions options;
final RequestManager _requestManager;
final NextcloudClient _client;

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

@ -13,7 +13,7 @@ part 'blocs/notifications.dart';
part 'options.dart';
part 'pages/main.dart';
class NotificationsApp extends AppImplementation<NotificationsBloc, NotificationsAppSpecificOptions> {
class NotificationsApp extends NotificationsAppInterface {
NotificationsApp(super.sharedPreferences, super.requestManager, super.platform);
@override

2
packages/neon/neon_notifications/lib/options.dart

@ -1,6 +1,6 @@
part of 'neon_notifications.dart';
class NotificationsAppSpecificOptions extends NextcloudAppSpecificOptions {
class NotificationsAppSpecificOptions extends NotificationsOptionsInterface {
NotificationsAppSpecificOptions(super.storage) {
super.categories = [];
super.options = [];

Loading…
Cancel
Save