Skip to content

armgit / ente

Public Imported from GitHub
0

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

Fix selection state after multi-download

ashilkncd6273d484d6
diff --git a/mobile/apps/photos/lib/models/selected_files.dart b/mobile/apps/photos/lib/models/selected_files.dart
index 88a84365b9..398f7b82fb 100644
--- a/mobile/apps/photos/lib/models/selected_files.dart
+++ b/mobile/apps/photos/lib/models/selected_files.dart
@@ -121,4 +121,17 @@ class SelectedFiles extends ChangeNotifier {
files.retainAll(filesToRetain);
notifyListeners();
}
+
+ ///Replaces the current selection with [filesToSelect] in a single update.
+ void replaceSelection(Set<EnteFile> filesToSelect) {
+ final nonDummyFiles =
+ filesToSelect.where((file) => file is! DummyFile).toSet();
+ lastSelectionOperationFiles.clear();
+ lastSelectionOperationFiles.addAll(files);
+ files
+ ..clear()
+ ..addAll(nonDummyFiles);
+ lastSelectionOperationFiles.addAll(nonDummyFiles);
+ notifyListeners();
+ }
}
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 04ee8c2c60..eb1aa48a8f 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
@@ -1124,7 +1124,9 @@ class _FileSelectionActionsWidgetState
for (final file in remoteFiles) {
futures.add(
taskQueue.add(() async {
- await downloadToGallery(file);
+ // Avoid mutating selected file instances since `localID` is part
+ // of EnteFile hashCode and selection is maintained in a Set.
+ await downloadToGallery(file.copyWith());
downloadedFiles++;
dialog.update(
message: AppLocalizations.of(context).downloading +
@@ -1173,8 +1175,8 @@ class _FileSelectionActionsWidgetState
if (skippedFilesCount == 0) {
widget.selectedFiles.clearAll();
- } else if (remoteFiles.isNotEmpty) {
- widget.selectedFiles.unSelectAll(remoteFiles.toSet());
+ } else {
+ widget.selectedFiles.replaceSelection(skippedFiles.toSet());
}
}
}