2025-07-05 00:38:06 +05:30
|
|
|
import 'dart:async';
|
|
|
|
|
2025-07-02 23:54:37 +05:30
|
|
|
import 'package:hooks_riverpod/hooks_riverpod.dart';
|
|
|
|
import 'package:immich_mobile/domain/models/asset/base_asset.model.dart';
|
|
|
|
import 'package:immich_mobile/providers/infrastructure/asset.provider.dart';
|
|
|
|
|
|
|
|
final currentAssetNotifier =
|
2025-07-05 00:38:06 +05:30
|
|
|
AutoDisposeNotifierProvider<CurrentAssetNotifier, BaseAsset?>(
|
2025-07-04 21:00:34 +05:30
|
|
|
CurrentAssetNotifier.new,
|
|
|
|
);
|
|
|
|
|
2025-07-05 00:38:06 +05:30
|
|
|
class CurrentAssetNotifier extends AutoDisposeNotifier<BaseAsset?> {
|
2025-07-04 21:00:34 +05:30
|
|
|
KeepAliveLink? _keepAliveLink;
|
2025-07-05 00:38:06 +05:30
|
|
|
StreamSubscription<BaseAsset?>? _assetSubscription;
|
2025-07-02 23:54:37 +05:30
|
|
|
|
|
|
|
@override
|
2025-07-05 00:38:06 +05:30
|
|
|
BaseAsset? build() => null;
|
2025-07-02 23:54:37 +05:30
|
|
|
|
|
|
|
void setAsset(BaseAsset asset) {
|
2025-07-04 21:00:34 +05:30
|
|
|
_keepAliveLink?.close();
|
2025-07-05 00:38:06 +05:30
|
|
|
_assetSubscription?.cancel();
|
2025-07-02 23:54:37 +05:30
|
|
|
state = asset;
|
2025-07-05 00:38:06 +05:30
|
|
|
_assetSubscription = ref
|
|
|
|
.watch(assetServiceProvider)
|
|
|
|
.watchAsset(asset)
|
|
|
|
.listen((updatedAsset) {
|
|
|
|
if (updatedAsset != null) {
|
|
|
|
state = updatedAsset;
|
|
|
|
}
|
|
|
|
});
|
2025-07-04 21:00:34 +05:30
|
|
|
_keepAliveLink = ref.keepAlive();
|
|
|
|
}
|
|
|
|
|
|
|
|
void dispose() {
|
|
|
|
_keepAliveLink?.close();
|
2025-07-05 00:38:06 +05:30
|
|
|
_assetSubscription?.cancel();
|
2025-07-02 23:54:37 +05:30
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2025-07-04 21:00:34 +05:30
|
|
|
final currentAssetExifProvider = FutureProvider.autoDispose(
|
2025-07-02 23:54:37 +05:30
|
|
|
(ref) {
|
|
|
|
final currentAsset = ref.watch(currentAssetNotifier);
|
2025-07-05 00:38:06 +05:30
|
|
|
if (currentAsset == null) {
|
|
|
|
return null;
|
|
|
|
}
|
2025-07-02 23:54:37 +05:30
|
|
|
return ref.watch(assetServiceProvider).getExif(currentAsset);
|
|
|
|
},
|
|
|
|
);
|