From f0808e6997e837a24e47e59319bb560df389ca48 Mon Sep 17 00:00:00 2001 From: Dimitry Ivanov Date: Wed, 29 Jul 2020 13:20:28 +0300 Subject: [PATCH] Sample, handle noties.io deeplinks alongside with custom markwon scheme --- app-sample/src/main/AndroidManifest.xml | 16 +++++++ .../io/noties/markwon/app/sample/Deeplink.kt | 43 ++++++++++++++++--- 2 files changed, 53 insertions(+), 6 deletions(-) diff --git a/app-sample/src/main/AndroidManifest.xml b/app-sample/src/main/AndroidManifest.xml index 411c6a42..82902900 100644 --- a/app-sample/src/main/AndroidManifest.xml +++ b/app-sample/src/main/AndroidManifest.xml @@ -22,6 +22,7 @@ + @@ -30,6 +31,21 @@ + + + + + + + + + + + + + parseSample(data.lastPathSegment) - // markwon://search?a=ext-latex&q=text - "search" -> parseSearch(data.query) + return when (data.scheme) { + // local deeplink with custom scheme (`markwon://`) + BuildConfig.DEEPLINK_SCHEME -> { + when (data.host) { + "sample" -> parseSample(data.lastPathSegment) + "search" -> parseSearch(data.query) + else -> null + } + } + // https deeplink, `https://noties.io/Markwon/sample` + "https" -> { + // https://noties.io/Markwon/app/sample/ID + // https://noties.io/Markwon/app/search?a=core + val segments = data.pathSegments + if (segments.size == 3 + && "Markwon" == segments[0] + && "app" == segments[1]) { + when (segments[2]) { + "sample" -> parseSample(data.lastPathSegment) + "search" -> parseSearch(data.query) + else -> null + } + } else { + null + } + } else -> null } } @@ -33,6 +53,15 @@ sealed class Deeplink { Debug.i("query: '$query'") val params = query + ?.let { + // `https:.*` has query with `search?a=core` + val index = it.indexOf('?') + if (index > -1) { + it.substring(index + 1) + } else { + it + } + } ?.split("&") ?.map { val (k, v) = it.split("=") @@ -41,6 +70,8 @@ sealed class Deeplink { ?.toMap() ?: return null + Debug.i("params: $params") + val artifact = params["a"] val tag = params["t"] val search = params["q"]