Ganma: cleanup for chapter list and preferences (#12371)
This commit is contained in:
parent
7bc4e3f647
commit
fbb06aadb9
|
@ -6,7 +6,7 @@ ext {
|
||||||
extName = 'GANMA!'
|
extName = 'GANMA!'
|
||||||
pkgNameSuffix = 'ja.ganma'
|
pkgNameSuffix = 'ja.ganma'
|
||||||
extClass = '.GanmaFactory'
|
extClass = '.GanmaFactory'
|
||||||
extVersionCode = 1
|
extVersionCode = 2
|
||||||
}
|
}
|
||||||
|
|
||||||
apply from: "$rootDir/common.gradle"
|
apply from: "$rootDir/common.gradle"
|
||||||
|
|
|
@ -75,7 +75,7 @@ open class Ganma : HttpSource(), ConfigurableSource {
|
||||||
|
|
||||||
override fun fetchMangaDetails(manga: SManga): Observable<SManga> =
|
override fun fetchMangaDetails(manga: SManga): Observable<SManga> =
|
||||||
client.newCall(realMangaDetailsRequest(manga)).asObservableSuccess()
|
client.newCall(realMangaDetailsRequest(manga)).asObservableSuccess()
|
||||||
.map { mangaDetailsParse(it).apply { initialized = true } }
|
.map { mangaDetailsParse(it) }
|
||||||
|
|
||||||
override fun mangaDetailsParse(response: Response): SManga =
|
override fun mangaDetailsParse(response: Response): SManga =
|
||||||
response.parseAs<Magazine>().toSMangaDetails()
|
response.parseAs<Magazine>().toSMangaDetails()
|
||||||
|
@ -117,10 +117,6 @@ open class Ganma : HttpSource(), ConfigurableSource {
|
||||||
key = METADATA_PREF
|
key = METADATA_PREF
|
||||||
title = "Metadata (Debug)"
|
title = "Metadata (Debug)"
|
||||||
setDefaultValue("")
|
setDefaultValue("")
|
||||||
setOnPreferenceChangeListener { _, newValue ->
|
|
||||||
preferences.edit().putString(METADATA_PREF, newValue as String).apply()
|
|
||||||
true
|
|
||||||
}
|
|
||||||
}.let { screen.addPreference(it) }
|
}.let { screen.addPreference(it) }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -8,8 +8,6 @@ import eu.kanade.tachiyomi.network.POST
|
||||||
import eu.kanade.tachiyomi.source.model.Page
|
import eu.kanade.tachiyomi.source.model.Page
|
||||||
import eu.kanade.tachiyomi.source.model.SChapter
|
import eu.kanade.tachiyomi.source.model.SChapter
|
||||||
import eu.kanade.tachiyomi.source.model.SManga
|
import eu.kanade.tachiyomi.source.model.SManga
|
||||||
import kotlinx.serialization.json.JsonObject
|
|
||||||
import kotlinx.serialization.json.jsonPrimitive
|
|
||||||
import okhttp3.Cookie
|
import okhttp3.Cookie
|
||||||
import okhttp3.CookieJar
|
import okhttp3.CookieJar
|
||||||
import okhttp3.FormBody
|
import okhttp3.FormBody
|
||||||
|
@ -57,9 +55,9 @@ class GanmaApp(private val metadata: Metadata) : Ganma() {
|
||||||
var field2 = preferences.getString(TOKEN_FIELD2_PREF, "")!!
|
var field2 = preferences.getString(TOKEN_FIELD2_PREF, "")!!
|
||||||
if (field1.isEmpty() || field2.isEmpty()) {
|
if (field1.isEmpty() || field2.isEmpty()) {
|
||||||
val response = client.newCall(POST(metadata.baseUrl + metadata.tokenUrl, appHeaders)).execute()
|
val response = client.newCall(POST(metadata.baseUrl + metadata.tokenUrl, appHeaders)).execute()
|
||||||
val token: JsonObject = response.parseAs()
|
val token: Map<String, String> = response.parseAs()
|
||||||
field1 = token[metadata.tokenField1]!!.jsonPrimitive.content
|
field1 = token[metadata.tokenField1]!!
|
||||||
field2 = token[metadata.tokenField2]!!.jsonPrimitive.content
|
field2 = token[metadata.tokenField2]!!
|
||||||
}
|
}
|
||||||
val requestBody = FormBody.Builder().apply {
|
val requestBody = FormBody.Builder().apply {
|
||||||
add(metadata.tokenField1, field1)
|
add(metadata.tokenField1, field1)
|
||||||
|
@ -89,7 +87,7 @@ class GanmaApp(private val metadata: Metadata) : Ganma() {
|
||||||
super.setupPreferenceScreen(screen)
|
super.setupPreferenceScreen(screen)
|
||||||
SwitchPreferenceCompat(screen.context).apply {
|
SwitchPreferenceCompat(screen.context).apply {
|
||||||
title = "Clear session"
|
title = "Clear session"
|
||||||
setOnPreferenceClickListener {
|
setOnPreferenceChangeListener { _, _ ->
|
||||||
clearSession(clearToken = false)
|
clearSession(clearToken = false)
|
||||||
Toast.makeText(screen.context, "Session cleared", Toast.LENGTH_SHORT).show()
|
Toast.makeText(screen.context, "Session cleared", Toast.LENGTH_SHORT).show()
|
||||||
false
|
false
|
||||||
|
@ -97,7 +95,7 @@ class GanmaApp(private val metadata: Metadata) : Ganma() {
|
||||||
}.let { screen.addPreference(it) }
|
}.let { screen.addPreference(it) }
|
||||||
SwitchPreferenceCompat(screen.context).apply {
|
SwitchPreferenceCompat(screen.context).apply {
|
||||||
title = "Clear token"
|
title = "Clear token"
|
||||||
setOnPreferenceClickListener {
|
setOnPreferenceChangeListener { _, _ ->
|
||||||
clearSession(clearToken = true)
|
clearSession(clearToken = true)
|
||||||
Toast.makeText(screen.context, "Token cleared", Toast.LENGTH_SHORT).show()
|
Toast.makeText(screen.context, "Token cleared", Toast.LENGTH_SHORT).show()
|
||||||
false
|
false
|
||||||
|
|
|
@ -4,13 +4,15 @@ import eu.kanade.tachiyomi.source.model.Page
|
||||||
import eu.kanade.tachiyomi.source.model.SChapter
|
import eu.kanade.tachiyomi.source.model.SChapter
|
||||||
import eu.kanade.tachiyomi.source.model.SManga
|
import eu.kanade.tachiyomi.source.model.SManga
|
||||||
import kotlinx.serialization.Serializable
|
import kotlinx.serialization.Serializable
|
||||||
|
import java.text.DateFormat.getDateTimeInstance
|
||||||
|
import java.util.Date
|
||||||
|
|
||||||
@Serializable
|
@Serializable
|
||||||
data class Result<T>(val root: T)
|
class Result<T>(val root: T)
|
||||||
|
|
||||||
// Manga
|
// Manga
|
||||||
@Serializable
|
@Serializable
|
||||||
data class Magazine(
|
class Magazine(
|
||||||
val id: String,
|
val id: String,
|
||||||
val alias: String? = null,
|
val alias: String? = null,
|
||||||
val title: String,
|
val title: String,
|
||||||
|
@ -38,6 +40,7 @@ data class Magazine(
|
||||||
!flagsText.isNullOrEmpty() -> SManga.ONGOING
|
!flagsText.isNullOrEmpty() -> SManga.ONGOING
|
||||||
else -> SManga.UNKNOWN
|
else -> SManga.UNKNOWN
|
||||||
}
|
}
|
||||||
|
initialized = true
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun generateDescription(flagsText: String?): String {
|
private fun generateDescription(flagsText: String?): String {
|
||||||
|
@ -48,12 +51,20 @@ data class Magazine(
|
||||||
return result.joinToString("\n\n")
|
return result.joinToString("\n\n")
|
||||||
}
|
}
|
||||||
|
|
||||||
fun getSChapterList() = items.map {
|
fun getSChapterList(): List<SChapter> {
|
||||||
|
val now = System.currentTimeMillis()
|
||||||
|
return items.map {
|
||||||
SChapter.create().apply {
|
SChapter.create().apply {
|
||||||
url = "${alias!!}#$id/${it.id ?: it.storyId}"
|
url = "${alias!!}#$id/${it.id ?: it.storyId}"
|
||||||
val prefix = if (it.kind == "free") "" else "🔒 "
|
name = buildString {
|
||||||
name = if (it.subtitle != null) "$prefix${it.title} ${it.subtitle}" else "$prefix${it.title}"
|
if (it.kind != "free") append("🔒 ")
|
||||||
date_upload = it.releaseStart ?: -1
|
append(it.title)
|
||||||
|
if (it.subtitle != null) append(' ').append(it.subtitle)
|
||||||
|
}
|
||||||
|
val time = it.releaseStart ?: -1
|
||||||
|
date_upload = time
|
||||||
|
if (time > now) scanlator = getDateTimeInstance().format(Date(time)) + '~'
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -68,7 +79,7 @@ fun String.chapterDir(): Pair<String, String> =
|
||||||
|
|
||||||
// Chapter
|
// Chapter
|
||||||
@Serializable
|
@Serializable
|
||||||
data class Story(
|
class Story(
|
||||||
val id: String? = null,
|
val id: String? = null,
|
||||||
val storyId: String? = null,
|
val storyId: String? = null,
|
||||||
val title: String,
|
val title: String,
|
||||||
|
@ -89,19 +100,19 @@ data class Story(
|
||||||
}
|
}
|
||||||
|
|
||||||
@Serializable
|
@Serializable
|
||||||
data class File(val url: String)
|
class File(val url: String)
|
||||||
|
|
||||||
@Serializable
|
@Serializable
|
||||||
data class Author(val penName: String? = null)
|
class Author(val penName: String? = null)
|
||||||
|
|
||||||
@Serializable
|
@Serializable
|
||||||
data class Top(val boxes: List<Box>)
|
class Top(val boxes: List<Box>)
|
||||||
|
|
||||||
@Serializable
|
@Serializable
|
||||||
data class Box(val panels: List<Magazine>)
|
class Box(val panels: List<Magazine>)
|
||||||
|
|
||||||
@Serializable
|
@Serializable
|
||||||
data class Flags(
|
class Flags(
|
||||||
val isMonday: Boolean = false,
|
val isMonday: Boolean = false,
|
||||||
val isTuesday: Boolean = false,
|
val isTuesday: Boolean = false,
|
||||||
val isWednesday: Boolean = false,
|
val isWednesday: Boolean = false,
|
||||||
|
@ -142,10 +153,10 @@ data class Flags(
|
||||||
}
|
}
|
||||||
|
|
||||||
@Serializable
|
@Serializable
|
||||||
data class Announcement(val text: String)
|
class Announcement(val text: String)
|
||||||
|
|
||||||
@Serializable
|
@Serializable
|
||||||
data class Directory(
|
class Directory(
|
||||||
val baseUrl: String,
|
val baseUrl: String,
|
||||||
val token: String,
|
val token: String,
|
||||||
val files: List<String>,
|
val files: List<String>,
|
||||||
|
@ -157,7 +168,7 @@ data class Directory(
|
||||||
}
|
}
|
||||||
|
|
||||||
@Serializable
|
@Serializable
|
||||||
data class AppStory(val pages: List<AppPage>) {
|
class AppStory(val pages: List<AppPage>) {
|
||||||
fun toPageList(): List<Page> {
|
fun toPageList(): List<Page> {
|
||||||
val result = ArrayList<Page>(pages.size)
|
val result = ArrayList<Page>(pages.size)
|
||||||
pages.forEach {
|
pages.forEach {
|
||||||
|
@ -171,7 +182,7 @@ data class AppStory(val pages: List<AppPage>) {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Serializable
|
@Serializable
|
||||||
data class AppPage(
|
class AppPage(
|
||||||
val imageURL: File? = null,
|
val imageURL: File? = null,
|
||||||
val afterwordImageURL: File? = null,
|
val afterwordImageURL: File? = null,
|
||||||
)
|
)
|
||||||
|
@ -179,7 +190,7 @@ data class AppPage(
|
||||||
// Please keep the data private to support the site,
|
// Please keep the data private to support the site,
|
||||||
// otherwise they might change their APIs.
|
// otherwise they might change their APIs.
|
||||||
@Serializable
|
@Serializable
|
||||||
data class Metadata(
|
class Metadata(
|
||||||
val userAgent: String,
|
val userAgent: String,
|
||||||
val baseUrl: String,
|
val baseUrl: String,
|
||||||
val tokenUrl: String,
|
val tokenUrl: String,
|
||||||
|
@ -192,4 +203,4 @@ data class Metadata(
|
||||||
)
|
)
|
||||||
|
|
||||||
@Serializable
|
@Serializable
|
||||||
data class Session(val expire: Long)
|
class Session(val expire: Long)
|
||||||
|
|
Loading…
Reference in New Issue