diff --git a/src/all/hitomi/AndroidManifest.xml b/src/all/hitomi/AndroidManifest.xml new file mode 100644 index 000000000..54a008461 --- /dev/null +++ b/src/all/hitomi/AndroidManifest.xml @@ -0,0 +1,18 @@ + + + + + + + + + + + + + diff --git a/src/all/hitomi/build.gradle b/src/all/hitomi/build.gradle index 425ac8bad..05bcae870 100644 --- a/src/all/hitomi/build.gradle +++ b/src/all/hitomi/build.gradle @@ -5,7 +5,7 @@ ext { extName = 'Hitomi.la' pkgNameSuffix = 'all.hitomi' extClass = '.HitomiFactory' - extVersionCode = 2 + extVersionCode = 3 libVersion = '1.2' containsNsfw = true } diff --git a/src/all/hitomi/src/eu/kanade/tachiyomi/extension/all/hitomi/Hitomi.kt b/src/all/hitomi/src/eu/kanade/tachiyomi/extension/all/hitomi/Hitomi.kt index 7d79e0a0f..60d0e9674 100644 --- a/src/all/hitomi/src/eu/kanade/tachiyomi/extension/all/hitomi/Hitomi.kt +++ b/src/all/hitomi/src/eu/kanade/tachiyomi/extension/all/hitomi/Hitomi.kt @@ -157,46 +157,52 @@ open class Hitomi(override val lang: String, private val nozomiLang: String) : H } override fun fetchSearchManga(page: Int, query: String, filters: FilterList): Observable { - val splitQuery = query.split(" ") - - val positive = splitQuery.filter { !it.startsWith('-') }.toMutableList() - if (nozomiLang != "all") positive += "language:$nozomiLang" - val negative = (splitQuery - positive).map { it.removePrefix("-") } - - // TODO Cache the results coming out of HitomiNozomi (this TODO dates back to TachiyomiEH) - val hn = Single.zip(tagIndexVersion(), galleryIndexVersion()) { tv, gv -> tv to gv } - .map { HitomiNozomi(client, it.first, it.second) } - - var base = if (positive.isEmpty()) { - hn.flatMap { n -> n.getGalleryIdsFromNozomi(null, "index", "all").map { n to it.toSet() } } + 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 q = positive.removeAt(0) - hn.flatMap { n -> n.getGalleryIdsForQuery(q).map { n to it.toSet() } } - } + val splitQuery = query.split(" ") - base = positive.fold(base) { acc, q -> - acc.flatMap { (nozomi, mangas) -> - nozomi.getGalleryIdsForQuery(q).map { - nozomi to mangas.intersect(it) + val positive = splitQuery.filter { !it.startsWith('-') }.toMutableList() + if (nozomiLang != "all") positive += "language:$nozomiLang" + val negative = (splitQuery - positive).map { it.removePrefix("-") } + + // TODO Cache the results coming out of HitomiNozomi (this TODO dates back to TachiyomiEH) + val hn = Single.zip(tagIndexVersion(), galleryIndexVersion()) { tv, gv -> tv to gv } + .map { HitomiNozomi(client, it.first, it.second) } + + var base = if (positive.isEmpty()) { + hn.flatMap { n -> n.getGalleryIdsFromNozomi(null, "index", "all").map { n to it.toSet() } } + } else { + val q = positive.removeAt(0) + hn.flatMap { n -> n.getGalleryIdsForQuery(q).map { n to it.toSet() } } + } + + base = positive.fold(base) { acc, q -> + acc.flatMap { (nozomi, mangas) -> + nozomi.getGalleryIdsForQuery(q).map { + nozomi to mangas.intersect(it) + } } } - } - base = negative.fold(base) { acc, q -> - acc.flatMap { (nozomi, mangas) -> - nozomi.getGalleryIdsForQuery(q).map { - nozomi to (mangas - it) + base = negative.fold(base) { acc, q -> + acc.flatMap { (nozomi, mangas) -> + nozomi.getGalleryIdsForQuery(q).map { + nozomi to (mangas - it) + } } } + + base.flatMap { (_, ids) -> + val chunks = ids.chunked(PAGE_SIZE) + + nozomiIdsToMangas(chunks[page - 1]).map { mangas -> + MangasPage(mangas, page < chunks.size) + } + }.toObservable() } - - return base.flatMap { (_, ids) -> - val chunks = ids.chunked(PAGE_SIZE) - - nozomiIdsToMangas(chunks[page - 1]).map { mangas -> - MangasPage(mangas, page < chunks.size) - } - }.toObservable() } override fun searchMangaRequest(page: Int, query: String, filters: FilterList) = 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" diff --git a/src/all/hitomi/src/eu/kanade/tachiyomi/extension/all/hitomi/HitomiActivity.kt b/src/all/hitomi/src/eu/kanade/tachiyomi/extension/all/hitomi/HitomiActivity.kt new file mode 100644 index 000000000..324595d34 --- /dev/null +++ b/src/all/hitomi/src/eu/kanade/tachiyomi/extension/all/hitomi/HitomiActivity.kt @@ -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) + } +}