Browse Source

Merge pull request #13518 from nextcloud/bugfix/share-link

BugFix - Share Link
Alper Öztürk 9 months ago
parent
commit
5116cdcca9

+ 6 - 6
app/src/androidTest/java/com/nextcloud/client/files/DeepLinkHandlerTest.kt

@@ -37,8 +37,8 @@ class DeepLinkHandlerTest {
     class DeepLinkPattern {
 
         companion object {
-            val FILE_ID = 1234
-            val SERVER_BASE_URLS = listOf(
+            private const val FILE_ID = 1234
+            private val SERVER_BASE_URLS = listOf(
                 "http://hostname.net",
                 "https://hostname.net",
                 "http://hostname.net/subdir1",
@@ -48,7 +48,7 @@ class DeepLinkHandlerTest {
                 "http://hostname.net/subdir1/subdir2/subdir3",
                 "https://hostname.net/subdir1/subdir2/subdir3"
             )
-            val INDEX_PHP_PATH = listOf(
+            private val INDEX_PHP_PATH = listOf(
                 "",
                 "/index.php"
             )
@@ -102,7 +102,7 @@ class DeepLinkHandlerTest {
             const val OTHER_SERVER_BASE_URL = "https://someotherserver.net"
             const val SERVER_BASE_URL = "https://server.net"
             const val FILE_ID = "1234567890"
-            val DEEP_LINK = Uri.parse("$SERVER_BASE_URL/index.php/f/$FILE_ID")
+            val DEEP_LINK: Uri = Uri.parse("$SERVER_BASE_URL/index.php/f/$FILE_ID")
 
             fun createMockUser(serverBaseUrl: String): User {
                 val user = mock<User>()
@@ -115,8 +115,8 @@ class DeepLinkHandlerTest {
 
         @Mock
         lateinit var userAccountManager: UserAccountManager
-        lateinit var allUsers: List<User>
-        lateinit var handler: DeepLinkHandler
+        private lateinit var allUsers: List<User>
+        private lateinit var handler: DeepLinkHandler
 
         @Before
         fun setUp() {

+ 0 - 2
app/src/main/java/com/nextcloud/client/files/DeepLinkConstants.kt

@@ -29,7 +29,5 @@ enum class DeepLinkConstants(val route: String, val navId: Int) {
         fun fromPath(path: String?): DeepLinkConstants? {
             return entries.find { it.route == path }
         }
-
-        val navigationPaths = entries.map { it.route }
     }
 }

+ 3 - 6
app/src/main/java/com/nextcloud/client/files/DeepLinkHandler.kt

@@ -30,12 +30,9 @@ class DeepLinkHandler(
 
     companion object {
         val DEEP_LINK_PATTERN = Regex("""(.*?)(/index\.php)?/f/([0-9]+)$""")
-        val BASE_URL_GROUP_INDEX = 1
-        val INDEX_PATH_GROUP_INDEX = 2
-        val FILE_ID_GROUP_INDEX = 3
-
-        fun isDeepLinkTypeIsNavigation(deepLinkUrl: String): Boolean =
-            DeepLinkConstants.navigationPaths.any { deepLinkUrl.endsWith(it) }
+        const val BASE_URL_GROUP_INDEX = 1
+        const val INDEX_PATH_GROUP_INDEX = 2
+        const val FILE_ID_GROUP_INDEX = 3
     }
 
     /**

+ 2 - 10
app/src/main/java/com/owncloud/android/ui/activity/FileDisplayActivity.java

@@ -563,8 +563,6 @@ public class FileDisplayActivity extends FileActivity
                 DrawerActivity.menuItemId = R.id.nav_groupfolders;
                 setLeftFragment(new GroupfolderListFragment());
                 getSupportFragmentManager().executePendingTransactions();
-            } else {
-                handleOpenFileViaIntent(intent);
             }
         }
     }
@@ -2366,10 +2364,7 @@ public class FileDisplayActivity extends FileActivity
     }
 
     private void handleOpenFileViaIntent(Intent intent) {
-        Uri deepLinkUri = getIntent().getData();
-        if (deepLinkUri == null || !DeepLinkHandler.Companion.isDeepLinkTypeIsNavigation(deepLinkUri.toString())) {
-            showLoadingDialog(getString(R.string.retrieving_file));
-        }
+        DisplayUtils.showSnackMessage(this, getString(R.string.retrieving_file));
 
         String userName = intent.getStringExtra(KEY_ACCOUNT);
         String fileId = intent.getStringExtra(KEY_FILE_ID);
@@ -2385,11 +2380,9 @@ public class FileDisplayActivity extends FileActivity
                 } else if (!TextUtils.isEmpty(filePath)) {
                     openFileByPath(optionalUser.get(), filePath);
                 } else {
-                    dismissLoadingDialog();
                     accountClicked(optionalUser.get().hashCode());
                 }
             } else {
-                dismissLoadingDialog();
                 DisplayUtils.showSnackMessage(this, getString(R.string.associated_account_not_found));
             }
         }
@@ -2398,11 +2391,10 @@ public class FileDisplayActivity extends FileActivity
     private void openDeepLink(Uri uri) {
         DeepLinkHandler linkHandler = new DeepLinkHandler(getUserAccountManager());
         DeepLinkHandler.Match match = linkHandler.parseDeepLink(uri);
+
         if (match == null) {
-            dismissLoadingDialog();
             handleDeepLink(uri);
         } else if (match.getUsers().isEmpty()) {
-            dismissLoadingDialog();
             DisplayUtils.showSnackMessage(this, getString(R.string.associated_account_not_found));
         } else if (match.getUsers().size() == SINGLE_USER_SIZE) {
             openFile(match.getUsers().get(0), match.getFileId());