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