Browse Source

Merge pull request #13166 from nextcloud/crash-fix-share-link

Share Link Crash Fix
Alper Öztürk 1 năm trước cách đây
mục cha
commit
b9d94e8be8

+ 14 - 7
app/src/main/java/com/owncloud/android/ui/activity/FileActivity.java

@@ -790,11 +790,14 @@ public abstract class FileActivity extends DrawerActivity
             String link = "";
             OCFile file = null;
             for (Object object : result.getData()) {
-                OCShare shareLink = (OCShare) object;
-                if (TAG_PUBLIC_LINK.equalsIgnoreCase(shareLink.getShareType().name())) {
-                    link = shareLink.getShareLink();
-                    file = getStorageManager().getFileByPath(shareLink.getPath());
-                    break;
+                if (object instanceof OCShare shareLink) {
+                    ShareType shareType = shareLink.getShareType();
+
+                    if (shareType != null && TAG_PUBLIC_LINK.equalsIgnoreCase(shareType.name())) {
+                        link = shareLink.getShareLink();
+                        file = getStorageManager().getFileByEncryptedRemotePath(shareLink.getPath());
+                        break;
+                    }
                 }
             }
 
@@ -804,8 +807,12 @@ public abstract class FileActivity extends DrawerActivity
                 sharingFragment.onUpdateShareInformation(result, file);
             }
 
-            if (fileListFragment instanceof OCFileListFragment && file != null) {
-                ((OCFileListFragment) fileListFragment).updateOCFile(file);
+            if (fileListFragment instanceof OCFileListFragment ocFileListFragment && file != null) {
+                if (ocFileListFragment.getAdapterFiles().contains(file)) {
+                    ocFileListFragment.updateOCFile(file);
+                } else {
+                    DisplayUtils.showSnackMessage(this, R.string.file_activity_shared_file_cannot_be_updated);
+                }
             }
         } else {
             // Detect Failure (403) --> maybe needs password

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

@@ -1387,9 +1387,19 @@ public class OCFileListFragment extends ExtendedListFragment implements
         }
     }
 
-    public void updateOCFile(OCFile file) {
+    public List<OCFile> getAdapterFiles() {
+        return mAdapter.getFiles();
+    }
+
+    public void updateOCFile(@NonNull OCFile file) {
         List<OCFile> mFiles = mAdapter.getFiles();
-        mFiles.set(mFiles.indexOf(file), file);
+        int index = mFiles.indexOf(file);
+        if (index == -1) {
+            Log_OC.d(TAG, "File cannot be found in adapter's files");
+            return;
+        }
+
+        mFiles.set(index, file);
         mAdapter.notifyItemChanged(file);
     }
 

+ 2 - 1
app/src/main/java/com/owncloud/android/ui/preview/PreviewImageFragment.kt

@@ -530,7 +530,8 @@ class PreviewImageFragment : FileFragment(), Injectable {
 
                         try {
                             bitmapResult = BitmapUtils.decodeSampledBitmapFromFile(
-                                storagePath, minWidth,
+                                storagePath,
+                                minWidth,
                                 minHeight
                             )
 

+ 1 - 0
app/src/main/res/values/strings.xml

@@ -1154,6 +1154,7 @@
     <string name="check_back_later_or_reload">Check back later or reload.</string>
     <string name="e2e_not_yet_setup">E2E not yet setup</string>
     <string name="error_file_actions">Error showing file actions</string>
+    <string name="file_activity_shared_file_cannot_be_updated">Shared file cannot be updated</string>
     <string name="pin_home">Pin to Home screen</string>
     <string name="pin_shortcut_label">Open %1$s</string>
     <string name="displays_mnemonic">Displays your 12 word passphrase</string>