浏览代码

Added app deep link support for screens navigation

Signed-off-by: A117870935 <surinder.kumar@t-systems.com>
A117870935 1 年之前
父节点
当前提交
50f06834ab

+ 3 - 0
app/src/main/AndroidManifest.xml

@@ -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

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

@@ -0,0 +1,28 @@
+/*
+ * 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
+
+// deep link url format should be: https://example.com/app/<constants>
+object DeepLinkConstants {
+    const val OPEN_FILES = "openFiles"
+    const val OPEN_FAVORITES = "openFavorites"
+    const val OPEN_MEDIA = "openMedia"
+    const val OPEN_SHARED = "openShared"
+    const val OPEN_OFFLINE = "openOffline"
+    const val OPEN_NOTIFICATIONS = "openNotifications"
+    const val OPEN_DELETED = "openDeleted"
+    const val OPEN_SETTINGS = "openSettings"
+    const val OPEN_AUTO_UPLOAD = "openAutoUpload"
+
+    // for external url the url should have the following format
+    // https://example.com/app/openUrl?url=<url_to_open>
+    const val OPEN_EXTERNAL_URL = "openUrl"
+
+    const val ACTION_CREATE_NEW = "createNew"
+    const val ACTION_APP_UPDATE = "checkAppUpdate"
+}

+ 60 - 1
app/src/main/java/com/owncloud/android/ui/activity/DrawerActivity.java

@@ -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,61 @@ public abstract class DrawerActivity extends ToolbarActivity
             t.start();
         }
     }
+
+    protected void handleDeepLink(@NonNull Uri uri) {
+        String path = uri.getLastPathSegment();
+        if (path != null) {
+            switch (path) {
+                case DeepLinkConstants.OPEN_FILES:
+                    handleNavItemClickEvent(R.id.nav_all_files);
+                    break;
+                case DeepLinkConstants.OPEN_FAVORITES:
+                    handleNavItemClickEvent(R.id.nav_favorites);
+                    break;
+                case DeepLinkConstants.OPEN_MEDIA:
+                    handleNavItemClickEvent(R.id.nav_gallery);
+                    break;
+                case DeepLinkConstants.OPEN_SHARED:
+                    handleNavItemClickEvent(R.id.nav_shared);
+                    break;
+                case DeepLinkConstants.OPEN_OFFLINE:
+                    handleNavItemClickEvent(R.id.nav_on_device);
+                    break;
+                case DeepLinkConstants.OPEN_NOTIFICATIONS:
+                    handleNavItemClickEvent(R.id.nav_notifications);
+                    break;
+                case DeepLinkConstants.OPEN_DELETED:
+                    handleNavItemClickEvent(R.id.nav_trashbin);
+                    break;
+                case DeepLinkConstants.OPEN_SETTINGS:
+                    handleNavItemClickEvent(R.id.nav_settings);
+                    break;
+                case DeepLinkConstants.OPEN_AUTO_UPLOAD:
+                    startActivity(SyncedFoldersActivity.class);
+                    break;
+                case DeepLinkConstants.OPEN_EXTERNAL_URL:
+                    Intent intent = new Intent(Intent.ACTION_VIEW,
+                                               Uri.parse(uri.getQueryParameter("url")));
+                    startActivity(intent);
+                    break;
+                case DeepLinkConstants.ACTION_CREATE_NEW:
+                    findViewById(R.id.fab_main).callOnClick();
+                    break;
+                case DeepLinkConstants.ACTION_APP_UPDATE:
+                    openAppStore(getPackageName(), false);
+                    break;
+                default:
+                    DisplayUtils.showSnackMessage(this, getString(R.string.invalid_url));
+                    break;
+            }
+        }
+    }
+
+    private void handleNavItemClickEvent(@IdRes int menuItemId) {
+        if (mNavigationView == null) {
+            mNavigationView = findViewById(R.id.nav_view);
+        }
+        Menu navMenu = mNavigationView.getMenu();
+        onNavigationItemClicked(navMenu.findItem(menuItemId));
+    }
 }

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

@@ -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>
@@ -2355,7 +2355,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));