mirror of
https://github.com/nextcloud/android.git
synced 2024-11-21 20:55:31 +03:00
Merge pull request #13057 from nextcloud/nmc/deepLink
Added deep link support for screens navigation
This commit is contained in:
commit
e9cd67e237
5 changed files with 88 additions and 4 deletions
|
@ -2,6 +2,7 @@
|
|||
<!--
|
||||
~ Nextcloud - Android Client
|
||||
~
|
||||
~ SPDX-FileCopyrightText: 2024 TSI-mc <surinder.kumar@t-systems.com>
|
||||
~ 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
|
||||
|
|
|
@ -0,0 +1,35 @@
|
|||
/*
|
||||
* Nextcloud - Android Client
|
||||
*
|
||||
* SPDX-FileCopyrightText: 2024 TSI-mc <surinder.kumar@t-systems.com>
|
||||
* 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 }
|
||||
}
|
||||
}
|
|
@ -33,6 +33,9 @@ class DeepLinkHandler(
|
|||
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) }
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
/*
|
||||
* Nextcloud - Android Client
|
||||
*
|
||||
* SPDX-FileCopyrightText: 2021 TSI-mc
|
||||
* SPDX-FileCopyrightText: 2021-2024 TSI-mc <surinder.kumar@t-systems.com>
|
||||
* SPDX-FileCopyrightText: 2020 Infomaniak Network SA
|
||||
* SPDX-FileCopyrightText: 2020 Chris Narkiewicz <hello@ezaquarii.com>
|
||||
* SPDX-FileCopyrightText: 2017 Tobias Kaminsky <tobias@kaminsky.me>
|
||||
|
@ -51,6 +51,7 @@ import com.google.android.material.navigation.NavigationView;
|
|||
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 java.util.Optional;
|
|||
|
||||
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 @@ public abstract class DrawerActivity extends ToolbarActivity
|
|||
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));
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
/*
|
||||
* Nextcloud - Android Client
|
||||
*
|
||||
* SPDX-FileCopyrightText: 2023 TSI-mc
|
||||
* SPDX-FileCopyrightText: 2023-2024 TSI-mc <surinder.kumar@t-systems.com>
|
||||
* SPDX-FileCopyrightText: 2023 Archontis E. Kostis <arxontisk02@gmail.com>
|
||||
* SPDX-FileCopyrightText: 2019 Chris Narkiewicz <hello@ezaquarii.com>
|
||||
* SPDX-FileCopyrightText: 2018-2022 Tobias Kaminsky <tobias@kaminsky.me>
|
||||
|
@ -2324,7 +2324,10 @@ public class FileDisplayActivity extends FileActivity
|
|||
}
|
||||
|
||||
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 @@ public class FileDisplayActivity extends FileActivity
|
|||
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));
|
||||
|
|
Loading…
Reference in a new issue