소스 검색

Deep link handler prototype

Signed-off-by: Chris Narkiewicz <hello@ezaquarii.com>
Chris Narkiewicz 5 년 전
부모
커밋
bcb1262064

+ 57 - 0
src/androidTest/java/com/nextcloud/client/files/DeepLinkHandlerTest.kt

@@ -0,0 +1,57 @@
+package com.nextcloud.client.files
+
+import org.junit.Test
+
+class DeepLinkHandlerTest {
+
+    @Test
+    fun valid_uri_can_be_handled_by_one_user() {
+        // GIVEN
+        //      uri matching allowed pattern
+        //      one user can open the file
+
+        // WHEN
+        //      deep link is handled
+
+        // THEN
+        //      file is opened immediately
+    }
+
+    @Test
+    fun valid_uri_can_be_handled_by_multiple_users() {
+        // GIVEN
+        //      uri matching allowed pattern
+        //      multiple users can open the file
+
+        // WHEN
+        //      deep link is handled
+
+        // THEN
+        //      user chooser dialog is opened
+    }
+
+    @Test
+    fun valid_uri_cannot_be_handled_by_any_user() {
+        // GIVEN
+        //      uri matching allowed pattern
+        //      no user can open given uri
+
+        // WHEN
+        //      deep link is handled
+
+        // THEN
+        //      deep link is ignored
+    }
+
+    @Test
+    fun invalid_uri_is_ignored() {
+        // GIVEN
+        //      file uri does not match allowed pattern
+
+        // WHEN
+        //      deep link is handled
+
+        // THEN
+        //      deep link is ignored
+    }
+}

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

@@ -0,0 +1,28 @@
+package com.nextcloud.client.files
+
+import android.content.Context
+import android.net.Uri
+import com.nextcloud.client.account.User
+import com.nextcloud.client.account.UserAccountManager
+
+
+class DeepLinkHandler(
+    private val context: Context,
+    private val userAccountManager: UserAccountManager,
+    private val onUserChoiceRequired: (users: List<User>, fileId: String)->Unit
+) {
+
+    /**
+     * Open deep link.
+     *
+     * If deep link can be opened immediately, new activity is launched.
+     * If link can be handled by multiple users, [onUserChoiceRequired] callback
+     * is invoked with list of matching users.
+     *
+     * @param uri Deep link received in incoming [Intent]
+     * @return true if deep link can be handled
+     */
+    fun openDeepLink(uri: Uri): Boolean {
+        throw NotImplementedError()
+    }
+}