diff --git a/packages/neon/neon/lib/blocs.dart b/packages/neon/neon/lib/blocs.dart index bc6f4cb2..c7c95a68 100644 --- a/packages/neon/neon/lib/blocs.dart +++ b/packages/neon/neon/lib/blocs.dart @@ -1,5 +1,6 @@ export 'package:neon/src/bloc/bloc.dart'; export 'package:neon/src/bloc/result.dart'; export 'package:neon/src/bloc/result_builder.dart'; -export 'package:neon/src/blocs/accounts.dart'; // TODO: Remove access to the AccountsBloc. Apps should not need to access this +// TODO: Remove access to the AccountsBloc. Apps should not need to access this +export 'package:neon/src/blocs/accounts.dart' show AccountsBloc; export 'package:neon/src/blocs/timer.dart' hide TimerBlocEvents, TimerBlocStates; diff --git a/packages/neon/neon/lib/src/blocs/accounts.dart b/packages/neon/neon/lib/src/blocs/accounts.dart index 2bbf0331..c4ca84a8 100644 --- a/packages/neon/neon/lib/src/blocs/accounts.dart +++ b/packages/neon/neon/lib/src/blocs/accounts.dart @@ -2,6 +2,7 @@ import 'dart:async'; import 'dart:convert'; import 'package:flutter/foundation.dart'; +import 'package:meta/meta.dart'; import 'package:neon/src/bloc/bloc.dart'; import 'package:neon/src/blocs/apps.dart'; import 'package:neon/src/blocs/capabilities.dart'; @@ -17,6 +18,7 @@ import 'package:rxdart/rxdart.dart'; const _keyAccounts = 'accounts'; +@internal abstract interface class AccountsBlocEvents { /// Logs in the given [account]. /// @@ -40,6 +42,7 @@ abstract interface class AccountsBlocEvents { void setActiveAccount(final Account account); } +@internal abstract interface class AccountsBlocStates { /// All registered accounts. /// diff --git a/packages/neon/neon/lib/src/widgets/cached_image.dart b/packages/neon/neon/lib/src/widgets/cached_image.dart index 68842406..61240bf0 100644 --- a/packages/neon/neon/lib/src/widgets/cached_image.dart +++ b/packages/neon/neon/lib/src/widgets/cached_image.dart @@ -5,15 +5,20 @@ import 'dart:typed_data'; import 'package:flutter/material.dart'; import 'package:flutter_cache_manager/flutter_cache_manager.dart'; import 'package:flutter_svg/flutter_svg.dart'; +import 'package:neon/nextcloud.dart'; +import 'package:neon/src/blocs/accounts.dart'; import 'package:neon/src/models/account.dart'; import 'package:neon/src/widgets/exception.dart'; import 'package:neon/src/widgets/linear_progress_indicator.dart'; +import 'package:provider/provider.dart'; typedef CacheReviver = FutureOr Function(CacheManager cacheManager); typedef ImageDownloader = FutureOr Function(); typedef CacheWriter = Future Function(CacheManager cacheManager, Uint8List image); typedef ErrorWidgetBuilder = Widget? Function(BuildContext, dynamic); +typedef ApiImageDownloader = FutureOr Function(NextcloudClient client); + class NeonCachedImage extends StatefulWidget { const NeonCachedImage({ required this.image, @@ -186,3 +191,40 @@ class _NeonCachedImageState extends State { iconSize: widget.size?.shortestSide, ); } + +class NeonApiImage extends StatelessWidget { + const NeonApiImage({ + required this.getImage, + required this.cacheKey, + this.reviver, + this.writeCache, + this.isSvgHint = false, + this.size, + this.fit, + this.svgColor, + this.iconColor, + this.errorBuilder, + super.key, + }); + + final ApiImageDownloader getImage; + final String cacheKey; + final CacheReviver? reviver; + final CacheWriter? writeCache; + final bool isSvgHint; + final Size? size; + final BoxFit? fit; + final Color? svgColor; + final Color? iconColor; + final ErrorWidgetBuilder? errorBuilder; + + @override + Widget build(final BuildContext context) { + final account = Provider.of(context, listen: false).activeAccount.value!; + + return NeonCachedImage.custom( + getImage: () async => getImage(account.client), + cacheKey: '${account.id}-$cacheKey', + ); + } +} diff --git a/packages/neon/neon/test/settings_export_test.dart b/packages/neon/neon/test/settings_export_test.dart index 3eedb039..6540b559 100644 --- a/packages/neon/neon/test/settings_export_test.dart +++ b/packages/neon/neon/test/settings_export_test.dart @@ -4,7 +4,7 @@ import 'dart:convert'; import 'dart:typed_data'; import 'package:mocktail/mocktail.dart'; -import 'package:neon/blocs.dart'; +import 'package:neon/src/blocs/accounts.dart'; import 'package:neon/src/models/account.dart'; import 'package:neon/src/models/app_implementation.dart'; import 'package:neon/src/settings/models/exportable.dart'; diff --git a/packages/neon/neon_files/lib/widgets/file_preview.dart b/packages/neon/neon_files/lib/widgets/file_preview.dart index f1cebde2..5a76d077 100644 --- a/packages/neon/neon_files/lib/widgets/file_preview.dart +++ b/packages/neon/neon_files/lib/widgets/file_preview.dart @@ -41,9 +41,7 @@ class FilePreview extends StatelessWidget { valueListenable: bloc.options.showPreviewsOption, builder: (final context, final showPreviews, final child) { if (showPreviews && (details.hasPreview ?? false)) { - final account = Provider.of(context, listen: false).activeAccount.value!; final preview = FilePreviewImage( - account: account, file: details, size: size, ); @@ -72,19 +70,17 @@ class FilePreview extends StatelessWidget { } } -class FilePreviewImage extends NeonCachedImage { +class FilePreviewImage extends NeonApiImage { factory FilePreviewImage({ - required final Account account, required final FileDetails file, required final Size size, }) { final width = size.width.toInt(); final height = size.height.toInt(); final path = file.path.join('/'); - final cacheKey = '${account.id}-preview-$path-$width-$height'; + final cacheKey = 'preview-$path-$width-$height'; return FilePreviewImage._( - account: account, file: file, size: size, cacheKey: cacheKey, @@ -95,15 +91,14 @@ class FilePreviewImage extends NeonCachedImage { } FilePreviewImage._({ - required final Account account, required final FileDetails file, required Size super.size, required super.cacheKey, required final String path, required final int width, required final int height, - }) : super.custom( - getImage: () async => account.client.core.preview.getPreview( + }) : super( + getImage: (final client) async => client.core.preview.getPreview( file: path, x: width, y: height, diff --git a/packages/neon/neon_notifications/lib/pages/main.dart b/packages/neon/neon_notifications/lib/pages/main.dart index 39cdd284..6b2e9d37 100644 --- a/packages/neon/neon_notifications/lib/pages/main.dart +++ b/packages/neon/neon_notifications/lib/pages/main.dart @@ -89,6 +89,7 @@ class _NotificationsMainPageState extends State { return; } if (app != null) { + // TODO: use go_router once implemented final accountsBloc = Provider.of(context, listen: false); await accountsBloc.activeAppsBloc.setActiveApp(app.id); } else {