Add hentainexus URL intent (#4588)

Add hentainexus URL intent
This commit is contained in:
ObserverOfTime 2020-10-12 15:50:33 +03:00 committed by GitHub
parent 019f12b61d
commit 50ed3b7583
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 74 additions and 1 deletions

View File

@ -0,0 +1,18 @@
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android">
<application>
<activity
android:name=".HentaiNexusActivity"
android:theme="@android:style/Theme.NoDisplay"
android:excludeFromRecents="true">
<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"
android:host="hentainexus.com"
android:pathPattern="/view/..*"/>
</intent-filter>
</activity>
</application>
</manifest>

View File

@ -5,7 +5,7 @@ ext {
extName = 'HentaiNexus' extName = 'HentaiNexus'
pkgNameSuffix = 'en.hentainexus' pkgNameSuffix = 'en.hentainexus'
extClass = '.HentaiNexus' extClass = '.HentaiNexus'
extVersionCode = 2 extVersionCode = 3
libVersion = '1.2' libVersion = '1.2'
containsNsfw = true containsNsfw = true
} }

View File

@ -2,8 +2,10 @@ package eu.kanade.tachiyomi.extension.en.hentainexus
import eu.kanade.tachiyomi.annotations.Nsfw import eu.kanade.tachiyomi.annotations.Nsfw
import eu.kanade.tachiyomi.network.GET import eu.kanade.tachiyomi.network.GET
import eu.kanade.tachiyomi.network.asObservableSuccess
import eu.kanade.tachiyomi.source.model.Filter import eu.kanade.tachiyomi.source.model.Filter
import eu.kanade.tachiyomi.source.model.FilterList import eu.kanade.tachiyomi.source.model.FilterList
import eu.kanade.tachiyomi.source.model.MangasPage
import eu.kanade.tachiyomi.source.model.Page import eu.kanade.tachiyomi.source.model.Page
import eu.kanade.tachiyomi.source.model.SChapter import eu.kanade.tachiyomi.source.model.SChapter
import eu.kanade.tachiyomi.source.model.SManga import eu.kanade.tachiyomi.source.model.SManga
@ -12,6 +14,7 @@ import okhttp3.OkHttpClient
import okhttp3.Request import okhttp3.Request
import org.jsoup.nodes.Document import org.jsoup.nodes.Document
import org.jsoup.nodes.Element import org.jsoup.nodes.Element
import rx.Observable
import java.net.URLEncoder import java.net.URLEncoder
@Nsfw @Nsfw
@ -92,6 +95,16 @@ class HentaiNexus : ParsedHttpSource() {
return GET(if (queryString != null) "$builtUrl?$queryString" else builtUrl) return GET(if (queryString != null) "$builtUrl?$queryString" else builtUrl)
} }
override fun fetchSearchManga(page: Int, query: String, filters: FilterList): Observable<MangasPage> {
return if (query.startsWith(PREFIX_ID_SEARCH)) {
val id = query.removePrefix(PREFIX_ID_SEARCH)
client.newCall(GET("$baseUrl/view/$id", headers)).asObservableSuccess()
.map { MangasPage(listOf(mangaDetailsParse(it).apply { url = "/view/$id" }), false) }
} else {
super.fetchSearchManga(page, query, filters)
}
}
override fun searchMangaSelector() = latestUpdatesSelector() override fun searchMangaSelector() = latestUpdatesSelector()
override fun searchMangaFromElement(element: Element) = latestUpdatesFromElement(element) override fun searchMangaFromElement(element: Element) = latestUpdatesFromElement(element)
@ -199,6 +212,10 @@ class HentaiNexus : ParsedHttpSource() {
class ArtistFilter : Filter.Text("Search by Artist (must be exact match)") class ArtistFilter : Filter.Text("Search by Artist (must be exact match)")
class TagFilter : Filter.Text("Search by Tag (must be exact match)") class TagFilter : Filter.Text("Search by Tag (must be exact match)")
companion object {
const val PREFIX_ID_SEARCH = "id:"
}
} }
private inline fun <reified T> Iterable<*>.findInstance() = find { it is T } as? T private inline fun <reified T> Iterable<*>.findInstance() = find { it is T } as? T

View File

@ -0,0 +1,38 @@
package eu.kanade.tachiyomi.extension.en.hentainexus
import android.app.Activity
import android.content.ActivityNotFoundException
import android.content.Intent
import android.os.Bundle
import android.util.Log
import kotlin.system.exitProcess
/**
* Springboard that accepts https://hentainexus.com/view/xxxx intents
* and redirects them to the main Tachiyomi process.
*/
class HentaiNexusActivity : Activity() {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
val pathSegments = intent?.data?.pathSegments
if (pathSegments != null && pathSegments.size > 1) {
val id = pathSegments[1]
val mainIntent = Intent().apply {
action = "eu.kanade.tachiyomi.SEARCH"
putExtra("query", "${HentaiNexus.PREFIX_ID_SEARCH}$id")
putExtra("filter", packageName)
}
try {
startActivity(mainIntent)
} catch (e: ActivityNotFoundException) {
Log.e("HentaiNexusActivity", e.toString())
}
} else {
Log.e("HentaiNexusActivity", "Could not parse URI from intent $intent")
}
finish()
exitProcess(0)
}
}