Browse Source

neon: Move account options

pull/67/head
jld3103 2 years ago
parent
commit
3e3c3256c6
No known key found for this signature in database
GPG Key ID: 9062417B9E8EB7B3
  1. 53
      packages/neon/lib/src/models/account.dart
  2. 1
      packages/neon/lib/src/neon.dart
  3. 48
      packages/neon/lib/src/utils/account_options.dart

53
packages/neon/lib/src/models/account.dart

@ -1,15 +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/blocs/apps.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';
@ -87,50 +81,3 @@ extension NextcloudClientHelpers on NextcloudClient {
return '${username!}@${uri.port != 443 ? '${uri.host}:${uri.port}' : uri.host}';
}
}
class AccountSpecificOptions {
AccountSpecificOptions(
this._storage,
this._appsBloc,
) {
_appsBloc.appImplementations.listen((final result) {
if (result.data != null) {
_appIDsSubject.add({
null: (final context) => AppLocalizations.of(context).accountOptionsAutomatic,
for (final app in result.data!) ...{
app.id: app.name,
},
});
}
});
}
final Storage _storage;
final AppsBloc _appsBloc;
final _appIDsSubject = BehaviorSubject<Map<String?, LabelBuilder>>();
late final List<Option> options = [
initialApp,
];
Future reset() async {
for (final option in options) {
await option.reset();
}
}
void dispose() {
unawaited(_appIDsSubject.close());
for (final option in options) {
option.dispose();
}
}
late final initialApp = SelectOption<String?>(
storage: _storage,
key: 'initial-app',
label: (final context) => AppLocalizations.of(context).accountOptionsInitialApp,
defaultValue: BehaviorSubject.seeded(null),
values: _appIDsSubject,
);
}

1
packages/neon/lib/src/neon.dart

@ -64,6 +64,7 @@ part 'platform/abstract.dart';
part 'platform/android.dart';
part 'platform/linux.dart';
part 'platform/platform.dart';
part 'utils/account_options.dart';
part 'utils/app_implementation.dart';
part 'utils/confirmation_dialog.dart';
part 'utils/custom_timeago.dart';

48
packages/neon/lib/src/utils/account_options.dart

@ -0,0 +1,48 @@
part of '../neon.dart';
class AccountSpecificOptions {
AccountSpecificOptions(
this._storage,
this._appsBloc,
) {
_appsBloc.appImplementations.listen((final result) {
if (result.data != null) {
_appIDsSubject.add({
null: (final context) => AppLocalizations.of(context).accountOptionsAutomatic,
for (final app in result.data!) ...{
app.id: app.name,
},
});
}
});
}
final Storage _storage;
final AppsBloc _appsBloc;
final _appIDsSubject = BehaviorSubject<Map<String?, LabelBuilder>>();
late final List<Option> options = [
initialApp,
];
Future reset() async {
for (final option in options) {
await option.reset();
}
}
void dispose() {
unawaited(_appIDsSubject.close());
for (final option in options) {
option.dispose();
}
}
late final initialApp = SelectOption<String?>(
storage: _storage,
key: 'initial-app',
label: (final context) => AppLocalizations.of(context).accountOptionsInitialApp,
defaultValue: BehaviorSubject.seeded(null),
values: _appIDsSubject,
);
}
Loading…
Cancel
Save