Browse Source

refactor(neon,neon_files): Adjust to generated specs

pull/465/head
jld3103 1 year ago
parent
commit
e222ac5593
No known key found for this signature in database
GPG Key ID: 9062417B9E8EB7B3
  1. 4
      packages/neon/neon/lib/src/app.dart
  2. 2
      packages/neon/neon/lib/src/blocs/accounts.dart
  3. 11
      packages/neon/neon/lib/src/blocs/apps.dart
  4. 13
      packages/neon/neon/lib/src/blocs/capabilities.dart
  5. 2
      packages/neon/neon/lib/src/blocs/login_check_account.dart
  6. 4
      packages/neon/neon/lib/src/blocs/login_check_server_status.dart
  7. 14
      packages/neon/neon/lib/src/blocs/login_flow.dart
  8. 5
      packages/neon/neon/lib/src/blocs/user_details.dart
  9. 23
      packages/neon/neon/lib/src/blocs/user_statuses.dart
  10. 1
      packages/neon/neon/lib/src/models/account.dart
  11. 2
      packages/neon/neon/lib/src/models/push_notification.dart
  12. 2
      packages/neon/neon/lib/src/models/push_notification.g.dart
  13. 8
      packages/neon/neon/lib/src/pages/account_settings.dart
  14. 4
      packages/neon/neon/lib/src/pages/login_check_server_status.dart
  15. 12
      packages/neon/neon/lib/src/theme/colors.dart
  16. 4
      packages/neon/neon/lib/src/theme/theme.dart
  17. 28
      packages/neon/neon/lib/src/widgets/drawer.dart
  18. 16
      packages/neon/neon/lib/src/widgets/user_avatar.dart
  19. 2
      packages/neon/neon_files/lib/widgets/file_preview.dart
  20. 4
      packages/neon/neon_news/lib/blocs/articles.dart

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

