Skip to content

Commit

Permalink
Merge pull request #13518 from nextcloud/bugfix/share-link
Browse files Browse the repository at this point in the history
BugFix - Share Link
  • Loading branch information
alperozturk96 committed Sep 12, 2024
2 parents af3b19d + 6076aca commit 5116cdc
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 24 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand All @@ -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"
)
Expand Down Expand Up @@ -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>()
Expand All @@ -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() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 }
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -563,8 +563,6 @@ protected void onNewIntent(Intent intent) {
DrawerActivity.menuItemId = R.id.nav_groupfolders;
setLeftFragment(new GroupfolderListFragment());
getSupportFragmentManager().executePendingTransactions();
} else {
handleOpenFileViaIntent(intent);
}
}
}
Expand Down Expand Up @@ -2366,10 +2364,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);
Expand All @@ -2385,11 +2380,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));
}
}
Expand All @@ -2398,11 +2391,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());
Expand Down

0 comments on commit 5116cdc

Please sign in to comment.