From 6076aca850ae625cc71aa1b6d9d0cbd48c560e24 Mon Sep 17 00:00:00 2001 From: alperozturk Date: Thu, 5 Sep 2024 10:35:31 +0200 Subject: [PATCH] Fix Signed-off-by: alperozturk --- .../nextcloud/client/files/DeepLinkHandlerTest.kt | 12 ++++++------ .../com/nextcloud/client/files/DeepLinkConstants.kt | 2 -- .../com/nextcloud/client/files/DeepLinkHandler.kt | 9 +++------ .../android/ui/activity/FileDisplayActivity.java | 12 ++---------- 4 files changed, 11 insertions(+), 24 deletions(-) diff --git a/app/src/androidTest/java/com/nextcloud/client/files/DeepLinkHandlerTest.kt b/app/src/androidTest/java/com/nextcloud/client/files/DeepLinkHandlerTest.kt index 0209ba9224c9..16b22ec5936b 100644 --- a/app/src/androidTest/java/com/nextcloud/client/files/DeepLinkHandlerTest.kt +++ b/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() @@ -115,8 +115,8 @@ class DeepLinkHandlerTest { @Mock lateinit var userAccountManager: UserAccountManager - lateinit var allUsers: List - lateinit var handler: DeepLinkHandler + private lateinit var allUsers: List + private lateinit var handler: DeepLinkHandler @Before fun setUp() { diff --git a/app/src/main/java/com/nextcloud/client/files/DeepLinkConstants.kt b/app/src/main/java/com/nextcloud/client/files/DeepLinkConstants.kt index cc4fbdc4966c..dc498ceffde1 100644 --- a/app/src/main/java/com/nextcloud/client/files/DeepLinkConstants.kt +++ b/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 } } } diff --git a/app/src/main/java/com/nextcloud/client/files/DeepLinkHandler.kt b/app/src/main/java/com/nextcloud/client/files/DeepLinkHandler.kt index 3b1209780ac2..ca5d74c6831c 100644 --- a/app/src/main/java/com/nextcloud/client/files/DeepLinkHandler.kt +++ b/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 } /** diff --git a/app/src/main/java/com/owncloud/android/ui/activity/FileDisplayActivity.java b/app/src/main/java/com/owncloud/android/ui/activity/FileDisplayActivity.java index 9f4726d402ad..af33cd4e9076 100644 --- a/app/src/main/java/com/owncloud/android/ui/activity/FileDisplayActivity.java +++ b/app/src/main/java/com/owncloud/android/ui/activity/FileDisplayActivity.java @@ -570,8 +570,6 @@ protected void onNewIntent(Intent intent) { setLeftFragment(new GroupfolderListFragment()); getSupportFragmentManager().executePendingTransactions(); - } else { - handleOpenFileViaIntent(intent); } } } @@ -2378,10 +2376,7 @@ public void setSearchQuery(String query) { } 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); @@ -2397,11 +2392,9 @@ private void handleOpenFileViaIntent(Intent intent) { } 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)); } } @@ -2410,11 +2403,10 @@ private void handleOpenFileViaIntent(Intent intent) { 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());