From 9c7890d79777266742f64397e68c01b8e9eba085 Mon Sep 17 00:00:00 2001 From: Jonas Mayer Date: Thu, 11 Jan 2024 11:54:33 +0100 Subject: [PATCH 1/2] Make sure notifyDataSetChanged gets directly called after removing file Signed-off-by: Jonas Mayer --- .../owncloud/android/ui/adapter/OCFileListAdapter.java | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/app/src/main/java/com/owncloud/android/ui/adapter/OCFileListAdapter.java b/app/src/main/java/com/owncloud/android/ui/adapter/OCFileListAdapter.java index 32103f0e7f0f..2c2152b37789 100644 --- a/app/src/main/java/com/owncloud/android/ui/adapter/OCFileListAdapter.java +++ b/app/src/main/java/com/owncloud/android/ui/adapter/OCFileListAdapter.java @@ -220,12 +220,13 @@ public int getItemPosition(@NonNull OCFile file) { } public void setFavoriteAttributeForItemID(String remotePath, boolean favorite, boolean removeFromList) { + List filesToDelete = new ArrayList<>(); for (OCFile file : mFiles) { if (file.getRemotePath().equals(remotePath)) { file.setFavorite(favorite); if (removeFromList) { - mFiles.remove(file); + filesToDelete.add(file); } break; @@ -239,7 +240,7 @@ public void setFavoriteAttributeForItemID(String remotePath, boolean favorite, b mStorageManager.saveFile(file); if (removeFromList) { - mFiles.remove(file); + filesToDelete.add(file); } break; @@ -255,7 +256,10 @@ public void setFavoriteAttributeForItemID(String remotePath, boolean favorite, b mFiles = sortOrder.sortCloudFiles(mFiles); } - new Handler(Looper.getMainLooper()).post(this::notifyDataSetChanged); + new Handler(Looper.getMainLooper()).post(() -> { + mFiles.removeAll(filesToDelete); + notifyDataSetChanged(); + }); } public void refreshCommentsCount(String fileId) { From 1043070d5f84dcdd09536b9338477b566b54950c Mon Sep 17 00:00:00 2001 From: Jonas Mayer Date: Thu, 11 Jan 2024 13:32:35 +0100 Subject: [PATCH 2/2] suppress warning Signed-off-by: Jonas Mayer --- .../java/com/owncloud/android/ui/adapter/OCFileListAdapter.java | 1 + 1 file changed, 1 insertion(+) diff --git a/app/src/main/java/com/owncloud/android/ui/adapter/OCFileListAdapter.java b/app/src/main/java/com/owncloud/android/ui/adapter/OCFileListAdapter.java index 2c2152b37789..0251d16d42bd 100644 --- a/app/src/main/java/com/owncloud/android/ui/adapter/OCFileListAdapter.java +++ b/app/src/main/java/com/owncloud/android/ui/adapter/OCFileListAdapter.java @@ -219,6 +219,7 @@ public int getItemPosition(@NonNull OCFile file) { return position; } + @SuppressLint("NotifyDataSetChanged") public void setFavoriteAttributeForItemID(String remotePath, boolean favorite, boolean removeFromList) { List filesToDelete = new ArrayList<>(); for (OCFile file : mFiles) {