forked from nextcloud/android
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request nextcloud#13057 from nextcloud/nmc/deepLink
Added deep link support for screens navigation
- Loading branch information
Showing
5 changed files
with
88 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,6 +2,7 @@ | |
<!-- | ||
~ Nextcloud - Android Client | ||
~ | ||
~ SPDX-FileCopyrightText: 2024 TSI-mc <[email protected]> | ||
~ SPDX-FileCopyrightText: 2016-2024 Nextcloud GmbH and Nextcloud contributors | ||
~ SPDX-License-Identifier: AGPL-3.0-or-later OR GPL-2.0-only | ||
--> | ||
|
@@ -160,6 +161,8 @@ | |
<data android:pathPattern="/..*/f/..*" /> | ||
<data android:pathPattern="/..*/..*/f/..*" /> | ||
<data android:pathPattern="/..*/..*/..*/f/..*" /> | ||
<!-- path pattern to handle deep link --> | ||
<data android:pathPattern="/app/..*" /> | ||
</intent-filter> | ||
|
||
<meta-data | ||
|
35 changes: 35 additions & 0 deletions
35
app/src/main/java/com/nextcloud/client/files/DeepLinkConstants.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
/* | ||
* Nextcloud - Android Client | ||
* | ||
* SPDX-FileCopyrightText: 2024 TSI-mc <[email protected]> | ||
* SPDX-License-Identifier: AGPL-3.0-or-later | ||
*/ | ||
|
||
package com.nextcloud.client.files | ||
|
||
import com.owncloud.android.R | ||
|
||
enum class DeepLinkConstants(val route: String, val navId: Int) { | ||
OPEN_FILES("openFiles", R.id.nav_all_files), | ||
OPEN_FAVORITES("openFavorites", R.id.nav_favorites), | ||
OPEN_MEDIA("openMedia", R.id.nav_gallery), | ||
OPEN_SHARED("openShared", R.id.nav_shared), | ||
OPEN_OFFLINE("openOffline", R.id.nav_on_device), | ||
OPEN_NOTIFICATIONS("openNotifications", R.id.nav_notifications), | ||
OPEN_DELETED("openDeleted", R.id.nav_trashbin), | ||
OPEN_SETTINGS("openSettings", R.id.nav_settings), | ||
|
||
// Special case, handled separately | ||
OPEN_AUTO_UPLOAD("openAutoUpload", -1), | ||
OPEN_EXTERNAL_URL("openUrl", -1), | ||
ACTION_CREATE_NEW("createNew", -1), | ||
ACTION_APP_UPDATE("checkAppUpdate", -1); | ||
|
||
companion object { | ||
fun fromPath(path: String?): DeepLinkConstants? { | ||
return entries.find { it.route == path } | ||
} | ||
|
||
val navigationPaths = entries.map { it.route } | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,7 @@ | ||
/* | ||
* Nextcloud - Android Client | ||
* | ||
* SPDX-FileCopyrightText: 2021 TSI-mc | ||
* SPDX-FileCopyrightText: 2021-2024 TSI-mc <[email protected]> | ||
* SPDX-FileCopyrightText: 2020 Infomaniak Network SA | ||
* SPDX-FileCopyrightText: 2020 Chris Narkiewicz <[email protected]> | ||
* SPDX-FileCopyrightText: 2017 Tobias Kaminsky <[email protected]> | ||
|
@@ -51,6 +51,7 @@ | |
import com.google.android.material.progressindicator.LinearProgressIndicator; | ||
import com.nextcloud.client.account.User; | ||
import com.nextcloud.client.di.Injectable; | ||
import com.nextcloud.client.files.DeepLinkConstants; | ||
import com.nextcloud.client.network.ClientFactory; | ||
import com.nextcloud.client.onboarding.FirstRunActivity; | ||
import com.nextcloud.client.preferences.AppPreferences; | ||
|
@@ -113,6 +114,7 @@ | |
|
||
import javax.inject.Inject; | ||
|
||
import androidx.annotation.IdRes; | ||
import androidx.annotation.NonNull; | ||
import androidx.appcompat.app.ActionBarDrawerToggle; | ||
import androidx.core.content.ContextCompat; | ||
|
@@ -1272,4 +1274,42 @@ && getStorageManager() != null) { | |
t.start(); | ||
} | ||
} | ||
|
||
protected void handleDeepLink(@NonNull Uri uri) { | ||
String path = uri.getLastPathSegment(); | ||
if (path == null) return; | ||
|
||
DeepLinkConstants deepLinkType = DeepLinkConstants.Companion.fromPath(path); | ||
if (deepLinkType == null) { | ||
DisplayUtils.showSnackMessage(this, getString(R.string.invalid_url)); | ||
return; | ||
} | ||
|
||
switch (deepLinkType) { | ||
case OPEN_AUTO_UPLOAD: | ||
startActivity(new Intent(this, SyncedFoldersActivity.class)); | ||
break; | ||
case OPEN_EXTERNAL_URL: | ||
Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(uri.getQueryParameter("url"))); | ||
startActivity(intent); | ||
break; | ||
case ACTION_CREATE_NEW: | ||
findViewById(R.id.fab_main).callOnClick(); | ||
break; | ||
case ACTION_APP_UPDATE: | ||
openAppStore(getPackageName(), false); | ||
break; | ||
default: | ||
handleNavItemClickEvent(deepLinkType.getNavId()); | ||
break; | ||
} | ||
} | ||
|
||
private void handleNavItemClickEvent(@IdRes int menuItemId) { | ||
if (mNavigationView == null) { | ||
mNavigationView = findViewById(R.id.nav_view); | ||
} | ||
Menu navMenu = mNavigationView.getMenu(); | ||
onNavigationItemClicked(navMenu.findItem(menuItemId)); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,7 @@ | ||
/* | ||
* Nextcloud - Android Client | ||
* | ||
* SPDX-FileCopyrightText: 2023 TSI-mc | ||
* SPDX-FileCopyrightText: 2023-2024 TSI-mc <[email protected]> | ||
* SPDX-FileCopyrightText: 2023 Archontis E. Kostis <[email protected]> | ||
* SPDX-FileCopyrightText: 2019 Chris Narkiewicz <[email protected]> | ||
* SPDX-FileCopyrightText: 2018-2022 Tobias Kaminsky <[email protected]> | ||
|
@@ -2324,7 +2324,10 @@ public void setSearchQuery(String query) { | |
} | ||
|
||
private void handleOpenFileViaIntent(Intent intent) { | ||
showLoadingDialog(getString(R.string.retrieving_file)); | ||
Uri deepLinkUri = getIntent().getData(); | ||
if (deepLinkUri == null || !DeepLinkHandler.Companion.isDeepLinkTypeIsNavigation(deepLinkUri.toString())) { | ||
showLoadingDialog(getString(R.string.retrieving_file)); | ||
} | ||
|
||
String userName = intent.getStringExtra(KEY_ACCOUNT); | ||
String fileId = intent.getStringExtra(KEY_FILE_ID); | ||
|
@@ -2355,7 +2358,7 @@ private void openDeepLink(Uri uri) { | |
DeepLinkHandler.Match match = linkHandler.parseDeepLink(uri); | ||
if (match == null) { | ||
dismissLoadingDialog(); | ||
DisplayUtils.showSnackMessage(this, getString(R.string.invalid_url)); | ||
handleDeepLink(uri); | ||
} else if (match.getUsers().isEmpty()) { | ||
dismissLoadingDialog(); | ||
DisplayUtils.showSnackMessage(this, getString(R.string.associated_account_not_found)); | ||
|