Explorar o código

SharedListFragment: replace file in adapter when fetching the complete data

This fixes bugs with selection

Signed-off-by: Álvaro Brey <alvaro.brey@nextcloud.com>
Álvaro Brey %!s(int64=2) %!d(string=hai) anos
pai
achega
1a4aaf5224

+ 23 - 0
app/src/main/java/com/owncloud/android/ui/adapter/OCFileListAdapter.java

@@ -993,4 +993,27 @@ public class OCFileListAdapter extends RecyclerView.Adapter<RecyclerView.ViewHol
     public void notifyItemChanged(@NonNull OCFile file) {
         notifyItemChanged(getItemPosition(file));
     }
+
+    public void replaceFileByRemotePath(@NonNull OCFile newFile, boolean notify) {
+        final String remotePath = newFile.getRemotePath();
+        for (OCFile file : mFiles) {
+            if (file.getRemotePath().equals(remotePath)) {
+                final int index = mFiles.indexOf(file);
+                mFiles.set(index, newFile);
+                break;
+            }
+        }
+
+        for (OCFile file : mFilesAll) {
+            if (file.getRemotePath().equals(remotePath)) {
+                final int index = mFilesAll.indexOf(file);
+                mFilesAll.set(index, newFile);
+                break;
+            }
+        }
+
+        if (notify) {
+            notifyItemChanged(getItemPosition(newFile));
+        }
+    }
 }

+ 2 - 0
app/src/main/java/com/owncloud/android/ui/fragment/SharedListFragment.kt

@@ -101,6 +101,8 @@ class SharedListFragment : OCFileListFragment(), Injectable {
                     isSharedWithSharee = partialFile.isSharedWithSharee
                     sharees = partialFile.sharees
                 }
+                adapter.replaceFileByRemotePath(savedFile, false)
+                savedFile
             }
         }
     }