add to legacy control bottom bar

This commit is contained in:
timonrieger
2026-01-25 23:47:07 +01:00
parent 8ab396dcc6
commit 9d68e12a08
2 changed files with 48 additions and 0 deletions

View File

@@ -33,6 +33,7 @@ class ControlBottomAppBar extends HookConsumerWidget {
final void Function([bool force])? onDelete;
final void Function([bool force])? onDeleteServer;
final void Function(bool onlyBackedUp)? onDeleteLocal;
final void Function()? onSetAlbumCover;
final Function(Album album) onAddToAlbum;
final void Function() onCreateNewAlbum;
final void Function() onUpload;
@@ -57,6 +58,7 @@ class ControlBottomAppBar extends HookConsumerWidget {
this.onDelete,
this.onDeleteServer,
this.onDeleteLocal,
this.onSetAlbumCover,
required this.onAddToAlbum,
required this.onCreateNewAlbum,
required this.onUpload,
@@ -267,6 +269,15 @@ class ControlBottomAppBar extends HookConsumerWidget {
onPressed: enabled ? onRemoveFromAlbum : null,
),
),
if (onSetAlbumCover != null)
ConstrainedBox(
constraints: const BoxConstraints(maxWidth: 90),
child: ControlBoxButton(
iconData: Icons.image_outlined,
label: 'set_as_album_cover'.tr(),
onPressed: enabled ? onSetAlbumCover : null,
),
),
if (selectionAssetState.hasLocal)
ControlBoxButton(
iconData: Icons.backup_outlined,

View File

@@ -17,11 +17,13 @@ import 'package:immich_mobile/providers/album/album.provider.dart';
import 'package:immich_mobile/providers/asset.provider.dart';
import 'package:immich_mobile/providers/asset_viewer/download.provider.dart';
import 'package:immich_mobile/providers/backup/manual_upload.provider.dart';
import 'package:immich_mobile/providers/infrastructure/current_album.provider.dart';
import 'package:immich_mobile/providers/multiselect.provider.dart';
import 'package:immich_mobile/providers/routes.provider.dart';
import 'package:immich_mobile/providers/user.provider.dart';
import 'package:immich_mobile/routing/router.dart';
import 'package:immich_mobile/services/album.service.dart';
import 'package:immich_mobile/services/action.service.dart';
import 'package:immich_mobile/services/stack.service.dart';
import 'package:immich_mobile/utils/immich_loading_overlay.dart';
import 'package:immich_mobile/utils/selection_handlers.dart';
@@ -77,6 +79,7 @@ class MultiselectGrid extends HookConsumerWidget {
final selection = useState(<Asset>{});
final currentUser = ref.watch(currentUserProvider);
final currentAlbum = ref.watch(currentRemoteAlbumProvider);
final processing = useProcessingOverlay();
useEffect(() {
@@ -400,6 +403,37 @@ class MultiselectGrid extends HookConsumerWidget {
}
};
Future<bool> setAsAlbumCover() async {
final album = currentAlbum;
if (album == null) {
return false;
}
if (currentUser?.id != album.ownerId) {
return false;
}
if (selection.value.length != 1) {
return false;
}
final asset = selection.value.first;
final assetId = asset.remoteId;
if (assetId == null) {
ImmichToast.show(context: context, msg: 'errors.unable_to_update_album_cover'.tr(), toastType: ToastType.error);
return false;
}
try {
await ref.read(actionServiceProvider).setAlbumCover(album.id, assetId);
ImmichToast.show(context: context, msg: 'album_cover_updated'.tr(), toastType: ToastType.success);
return true;
} catch (_) {
ImmichToast.show(context: context, msg: 'errors.unable_to_update_album_cover'.tr(), toastType: ToastType.error);
return false;
}
}
return SafeArea(
top: true,
bottom: false,
@@ -447,6 +481,9 @@ class MultiselectGrid extends HookConsumerWidget {
unfavorite: unfavorite,
unarchive: unarchive,
onToggleLocked: onToggleLockedVisibility,
onSetAlbumCover: (currentAlbum != null && currentUser?.id == currentAlbum.ownerId)
? wrapLongRunningFun(setAsAlbumCover)
: null,
onRemoveFromAlbum: onRemoveFromAlbum != null
? wrapLongRunningFun(() => onRemoveFromAlbum!(selection.value))
: null,