Add Deep Link Support to Anchira (#1283)

Add Deep Link Support
This commit is contained in:
BrutuZ 2024-02-16 03:29:35 -03:00 committed by GitHub
parent 6c9a20f31e
commit 6399255e78
4 changed files with 80 additions and 1 deletions

View File

@ -0,0 +1,22 @@
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android">
<application>
<activity
android:name=".en.anchira.AnchiraUrlActivity"
android:excludeFromRecents="true"
android:exported="true"
android:theme="@android:style/Theme.NoDisplay">
<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:scheme="https" />
<data android:host="anchira.to" />
<data android:pathPattern="/g/.*/..*" />
</intent-filter>
</activity>
</application>
</manifest>

View File

@ -1,7 +1,7 @@
ext {
extName = 'Anchira'
extClass = '.Anchira'
extVersionCode = 7
extVersionCode = 8
isNsfw = true
}

View File

@ -9,6 +9,7 @@ import androidx.preference.SwitchPreferenceCompat
import eu.kanade.tachiyomi.extension.en.anchira.AnchiraHelper.getPathFromUrl
import eu.kanade.tachiyomi.extension.en.anchira.AnchiraHelper.prepareTags
import eu.kanade.tachiyomi.network.GET
import eu.kanade.tachiyomi.network.asObservableSuccess
import eu.kanade.tachiyomi.network.interceptor.rateLimit
import eu.kanade.tachiyomi.source.ConfigurableSource
import eu.kanade.tachiyomi.source.model.Filter
@ -27,6 +28,7 @@ import okhttp3.Interceptor
import okhttp3.OkHttpClient
import okhttp3.Request
import okhttp3.Response
import rx.Observable
import uy.kohesive.injekt.Injekt
import uy.kohesive.injekt.api.get
import java.io.IOException
@ -95,6 +97,25 @@ class Anchira : HttpSource(), ConfigurableSource {
// Search
override fun fetchSearchManga(
page: Int,
query: String,
filters: FilterList,
): Observable<MangasPage> {
return if (query.startsWith(SLUG_SEARCH_PREFIX)) {
// url deep link
val idKey = query.substringAfter(SLUG_SEARCH_PREFIX)
val manga = SManga.create().apply { this.url = "/g/$idKey" }
fetchMangaDetails(manga).map {
MangasPage(listOf(it), false)
}
} else {
// regular filtering without text search
client.newCall(searchMangaRequest(page, query, filters))
.asObservableSuccess()
.map(::searchMangaParse)
}
}
override fun searchMangaRequest(page: Int, query: String, filters: FilterList): Request {
var url = libraryUrl.toHttpUrl().newBuilder()
@ -342,6 +363,7 @@ class Anchira : HttpSource(), ConfigurableSource {
}
companion object {
const val SLUG_SEARCH_PREFIX = "id:"
private const val IMAGE_QUALITY_PREF = "image_quality"
private const val OPEN_SOURCE_PREF = "use_manga_source"
private const val USE_TAG_GROUPING = "use_tag_grouping"

View File

@ -0,0 +1,35 @@
package eu.kanade.tachiyomi.extension.en.anchira
import android.app.Activity
import android.content.ActivityNotFoundException
import android.content.Intent
import android.os.Bundle
import android.util.Log
import kotlin.system.exitProcess
class AnchiraUrlActivity : Activity() {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
val pathSegments = intent?.data?.pathSegments
if (pathSegments != null && pathSegments.size > 2) {
val id = pathSegments[1]
val key = pathSegments[2]
val mainIntent = Intent().apply {
action = "eu.kanade.tachiyomi.SEARCH"
putExtra("query", "${Anchira.SLUG_SEARCH_PREFIX}$id/$key")
putExtra("filter", packageName)
}
try {
startActivity(mainIntent)
} catch (e: ActivityNotFoundException) {
Log.e("AnchiraUrlActivity", e.toString())
}
} else {
Log.e("AnchiraUrlActivity", "could not parse uri from intent $intent")
}
finish()
exitProcess(0)
}
}