Cubari: reddit gallery intent and fix empty group name causing `NullPointerException` (#15402)
* Cubari: add reddit gallery url intent * fix empty group name causing `NullPointerException`
This commit is contained in:
parent
bfabc9b304
commit
e6f26da39d
|
@ -53,6 +53,19 @@
|
|||
android:pathPattern="/a/..*"
|
||||
android:scheme="https" />
|
||||
|
||||
<data
|
||||
android:pathPattern="/gallery/..*"
|
||||
android:scheme="https" />
|
||||
</intent-filter>
|
||||
<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="*.reddit.com" />
|
||||
<data android:host="reddit.com" />
|
||||
|
||||
<data
|
||||
android:pathPattern="/gallery/..*"
|
||||
android:scheme="https" />
|
||||
|
|
|
@ -6,7 +6,7 @@ ext {
|
|||
extName = 'Cubari'
|
||||
pkgNameSuffix = "all.cubari"
|
||||
extClass = '.CubariFactory'
|
||||
extVersionCode = 16
|
||||
extVersionCode = 17
|
||||
}
|
||||
|
||||
apply from: "$rootDir/common.gradle"
|
||||
|
|
|
@ -180,21 +180,20 @@ open class Cubari(override val lang: String) : HttpSource() {
|
|||
private fun seriesJsonPageListParse(response: Response, chapter: SChapter): List<Page> {
|
||||
val jsonObj = json.parseToJsonElement(response.body.string()).jsonObject
|
||||
val groups = jsonObj["groups"]!!.jsonObject
|
||||
val groupMap = groups.entries
|
||||
.map { Pair(it.value.jsonPrimitive.content, it.key) }
|
||||
.toMap()
|
||||
val groupMap = groups.entries.associateBy({ it.value.jsonPrimitive.content.ifEmpty { "default" } }, { it.key })
|
||||
val chapterScanlator = chapter.scanlator ?: "default" // workaround for "" as group causing NullPointerException (#13772)
|
||||
|
||||
val chapters = jsonObj["chapters"]!!.jsonObject
|
||||
|
||||
val pages = if (chapters[chapter.chapter_number.toString()] != null) {
|
||||
chapters[chapter.chapter_number.toString()]!!
|
||||
.jsonObject["groups"]!!
|
||||
.jsonObject[groupMap[chapter.scanlator]]!!
|
||||
.jsonObject[groupMap[chapterScanlator]]!!
|
||||
.jsonArray
|
||||
} else {
|
||||
chapters[chapter.chapter_number.toInt().toString()]!!
|
||||
.jsonObject["groups"]!!
|
||||
.jsonObject[groupMap[chapter.scanlator]]!!
|
||||
.jsonObject[groupMap[chapterScanlator]]!!
|
||||
.jsonArray
|
||||
}
|
||||
|
||||
|
@ -283,8 +282,8 @@ open class Cubari(override val lang: String) : HttpSource() {
|
|||
scanlator = groups[groupNum]!!.jsonPrimitive.content
|
||||
chapter_number = chapterNum.toFloatOrNull() ?: -1f
|
||||
|
||||
if (releaseDate != null) {
|
||||
date_upload = releaseDate.jsonPrimitive.double.toLong() * 1000
|
||||
date_upload = if (releaseDate != null) {
|
||||
releaseDate.jsonPrimitive.double.toLong() * 1000
|
||||
} else {
|
||||
val currentTimeMillis = System.currentTimeMillis()
|
||||
|
||||
|
@ -292,7 +291,7 @@ open class Cubari(override val lang: String) : HttpSource() {
|
|||
seriesPrefsEditor.putLong(chapterNum, currentTimeMillis)
|
||||
}
|
||||
|
||||
date_upload = seriesPrefs.getLong(chapterNum, currentTimeMillis)
|
||||
seriesPrefs.getLong(chapterNum, currentTimeMillis)
|
||||
}
|
||||
|
||||
name = if (volume != null) {
|
||||
|
|
|
@ -17,7 +17,8 @@ class CubariUrlActivity : Activity() {
|
|||
if (host != null && pathSegments != null) {
|
||||
val query = with(host) {
|
||||
when {
|
||||
equals("m.imgur.com") || equals("imgur.com") -> fromImgur(pathSegments)
|
||||
equals("m.imgur.com") || equals("imgur.com") -> fromSource("imgur", pathSegments)
|
||||
equals("m.reddit.com") || equals("reddit.com") || equals("www.reddit.com") -> fromSource("reddit", pathSegments)
|
||||
else -> fromCubari(pathSegments)
|
||||
}
|
||||
}
|
||||
|
@ -45,11 +46,11 @@ class CubariUrlActivity : Activity() {
|
|||
exitProcess(0)
|
||||
}
|
||||
|
||||
private fun fromImgur(pathSegments: List<String>): String? {
|
||||
private fun fromSource(source: String, pathSegments: List<String>): String? {
|
||||
if (pathSegments.size >= 2) {
|
||||
val id = pathSegments[1]
|
||||
|
||||
return "${Cubari.PROXY_PREFIX}imgur/$id"
|
||||
return "${Cubari.PROXY_PREFIX}$source/$id"
|
||||
}
|
||||
return null
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue