diff --git a/multisrc/src/main/java/eu/kanade/tachiyomi/multisrc/comicgamma/ComicGamma.kt b/multisrc/src/main/java/eu/kanade/tachiyomi/multisrc/comicgamma/ComicGamma.kt index 4ef60071b..16ff2dee8 100644 --- a/multisrc/src/main/java/eu/kanade/tachiyomi/multisrc/comicgamma/ComicGamma.kt +++ b/multisrc/src/main/java/eu/kanade/tachiyomi/multisrc/comicgamma/ComicGamma.kt @@ -22,7 +22,7 @@ open class ComicGamma( ) : ParsedHttpSource() { override val supportsLatest = true - override val client = network.client.newBuilder().addInterceptor(PtImgInterceptor()).build() + override val client = network.client.newBuilder().addInterceptor(PtImgInterceptor).build() override fun popularMangaRequest(page: Int) = GET("$baseUrl/manga/", headers) override fun popularMangaNextPageSelector(): String? = null @@ -99,20 +99,18 @@ open class ComicGamma( override fun imageUrlParse(document: Document) = throw UnsupportedOperationException("Not used.") - // for thread-safety (of subclasses) + // for thread-safety private val JST_FORMAT_DESC = getJSTFormat() private val JST_FORMAT_LIST = getJSTFormat() private val LOCAL_FORMAT_DESC = getDateTimeInstance() private val LOCAL_FORMAT_LIST = getDateTimeInstance() - companion object { - private fun SimpleDateFormat.parseJST(date: String) = parse(date)?.apply { - time += 12 * 3600 * 1000 // updates at 12 noon - } - - private fun getJSTFormat() = - SimpleDateFormat("yyyy年M月dd日(E)", Locale.JAPANESE).apply { - timeZone = TimeZone.getTimeZone("GMT+09:00") - } + private fun SimpleDateFormat.parseJST(date: String) = parse(date)?.apply { + time += 12 * 3600 * 1000 // updates at 12 noon } + + private fun getJSTFormat() = + SimpleDateFormat("yyyy年M月dd日(E)", Locale.JAPANESE).apply { + timeZone = TimeZone.getTimeZone("GMT+09:00") + } } diff --git a/multisrc/src/main/java/eu/kanade/tachiyomi/multisrc/comicgamma/ComicGammaGenerator.kt b/multisrc/src/main/java/eu/kanade/tachiyomi/multisrc/comicgamma/ComicGammaGenerator.kt index 9a2599729..79242b8ed 100644 --- a/multisrc/src/main/java/eu/kanade/tachiyomi/multisrc/comicgamma/ComicGammaGenerator.kt +++ b/multisrc/src/main/java/eu/kanade/tachiyomi/multisrc/comicgamma/ComicGammaGenerator.kt @@ -6,7 +6,7 @@ import generator.ThemeSourceGenerator class ComicGammaGenerator : ThemeSourceGenerator { override val themeClass = "ComicGamma" override val themePkg = "comicgamma" - override val baseVersionCode = 2 + override val baseVersionCode = 3 override val sources = listOf( SingleLang( name = "Web Comic Gamma", diff --git a/multisrc/src/main/java/eu/kanade/tachiyomi/multisrc/comicgamma/PtImgInterceptor.kt b/multisrc/src/main/java/eu/kanade/tachiyomi/multisrc/comicgamma/PtImgInterceptor.kt index d8ad97793..230993869 100644 --- a/multisrc/src/main/java/eu/kanade/tachiyomi/multisrc/comicgamma/PtImgInterceptor.kt +++ b/multisrc/src/main/java/eu/kanade/tachiyomi/multisrc/comicgamma/PtImgInterceptor.kt @@ -13,7 +13,7 @@ import okhttp3.ResponseBody.Companion.toResponseBody import uy.kohesive.injekt.injectLazy import java.io.ByteArrayOutputStream -class PtImgInterceptor : Interceptor { +object PtImgInterceptor : Interceptor { private val json: Json by injectLazy() @@ -40,7 +40,9 @@ class PtImgInterceptor : Interceptor { val output = ByteArrayOutputStream() result.compress(Bitmap.CompressFormat.JPEG, 90, output) - val responseBody = output.toByteArray().toResponseBody("image/jpeg".toMediaType()) + val responseBody = output.toByteArray().toResponseBody(jpegMediaType) return imgResponse.newBuilder().body(responseBody).build() } + + private val jpegMediaType = "image/jpeg".toMediaType() } diff --git a/src/ja/mangacross/build.gradle b/src/ja/mangacross/build.gradle index ec2093408..126dc449f 100644 --- a/src/ja/mangacross/build.gradle +++ b/src/ja/mangacross/build.gradle @@ -6,7 +6,7 @@ ext { extName = 'Manga Cross' pkgNameSuffix = 'ja.mangacross' extClass = '.MangaCross' - extVersionCode = 4 + extVersionCode = 5 } apply from: "$rootDir/common.gradle" diff --git a/src/ja/mangacross/src/eu/kanade/tachiyomi/extension/ja/mangacross/MangaCross.kt b/src/ja/mangacross/src/eu/kanade/tachiyomi/extension/ja/mangacross/MangaCross.kt index a870dbf9e..5413672b2 100644 --- a/src/ja/mangacross/src/eu/kanade/tachiyomi/extension/ja/mangacross/MangaCross.kt +++ b/src/ja/mangacross/src/eu/kanade/tachiyomi/extension/ja/mangacross/MangaCross.kt @@ -10,15 +10,13 @@ import eu.kanade.tachiyomi.source.model.Page import eu.kanade.tachiyomi.source.model.SManga import eu.kanade.tachiyomi.source.online.HttpSource import kotlinx.serialization.SerializationException -import kotlinx.serialization.decodeFromString import kotlinx.serialization.json.Json +import kotlinx.serialization.json.decodeFromStream import okhttp3.Response import rx.Observable import uy.kohesive.injekt.injectLazy import kotlin.concurrent.thread -const val maxEntries = 9999 - class MangaCross : HttpSource() { override val name = "Manga Cross" override val lang = "ja" @@ -27,17 +25,14 @@ class MangaCross : HttpSource() { private val json: Json by injectLazy() - override fun popularMangaRequest(page: Int) = GET("$baseUrl/api/comics.json?count=$maxEntries", headers) - - override fun popularMangaParse(response: Response) = MangasPage( - json.decodeFromString(response.body!!.string()).comics.map(MCComic::toSManga), - false // pagination does not work - ) + // Pagination does not work. 9999 is a dummy large number. + override fun popularMangaRequest(page: Int) = GET("$baseUrl/api/comics.json?count=9999", headers) + override fun popularMangaParse(response: Response) = + MangasPage(response.parseAs().comics.map { it.toSManga() }, false) override fun latestUpdatesRequest(page: Int) = GET("$baseUrl/api/episodes.json?page=$page", headers) - override fun latestUpdatesParse(response: Response): MangasPage { - val result = json.decodeFromString(response.body!!.string()) + val result: MCEpisodeList = response.parseAs() return MangasPage(result.episodes.map { it.comic!!.toSManga() }, result.current_page < result.total_pages) } @@ -53,24 +48,21 @@ class MangaCross : HttpSource() { override fun searchMangaParse(response: Response) = popularMangaParse(response) override fun fetchMangaDetails(manga: SManga): Observable = - client.newCall(chapterListRequest(manga)) - .asObservableSuccess() + client.newCall(chapterListRequest(manga)).asObservableSuccess() .map { mangaDetailsParse(it).apply { initialized = true } } // mangaDetailsRequest untouched in order to let WebView open web page instead of json - override fun mangaDetailsParse(response: Response) = - json.decodeFromString(response.body!!.string()).comic.toSManga() + override fun mangaDetailsParse(response: Response) = response.parseAs().comic.toSManga() override fun chapterListRequest(manga: SManga) = GET("$baseUrl/api${manga.url}.json", headers) - override fun chapterListParse(response: Response) = - json.decodeFromString(response.body!!.string()).comic.toSChapterList() + override fun chapterListParse(response: Response) = response.parseAs().comic.toSChapterList() override fun pageListParse(response: Response): List { return try { - json.decodeFromString(response.body!!.string()).episode_pages.mapIndexed { i, it -> - Page(i, "", it.image.original_url) + response.parseAs().episode_pages.mapIndexed { i, it -> + Page(i, imageUrl = it.image.original_url) } } catch (e: SerializationException) { throw Exception("Chapter is no longer available!") @@ -88,8 +80,8 @@ class MangaCross : HttpSource() { thread { try { val response = client.newCall(GET("$baseUrl/api/menus.json", headers)).execute() - val filterList = json.decodeFromString(response.body!!.string()).toFilterList() - tags = listOf(Pair("None", null)) + filterList + val filterList = response.parseAs().toFilterList() + tags = listOf(Pair("All", null)) + filterList } catch (e: Exception) { Log.e("MangaCross", "Failed to fetch filters ($e)") } finally { @@ -105,12 +97,15 @@ class MangaCross : HttpSource() { ) else { fetchTags() FilterList( - Filter.Header("Tags not fetched yet. Go back and retry."), + Filter.Header("Fetching tags..."), + Filter.Header("Go back to previous screen and retry.") ) } - private class TagFilter(displayName: String, private val tags: List>) : - Filter.Select(displayName, tags.map { it.first }.toTypedArray()) { + private class TagFilter(name: String, private val tags: List>) : + Filter.Select(name, tags.map { it.first }.toTypedArray()) { fun getTag() = tags[state].second } + + private inline fun Response.parseAs(): T = json.decodeFromStream(this.body!!.byteStream()) }