From 3ffa78ae2b38e71d23c3d2fac71f2fa73c4c7964 Mon Sep 17 00:00:00 2001
From: lord-ne <34069872+lord-ne@users.noreply.github.com>
Date: Mon, 19 Jul 2021 06:28:48 -0400
Subject: [PATCH] Purple Cress: Add search and deepliking (#8176)
---
src/en/purplecress/AndroidManifest.xml | 36 ++++++++++++++++++-
src/en/purplecress/build.gradle | 2 +-
.../extension/en/purplecress/PurpleCress.kt | 30 +++++++++++++---
.../en/purplecress/PurpleCressURLActivity.kt | 35 ++++++++++++++++++
4 files changed, 97 insertions(+), 6 deletions(-)
create mode 100644 src/en/purplecress/src/eu/kanade/tachiyomi/extension/en/purplecress/PurpleCressURLActivity.kt
diff --git a/src/en/purplecress/AndroidManifest.xml b/src/en/purplecress/AndroidManifest.xml
index 30deb7f79..f0ed63cc6 100644
--- a/src/en/purplecress/AndroidManifest.xml
+++ b/src/en/purplecress/AndroidManifest.xml
@@ -1,2 +1,36 @@
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/src/en/purplecress/build.gradle b/src/en/purplecress/build.gradle
index a9a8d39d8..943057100 100644
--- a/src/en/purplecress/build.gradle
+++ b/src/en/purplecress/build.gradle
@@ -5,7 +5,7 @@ ext {
extName = 'Purple Cress'
pkgNameSuffix = 'en.purplecress'
extClass = '.PurpleCress'
- extVersionCode = 1
+ extVersionCode = 2
libVersion = '1.2'
}
diff --git a/src/en/purplecress/src/eu/kanade/tachiyomi/extension/en/purplecress/PurpleCress.kt b/src/en/purplecress/src/eu/kanade/tachiyomi/extension/en/purplecress/PurpleCress.kt
index 70431ff1f..5acb0e31d 100644
--- a/src/en/purplecress/src/eu/kanade/tachiyomi/extension/en/purplecress/PurpleCress.kt
+++ b/src/en/purplecress/src/eu/kanade/tachiyomi/extension/en/purplecress/PurpleCress.kt
@@ -121,13 +121,35 @@ class PurpleCress : HttpSource() {
return Observable.just(page.imageUrl)
}
- override fun imageUrlRequest(page: Page): Request = throw UnsupportedOperationException("Not used")
+ companion object {
+ const val URL_SEARCH_PREFIX = "purplecress_url:"
+ }
- override fun imageUrlParse(response: Response): String = throw UnsupportedOperationException("Not used")
-
- override fun fetchSearchManga(page: Int, query: String, filters: FilterList): Observable = Observable.just(MangasPage(emptyList(), false))
+ override fun fetchSearchManga(page: Int, query: String, filters: FilterList): Observable {
+ if (query.startsWith(URL_SEARCH_PREFIX)) {
+ val manga = SManga.create().apply {
+ url = query.removePrefix(URL_SEARCH_PREFIX)
+ }
+ return fetchMangaDetails(manga).map {
+ MangasPage(listOf(it), false)
+ }
+ }
+ return fetchPopularManga(page).map {
+ mangasPage ->
+ MangasPage(
+ mangasPage.mangas.filter {
+ it.title.contains(query, true)
+ },
+ mangasPage.hasNextPage
+ )
+ }
+ }
override fun searchMangaRequest(page: Int, query: String, filters: FilterList): Request = throw UnsupportedOperationException("Not used")
override fun searchMangaParse(response: Response): MangasPage = throw UnsupportedOperationException("Not used")
+
+ override fun imageUrlRequest(page: Page): Request = throw UnsupportedOperationException("Not used")
+
+ override fun imageUrlParse(response: Response): String = throw UnsupportedOperationException("Not used")
}
diff --git a/src/en/purplecress/src/eu/kanade/tachiyomi/extension/en/purplecress/PurpleCressURLActivity.kt b/src/en/purplecress/src/eu/kanade/tachiyomi/extension/en/purplecress/PurpleCressURLActivity.kt
new file mode 100644
index 000000000..438b7eb58
--- /dev/null
+++ b/src/en/purplecress/src/eu/kanade/tachiyomi/extension/en/purplecress/PurpleCressURLActivity.kt
@@ -0,0 +1,35 @@
+package eu.kanade.tachiyomi.extension.en.purplecress
+
+import android.app.Activity
+import android.content.ActivityNotFoundException
+import android.content.Intent
+import android.net.Uri
+import android.os.Bundle
+import android.util.Log
+import kotlin.system.exitProcess
+
+class PurpleCressURLActivity : Activity() {
+ override fun onCreate(savedInstanceState: Bundle?) {
+ super.onCreate(savedInstanceState)
+ val pathSegments = intent?.data?.pathSegments
+ if (pathSegments != null && pathSegments.size >= 2) {
+ val url = "/series/" + Uri.encode(pathSegments[1])
+ val mainIntent = Intent().apply {
+ action = "eu.kanade.tachiyomi.SEARCH"
+ putExtra("query", PurpleCress.URL_SEARCH_PREFIX + url)
+ putExtra("filter", packageName)
+ }
+
+ try {
+ startActivity(mainIntent)
+ } catch (e: ActivityNotFoundException) {
+ Log.e("PurpleCressUrlActivity", e.toString())
+ }
+ } else {
+ Log.e("PurpleCressUrlActivity", "could not parse uri from intent $intent")
+ }
+
+ finish()
+ exitProcess(0)
+ }
+}