From bcb126206426f8ca3e1ad98828791d3bc7b223ce Mon Sep 17 00:00:00 2001 From: Chris Narkiewicz Date: Sat, 23 May 2020 23:32:18 +0100 Subject: [PATCH] Deep link handler prototype Signed-off-by: Chris Narkiewicz --- .../client/files/DeepLinkHandlerTest.kt | 57 +++++++++++++++++++ .../nextcloud/client/files/DeepLinkHandler.kt | 28 +++++++++ 2 files changed, 85 insertions(+) create mode 100644 src/androidTest/java/com/nextcloud/client/files/DeepLinkHandlerTest.kt create mode 100644 src/main/java/com/nextcloud/client/files/DeepLinkHandler.kt diff --git a/src/androidTest/java/com/nextcloud/client/files/DeepLinkHandlerTest.kt b/src/androidTest/java/com/nextcloud/client/files/DeepLinkHandlerTest.kt new file mode 100644 index 0000000000..0456eff8fb --- /dev/null +++ b/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 + } +} diff --git a/src/main/java/com/nextcloud/client/files/DeepLinkHandler.kt b/src/main/java/com/nextcloud/client/files/DeepLinkHandler.kt new file mode 100644 index 0000000000..e140d9ef0f --- /dev/null +++ b/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, 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() + } +}