Sample, handle noties.io deeplinks alongside with custom markwon scheme
This commit is contained in:
parent
0a6c5df0f2
commit
f0808e6997
@ -22,6 +22,7 @@
|
|||||||
<category android:name="android.intent.category.LAUNCHER" />
|
<category android:name="android.intent.category.LAUNCHER" />
|
||||||
</intent-filter>
|
</intent-filter>
|
||||||
|
|
||||||
|
<!-- local deeplink (with custom scheme) -->
|
||||||
<intent-filter>
|
<intent-filter>
|
||||||
<action android:name="android.intent.action.VIEW" />
|
<action android:name="android.intent.action.VIEW" />
|
||||||
|
|
||||||
@ -30,6 +31,21 @@
|
|||||||
|
|
||||||
<data android:scheme="${deeplink_scheme}" />
|
<data android:scheme="${deeplink_scheme}" />
|
||||||
</intent-filter>
|
</intent-filter>
|
||||||
|
|
||||||
|
<intent-filter>
|
||||||
|
<action android:name="android.intent.action.VIEW" />
|
||||||
|
|
||||||
|
<category android:name="android.intent.category.DEFAULT" />
|
||||||
|
<category android:name="android.intent.category.BROWSABLE" />
|
||||||
|
|
||||||
|
<data
|
||||||
|
android:host="noties.io"
|
||||||
|
android:scheme="https" />
|
||||||
|
|
||||||
|
<data android:pathPattern="/Markwon/app/sample/.*" />
|
||||||
|
<data android:pathPattern="/Markwon/app/search" />
|
||||||
|
|
||||||
|
</intent-filter>
|
||||||
</activity>
|
</activity>
|
||||||
|
|
||||||
<activity
|
<activity
|
||||||
|
@ -14,15 +14,35 @@ sealed class Deeplink {
|
|||||||
Debug.i(data)
|
Debug.i(data)
|
||||||
@Suppress("NAME_SHADOWING")
|
@Suppress("NAME_SHADOWING")
|
||||||
val data = data ?: return null
|
val data = data ?: return null
|
||||||
if (BuildConfig.DEEPLINK_SCHEME != data.scheme) return null
|
return when (data.scheme) {
|
||||||
return when (data.host) {
|
// local deeplink with custom scheme (`markwon://`)
|
||||||
// markwon://sample/20202827
|
BuildConfig.DEEPLINK_SCHEME -> {
|
||||||
|
when (data.host) {
|
||||||
"sample" -> parseSample(data.lastPathSegment)
|
"sample" -> parseSample(data.lastPathSegment)
|
||||||
// markwon://search?a=ext-latex&q=text
|
|
||||||
"search" -> parseSearch(data.query)
|
"search" -> parseSearch(data.query)
|
||||||
else -> null
|
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
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private fun parseSample(id: String?): Sample? {
|
private fun parseSample(id: String?): Sample? {
|
||||||
if (id == null) return null
|
if (id == null) return null
|
||||||
@ -33,6 +53,15 @@ sealed class Deeplink {
|
|||||||
Debug.i("query: '$query'")
|
Debug.i("query: '$query'")
|
||||||
|
|
||||||
val params = 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("&")
|
?.split("&")
|
||||||
?.map {
|
?.map {
|
||||||
val (k, v) = it.split("=")
|
val (k, v) = it.split("=")
|
||||||
@ -41,6 +70,8 @@ sealed class Deeplink {
|
|||||||
?.toMap()
|
?.toMap()
|
||||||
?: return null
|
?: return null
|
||||||
|
|
||||||
|
Debug.i("params: $params")
|
||||||
|
|
||||||
val artifact = params["a"]
|
val artifact = params["a"]
|
||||||
val tag = params["t"]
|
val tag = params["t"]
|
||||||
val search = params["q"]
|
val search = params["q"]
|
||||||
|
Loading…
x
Reference in New Issue
Block a user