diff --git a/packages/neon/integration_test/screenshot_test.dart b/packages/neon/integration_test/screenshot_test.dart index d5050324..97dd1c30 100644 --- a/packages/neon/integration_test/screenshot_test.dart +++ b/packages/neon/integration_test/screenshot_test.dart @@ -119,6 +119,7 @@ Future pumpAppPage( sharedPreferences, globalOptions, packageInfo, + allAppImplementations, ); if (account != null) { accountsBloc.addAccount(account..setupClient(packageInfo)); diff --git a/packages/neon/lib/main.dart b/packages/neon/lib/main.dart index 7220b928..4207a6ef 100644 --- a/packages/neon/lib/main.dart +++ b/packages/neon/lib/main.dart @@ -47,6 +47,7 @@ Future main() async { sharedPreferences, globalOptions, packageInfo, + allAppImplementations, ); final pushNotificationsBloc = PushNotificationsBloc( accountsBloc, diff --git a/packages/neon/lib/src/blocs/accounts.dart b/packages/neon/lib/src/blocs/accounts.dart index 31e78167..73aef222 100644 --- a/packages/neon/lib/src/blocs/accounts.dart +++ b/packages/neon/lib/src/blocs/accounts.dart @@ -1,6 +1,7 @@ import 'dart:async'; import 'dart:convert'; +import 'package:neon/src/blocs/apps.dart'; import 'package:neon/src/blocs/user_details.dart'; import 'package:neon/src/blocs/user_status.dart'; import 'package:neon/src/models/account.dart'; @@ -32,6 +33,7 @@ class AccountsBloc extends $AccountsBloc { this._sharedPreferences, this._globalOptions, this._packageInfo, + this._allAppImplementations, ) { _accountsSubject.listen((final accounts) async { _globalOptions.updateAccounts(accounts); @@ -118,30 +120,34 @@ class AccountsBloc extends $AccountsBloc { } } - AccountSpecificOptions? getOptions([Account? account]) { - account ??= _activeAccountSubject.valueOrNull; - if (account != null) { - final accountID = account.id; - if (_accountsOptions[accountID] != null) { - return _accountsOptions[accountID]; - } + AccountSpecificOptions getOptions(final Account account) => _accountsOptions[account.id] ??= AccountSpecificOptions( + Storage('accounts-${account.id}', _sharedPreferences), + getAppsBloc(account), + ); - return _accountsOptions[accountID] = - AccountSpecificOptions(Storage('accounts-${account.id}', _sharedPreferences)); + AppsBloc getAppsBloc(final Account account) { + if (_accountsAppsBlocs[account.id] != null) { + return _accountsAppsBlocs[account.id]!; } - - return null; + return AppsBloc( + _requestManager, + this, + account, + _allAppImplementations, + ); } final RequestManager _requestManager; final Storage _storage; final SharedPreferences _sharedPreferences; final GlobalOptions _globalOptions; + final List _allAppImplementations; final PackageInfo _packageInfo; final _keyAccounts = 'accounts'; final _keyLastUsedAccount = 'last-used-account'; final _accountsOptions = {}; + final _accountsAppsBlocs = {}; late final _activeAccountSubject = BehaviorSubject.seeded(null); late final _accountsSubject = BehaviorSubject>.seeded([]); String? pushNotificationApp; diff --git a/packages/neon/lib/src/blocs/apps.dart b/packages/neon/lib/src/blocs/apps.dart index a8b9e1e5..55a8a50f 100644 --- a/packages/neon/lib/src/blocs/apps.dart +++ b/packages/neon/lib/src/blocs/apps.dart @@ -66,7 +66,7 @@ class AppsBloc extends $AppsBloc { setActiveApp(_accountsBloc.pushNotificationApp); _accountsBloc.pushNotificationApp = null; } else { - final options = _accountsBloc.getOptions(_account)!..updateApps(appImplementations); + final options = _accountsBloc.getOptions(_account); unawaited( options.initialApp.stream.first.then((var initialApp) { if (initialApp == null) { diff --git a/packages/neon/lib/src/models/account.dart b/packages/neon/lib/src/models/account.dart index 0dae71cf..09c9cdf0 100644 --- a/packages/neon/lib/src/models/account.dart +++ b/packages/neon/lib/src/models/account.dart @@ -1,14 +1,9 @@ -import 'dart:async'; import 'dart:convert'; import 'package:crypto/crypto.dart'; import 'package:json_annotation/json_annotation.dart'; -import 'package:neon/l10n/localizations.dart'; -import 'package:neon/src/neon.dart'; import 'package:nextcloud/nextcloud.dart'; import 'package:package_info_plus/package_info_plus.dart'; -import 'package:rxdart/rxdart.dart'; -import 'package:settings/settings.dart'; part 'account.g.dart'; @@ -86,47 +81,3 @@ extension NextcloudClientHelpers on NextcloudClient { return '${username!}@${uri.port != 443 ? '${uri.host}:${uri.port}' : uri.host}'; } } - -class AccountSpecificOptions { - AccountSpecificOptions(this._storage); - - final Storage _storage; - final _appIDsSubject = BehaviorSubject>(); - - late final List