@ -8,7 +8,6 @@ import 'package:flutter_native_splash/flutter_native_splash.dart';
import 'package:neon/l10n/localizations.dart';
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';
@ -22,6 +21,7 @@ import 'package:neon/src/utils/global.dart';
import 'package:neon/src/utils/global_options.dart';
import 'package:neon/src/utils/localizations.dart';
import 'package:neon/src/utils/push_utils.dart';
import 'package:nextcloud/nextcloud.dart';
import 'package:provider/provider.dart';
import 'package:quick_actions/quick_actions.dart';
import 'package:tray_manager/tray_manager.dart' as tray;
@ -285,7 +285,7 @@ class _NeonAppState extends State<NeonApp> with WidgetsBindingObserver, tray.Tra
stream: _accountsBloc.activeAccount,
builder: (final context, final activeAccountSnapshot) {
FlutterNativeSplash.remove();
return ResultBuilder<Capabilities?>.behaviorSubject(
return ResultBuilder<CoreOcsGetCapabilitiesResponse200ApplicationJson_Ocs_Data?>.behaviorSubject(
stream: activeAccountSnapshot.hasData
? _accountsBloc.getCapabilitiesBlocFor(activeAccountSnapshot.data!).capabilities
: null,

2
packages/neon/neon/lib/src/blocs/accounts.dart

@ -157,7 +157,7 @@ class AccountsBloc extends Bloc implements AccountsBlocEvents, AccountsBlocState
unawaited(() async {
try {
await account.client.core.deleteAppPassword();
await account.client.core.appPassword.deleteAppPassword();
} catch (e, s) {
debugPrint(e.toString());
debugPrint(s.toString());

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

@ -16,8 +16,6 @@ import 'package:nextcloud/nextcloud.dart';
import 'package:provider/provider.dart';
import 'package:rxdart/rxdart.dart';
typedef NextcloudApp = CoreNavigationApps_Ocs_Data;
abstract class AppsBlocEvents {
/// Sets the active app using the [appID].
///
@ -27,7 +25,7 @@ abstract class AppsBlocEvents {
}
abstract class AppsBlocStates {
BehaviorSubject<Result<List<NextcloudApp>>> get apps;
BehaviorSubject<Result<List<CoreNavigationEntry>>> get apps;
BehaviorSubject<Result<Iterable<AppImplementation>>> get appImplementations;
@ -181,7 +179,7 @@ class AppsBloc extends InteractiveBloc implements AppsBlocEvents, AppsBlocStates
BehaviorSubject<Result<Iterable<AppImplementation>>>();
@override
BehaviorSubject<Result<List<NextcloudApp>>> apps = BehaviorSubject<Result<List<NextcloudApp>>>();
BehaviorSubject<Result<List<CoreNavigationEntry>>> apps = BehaviorSubject<Result<List<CoreNavigationEntry>>>();
@override
BehaviorSubject<Result<NotificationsAppInterface?>> notificationsAppImplementation =
@ -195,11 +193,12 @@ class AppsBloc extends InteractiveBloc implements AppsBlocEvents, AppsBlocStates
@override
Future refresh() async {
await _requestManager.wrapNextcloud<List<NextcloudApp>, CoreNavigationApps>(
await _requestManager
.wrapNextcloud<List<CoreNavigationEntry>, CoreNavigationGetAppsNavigationResponse200ApplicationJson>(
_account.id,
'apps-apps',
apps,
() async => _account.client.core.getNavigationApps(),
() async => _account.client.core.navigation.getAppsNavigation(),
(final response) => response.ocs.data.toList(),
);
}

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

@ -8,13 +8,10 @@ import 'package:neon/src/utils/request_manager.dart';
import 'package:nextcloud/nextcloud.dart';
import 'package:rxdart/rxdart.dart';
typedef Capabilities = CoreServerCapabilities_Ocs_Data;
typedef NextcloudTheme = CoreServerCapabilities_Ocs_Data_Capabilities_Theming;
abstract class CapabilitiesBlocEvents {}
abstract class CapabilitiesBlocStates {
BehaviorSubject<Result<Capabilities>> get capabilities;
BehaviorSubject<Result<CoreOcsGetCapabilitiesResponse200ApplicationJson_Ocs_Data>> get capabilities;
}
@internal
@ -36,15 +33,17 @@ class CapabilitiesBloc extends InteractiveBloc implements CapabilitiesBlocEvents
}
@override
BehaviorSubject<Result<Capabilities>> capabilities = BehaviorSubject<Result<Capabilities>>();
BehaviorSubject<Result<CoreOcsGetCapabilitiesResponse200ApplicationJson_Ocs_Data>> capabilities =
BehaviorSubject<Result<CoreOcsGetCapabilitiesResponse200ApplicationJson_Ocs_Data>>();
@override
Future refresh() async {
await _requestManager.wrapNextcloud<CoreServerCapabilities_Ocs_Data, CoreServerCapabilities>(
await _requestManager.wrapNextcloud<CoreOcsGetCapabilitiesResponse200ApplicationJson_Ocs_Data,
CoreOcsGetCapabilitiesResponse200ApplicationJson>(
_account.id,
'capabilities',
capabilities,
() async => _account.client.core.getCapabilities(),
() async => _account.client.core.ocs.getCapabilities(),
(final response) => response.ocs.data,
);
}

2
packages/neon/neon/lib/src/blocs/login_check_account.dart

@ -49,7 +49,7 @@ class LoginCheckAccountBloc extends InteractiveBloc
userAgentOverride: neonUserAgent,
);
final response = await client.provisioningApi.getCurrentUser();
final response = await client.provisioningApi.users.getCurrentUser();
final account = Account(
serverURL: serverURL,

4
packages/neon/neon/lib/src/blocs/login_check_server_status.dart

@ -11,7 +11,7 @@ abstract interface class LoginCheckServerStatusBlocEvents {}
abstract interface class LoginCheckServerStatusBlocStates {
/// Contains the current server connection state
BehaviorSubject<Result<CoreServerStatus>> get state;
BehaviorSubject<Result<CoreStatus>> get state;
}
class LoginCheckServerStatusBloc extends InteractiveBloc
@ -28,7 +28,7 @@ class LoginCheckServerStatusBloc extends InteractiveBloc
}
@override
BehaviorSubject<Result<CoreServerStatus>> state = BehaviorSubject();
BehaviorSubject<Result<CoreStatus>> state = BehaviorSubject();
@override
Future refresh() async {

14
packages/neon/neon/lib/src/blocs/login_flow.dart

@ -10,9 +10,9 @@ import 'package:rxdart/rxdart.dart';
abstract class LoginFlowBlocEvents {}
abstract class LoginFlowBlocStates {
BehaviorSubject<Result<CoreLoginFlowInit>> get init;
BehaviorSubject<Result<CoreLoginFlowV2>> get init;
Stream<CoreLoginFlowResult> get result;
Stream<CoreLoginFlowV2Credentials> get result;
}
class LoginFlowBloc extends InteractiveBloc implements LoginFlowBlocEvents, LoginFlowBlocStates {
@ -25,7 +25,7 @@ class LoginFlowBloc extends InteractiveBloc implements LoginFlowBlocEvents, Logi
serverURL,
userAgentOverride: neonUserAgent,
);
final _resultController = StreamController<CoreLoginFlowResult>();
final _resultController = StreamController<CoreLoginFlowV2Credentials>();
Timer? _pollTimer;
@ -37,23 +37,23 @@ class LoginFlowBloc extends InteractiveBloc implements LoginFlowBlocEvents, Logi
}
@override
BehaviorSubject<Result<CoreLoginFlowInit>> init = BehaviorSubject<Result<CoreLoginFlowInit>>();
BehaviorSubject<Result<CoreLoginFlowV2>> init = BehaviorSubject<Result<CoreLoginFlowV2>>();
@override
late Stream<CoreLoginFlowResult> result = _resultController.stream.asBroadcastStream();
late Stream<CoreLoginFlowV2Credentials> result = _resultController.stream.asBroadcastStream();
@override
Future refresh() async {
try {
init.add(Result.loading());
final initResponse = await _client.core.initLoginFlow();
final initResponse = await _client.core.clientFlowLoginV2.init();
init.add(Result.success(initResponse));
_cancelPollTimer();
_pollTimer = Timer.periodic(const Duration(seconds: 1), (final _) async {
try {
final resultResponse = await _client.core.getLoginFlowResult(token: initResponse.poll.token);
final resultResponse = await _client.core.clientFlowLoginV2.poll(token: initResponse.poll.token);
_cancelPollTimer();
_resultController.add(resultResponse);
} catch (e, s) {

5
packages/neon/neon/lib/src/blocs/user_details.dart

@ -38,11 +38,12 @@ class UserDetailsBloc extends InteractiveBloc implements UserDetailsBlocEvents,
@override
Future refresh() async {
await _requestManager.wrapNextcloud<ProvisioningApiUserDetails, ProvisioningApiUser>(
await _requestManager
.wrapNextcloud<ProvisioningApiUserDetails, ProvisioningApiUsersGetCurrentUserResponse200ApplicationJson>(
_account.id,
'user-details',
userDetails,
() async => _account.client.provisioningApi.getCurrentUser(),
() async => _account.client.provisioningApi.users.getCurrentUser(),
(final response) => response.ocs.data,
);
}

23
packages/neon/neon/lib/src/blocs/user_statuses.dart

@ -16,7 +16,7 @@ abstract class UserStatusesBlocEvents {
}
abstract class UserStatusesBlocStates {
BehaviorSubject<Map<String, Result<UserStatusPublicStatus?>>> get statuses;
BehaviorSubject<Map<String, Result<UserStatusPublic?>>> get statuses;
}
@internal
@ -41,8 +41,8 @@ class UserStatusesBloc extends InteractiveBloc implements UserStatusesBlocEvents
}
@override
BehaviorSubject<Map<String, Result<UserStatusPublicStatus?>>> statuses =
BehaviorSubject<Map<String, Result<UserStatusPublicStatus?>>>();
BehaviorSubject<Map<String, Result<UserStatusPublic?>>> statuses =
BehaviorSubject<Map<String, Result<UserStatusPublic?>>>();
@override
Future refresh() async {
@ -60,17 +60,17 @@ class UserStatusesBloc extends InteractiveBloc implements UserStatusesBlocEvents
try {
_updateStatus(username, Result.loading());
UserStatusPublicStatus? data;
UserStatusPublic? data;
if (_account.username == username) {
final isAway =
_platform.canUseWindowManager && (!(await windowManager.isFocused()) || !(await windowManager.isVisible()));
final response = await _account.client.userStatus.heartbeat(
status: isAway ? UserStatusType.away : UserStatusType.online,
final response = await _account.client.userStatus.heartbeat.heartbeat(
status: isAway ? 'away' : 'online',
);
data = response.ocs.data.status?.publicStatus;
data = response.ocs.data.public;
} else {
final response = await _account.client.userStatus.getPublicStatus(userId: username);
data = response.ocs.data.publicStatus;
final response = await _account.client.userStatus.statuses.find(userId: username);
data = response.ocs.data;
}
_updateStatus(username, Result.success(data));
@ -85,10 +85,9 @@ class UserStatusesBloc extends InteractiveBloc implements UserStatusesBlocEvents
}
}
Map<String, Result<UserStatusPublicStatus?>> get _statuses =>
statuses.valueOrNull ?? <String, Result<UserStatusPublicStatus?>>{};
Map<String, Result<UserStatusPublic?>> get _statuses => statuses.valueOrNull ?? <String, Result<UserStatusPublic?>>{};
void _updateStatus(final String username, final Result<UserStatusPublicStatus?> result) {
void _updateStatus(final String username, final Result<UserStatusPublic?> result) {
statuses.add({
..._statuses,
username: result,

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

@ -39,6 +39,7 @@ class Account implements Credentials {
);
factory Account.fromJson(final Map<String, dynamic> json) => _$AccountFromJson(json);
Map<String, dynamic> toJson() => _$AccountToJson(this);
@override

2
packages/neon/neon/lib/src/models/push_notification.dart

@ -24,5 +24,5 @@ class PushNotification {
final String type;
final NotificationsNotificationDecryptedSubject subject;
final NotificationsDecryptedSubject subject;
}

2
packages/neon/neon/lib/src/models/push_notification.g.dart

@ -10,7 +10,7 @@ PushNotification _$PushNotificationFromJson(Map<String, dynamic> json) => PushNo
accountID: json['accountID'] as String,
priority: json['priority'] as String,
type: json['type'] as String,
subject: NotificationsNotificationDecryptedSubject.fromJson(json['subject'] as Map<String, dynamic>),
subject: NotificationsDecryptedSubject.fromJson(json['subject'] as Map<String, dynamic>),
);
Map<String, dynamic> _$PushNotificationToJson(PushNotification instance) => <String, dynamic>{

8
packages/neon/neon/lib/src/pages/account_settings.dart

@ -88,7 +88,7 @@ class AccountSettingsPage extends StatelessWidget {
children: [
if (userDetails.hasData) ...[
LinearProgressIndicator(
value: userDetails.requireData.quota.relative / 100,
value: (userDetails.requireData.quota.relative ?? 0) / 100,
backgroundColor: Theme.of(context).colorScheme.primary.withOpacity(0.3),
),
const SizedBox(
@ -96,9 +96,9 @@ class AccountSettingsPage extends StatelessWidget {
),
Text(
AppLocalizations.of(context).accountOptionsQuotaUsedOf(
filesize(userDetails.requireData.quota.used, 1),
filesize(userDetails.requireData.quota.total, 1),
userDetails.requireData.quota.relative.toString(),
filesize(userDetails.requireData.quota.used ?? 0, 1),
filesize(userDetails.requireData.quota.total ?? 0, 1),
(userDetails.requireData.quota.relative ?? 0).toString(),
),
),
],

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

@ -103,7 +103,7 @@ class _LoginCheckServerStatusPageState extends State<LoginCheckServerStatusPage>
}
}
Widget _buildServerVersionTile(final Result<CoreServerStatus> result) {
Widget _buildServerVersionTile(final Result<CoreStatus> result) {
if (result.hasError) {
return NeonValidationTile(
title: AppLocalizations.of(context).loginCheckingServerVersion,
@ -131,7 +131,7 @@ class _LoginCheckServerStatusPageState extends State<LoginCheckServerStatusPage>
);
}
Widget _buildMaintenanceModeTile(final Result<CoreServerStatus> result) {
Widget _buildMaintenanceModeTile(final Result<CoreStatus> result) {
if (result.hasError) {
return NeonValidationTile(
title: AppLocalizations.of(context).loginCheckingMaintenanceMode,

12
packages/neon/neon/lib/src/theme/colors.dart

@ -29,13 +29,13 @@ abstract final class NcColors {
static const Color accept = Colors.green;
}
/// [UserStatusType] color mapping.
extension UserStatusTypeColors on UserStatusType {
/// [UserStatusPublic] status color mapping.
extension UserStatusTypeColors on UserStatusPublic {
/// The color for the user status.
Color? get color => switch (this) {
UserStatusType.online => const Color(0xFF49B382),
UserStatusType.away => const Color(0xFFF4A331),
UserStatusType.dnd => const Color(0xFFED484C),
Color? get color => switch (status) {
'online' => const Color(0xFF49B382),
'away' => const Color(0xFFF4A331),
'dnd' => const Color(0xFFED484C),
_ => null,
};
}

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

@ -16,14 +16,14 @@ class AppTheme {
this.appThemes,
}) : keepOriginalAccentColor = nextcloudTheme == null || keepOriginalAccentColor;
final CoreServerCapabilities_Ocs_Data_Capabilities_Theming? nextcloudTheme;
final CoreOcsGetCapabilitiesResponse200ApplicationJson_Ocs_Data_Capabilities_Theming? nextcloudTheme;
final bool keepOriginalAccentColor;
final bool oledAsDark;
final Iterable<ThemeExtension>? appThemes;
final NeonTheme neonTheme;
ColorScheme _buildColorScheme(final Brightness brightness) {
final primary = nextcloudTheme?.color != null ? HexColor(nextcloudTheme!.color!) : neonTheme.colorScheme.primary;
final primary = nextcloudTheme?.color != null ? HexColor(nextcloudTheme!.color) : neonTheme.colorScheme.primary;
final keepOriginalAccentColorOverride = keepOriginalAccentColor ? primary : null;
final oledBackgroundOverride = oledAsDark && brightness == Brightness.dark ? NcColors.oledBackground : null;

28
packages/neon/neon/lib/src/widgets/drawer.dart

@ -6,13 +6,13 @@ import 'package:neon/l10n/localizations.dart';
import 'package:neon/src/bloc/result_builder.dart';
import 'package:neon/src/blocs/accounts.dart';
import 'package:neon/src/blocs/apps.dart';
import 'package:neon/src/blocs/capabilities.dart';
import 'package:neon/src/models/app_implementation.dart';
import 'package:neon/src/router.dart';
import 'package:neon/src/widgets/cached_image.dart';
import 'package:neon/src/widgets/drawer_destination.dart';
import 'package:neon/src/widgets/exception.dart';
import 'package:neon/src/widgets/linear_progress_indicator.dart';
import 'package:nextcloud/nextcloud.dart';
import 'package:provider/provider.dart';
@internal
@ -121,7 +121,7 @@ class NeonDrawerHeader extends StatelessWidget {
final accountsBloc = Provider.of<AccountsBloc>(context, listen: false);
final capabilitiesBloc = accountsBloc.activeCapabilitiesBloc;
final branding = ResultBuilder<Capabilities>.behaviorSubject(
final branding = ResultBuilder<CoreOcsGetCapabilitiesResponse200ApplicationJson_Ocs_Data>.behaviorSubject(
stream: capabilitiesBloc.capabilities,
builder: (final context, final capabilities) {
if (!capabilities.hasData) {
@ -147,21 +147,17 @@ class NeonDrawerHeader extends StatelessWidget {
crossAxisAlignment: CrossAxisAlignment.start,
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
if (theme.name != null) ...[
Text(
theme.name!,
style: DefaultTextStyle.of(context).style.copyWith(
color: Theme.of(context).appBarTheme.foregroundColor,
),
Text(
theme.name,
style: DefaultTextStyle.of(context).style.copyWith(
color: Theme.of(context).appBarTheme.foregroundColor,
),
),
Flexible(
child: NeonCachedImage.url(
url: theme.logo,
),
],
if (theme.logo != null) ...[
Flexible(
child: NeonCachedImage.url(
url: theme.logo!,
),
),
],
),
],
);
},

16
packages/neon/neon/lib/src/widgets/user_avatar.dart

@ -68,22 +68,24 @@ class _UserAvatarState extends State<NeonUserAvatar> {
cacheKey: '${widget.account.id}-avatar-${widget.username}-$brightness$pixelSize',
getImage: () async {
if (brightness == Brightness.dark) {
return widget.account.client.core.getDarkAvatar(
return (await widget.account.client.core.avatar.getAvatarDark(
userId: widget.username,
size: pixelSize,
);
))
.data;
} else {
return widget.account.client.core.getAvatar(
return (await widget.account.client.core.avatar.getAvatar(
userId: widget.username,
size: pixelSize,
);
))
.data;
}
},
),
),
),
if (widget.showStatus) ...[
ResultBuilder<UserStatusPublicStatus?>(
ResultBuilder<UserStatusPublic?>(
stream: _userStatusBloc.statuses.mapNotNull((final statuses) => statuses[widget.username]),
builder: _userStatusIconBuilder,
),
@ -93,7 +95,7 @@ class _UserAvatarState extends State<NeonUserAvatar> {
},
);
Widget _userStatusIconBuilder(final BuildContext context, final Result<UserStatusPublicStatus?> result) {
Widget _userStatusIconBuilder(final BuildContext context, final Result<UserStatusPublic?> result) {
final hasEmoji = result.data?.icon != null;
final scaledSize = size / (hasEmoji ? 2 : 3);
@ -120,7 +122,7 @@ class _UserAvatarState extends State<NeonUserAvatar> {
} else if (result.hasData) {
decoration = BoxDecoration(
shape: BoxShape.circle,
color: result.data!.status.color,
color: result.data!.color,
);
}

2
packages/neon/neon_files/lib/widgets/file_preview.dart

@ -103,7 +103,7 @@ class FilePreviewImage extends NeonCachedImage {
required final int width,
required final int height,
}) : super.custom(
getImage: () async => account.client.core.getPreview(
getImage: () async => account.client.core.preview.getPreview(
file: path,
x: width,
y: height,

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

@ -127,10 +127,10 @@ class NewsArticlesBloc extends InteractiveBloc implements NewsArticlesBlocEvents
await requestManager.wrapNextcloud<List<NewsArticle>, NewsListArticles>(
account.id,
'news-articles-${type.code}-$id-$getRead',
'news-articles-${type.index}-$id-$getRead',
articles,
() async => account.client.news.listArticles(
type: type.code,
type: type.index,
id: id ?? 0,
getRead: getRead ?? true ? 1 : 0,
),

Loading…
Cancel
Save