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) {