1
0
mirror of https://github.com/immich-app/immich.git synced 2024-12-25 10:43:13 +02:00

fix(mobile): restore button in asset viewer (#8919)

* fix:(mobile): spell error in top_control_app_bar.dart in function buildAddToAlbumButtom

* fix(mobile): add restore button to individual image view of trashed assets

* formatting
This commit is contained in:
Conner Hnatiuk 2024-04-26 00:01:03 -06:00 committed by GitHub
parent 59537f8f1b
commit 3e03f5348f
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
4 changed files with 70 additions and 2 deletions

View File

@ -1,5 +1,6 @@
import 'package:auto_route/auto_route.dart';
import 'package:flutter/material.dart';
import 'package:fluttertoast/fluttertoast.dart';
import 'package:hooks_riverpod/hooks_riverpod.dart';
import 'package:immich_mobile/modules/album/providers/current_album.provider.dart';
import 'package:immich_mobile/modules/album/ui/add_to_album_bottom_sheet.dart';
@ -7,12 +8,14 @@ import 'package:immich_mobile/modules/asset_viewer/providers/image_viewer_page_s
import 'package:immich_mobile/modules/asset_viewer/providers/show_controls.provider.dart';
import 'package:immich_mobile/modules/asset_viewer/ui/top_control_app_bar.dart';
import 'package:immich_mobile/modules/backup/providers/manual_upload.provider.dart';
import 'package:immich_mobile/modules/trash/providers/trashed_asset.provider.dart';
import 'package:immich_mobile/modules/home/ui/upload_dialog.dart';
import 'package:immich_mobile/modules/partner/providers/partner.provider.dart';
import 'package:immich_mobile/routing/router.dart';
import 'package:immich_mobile/shared/models/asset.dart';
import 'package:immich_mobile/shared/providers/asset.provider.dart';
import 'package:immich_mobile/shared/providers/user.provider.dart';
import 'package:immich_mobile/shared/ui/immich_toast.dart';
class GalleryAppBar extends ConsumerWidget {
final Asset asset;
@ -47,6 +50,18 @@ class GalleryAppBar extends ConsumerWidget {
}
}
handleRestore(Asset asset) async {
final result = await ref.read(trashProvider.notifier).restoreAsset(asset);
if (result && context.mounted) {
ImmichToast.show(
context: context,
msg: 'asset restored successfully',
gravity: ToastGravity.BOTTOM,
);
}
}
handleUpload(Asset asset) {
showDialog(
context: context,
@ -91,6 +106,7 @@ class GalleryAppBar extends ConsumerWidget {
asset: asset,
onMoreInfoPressed: showInfo,
onFavorite: toggleFavorite,
onRestorePressed: () => handleRestore(asset),
onUploadPressed: asset.isLocal ? () => handleUpload(asset) : null,
onDownloadPressed: asset.isLocal
? null

View File

@ -13,6 +13,7 @@ class TopControlAppBar extends HookConsumerWidget {
required this.onMoreInfoPressed,
required this.onDownloadPressed,
required this.onAddToAlbumPressed,
required this.onRestorePressed,
required this.onToggleMotionVideo,
required this.isPlayingMotionVideo,
required this.onFavorite,
@ -28,6 +29,7 @@ class TopControlAppBar extends HookConsumerWidget {
final VoidCallback? onDownloadPressed;
final VoidCallback onToggleMotionVideo;
final VoidCallback onAddToAlbumPressed;
final VoidCallback onRestorePressed;
final VoidCallback onActivitiesPressed;
final Function(Asset) onFavorite;
final bool isPlayingMotionVideo;
@ -94,7 +96,7 @@ class TopControlAppBar extends HookConsumerWidget {
);
}
Widget buildAddToAlbumButtom() {
Widget buildAddToAlbumButton() {
return IconButton(
onPressed: () {
onAddToAlbumPressed();
@ -106,6 +108,18 @@ class TopControlAppBar extends HookConsumerWidget {
);
}
Widget buildRestoreButton() {
return IconButton(
onPressed: () {
onRestorePressed();
},
icon: Icon(
Icons.history_rounded,
color: Colors.grey[200],
),
);
}
Widget buildActivitiesButton() {
return IconButton(
onPressed: () {
@ -170,7 +184,9 @@ class TopControlAppBar extends HookConsumerWidget {
if (asset.isLocal && !asset.isRemote) buildUploadButton(),
if (asset.isRemote && !asset.isLocal && !asset.isOffline && isOwner)
buildDownloadButton(),
if (asset.isRemote && (isOwner || isPartner)) buildAddToAlbumButtom(),
if (asset.isRemote && (isOwner || isPartner) && !asset.isTrashed)
buildAddToAlbumButton(),
if (asset.isTrashed) buildRestoreButton(),
if (album != null && album.shared) buildActivitiesButton(),
buildMoreInfoButton(),
],

View File

@ -75,6 +75,28 @@ class TrashNotifier extends StateNotifier<bool> {
return false;
}
Future<bool> restoreAsset(Asset asset) async {
try {
final result = await _trashService.restoreAsset(asset);
if (result) {
final remoteAsset = asset.isRemote;
asset.isTrashed = false;
if (remoteAsset) {
await _db.writeTxn(() async {
await _db.assets.put(asset);
});
}
return true;
}
} catch (error, stack) {
_log.severe("Cannot restore asset", error, stack);
}
return false;
}
Future<bool> restoreAssets(Iterable<Asset> assetList) async {
try {
final result = await _trashService.restoreAssets(assetList);

View File

@ -30,6 +30,20 @@ class TrashService {
}
}
Future<bool> restoreAsset(Asset asset) async {
try {
if (asset.isRemote) {
List<String> remoteId = [asset.remoteId!];
await _apiService.trashApi.restoreAssets(BulkIdsDto(ids: remoteId));
}
return true;
} catch (error, stack) {
_log.severe("Cannot restore assets", error, stack);
return false;
}
}
Future<void> emptyTrash() async {
try {
await _apiService.trashApi.emptyTrash();