mirror of
https://github.com/immich-app/immich.git
synced 2024-11-24 08:52:28 +02:00
feat(mobile): remove asset from album in gallery view (#11184)
Co-authored-by: Alex <alex.tran1502@gmail.com>
This commit is contained in:
parent
a469fe44a1
commit
745b16e4b4
@ -420,7 +420,7 @@ class GalleryViewerPage extends HookConsumerWidget {
|
||||
showStack: showStack,
|
||||
stackIndex: stackIndex.value,
|
||||
asset: asset,
|
||||
assetIndex: currentIndex.value,
|
||||
assetIndex: currentIndex,
|
||||
showVideoPlayerControls: !asset.isImage && !isMotionPhoto,
|
||||
),
|
||||
],
|
||||
|
@ -247,7 +247,7 @@ class ControlBottomAppBar extends HookConsumerWidget {
|
||||
ConstrainedBox(
|
||||
constraints: const BoxConstraints(maxWidth: 90),
|
||||
child: ControlBoxButton(
|
||||
iconData: Icons.delete_sweep_rounded,
|
||||
iconData: Icons.remove_circle_outline,
|
||||
label: 'album_viewer_appbar_share_remove'.tr(),
|
||||
onPressed: enabled ? onRemoveFromAlbum : null,
|
||||
),
|
||||
|
@ -6,6 +6,8 @@ import 'package:flutter/material.dart';
|
||||
import 'package:fluttertoast/fluttertoast.dart';
|
||||
import 'package:hooks_riverpod/hooks_riverpod.dart';
|
||||
import 'package:immich_mobile/extensions/build_context_extensions.dart';
|
||||
import 'package:immich_mobile/providers/album/current_album.provider.dart';
|
||||
import 'package:immich_mobile/providers/album/shared_album.provider.dart';
|
||||
import 'package:immich_mobile/providers/asset_viewer/asset_stack.provider.dart';
|
||||
import 'package:immich_mobile/providers/asset_viewer/image_viewer_page_state.provider.dart';
|
||||
import 'package:immich_mobile/providers/asset_viewer/show_controls.provider.dart';
|
||||
@ -22,7 +24,7 @@ import 'package:immich_mobile/widgets/common/immich_toast.dart';
|
||||
|
||||
class BottomGalleryBar extends ConsumerWidget {
|
||||
final Asset asset;
|
||||
final int assetIndex;
|
||||
final ValueNotifier<int> assetIndex;
|
||||
final bool showStack;
|
||||
final int stackIndex;
|
||||
final ValueNotifier<int> totalAssets;
|
||||
@ -57,6 +59,7 @@ class BottomGalleryBar extends ConsumerWidget {
|
||||
final isFromTrash = isTrashEnabled &&
|
||||
navStack.length > 2 &&
|
||||
navStack.elementAt(navStack.length - 2).name == TrashRoute.name;
|
||||
final isInAlbum = ref.watch(currentAlbumProvider)?.isRemote ?? false;
|
||||
// !!!! itemsList and actionlist should always be in sync
|
||||
final itemsList = [
|
||||
BottomNavigationBarItem(
|
||||
@ -96,6 +99,12 @@ class BottomGalleryBar extends ConsumerWidget {
|
||||
label: 'download'.tr(),
|
||||
tooltip: 'download'.tr(),
|
||||
),
|
||||
if (isInAlbum)
|
||||
BottomNavigationBarItem(
|
||||
icon: const Icon(Icons.remove_circle_outline),
|
||||
label: 'album_viewer_appbar_share_remove'.tr(),
|
||||
tooltip: 'album_viewer_appbar_share_remove'.tr(),
|
||||
),
|
||||
];
|
||||
|
||||
void removeAssetFromStack() {
|
||||
@ -118,7 +127,8 @@ class BottomGalleryBar extends ConsumerWidget {
|
||||
|
||||
// `assetIndex == totalAssets.value - 1` handle the case of removing the last asset
|
||||
// to not throw the error when the next preCache index is called
|
||||
if (totalAssets.value == 1 || assetIndex == totalAssets.value - 1) {
|
||||
if (totalAssets.value == 1 ||
|
||||
assetIndex.value == totalAssets.value - 1) {
|
||||
// Handle only one asset
|
||||
context.maybePop();
|
||||
}
|
||||
@ -299,12 +309,45 @@ class BottomGalleryBar extends ConsumerWidget {
|
||||
);
|
||||
}
|
||||
|
||||
handleRemoveFromAlbum() async {
|
||||
final album = ref.read(currentAlbumProvider);
|
||||
final bool isSuccess = album != null &&
|
||||
await ref
|
||||
.read(sharedAlbumProvider.notifier)
|
||||
.removeAssetFromAlbum(album, [asset]);
|
||||
|
||||
if (isSuccess) {
|
||||
// Workaround for asset remaining in the gallery
|
||||
renderList.deleteAsset(asset);
|
||||
|
||||
if (totalAssets.value == 1) {
|
||||
// Handle empty viewer
|
||||
await context.maybePop();
|
||||
} else {
|
||||
// changing this also for the last asset causes the parent to rebuild with an error
|
||||
totalAssets.value -= 1;
|
||||
}
|
||||
if (assetIndex.value == totalAssets.value && assetIndex.value > 0) {
|
||||
// handle the case of removing the last asset in the list
|
||||
assetIndex.value -= 1;
|
||||
}
|
||||
} else {
|
||||
ImmichToast.show(
|
||||
context: context,
|
||||
msg: "album_viewer_appbar_share_err_remove".tr(),
|
||||
toastType: ToastType.error,
|
||||
gravity: ToastGravity.BOTTOM,
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
List<Function(int)> actionslist = [
|
||||
(_) => shareAsset(),
|
||||
if (isOwner) (_) => handleArchive(),
|
||||
if (isOwner && stack.isNotEmpty) (_) => showStackActionItems(),
|
||||
if (isOwner) (_) => handleDelete(),
|
||||
if (!isOwner) (_) => handleDownload(),
|
||||
if (isInAlbum) (_) => handleRemoveFromAlbum(),
|
||||
];
|
||||
|
||||
return IgnorePointer(
|
||||
|
Loading…
Reference in New Issue
Block a user