|
|
@ -1,7 +1,8 @@ |
|
|
|
import 'dart:async'; |
|
|
|
import 'dart:async'; |
|
|
|
|
|
|
|
|
|
|
|
import 'package:flutter/foundation.dart'; |
|
|
|
import 'package:neon/src/apps/notifications/app.dart'; |
|
|
|
import 'package:neon/src/blocs/accounts.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/account.dart'; |
|
|
|
import 'package:neon/src/neon.dart'; |
|
|
|
import 'package:neon/src/neon.dart'; |
|
|
|
import 'package:nextcloud/nextcloud.dart'; |
|
|
|
import 'package:nextcloud/nextcloud.dart'; |
|
|
@ -22,6 +23,8 @@ abstract class AppsBlocStates { |
|
|
|
|
|
|
|
|
|
|
|
BehaviorSubject<Result<List<AppImplementation>>> get appImplementations; |
|
|
|
BehaviorSubject<Result<List<AppImplementation>>> get appImplementations; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
BehaviorSubject<Result<NotificationsApp?>> get notificationsAppImplementation; |
|
|
|
|
|
|
|
|
|
|
|
BehaviorSubject<String?> get activeAppID; |
|
|
|
BehaviorSubject<String?> get activeAppID; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
@ -29,6 +32,7 @@ abstract class AppsBlocStates { |
|
|
|
class AppsBloc extends $AppsBloc { |
|
|
|
class AppsBloc extends $AppsBloc { |
|
|
|
AppsBloc( |
|
|
|
AppsBloc( |
|
|
|
this._requestManager, |
|
|
|
this._requestManager, |
|
|
|
|
|
|
|
this._capabilitiesBloc, |
|
|
|
this._accountsBloc, |
|
|
|
this._accountsBloc, |
|
|
|
this._account, |
|
|
|
this._account, |
|
|
|
this._allAppImplementations, |
|
|
|
this._allAppImplementations, |
|
|
@ -40,28 +44,31 @@ class AppsBloc extends $AppsBloc { |
|
|
|
if (_activeAppSubject.valueOrNull != appId) { |
|
|
|
if (_activeAppSubject.valueOrNull != appId) { |
|
|
|
_activeAppSubject.add(appId); |
|
|
|
_activeAppSubject.add(appId); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
} else if (appId == 'notifications') { |
|
|
|
|
|
|
|
// TODO: Open notifications page |
|
|
|
} else { |
|
|
|
} else { |
|
|
|
debugPrint('App $appId not found'); |
|
|
|
throw Exception('App $appId not found'); |
|
|
|
} |
|
|
|
} |
|
|
|
}); |
|
|
|
}); |
|
|
|
|
|
|
|
|
|
|
|
_appsSubject.listen((final result) { |
|
|
|
_appsSubject.listen((final result) { |
|
|
|
if (result is ResultLoading) { |
|
|
|
if (result is ResultLoading) { |
|
|
|
_appImplementationsSubject.add(Result.loading()); |
|
|
|
_appImplementationsSubject.add(Result.loading()); |
|
|
|
} else if (result is ResultError) { |
|
|
|
} else if (result is ResultError<List<NextcloudApp>>) { |
|
|
|
_appImplementationsSubject.add(Result.error((result as ResultError).error)); |
|
|
|
_appImplementationsSubject.add(Result.error(result.error)); |
|
|
|
} else if (result is ResultSuccess) { |
|
|
|
} else if (result is ResultSuccess<List<NextcloudApp>>) { |
|
|
|
_appImplementationsSubject.add( |
|
|
|
_appImplementationsSubject.add( |
|
|
|
Result.success(_filteredAppImplementations((result as ResultSuccess<List<NextcloudApp>>).data)), |
|
|
|
Result.success(_filteredAppImplementations(result.data.map((final a) => a.id).toList())), |
|
|
|
); |
|
|
|
); |
|
|
|
} else if (result is ResultCached && result.data != null) { |
|
|
|
} else if (result is ResultCached<List<NextcloudApp>>) { |
|
|
|
_appImplementationsSubject.add( |
|
|
|
_appImplementationsSubject.add( |
|
|
|
ResultCached(_filteredAppImplementations((result as ResultCached<List<NextcloudApp>>).data)), |
|
|
|
ResultCached(_filteredAppImplementations(result.data.map((final a) => a.id).toList())), |
|
|
|
); |
|
|
|
); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
final appImplementations = |
|
|
|
final appImplementations = result.data != null |
|
|
|
result.data != null ? _filteredAppImplementations(result.data!) : <AppImplementation>[]; |
|
|
|
? _filteredAppImplementations(result.data!.map((final a) => a.id).toList()) |
|
|
|
|
|
|
|
: <AppImplementation>[]; |
|
|
|
|
|
|
|
|
|
|
|
if (result.data != null) { |
|
|
|
if (result.data != null) { |
|
|
|
final options = _accountsBloc.getOptions(_account); |
|
|
|
final options = _accountsBloc.getOptions(_account); |
|
|
@ -84,16 +91,39 @@ class AppsBloc extends $AppsBloc { |
|
|
|
} |
|
|
|
} |
|
|
|
}); |
|
|
|
}); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
_capabilitiesBloc.capabilities.listen((final result) { |
|
|
|
|
|
|
|
if (result is ResultLoading) { |
|
|
|
|
|
|
|
_notificationsAppImplementationSubject.add(Result.loading()); |
|
|
|
|
|
|
|
} else if (result is ResultError<CoreServerCapabilities_Ocs_Data>) { |
|
|
|
|
|
|
|
_notificationsAppImplementationSubject.add(Result.error(result.error)); |
|
|
|
|
|
|
|
} else if (result is ResultSuccess<CoreServerCapabilities_Ocs_Data>) { |
|
|
|
|
|
|
|
_notificationsAppImplementationSubject.add( |
|
|
|
|
|
|
|
Result.success( |
|
|
|
|
|
|
|
result.data.capabilities.notifications != null ? _findAppImplementation('notifications') : null, |
|
|
|
|
|
|
|
), |
|
|
|
|
|
|
|
); |
|
|
|
|
|
|
|
} else if (result is ResultCached<CoreServerCapabilities_Ocs_Data>) { |
|
|
|
|
|
|
|
_notificationsAppImplementationSubject.add( |
|
|
|
|
|
|
|
ResultCached(result.data.capabilities.notifications != null ? _findAppImplementation('notifications') : null), |
|
|
|
|
|
|
|
); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
}); |
|
|
|
|
|
|
|
|
|
|
|
_loadApps(); |
|
|
|
_loadApps(); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
final _extraApps = ['notifications']; |
|
|
|
T? _findAppImplementation<T extends AppImplementation>(final String id) { |
|
|
|
|
|
|
|
final matches = _filteredAppImplementations([id]); |
|
|
|
|
|
|
|
if (matches.isNotEmpty) { |
|
|
|
|
|
|
|
return matches.single as T; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
List<AppImplementation> _filteredAppImplementations(final List<NextcloudApp> apps) { |
|
|
|
return null; |
|
|
|
final appIds = apps.map((final a) => a.id).toList(); |
|
|
|
|
|
|
|
return _allAppImplementations.where((final a) => appIds.contains(a.id) || _extraApps.contains(a.id)).toList(); |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
List<AppImplementation> _filteredAppImplementations(final List<String> appIds) => |
|
|
|
|
|
|
|
_allAppImplementations.where((final a) => appIds.contains(a.id)).toList(); |
|
|
|
|
|
|
|
|
|
|
|
void _loadApps() { |
|
|
|
void _loadApps() { |
|
|
|
_requestManager |
|
|
|
_requestManager |
|
|
|
.wrapNextcloud<List<NextcloudApp>, CoreNavigationApps>( |
|
|
|
.wrapNextcloud<List<NextcloudApp>, CoreNavigationApps>( |
|
|
@ -107,12 +137,14 @@ class AppsBloc extends $AppsBloc { |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
final RequestManager _requestManager; |
|
|
|
final RequestManager _requestManager; |
|
|
|
|
|
|
|
final CapabilitiesBloc _capabilitiesBloc; |
|
|
|
final AccountsBloc _accountsBloc; |
|
|
|
final AccountsBloc _accountsBloc; |
|
|
|
final Account _account; |
|
|
|
final Account _account; |
|
|
|
final List<AppImplementation> _allAppImplementations; |
|
|
|
final List<AppImplementation> _allAppImplementations; |
|
|
|
|
|
|
|
|
|
|
|
final _appsSubject = BehaviorSubject<Result<List<NextcloudApp>>>(); |
|
|
|
final _appsSubject = BehaviorSubject<Result<List<NextcloudApp>>>(); |
|
|
|
final _appImplementationsSubject = BehaviorSubject<Result<List<AppImplementation>>>(); |
|
|
|
final _appImplementationsSubject = BehaviorSubject<Result<List<AppImplementation>>>(); |
|
|
|
|
|
|
|
final _notificationsAppImplementationSubject = BehaviorSubject<Result<NotificationsApp?>>(); |
|
|
|
late final _activeAppSubject = BehaviorSubject<String?>(); |
|
|
|
late final _activeAppSubject = BehaviorSubject<String?>(); |
|
|
|
|
|
|
|
|
|
|
|
final Map<String, RxBlocBase> _blocs = {}; |
|
|
|
final Map<String, RxBlocBase> _blocs = {}; |
|
|
@ -128,6 +160,8 @@ class AppsBloc extends $AppsBloc { |
|
|
|
@override |
|
|
|
@override |
|
|
|
void dispose() { |
|
|
|
void dispose() { |
|
|
|
unawaited(_appsSubject.close()); |
|
|
|
unawaited(_appsSubject.close()); |
|
|
|
|
|
|
|
unawaited(_appImplementationsSubject.close()); |
|
|
|
|
|
|
|
unawaited(_notificationsAppImplementationSubject.close()); |
|
|
|
unawaited(_activeAppSubject.close()); |
|
|
|
unawaited(_activeAppSubject.close()); |
|
|
|
for (final key in _blocs.keys) { |
|
|
|
for (final key in _blocs.keys) { |
|
|
|
_blocs[key]!.dispose(); |
|
|
|
_blocs[key]!.dispose(); |
|
|
@ -142,6 +176,10 @@ class AppsBloc extends $AppsBloc { |
|
|
|
BehaviorSubject<Result<List<AppImplementation<RxBlocBase, NextcloudAppSpecificOptions>>>> |
|
|
|
BehaviorSubject<Result<List<AppImplementation<RxBlocBase, NextcloudAppSpecificOptions>>>> |
|
|
|
_mapToAppImplementationsState() => _appImplementationsSubject; |
|
|
|
_mapToAppImplementationsState() => _appImplementationsSubject; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@override |
|
|
|
|
|
|
|
BehaviorSubject<Result<NotificationsApp?>> _mapToNotificationsAppImplementationState() => |
|
|
|
|
|
|
|
_notificationsAppImplementationSubject; |
|
|
|
|
|
|
|
|
|
|
|
@override |
|
|
|
@override |
|
|
|
BehaviorSubject<String?> _mapToActiveAppIDState() => _activeAppSubject; |
|
|
|
BehaviorSubject<String?> _mapToActiveAppIDState() => _activeAppSubject; |
|
|
|
} |
|
|
|
} |
|
|
|