Add hentai2read URL intent (#4591)

Add hentai2read URL intent
This commit is contained in:
ObserverOfTime 2020-10-12 15:51:09 +03:00 committed by GitHub
parent 50ed3b7583
commit 672cdad094
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 69 additions and 7 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=".Hentai2ReadActivity"
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="hentai2read.com"
android:pathPattern="/..*"/>
</intent-filter>
</activity>
</application>
</manifest>

View File

@ -5,7 +5,7 @@ ext {
extName = 'Hentai2Read'
pkgNameSuffix = 'en.hentai2read'
extClass = '.Hentai2Read'
extVersionCode = 9
extVersionCode = 10
libVersion = '1.2'
containsNsfw = true
}

View File

@ -39,6 +39,8 @@ class Hentai2Read : ParsedHttpSource() {
companion object {
const val imageBaseUrl = "https://static.hentaicdn.com/hentai"
const val PREFIX_ID_SEARCH = "id:"
val pagesUrlPattern by lazy {
Pattern.compile("""'images' : \[\"(.*?)[,]?\"\]""")
}
@ -77,12 +79,15 @@ class Hentai2Read : ParsedHttpSource() {
override fun latestUpdatesNextPageSelector() = popularMangaNextPageSelector()
override fun fetchSearchManga(page: Int, query: String, filters: FilterList): Observable<MangasPage> {
val search = requestSearch(page, query, filters)
return client.newCall(search.first)
.asObservableSuccess()
.map { response ->
parseSearch(response, page, search.second)
}
return if (query.startsWith(PREFIX_ID_SEARCH)) {
val id = query.removePrefix(PREFIX_ID_SEARCH)
client.newCall(GET("$baseUrl/$id/", headers)).asObservableSuccess()
.map { MangasPage(listOf(mangaDetailsParse(it).apply { url = "/$id/" }), false) }
} else {
val search = requestSearch(page, query, filters)
client.newCall(search.first).asObservableSuccess()
.map { parseSearch(it, page, search.second) }
}
}
private fun requestSearch(page: Int, query: String, filters: FilterList): Pair<Request, String?> {

View File

@ -0,0 +1,39 @@
package eu.kanade.tachiyomi.extension.en.hentai2read
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://hentai2read.com/xxxx intents
* and redirects them to the main Tachiyomi process.
*/
class Hentai2ReadActivity : Activity() {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
val pathSegments = intent?.data?.pathSegments
if (pathSegments != null) {
// TODO: filter standard paths
val id = pathSegments[0]
val mainIntent = Intent().apply {
action = "eu.kanade.tachiyomi.SEARCH"
putExtra("query", "${Hentai2Read.PREFIX_ID_SEARCH}$id")
putExtra("filter", packageName)
}
try {
startActivity(mainIntent)
} catch (e: ActivityNotFoundException) {
Log.e("Hentai2ReadActivity", e.toString())
}
} else {
Log.e("Hentai2ReadActivity", "Could not parse URI from intent $intent")
}
finish()
exitProcess(0)
}
}