Add hitomi.la URL intent (#4587)

Add hitomi.la URL intent
This commit is contained in:
ObserverOfTime 2020-10-12 15:49:56 +03:00 committed by GitHub
parent 36f5609434
commit 019f12b61d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 97 additions and 33 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=".HitomiActivity"
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="hitomi.la"
android:pathPattern="/cg/..*"/>
</intent-filter>
</activity>
</application>
</manifest>

View File

@ -5,7 +5,7 @@ ext {
extName = 'Hitomi.la'
pkgNameSuffix = 'all.hitomi'
extClass = '.HitomiFactory'
extVersionCode = 2
extVersionCode = 3
libVersion = '1.2'
containsNsfw = true
}

View File

@ -157,6 +157,11 @@ open class Hitomi(override val lang: String, private val nozomiLang: String) : H
}
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/cg/$id", headers)).asObservableSuccess()
.map { MangasPage(listOf(mangaDetailsParse(it).apply { url = "/cg/$id" }), false) }
} else {
val splitQuery = query.split(" ")
val positive = splitQuery.filter { !it.startsWith('-') }.toMutableList()
@ -190,7 +195,7 @@ open class Hitomi(override val lang: String, private val nozomiLang: String) : H
}
}
return base.flatMap { (_, ids) ->
base.flatMap { (_, ids) ->
val chunks = ids.chunked(PAGE_SIZE)
nozomiIdsToMangas(chunks[page - 1]).map { mangas ->
@ -198,6 +203,7 @@ open class Hitomi(override val lang: String, private val nozomiLang: String) : H
}
}.toObservable()
}
}
override fun searchMangaRequest(page: Int, query: String, filters: FilterList) = throw UnsupportedOperationException("Not used")
override fun searchMangaParse(response: Response) = throw UnsupportedOperationException("Not used")
@ -307,6 +313,8 @@ open class Hitomi(override val lang: String, private val nozomiLang: String) : H
private const val INDEX_VERSION_CACHE_TIME_MS = 1000 * 60 * 10
private const val PAGE_SIZE = 25
const val PREFIX_ID_SEARCH = "id:"
// From HitomiSearchMetaData
const val LTN_BASE_URL = "https://ltn.hitomi.la"
const val BASE_URL = "https://hitomi.la"

View File

@ -0,0 +1,38 @@
package eu.kanade.tachiyomi.extension.all.hitomi
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://hitomi.la/cg/xxxx intents
* and redirects them to the main Tachiyomi process.
*/
class HitomiActivity : 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", "${Hitomi.PREFIX_ID_SEARCH}$id")
putExtra("filter", packageName)
}
try {
startActivity(mainIntent)
} catch (e: ActivityNotFoundException) {
Log.e("HitomiActivity", e.toString())
}
} else {
Log.e("HitomiActivity", "Could not parse URI from intent $intent")
}
finish()
exitProcess(0)
}
}