mirror of
https://github.com/immich-app/immich.git
synced 2025-07-09 03:04:16 -04:00
refactor(mobile): asset stack provider (#16100)
* refactor(mobile): asset stack provider * remove file from ignore list
This commit is contained in:
parent
8ab87a8803
commit
47203d2760
@ -77,7 +77,7 @@ custom_lint:
|
|||||||
- test/**.dart
|
- test/**.dart
|
||||||
# refactor the remaining providers
|
# refactor the remaining providers
|
||||||
- lib/providers/{archive,asset,authentication,db,favorite,partner,trash,user}.provider.dart
|
- 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:
|
- import_rule_openapi:
|
||||||
message: openapi must only be used through ApiRepositories
|
message: openapi must only be used through ApiRepositories
|
||||||
|
@ -57,6 +57,8 @@ abstract interface class IAssetRepository implements IDatabaseRepository {
|
|||||||
Future<void> upsertDuplicatedAssets(Iterable<String> duplicatedAssets);
|
Future<void> upsertDuplicatedAssets(Iterable<String> duplicatedAssets);
|
||||||
|
|
||||||
Future<List<String>> getAllDuplicatedAssetIds();
|
Future<List<String>> getAllDuplicatedAssetIds();
|
||||||
|
|
||||||
|
Future<List<Asset>> getStackAssets(String stackId);
|
||||||
}
|
}
|
||||||
|
|
||||||
enum AssetSort { checksum, ownerIdChecksum }
|
enum AssetSort { checksum, ownerIdChecksum }
|
||||||
|
@ -1,16 +1,15 @@
|
|||||||
import 'package:hooks_riverpod/hooks_riverpod.dart';
|
import 'package:hooks_riverpod/hooks_riverpod.dart';
|
||||||
import 'package:immich_mobile/entities/asset.entity.dart';
|
import 'package:immich_mobile/entities/asset.entity.dart';
|
||||||
import 'package:immich_mobile/providers/db.provider.dart';
|
import 'package:immich_mobile/services/asset.service.dart';
|
||||||
import 'package:isar/isar.dart';
|
|
||||||
import 'package:riverpod_annotation/riverpod_annotation.dart';
|
import 'package:riverpod_annotation/riverpod_annotation.dart';
|
||||||
|
|
||||||
part 'asset_stack.provider.g.dart';
|
part 'asset_stack.provider.g.dart';
|
||||||
|
|
||||||
class AssetStackNotifier extends StateNotifier<List<Asset>> {
|
class AssetStackNotifier extends StateNotifier<List<Asset>> {
|
||||||
|
final AssetService assetService;
|
||||||
final String _stackId;
|
final String _stackId;
|
||||||
final Ref _ref;
|
|
||||||
|
|
||||||
AssetStackNotifier(this._stackId, this._ref) : super([]) {
|
AssetStackNotifier(this.assetService, this._stackId) : super([]) {
|
||||||
_fetchStack(_stackId);
|
_fetchStack(_stackId);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -19,7 +18,7 @@ class AssetStackNotifier extends StateNotifier<List<Asset>> {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
final stack = await _ref.read(assetStackProvider(stackId).future);
|
final stack = await assetService.getStackAssets(stackId);
|
||||||
if (stack.isNotEmpty) {
|
if (stack.isNotEmpty) {
|
||||||
state = stack;
|
state = stack;
|
||||||
}
|
}
|
||||||
@ -35,24 +34,10 @@ class AssetStackNotifier extends StateNotifier<List<Asset>> {
|
|||||||
|
|
||||||
final assetStackStateProvider = StateNotifierProvider.autoDispose
|
final assetStackStateProvider = StateNotifierProvider.autoDispose
|
||||||
.family<AssetStackNotifier, List<Asset>, String>(
|
.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
|
@riverpod
|
||||||
int assetStackIndex(AssetStackIndexRef ref, Asset asset) {
|
int assetStackIndex(AssetStackIndexRef ref, Asset asset) {
|
||||||
return -1;
|
return -1;
|
||||||
|
@ -197,6 +197,19 @@ class AssetRepository extends DatabaseRepository implements IAssetRepository {
|
|||||||
@override
|
@override
|
||||||
Future<void> deleteAllByRemoteId(List<String> ids, {AssetState? state}) =>
|
Future<void> deleteAllByRemoteId(List<String> ids, {AssetState? state}) =>
|
||||||
txn(() => _getAllByRemoteIdImpl(ids, state).deleteAll());
|
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(
|
Future<List<Asset>> _getMatchesImpl(
|
||||||
|
@ -1060,6 +1060,7 @@ class NativeVideoViewerRoute extends PageRouteInfo<NativeVideoViewerRouteArgs> {
|
|||||||
required Asset asset,
|
required Asset asset,
|
||||||
required Widget image,
|
required Widget image,
|
||||||
bool showControls = true,
|
bool showControls = true,
|
||||||
|
int playbackDelayFactor = 1,
|
||||||
List<PageRouteInfo>? children,
|
List<PageRouteInfo>? children,
|
||||||
}) : super(
|
}) : super(
|
||||||
NativeVideoViewerRoute.name,
|
NativeVideoViewerRoute.name,
|
||||||
@ -1068,6 +1069,7 @@ class NativeVideoViewerRoute extends PageRouteInfo<NativeVideoViewerRouteArgs> {
|
|||||||
asset: asset,
|
asset: asset,
|
||||||
image: image,
|
image: image,
|
||||||
showControls: showControls,
|
showControls: showControls,
|
||||||
|
playbackDelayFactor: playbackDelayFactor,
|
||||||
),
|
),
|
||||||
initialChildren: children,
|
initialChildren: children,
|
||||||
);
|
);
|
||||||
@ -1083,6 +1085,7 @@ class NativeVideoViewerRoute extends PageRouteInfo<NativeVideoViewerRouteArgs> {
|
|||||||
asset: args.asset,
|
asset: args.asset,
|
||||||
image: args.image,
|
image: args.image,
|
||||||
showControls: args.showControls,
|
showControls: args.showControls,
|
||||||
|
playbackDelayFactor: args.playbackDelayFactor,
|
||||||
);
|
);
|
||||||
},
|
},
|
||||||
);
|
);
|
||||||
@ -1094,6 +1097,7 @@ class NativeVideoViewerRouteArgs {
|
|||||||
required this.asset,
|
required this.asset,
|
||||||
required this.image,
|
required this.image,
|
||||||
this.showControls = true,
|
this.showControls = true,
|
||||||
|
this.playbackDelayFactor = 1,
|
||||||
});
|
});
|
||||||
|
|
||||||
final Key? key;
|
final Key? key;
|
||||||
@ -1104,9 +1108,11 @@ class NativeVideoViewerRouteArgs {
|
|||||||
|
|
||||||
final bool showControls;
|
final bool showControls;
|
||||||
|
|
||||||
|
final int playbackDelayFactor;
|
||||||
|
|
||||||
@override
|
@override
|
||||||
String toString() {
|
String toString() {
|
||||||
return 'NativeVideoViewerRouteArgs{key: $key, asset: $asset, image: $image, showControls: $showControls}';
|
return 'NativeVideoViewerRouteArgs{key: $key, asset: $asset, image: $image, showControls: $showControls, playbackDelayFactor: $playbackDelayFactor}';
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -428,4 +428,8 @@ class AssetService {
|
|||||||
|
|
||||||
return 1.0;
|
return 1.0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Future<List<Asset>> getStackAssets(String stackId) {
|
||||||
|
return _assetRepository.getStackAssets(stackId);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user