Skip to content

armgit / ente

Public Imported from GitHub
0

πŸ’š End-to-end encrypted cloud for everything.

[mobile][photos] use device trash plugin and move toAssetEntity into device trash file class

Priyanshu Dangaref8ed126e6596
diff --git a/mobile/apps/photos/lib/models/file/trash_file.dart b/mobile/apps/photos/lib/models/file/trash_file.dart
index 53d6bfd9a2..997e2176f1 100644
--- a/mobile/apps/photos/lib/models/file/trash_file.dart
+++ b/mobile/apps/photos/lib/models/file/trash_file.dart
@@ -19,11 +19,7 @@ class EnteTrashFile extends TrashFile {
required super.deleteBy,
required this.createdAt,
required this.updateAt,
- }) : super.from() {
- if (localID != null) {
- generatedID = -int.parse(localID!);
- }
- }
+ }) : super.from();
// Time first moved to Trash.
late int createdAt;
@@ -36,17 +32,17 @@ class DeviceTrashFile extends TrashFile {
DeviceTrashFile();
DeviceTrashFile.from(super.file, {required super.deleteBy}) : super.from();
-}
-AssetEntity trashFileToAssetEntity(EnteFile file) {
- return AssetEntity(
- id: file.localID!,
- typeInt: switch (file.fileType) {
- FileType.image || FileType.livePhoto => AssetType.image.index,
- FileType.video => AssetType.video.index,
- FileType.other => AssetType.other.index,
- },
- width: 0,
- height: 0,
- );
+ AssetEntity toAssetEntity() {
+ return AssetEntity(
+ id: localID!,
+ typeInt: switch (fileType) {
+ FileType.image || FileType.livePhoto => AssetType.image.index,
+ FileType.video => AssetType.video.index,
+ FileType.other => AssetType.other.index,
+ },
+ width: 0,
+ height: 0,
+ );
+ }
}
diff --git a/mobile/apps/photos/lib/ui/viewer/actions/file_selection_actions_widget.dart b/mobile/apps/photos/lib/ui/viewer/actions/file_selection_actions_widget.dart
index 0489410294..13d28efa3b 100644
--- a/mobile/apps/photos/lib/ui/viewer/actions/file_selection_actions_widget.dart
+++ b/mobile/apps/photos/lib/ui/viewer/actions/file_selection_actions_widget.dart
@@ -1308,7 +1308,9 @@ class _FileSelectionActionsWidgetState
}
Future<void> _restoreFilesFromDeviceTrash(SelectedFiles selectedFiles) async {
- final files = selectedFiles.files.map(trashFileToAssetEntity).toList();
+ final files = selectedFiles.files
+ .map((f) => f.asDeviceTrashFile!.toAssetEntity())
+ .toList();
final restoredIDs = <String>{};
try {
for (final batch in files.chunks(batchSize)) {
diff --git a/mobile/apps/photos/lib/ui/viewer/file/file_bottom_bar.dart b/mobile/apps/photos/lib/ui/viewer/file/file_bottom_bar.dart
index 3413e5a91e..b7ba51c6ca 100644
--- a/mobile/apps/photos/lib/ui/viewer/file/file_bottom_bar.dart
+++ b/mobile/apps/photos/lib/ui/viewer/file/file_bottom_bar.dart
@@ -13,7 +13,6 @@ import "package:photos/events/guest_view_event.dart";
import "package:photos/models/collection/collection.dart";
import "package:photos/models/file/extensions/file_props.dart";
import "package:photos/models/file/file.dart";
-import "package:photos/models/file/trash_file.dart";
import "package:photos/models/selected_files.dart";
import 'package:photos/module/metadata/panorama.dart';
import "package:photos/service_locator.dart";
@@ -329,9 +328,8 @@ class FileBottomBarState extends State<FileBottomBar> {
}
Future<void> _restoreFromDeviceTrash() async {
- final asset = trashFileToAssetEntity(widget.file);
final restoredIDs = await PhotoManager.editor.android.restoreFromTrash([
- asset,
+ widget.file.asDeviceTrashFile!.toAssetEntity(),
]);
if (restoredIDs.isEmpty) return;
Bus.instance.fire(ForceReloadTrashPageEvent());
diff --git a/mobile/apps/photos/lib/ui/viewer/gallery/trash_page.dart b/mobile/apps/photos/lib/ui/viewer/gallery/trash_page.dart
index bd9300105c..647af08101 100644
--- a/mobile/apps/photos/lib/ui/viewer/gallery/trash_page.dart
+++ b/mobile/apps/photos/lib/ui/viewer/gallery/trash_page.dart
@@ -2,6 +2,7 @@ import "dart:io";
import "package:collection/collection.dart";
import "package:ente_components/ente_components.dart";
+import "package:ente_photos_platform/ente_photos_platform.dart";
import "package:ente_pure_utils/ente_pure_utils.dart";
import "package:ente_strings/extensions.dart";
import 'package:flutter/material.dart';
@@ -18,7 +19,6 @@ import "package:photos/models/gallery_type.dart";
import "package:photos/models/selected_files.dart";
import "package:photos/module/metadata/local_file.dart";
import "package:photos/service_locator.dart";
-import "package:photos/services/native_service.dart";
import "package:photos/ui/components/empty_state_component.dart";
import "package:photos/ui/viewer/actions/file_selection_overlay_bar.dart";
import "package:photos/ui/viewer/gallery/gallery.dart";
@@ -157,7 +157,7 @@ class _TrashPageState extends State<_TrashPage> {
asc: asc,
);
}
- final deviceTrash = await NativeService.getTrash();
+ final deviceTrash = await SystemTrashClient.instance.getFiles();
final deviceTrashAssets = await Future.wait(
deviceTrash.map((t) => AssetEntity.fromId(t.localID.toString())),
);