MyHentaiGallery - Implement Url Intent and add Latest (#2788)

MyHentaiGallery - Implement Url Intent and add Latest
This commit is contained in:
Thiago França da Silva 2020-04-23 23:17:14 -03:00 committed by GitHub
parent eefbc2896b
commit 71953e59c0
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 88 additions and 8 deletions

View File

@ -0,0 +1,19 @@
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android">
<application>
<activity
android:name=".MyHentaiGalleryUrlActivity"
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="myhentaigallery.com"
android:pathPattern="/gallery/thumbnails/..*" />
</intent-filter>
</activity>
</application>
</manifest>

View File

@ -5,7 +5,7 @@ ext {
appName = 'Tachiyomi: MyHentaiGallery'
pkgNameSuffix = 'en.myhentaigallery'
extClass = '.MyHentaiGallery'
extVersionCode = 1
extVersionCode = 2
libVersion = '1.2'
}

View File

@ -1,6 +1,7 @@
package eu.kanade.tachiyomi.extension.en.myhentaigallery
import eu.kanade.tachiyomi.network.GET
import eu.kanade.tachiyomi.network.asObservableSuccess
import eu.kanade.tachiyomi.source.model.*
import eu.kanade.tachiyomi.source.online.ParsedHttpSource
import okhttp3.HttpUrl
@ -9,6 +10,7 @@ import okhttp3.Request
import okhttp3.Response
import org.jsoup.nodes.Document
import org.jsoup.nodes.Element
import rx.Observable
class MyHentaiGallery : ParsedHttpSource() {
@ -18,7 +20,7 @@ class MyHentaiGallery : ParsedHttpSource() {
override val lang = "en"
override val supportsLatest = false
override val supportsLatest = true
override val client: OkHttpClient = network.cloudflareClient
@ -42,18 +44,35 @@ class MyHentaiGallery : ParsedHttpSource() {
// Latest
override fun latestUpdatesRequest(page: Int): Request = throw UnsupportedOperationException("Not used")
override fun latestUpdatesRequest(page: Int): Request = GET("$baseUrl/gallery/$page")
override fun latestUpdatesParse(response: Response): MangasPage = throw UnsupportedOperationException("Not used")
override fun latestUpdatesSelector() = popularMangaSelector()
override fun latestUpdatesSelector() = throw UnsupportedOperationException("Not used")
override fun latestUpdatesFromElement(element: Element): SManga = popularMangaFromElement(element)
override fun latestUpdatesFromElement(element: Element): SManga = throw UnsupportedOperationException("Not used")
override fun latestUpdatesNextPageSelector() = throw UnsupportedOperationException("Not used")
override fun latestUpdatesNextPageSelector() = popularMangaNextPageSelector()
// Search
private fun searchMangaByIdRequest(id: String) = GET("$baseUrl/gallery/thumbnails/$id", headers)
private fun searchMangaByIdParse(response: Response, id: String): MangasPage {
val details = mangaDetailsParse(response)
details.url = "/gallery/thumbnails/$id"
return MangasPage(listOf(details), false)
}
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(searchMangaByIdRequest(id))
.asObservableSuccess()
.map { response -> searchMangaByIdParse(response, id) }
} else {
super.fetchSearchManga(page, query, filters)
}
}
override fun searchMangaRequest(page: Int, query: String, filters: FilterList): Request {
return if (query.isNotBlank()) {
GET("$baseUrl/search/$page?query=$query", headers)
@ -212,4 +231,8 @@ class MyHentaiGallery : ParsedHttpSource() {
Filter.Select<String>(displayName, vals.map { it.first }.toTypedArray()) {
fun toUriPart() = vals[state].second
}
companion object {
const val PREFIX_ID_SEARCH = "id:"
}
}

View File

@ -0,0 +1,38 @@
package eu.kanade.tachiyomi.extension.en.myhentaigallery
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://myhentaigallery.com/gallery/thumbnails/xxxxx intents and redirects them to
* the main Tachiyomi process.
*/
class MyHentaiGalleryUrlActivity : Activity() {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
val pathSegments = intent?.data?.pathSegments
if (pathSegments != null && pathSegments.size > 2) {
val id = pathSegments[2]
val mainIntent = Intent().apply {
action = "eu.kanade.tachiyomi.SEARCH"
putExtra("query", "${MyHentaiGallery.PREFIX_ID_SEARCH}$id")
putExtra("filter", packageName)
}
try {
startActivity(mainIntent)
} catch (e: ActivityNotFoundException) {
Log.e("MyHentaiGalUrlActivity", e.toString())
}
} else {
Log.e("MyHentaiGalUrlActivity", "could not parse uri from intent $intent")
}
finish()
exitProcess(0)
}
}