From b060c25091eefe89cbda42e001e8e5a9855ed379 Mon Sep 17 00:00:00 2001 From: ObserverOfTime Date: Sun, 19 Dec 2021 14:04:06 +0200 Subject: [PATCH] Monochrome: add URL intent (#10143) --- .../monochrome/default/AndroidManifest.xml | 21 +++++++++ .../monochromecustom/AndroidManifest.xml | 3 ++ .../multisrc/monochrome/MonochromeAPI.kt | 2 + .../multisrc/monochrome/MonochromeActivity.kt | 35 ++++++++++++++ .../multisrc/monochrome/MonochromeCMS.kt | 47 ++++++++++++------- .../monochrome/MonochromeGenerator.kt | 2 +- 6 files changed, 92 insertions(+), 18 deletions(-) create mode 100644 multisrc/overrides/monochrome/default/AndroidManifest.xml create mode 100644 multisrc/overrides/monochrome/monochromecustom/AndroidManifest.xml create mode 100644 multisrc/src/main/java/eu/kanade/tachiyomi/multisrc/monochrome/MonochromeActivity.kt diff --git a/multisrc/overrides/monochrome/default/AndroidManifest.xml b/multisrc/overrides/monochrome/default/AndroidManifest.xml new file mode 100644 index 000000000..c1dc6e6ea --- /dev/null +++ b/multisrc/overrides/monochrome/default/AndroidManifest.xml @@ -0,0 +1,21 @@ + + + + + + + + + + + + + + + + diff --git a/multisrc/overrides/monochrome/monochromecustom/AndroidManifest.xml b/multisrc/overrides/monochrome/monochromecustom/AndroidManifest.xml new file mode 100644 index 000000000..e67f63d35 --- /dev/null +++ b/multisrc/overrides/monochrome/monochromecustom/AndroidManifest.xml @@ -0,0 +1,3 @@ + + + diff --git a/multisrc/src/main/java/eu/kanade/tachiyomi/multisrc/monochrome/MonochromeAPI.kt b/multisrc/src/main/java/eu/kanade/tachiyomi/multisrc/monochrome/MonochromeAPI.kt index c4a529db8..6479e6c29 100644 --- a/multisrc/src/main/java/eu/kanade/tachiyomi/multisrc/monochrome/MonochromeAPI.kt +++ b/multisrc/src/main/java/eu/kanade/tachiyomi/multisrc/monochrome/MonochromeAPI.kt @@ -5,6 +5,8 @@ import java.text.DecimalFormat import java.text.SimpleDateFormat import java.util.Locale +internal const val UUID_QUERY = "uuid:" + private const val ISO_DATE = "yyyy-MM-dd'T'HH:mm:ss.SSSSSS" private val dateFormat = SimpleDateFormat(ISO_DATE, Locale.ROOT) diff --git a/multisrc/src/main/java/eu/kanade/tachiyomi/multisrc/monochrome/MonochromeActivity.kt b/multisrc/src/main/java/eu/kanade/tachiyomi/multisrc/monochrome/MonochromeActivity.kt new file mode 100644 index 000000000..7e7ee8ddb --- /dev/null +++ b/multisrc/src/main/java/eu/kanade/tachiyomi/multisrc/monochrome/MonochromeActivity.kt @@ -0,0 +1,35 @@ +package eu.kanade.tachiyomi.multisrc.monochrome + +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 `{baseUrl}/manga/{uuid}` + * intents and redirects them to the main Tachiyomi process. + */ +class MonochromeActivity : Activity() { + override fun onCreate(savedInstanceState: Bundle?) { + super.onCreate(savedInstanceState) + val segments = intent?.data?.pathSegments + if (segments != null && segments.size > 1) { + val activity = Intent().apply { + action = "eu.kanade.tachiyomi.SEARCH" + putExtra("query", UUID_QUERY + segments[1]) + putExtra("filter", packageName) + } + try { + startActivity(activity) + } catch (ex: ActivityNotFoundException) { + Log.e("MonochromeActivity", ex.message, ex) + } + } else { + Log.e("MonochromeActivity", "Failed to parse URI from intent: $intent") + } + finish() + exitProcess(0) + } +} diff --git a/multisrc/src/main/java/eu/kanade/tachiyomi/multisrc/monochrome/MonochromeCMS.kt b/multisrc/src/main/java/eu/kanade/tachiyomi/multisrc/monochrome/MonochromeCMS.kt index de12babac..eabb7f534 100644 --- a/multisrc/src/main/java/eu/kanade/tachiyomi/multisrc/monochrome/MonochromeCMS.kt +++ b/multisrc/src/main/java/eu/kanade/tachiyomi/multisrc/monochrome/MonochromeCMS.kt @@ -8,6 +8,7 @@ import eu.kanade.tachiyomi.source.model.Page import eu.kanade.tachiyomi.source.model.SChapter import eu.kanade.tachiyomi.source.model.SManga import eu.kanade.tachiyomi.source.online.HttpSource +import kotlinx.serialization.ExperimentalSerializationApi import kotlinx.serialization.decodeFromString import kotlinx.serialization.json.Json import okhttp3.Headers @@ -15,6 +16,7 @@ import okhttp3.Response import rx.Observable import uy.kohesive.injekt.injectLazy +@ExperimentalSerializationApi open class MonochromeCMS( override val name: String, override val baseUrl: String, @@ -38,25 +40,21 @@ open class MonochromeCMS( GET("$apiUrl/manga?limit=10&offset=${10 * (page - 1)}&title=$query", headers) override fun searchMangaParse(response: Response) = - response.decode().let { results -> - val mp = results.map { - SManga.create().apply { - url = it.id - title = it.title - author = it.author - artist = it.artist - description = it.description - thumbnail_url = apiUrl + it.cover - status = when (it.status) { - "ongoing", "hiatus" -> SManga.ONGOING - "completed", "cancelled" -> SManga.COMPLETED - else -> SManga.UNKNOWN - } - } - } - MangasPage(mp, results.hasNext) + response.decode().let { + MangasPage(it.map(::mangaFromAPI), it.hasNext) } + override fun fetchSearchManga( + page: Int, query: String, filters: FilterList + ): Observable { + if (!query.startsWith(UUID_QUERY)) + return super.fetchSearchManga(page, query, filters) + val req = GET("$apiUrl/manga/${query.substringAfter(UUID_QUERY)}") + return client.newCall(req).asObservableSuccess().map { + MangasPage(listOf(mangaFromAPI(it.decode())), false) + } + } + // Request the actual manga URL for the webview override fun mangaDetailsRequest(manga: SManga) = GET("$baseUrl/manga/${manga.url}", headers) @@ -88,6 +86,21 @@ open class MonochromeCMS( return Observable.just(pages) } + private fun mangaFromAPI(manga: Manga) = + SManga.create().apply { + url = manga.id + title = manga.title + author = manga.author + artist = manga.artist + description = manga.description + thumbnail_url = apiUrl + manga.cover + status = when (manga.status) { + "ongoing", "hiatus" -> SManga.ONGOING + "completed", "cancelled" -> SManga.COMPLETED + else -> SManga.UNKNOWN + } + } + private inline fun Response.decode() = json.decodeFromString(body!!.string()) diff --git a/multisrc/src/main/java/eu/kanade/tachiyomi/multisrc/monochrome/MonochromeGenerator.kt b/multisrc/src/main/java/eu/kanade/tachiyomi/multisrc/monochrome/MonochromeGenerator.kt index 909be55b6..dd2d4ad1f 100644 --- a/multisrc/src/main/java/eu/kanade/tachiyomi/multisrc/monochrome/MonochromeGenerator.kt +++ b/multisrc/src/main/java/eu/kanade/tachiyomi/multisrc/monochrome/MonochromeGenerator.kt @@ -8,7 +8,7 @@ class MonochromeGenerator : ThemeSourceGenerator { override val themeClass = "MonochromeCMS" - override val baseVersionCode = 1 + override val baseVersionCode = 2 override val sources = listOf( SingleLang("Monochrome Scans", "https://manga.d34d.one", "en"),