0
Fork 0
mirror of https://github.com/immich-app/immich.git synced 2025-04-01 02:51:27 -05:00

refactor(mobile): asset stack provider (#16100)

* refactor(mobile): asset stack provider

* remove file from ignore list
This commit is contained in:
Alex 2025-02-14 13:23:14 -06:00 committed by GitHub
parent 8ab87a8803
commit 47203d2760
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
6 changed files with 33 additions and 23 deletions

View file

@ -77,7 +77,7 @@ custom_lint:
- test/**.dart
# refactor the remaining providers
- lib/providers/{archive,asset,authentication,db,favorite,partner,trash,user}.provider.dart
- lib/providers/{album/album,album/shared_album,asset_viewer/asset_stack,asset_viewer/render_list,backup/backup,search/all_motion_photos,search/recently_added_asset}.provider.dart
- lib/providers/{album/album,album/shared_album,asset_viewer/render_list,backup/backup,search/all_motion_photos,search/recently_added_asset}.provider.dart
- import_rule_openapi:
message: openapi must only be used through ApiRepositories

View file

@ -57,6 +57,8 @@ abstract interface class IAssetRepository implements IDatabaseRepository {
Future<void> upsertDuplicatedAssets(Iterable<String> duplicatedAssets);
Future<List<String>> getAllDuplicatedAssetIds();
Future<List<Asset>> getStackAssets(String stackId);
}
enum AssetSort { checksum, ownerIdChecksum }

View file

@ -1,16 +1,15 @@
import 'package:hooks_riverpod/hooks_riverpod.dart';
import 'package:immich_mobile/entities/asset.entity.dart';
import 'package:immich_mobile/providers/db.provider.dart';
import 'package:isar/isar.dart';
import 'package:immich_mobile/services/asset.service.dart';
import 'package:riverpod_annotation/riverpod_annotation.dart';
part 'asset_stack.provider.g.dart';
class AssetStackNotifier extends StateNotifier<List<Asset>> {
final AssetService assetService;
final String _stackId;
final Ref _ref;
AssetStackNotifier(this._stackId, this._ref) : super([]) {
AssetStackNotifier(this.assetService, this._stackId) : super([]) {
_fetchStack(_stackId);
}
@ -19,7 +18,7 @@ class AssetStackNotifier extends StateNotifier<List<Asset>> {
return;
}
final stack = await _ref.read(assetStackProvider(stackId).future);
final stack = await assetService.getStackAssets(stackId);
if (stack.isNotEmpty) {
state = stack;
}
@ -35,24 +34,10 @@ class AssetStackNotifier extends StateNotifier<List<Asset>> {
final assetStackStateProvider = StateNotifierProvider.autoDispose
.family<AssetStackNotifier, List<Asset>, String>(
(ref, stackId) => AssetStackNotifier(stackId, ref),
(ref, stackId) =>
AssetStackNotifier(ref.watch(assetServiceProvider), stackId),
);
final assetStackProvider =
FutureProvider.autoDispose.family<List<Asset>, String>((ref, stackId) {
return ref
.watch(dbProvider)
.assets
.filter()
.isArchivedEqualTo(false)
.isTrashedEqualTo(false)
.stackIdEqualTo(stackId)
// orders primary asset first as its ID is null
.sortByStackPrimaryAssetId()
.thenByFileCreatedAtDesc()
.findAll();
});
@riverpod
int assetStackIndex(AssetStackIndexRef ref, Asset asset) {
return -1;

View file

@ -197,6 +197,19 @@ class AssetRepository extends DatabaseRepository implements IAssetRepository {
@override
Future<void> deleteAllByRemoteId(List<String> ids, {AssetState? state}) =>
txn(() => _getAllByRemoteIdImpl(ids, state).deleteAll());
@override
Future<List<Asset>> getStackAssets(String stackId) {
return db.assets
.filter()
.isArchivedEqualTo(false)
.isTrashedEqualTo(false)
.stackIdEqualTo(stackId)
// orders primary asset first as its ID is null
.sortByStackPrimaryAssetId()
.thenByFileCreatedAtDesc()
.findAll();
}
}
Future<List<Asset>> _getMatchesImpl(

View file

@ -1060,6 +1060,7 @@ class NativeVideoViewerRoute extends PageRouteInfo<NativeVideoViewerRouteArgs> {
required Asset asset,
required Widget image,
bool showControls = true,
int playbackDelayFactor = 1,
List<PageRouteInfo>? children,
}) : super(
NativeVideoViewerRoute.name,
@ -1068,6 +1069,7 @@ class NativeVideoViewerRoute extends PageRouteInfo<NativeVideoViewerRouteArgs> {
asset: asset,
image: image,
showControls: showControls,
playbackDelayFactor: playbackDelayFactor,
),
initialChildren: children,
);
@ -1083,6 +1085,7 @@ class NativeVideoViewerRoute extends PageRouteInfo<NativeVideoViewerRouteArgs> {
asset: args.asset,
image: args.image,
showControls: args.showControls,
playbackDelayFactor: args.playbackDelayFactor,
);
},
);
@ -1094,6 +1097,7 @@ class NativeVideoViewerRouteArgs {
required this.asset,
required this.image,
this.showControls = true,
this.playbackDelayFactor = 1,
});
final Key? key;
@ -1104,9 +1108,11 @@ class NativeVideoViewerRouteArgs {
final bool showControls;
final int playbackDelayFactor;
@override
String toString() {
return 'NativeVideoViewerRouteArgs{key: $key, asset: $asset, image: $image, showControls: $showControls}';
return 'NativeVideoViewerRouteArgs{key: $key, asset: $asset, image: $image, showControls: $showControls, playbackDelayFactor: $playbackDelayFactor}';
}
}

View file

@ -428,4 +428,8 @@ class AssetService {
return 1.0;
}
Future<List<Asset>> getStackAssets(String stackId) {
return _assetRepository.getStackAssets(stackId);
}
}