diff --git a/src/en/guya/AndroidManifest.xml b/src/en/guya/AndroidManifest.xml new file mode 100644 index 000000000..e56b70463 --- /dev/null +++ b/src/en/guya/AndroidManifest.xml @@ -0,0 +1,19 @@ + + + + + + + + + + + + + diff --git a/src/en/guya/build.gradle b/src/en/guya/build.gradle index 2dd05931b..1b5bf3638 100644 --- a/src/en/guya/build.gradle +++ b/src/en/guya/build.gradle @@ -5,7 +5,7 @@ ext { appName = 'Tachiyomi: Guya' pkgNameSuffix = "en.guya" extClass = '.Guya' - extVersionCode = 9 + extVersionCode = 10 libVersion = '1.2' } diff --git a/src/en/guya/src/eu/kanade/tachiyomi/extension/en/guya/Guya.kt b/src/en/guya/src/eu/kanade/tachiyomi/extension/en/guya/Guya.kt index 2a68899b0..3ff3199f8 100644 --- a/src/en/guya/src/eu/kanade/tachiyomi/extension/en/guya/Guya.kt +++ b/src/en/guya/src/eu/kanade/tachiyomi/extension/en/guya/Guya.kt @@ -131,11 +131,20 @@ open class Guya() : ConfigurableSource, HttpSource() { } override fun fetchSearchManga(page: Int, query: String, filters: FilterList): Observable { - return client.newCall(searchMangaRequest(page, query, filters)) - .asObservableSuccess() - .map { response -> - searchMangaParse(response, query) - } + return if ( query.startsWith(SLUG_PREFIX)) { + val slug = query.removePrefix(SLUG_PREFIX) + client.newCall(searchMangaRequest(page, query, filters)) + .asObservableSuccess() + .map { response -> + searchMangaParseWithSlug(response, slug) + } + } else { + client.newCall(searchMangaRequest(page, query, filters)) + .asObservableSuccess() + .map { response -> + searchMangaParse(response, query) + } + } } override fun searchMangaRequest(page: Int, query: String, filters: FilterList): Request { @@ -146,6 +155,24 @@ open class Guya() : ConfigurableSource, HttpSource() { throw Exception("Unused.") } + private fun searchMangaParseWithSlug(response: Response, slug: String) : MangasPage { + val results = JSONObject(response.body()!!.string()) + val mangaIter = results.keys() + val truncatedJSON = JSONObject() + + while (mangaIter.hasNext()) { + val mangaTitle = mangaIter.next() + val mangaDetails = results.getJSONObject(mangaTitle) + + if (mangaDetails.get("slug") == slug) { + truncatedJSON.put(mangaTitle, mangaDetails) + } + + } + + return parseManga(truncatedJSON) + } + private fun searchMangaParse(response: Response, query: String): MangasPage { val res = response.body()!!.string() val json = JSONObject(res) @@ -393,4 +420,7 @@ open class Guya() : ConfigurableSource, HttpSource() { throw Exception("Latest updates not supported.") } + companion object { + const val SLUG_PREFIX = "slug:" + } } diff --git a/src/en/guya/src/eu/kanade/tachiyomi/extension/en/guya/GuyaUrlActivity.kt b/src/en/guya/src/eu/kanade/tachiyomi/extension/en/guya/GuyaUrlActivity.kt new file mode 100644 index 000000000..3d887c79d --- /dev/null +++ b/src/en/guya/src/eu/kanade/tachiyomi/extension/en/guya/GuyaUrlActivity.kt @@ -0,0 +1,44 @@ +package eu.kanade.tachiyomi.extension.en.guya + +import android.app.Activity +import android.content.ActivityNotFoundException +import android.content.Intent +import android.os.Bundle +import android.util.Log +import kotlin.system.exitProcess + +/** + * Accepts https://guya.moe/read/manga/xyz intents + * + * Added due to requests from various users to allow for opening of titles when given the + * Guya URL whilst on mobile. + */ +class GuyaUrlActivity : Activity() { + + override fun onCreate(savedInstanceState: Bundle?) { + super.onCreate(savedInstanceState) + val pathSegments = intent?.data?.pathSegments + if (pathSegments != null && pathSegments.size == 3) { + val slug = pathSegments[2] + + // Gotta do it like this since slug title != actual title + val mainIntent = Intent().apply { + action = "eu.kanade.tachiyomi.SEARCH" + putExtra("query", "${Guya.SLUG_PREFIX}$slug") + putExtra("filter", packageName) + } + + try { + startActivity(mainIntent) + } catch (e: ActivityNotFoundException) { + Log.e("GuyaUrlActivity", e.toString()) + } + } else { + Log.e("GuyaUrlActivity", "Unable to parse URI from intent $intent") + } + + finish() + exitProcess(0) + } + +}