1
0
Fork 0
mirror of https://github.com/immich-app/immich.git synced 2025-01-06 03:46:47 +01:00

fix(mobile): asset state change not updated in gallery app bar (#4441)

This commit is contained in:
shenlong 2023-10-12 02:10:59 +00:00 committed by GitHub
parent 18fcca2884
commit 5dacea6f74
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 14 additions and 10 deletions

View file

@ -2,6 +2,7 @@ import 'package:auto_route/auto_route.dart';
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
import 'package:hooks_riverpod/hooks_riverpod.dart'; import 'package:hooks_riverpod/hooks_riverpod.dart';
import 'package:immich_mobile/shared/models/asset.dart'; import 'package:immich_mobile/shared/models/asset.dart';
import 'package:immich_mobile/shared/providers/asset.provider.dart';
class TopControlAppBar extends HookConsumerWidget { class TopControlAppBar extends HookConsumerWidget {
const TopControlAppBar({ const TopControlAppBar({
@ -14,7 +15,6 @@ class TopControlAppBar extends HookConsumerWidget {
required this.isPlayingMotionVideo, required this.isPlayingMotionVideo,
required this.onFavorite, required this.onFavorite,
required this.onUploadPressed, required this.onUploadPressed,
required this.isFavorite,
}) : super(key: key); }) : super(key: key);
final Asset asset; final Asset asset;
@ -23,19 +23,19 @@ class TopControlAppBar extends HookConsumerWidget {
final VoidCallback? onDownloadPressed; final VoidCallback? onDownloadPressed;
final VoidCallback onToggleMotionVideo; final VoidCallback onToggleMotionVideo;
final VoidCallback onAddToAlbumPressed; final VoidCallback onAddToAlbumPressed;
final VoidCallback? onFavorite; final Function(Asset) onFavorite;
final bool isPlayingMotionVideo; final bool isPlayingMotionVideo;
final bool isFavorite;
@override @override
Widget build(BuildContext context, WidgetRef ref) { Widget build(BuildContext context, WidgetRef ref) {
const double iconSize = 22.0; const double iconSize = 22.0;
final a = ref.watch(assetWatcher(asset)).value ?? asset;
Widget buildFavoriteButton() { Widget buildFavoriteButton(a) {
return IconButton( return IconButton(
onPressed: onFavorite, onPressed: () => onFavorite(a),
icon: Icon( icon: Icon(
isFavorite ? Icons.favorite : Icons.favorite_border, a.isFavorite ? Icons.favorite : Icons.favorite_border,
color: Colors.grey[200], color: Colors.grey[200],
), ),
); );
@ -123,7 +123,7 @@ class TopControlAppBar extends HookConsumerWidget {
size: iconSize, size: iconSize,
), ),
actions: [ actions: [
if (asset.isRemote) buildFavoriteButton(), if (asset.isRemote) buildFavoriteButton(a),
if (asset.livePhotoVideoId != null) buildLivePhotoButton(), if (asset.livePhotoVideoId != null) buildLivePhotoButton(),
if (asset.isLocal && !asset.isRemote) buildUploadButton(), if (asset.isLocal && !asset.isRemote) buildUploadButton(),
if (asset.isRemote && !asset.isLocal) buildDownloadButton(), if (asset.isRemote && !asset.isLocal) buildDownloadButton(),

View file

@ -297,10 +297,8 @@ class GalleryViewerPage extends HookConsumerWidget {
child: TopControlAppBar( child: TopControlAppBar(
isPlayingMotionVideo: isPlayingMotionVideo.value, isPlayingMotionVideo: isPlayingMotionVideo.value,
asset: asset(), asset: asset(),
isFavorite: asset().isFavorite,
onMoreInfoPressed: showInfo, onMoreInfoPressed: showInfo,
onFavorite: onFavorite: toggleFavorite,
asset().isRemote ? () => toggleFavorite(asset()) : null,
onUploadPressed: onUploadPressed:
asset().isLocal ? () => handleUpload(asset()) : null, asset().isLocal ? () => handleUpload(asset()) : null,
onDownloadPressed: asset().isLocal onDownloadPressed: asset().isLocal

View file

@ -200,6 +200,12 @@ final assetDetailProvider =
} }
}); });
final assetWatcher =
StreamProvider.autoDispose.family<Asset?, Asset>((ref, asset) {
final db = ref.watch(dbProvider);
return db.assets.watchObject(asset.id, fireImmediately: true);
});
final assetsProvider = final assetsProvider =
StreamProvider.family<RenderList, int?>((ref, userId) async* { StreamProvider.family<RenderList, int?>((ref, userId) async* {
if (userId == null) return; if (userId == null) return;