Monochrome: add URL intent (#10143)
This commit is contained in:
parent
08b3ab02b2
commit
b060c25091
|
@ -0,0 +1,21 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
package="eu.kanade.tachiyomi.extension">
|
||||
<application>
|
||||
<activity android:name="eu.kanade.tachiyomi.multisrc.monochrome.MonochromeActivity"
|
||||
android:theme="@android:style/Theme.NoDisplay"
|
||||
android:exported="true"
|
||||
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:host="${SOURCEHOST}"/>
|
||||
<data android:host="*.${SOURCEHOST}"/>
|
||||
<data android:pathPattern="/manga/..*"
|
||||
android:scheme="${SOURCESCHEME}" />
|
||||
</intent-filter>
|
||||
</activity>
|
||||
</application>
|
||||
</manifest>
|
|
@ -0,0 +1,3 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<!-- intents won't work because the host URL is technically blank -->
|
||||
<manifest package="eu.kanade.tachiyomi.extension"/>
|
|
@ -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)
|
||||
|
|
|
@ -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)
|
||||
}
|
||||
}
|
|
@ -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<Results>().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<Results>().let {
|
||||
MangasPage(it.map(::mangaFromAPI), it.hasNext)
|
||||
}
|
||||
|
||||
override fun fetchSearchManga(
|
||||
page: Int, query: String, filters: FilterList
|
||||
): Observable<MangasPage> {
|
||||
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 <reified T> Response.decode() =
|
||||
json.decodeFromString<T>(body!!.string())
|
||||
|
||||
|
|
|
@ -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"),
|
||||
|
|
Loading…
Reference in New Issue