Эх сурвалжийг харах

Fix toggling favorite on sharing

Signed-off-by: tobiasKaminsky <tobias@kaminsky.me>
tobiasKaminsky 2 жил өмнө
parent
commit
395af69162

+ 1 - 1
app/src/main/java/com/owncloud/android/datamodel/OCFile.java

@@ -602,7 +602,7 @@ public class OCFile implements Parcelable, Comparable<OCFile>, ServerFileInterfa
     public long getLocalId() {
         if (localId > 0) {
             return localId;
-        } else if (remoteId != null) {
+        } else if (remoteId != null && remoteId.length() > 8) {
             return Long.parseLong(remoteId.substring(0, 8).replaceAll("^0*", ""));
         } else {
             return -1;

+ 2 - 1
app/src/main/java/com/owncloud/android/operations/CreateShareWithShareeOperation.java

@@ -68,7 +68,8 @@ public class CreateShareWithShareeOperation extends SyncOperation {
      * @param shareeName  User or group name of the target sharee.
      * @param shareType   Type of share determines type of sharee; {@link ShareType#USER} and {@link ShareType#GROUP}
      *                    are the only valid values for the moment.
-     * @param permissions Share permissions key as detailed in https://doc.owncloud.org/server/8.2/developer_manual/core/ocs-share-api.html
+     * @param permissions Share permissions key as detailed in
+     *                    https://docs.nextcloud.com/server/latest/developer_manual/client_apis/OCS/ocs-share-api.html#create-a-new-share
      *                    .
      */
     public CreateShareWithShareeOperation(String path,

+ 10 - 4
app/src/main/java/com/owncloud/android/ui/adapter/OCFileListAdapter.java

@@ -206,9 +206,9 @@ public class OCFileListAdapter extends RecyclerView.Adapter<RecyclerView.ViewHol
         return position;
     }
 
-    public void setFavoriteAttributeForItemID(String fileId, boolean favorite, boolean removeFromList) {
+    public void setFavoriteAttributeForItemID(String remotePath, boolean favorite, boolean removeFromList) {
         for (OCFile file : mFiles) {
-            if (file.getRemoteId().equals(fileId)) {
+            if (file.getRemotePath().equals(remotePath)) {
                 file.setFavorite(favorite);
 
                 if (removeFromList) {
@@ -220,7 +220,7 @@ public class OCFileListAdapter extends RecyclerView.Adapter<RecyclerView.ViewHol
         }
 
         for (OCFile file : mFilesAll) {
-            if (file.getRemoteId().equals(fileId)) {
+            if (file.getRemotePath().equals(remotePath)) {
                 file.setFavorite(favorite);
 
                 mStorageManager.saveFile(file);
@@ -234,7 +234,13 @@ public class OCFileListAdapter extends RecyclerView.Adapter<RecyclerView.ViewHol
         }
 
         FileSortOrder sortOrder = preferences.getSortOrderByFolder(currentDirectory);
-        mFiles = sortOrder.sortCloudFiles(mFiles);
+        if (searchType == SearchType.SHARED_FILTER) {
+            Collections.sort(mFiles,
+                             (o1, o2) -> Long.compare(o2.getFirstShareTimestamp(), o1.getFirstShareTimestamp())
+                            );
+        } else {
+            mFiles = sortOrder.sortCloudFiles(mFiles);
+        }
 
         new Handler(Looper.getMainLooper()).post(this::notifyDataSetChanged);
     }

+ 1 - 1
app/src/main/java/com/owncloud/android/ui/adapter/OCShareToOCFileConverter.kt

@@ -56,7 +56,7 @@ object OCShareToOCFileConverter {
             mimeType = firstShare.mimetype
             note = firstShare.note
             fileId = firstShare.fileSource
-            remoteId = firstShare.remoteId.toString()
+            remoteId = "-1" // remoteId is not given from server
             // use first share timestamp as timestamp
             firstShareTimestamp = shares.minOf { it.sharedDate * MILLIS_PER_SECOND }
             // don't have file length or mod timestamp

+ 1 - 3
app/src/main/java/com/owncloud/android/ui/events/FavoriteEvent.java

@@ -25,11 +25,9 @@ package com.owncloud.android.ui.events;
 public class FavoriteEvent {
     public final String remotePath;
     public final boolean shouldFavorite;
-    public final String remoteId;
 
-    public FavoriteEvent(String remotePath, boolean shouldFavorite, String remoteId) {
+    public FavoriteEvent(String remotePath, boolean shouldFavorite) {
         this.remotePath = remotePath;
         this.shouldFavorite = shouldFavorite;
-        this.remoteId = remoteId;
     }
 }

+ 1 - 1
app/src/main/java/com/owncloud/android/ui/fragment/OCFileListFragment.java

@@ -1605,7 +1605,7 @@ public class OCFileListFragment extends ExtendedListFragment implements
 
             if (remoteOperationResult.isSuccess()) {
                 boolean removeFromList = currentSearchType == SearchType.FAVORITE_SEARCH && !event.shouldFavorite;
-                mAdapter.setFavoriteAttributeForItemID(event.remoteId, event.shouldFavorite, removeFromList);
+                mAdapter.setFavoriteAttributeForItemID(event.remotePath, event.shouldFavorite, removeFromList);
             }
 
         } catch (ClientFactory.CreationException e) {

+ 1 - 1
app/src/main/java/com/owncloud/android/ui/helpers/FileOperationsHelper.java

@@ -906,7 +906,7 @@ public class FileOperationsHelper {
 
     public void toggleFavoriteFile(OCFile file, boolean shouldBeFavorite) {
         if (file.isFavorite() != shouldBeFavorite) {
-            EventBus.getDefault().post(new FavoriteEvent(file.getRemotePath(), shouldBeFavorite, file.getRemoteId()));
+            EventBus.getDefault().post(new FavoriteEvent(file.getRemotePath(), shouldBeFavorite));
         }
     }
 

+ 4 - 0
app/src/main/java/com/owncloud/android/utils/FileSortOrder.kt

@@ -99,6 +99,10 @@ open class FileSortOrder(@JvmField var name: String, var isAscending: Boolean) {
         }
     }
 
+    open fun sortSharedFiles(files: MutableList<OCFile>): List<OCFile> {
+        return files.sortedByDescending { it.firstShareTimestamp }
+    }
+
     open fun sortCloudFiles(files: MutableList<OCFile>): List<OCFile> {
         return sortCloudFilesByFavourite(files)
     }