From 920a2812df01c6914888cfece88152a408d3e385 Mon Sep 17 00:00:00 2001 From: Rolando Lecca <90949336+bapeey@users.noreply.github.com> Date: Sun, 30 Jul 2023 16:37:17 -0500 Subject: [PATCH] YugenMangas: Fix not showing new chapters (#17318) * Use permUrl only if fetchAllTitles is true * Add extension setting * Move extension settings to Yugen * Set default to "true" so that users dont have to migrate * Import SwitchPreferenceCompact Co-authored-by: Alessandro Jean <14254807+alessandrojean@users.noreply.github.com> * Remove ChangeListener Co-authored-by: Alessandro Jean <14254807+alessandrojean@users.noreply.github.com> * Show toast --------- Co-authored-by: Alessandro Jean <14254807+alessandrojean@users.noreply.github.com> --- .../heancms/yugenmangas/src/YugenMangas.kt | 58 +++++++++++++++++-- .../tachiyomi/multisrc/heancms/HeanCms.kt | 16 ++--- .../tachiyomi/multisrc/heancms/HeanCmsDto.kt | 12 ++-- .../multisrc/heancms/HeanCmsGenerator.kt | 2 +- 4 files changed, 68 insertions(+), 20 deletions(-) diff --git a/multisrc/overrides/heancms/yugenmangas/src/YugenMangas.kt b/multisrc/overrides/heancms/yugenmangas/src/YugenMangas.kt index 8aa9f7310..c6822d9a8 100644 --- a/multisrc/overrides/heancms/yugenmangas/src/YugenMangas.kt +++ b/multisrc/overrides/heancms/yugenmangas/src/YugenMangas.kt @@ -1,22 +1,38 @@ package eu.kanade.tachiyomi.extension.es.yugenmangas +import android.app.Application +import android.content.SharedPreferences +import android.widget.Toast +import androidx.preference.PreferenceScreen +import androidx.preference.SwitchPreferenceCompat import eu.kanade.tachiyomi.multisrc.heancms.Genre import eu.kanade.tachiyomi.multisrc.heancms.HeanCms import eu.kanade.tachiyomi.network.interceptor.rateLimit +import eu.kanade.tachiyomi.source.ConfigurableSource +import uy.kohesive.injekt.Injekt +import uy.kohesive.injekt.api.get import java.text.SimpleDateFormat import java.util.TimeZone import java.util.concurrent.TimeUnit -class YugenMangas : HeanCms( - "YugenMangas", - "https://yugenmangas.net", - "es", - "https://api.yugenmangas.net", -) { +class YugenMangas : + HeanCms( + "YugenMangas", + "https://yugenmangas.net", + "es", + "https://api.yugenmangas.net", + ), + ConfigurableSource { + + private val preferences: SharedPreferences by lazy { + Injekt.get().getSharedPreferences("source_$id", 0x0000) + } // Site changed from Madara to HeanCms. override val versionId = 2 + override val fetchAllTitles = getFetchAllSeriesPref() + override val client = super.client.newBuilder() .connectTimeout(60, TimeUnit.SECONDS) .readTimeout(90, TimeUnit.SECONDS) @@ -29,6 +45,26 @@ class YugenMangas : HeanCms( timeZone = TimeZone.getTimeZone("UTC") } + private fun getFetchAllSeriesPref(): Boolean { + return preferences.getBoolean(FETCH_ALL_SERIES_PREF, FETCH_ALL_SERIES_DEFAULT_VALUE) + } + + override fun setupPreferenceScreen(screen: PreferenceScreen) { + val fetchAllSeriesPreference = SwitchPreferenceCompat(screen.context).apply { + key = FETCH_ALL_SERIES_PREF + title = FETCH_ALL_SERIES_TITLE + summary = FETCH_ALL_SERIES_SUMMARY + setDefaultValue(FETCH_ALL_SERIES_DEFAULT_VALUE) + + setOnPreferenceChangeListener { _, newValue -> + Toast.makeText(screen.context, "Reinicia la app para aplicar los cambios.", Toast.LENGTH_LONG).show() + true + } + } + + screen.addPreference(fetchAllSeriesPreference) + } + override fun getGenreList(): List = listOf( Genre("+18", 1), Genre("Acción", 36), @@ -79,4 +115,14 @@ class YugenMangas : HeanCms( Genre("Yaoi", 43), Genre("Yuri", 44), ) + + companion object { + private const val FETCH_ALL_SERIES_PREF = "fetchAllSeriesPref" + private const val FETCH_ALL_SERIES_TITLE = "Buscar todas las series" + private const val FETCH_ALL_SERIES_SUMMARY = "Busca las URLs actuales de las series. " + + "Habilitar esta opción evita la necesidad de migrar, " + + "pero puede llevar tiempo dependiendo del número total de series. \n" + + "Tendrá que migrar cada vez que cambie esta opción." + private const val FETCH_ALL_SERIES_DEFAULT_VALUE = true + } } diff --git a/multisrc/src/main/java/eu/kanade/tachiyomi/multisrc/heancms/HeanCms.kt b/multisrc/src/main/java/eu/kanade/tachiyomi/multisrc/heancms/HeanCms.kt index e0c96d501..3ac3c1128 100644 --- a/multisrc/src/main/java/eu/kanade/tachiyomi/multisrc/heancms/HeanCms.kt +++ b/multisrc/src/main/java/eu/kanade/tachiyomi/multisrc/heancms/HeanCms.kt @@ -81,7 +81,7 @@ abstract class HeanCms( if (json.startsWith("{")) { val result = json.parseAs() - val mangaList = result.data.map { it.toSManga(apiUrl, coverPath) } + val mangaList = result.data.map { it.toSManga(apiUrl, coverPath, fetchAllTitles) } fetchAllTitles() @@ -89,7 +89,7 @@ abstract class HeanCms( } val mangaList = json.parseAs>() - .map { it.toSManga(apiUrl, coverPath) } + .map { it.toSManga(apiUrl, coverPath, fetchAllTitles) } fetchAllTitles() @@ -179,14 +179,14 @@ abstract class HeanCms( val result = json.parseAs>() val mangaList = result .filter { it.type == "Comic" } - .map { it.toSManga(apiUrl, coverPath, seriesSlugMap.orEmpty()) } + .map { it.toSManga(apiUrl, coverPath, seriesSlugMap.orEmpty(), fetchAllTitles) } return MangasPage(mangaList, false) } if (json.startsWith("{")) { val result = json.parseAs() - val mangaList = result.data.map { it.toSManga(apiUrl, coverPath) } + val mangaList = result.data.map { it.toSManga(apiUrl, coverPath, fetchAllTitles) } fetchAllTitles() @@ -194,7 +194,7 @@ abstract class HeanCms( } val mangaList = json.parseAs>() - .map { it.toSManga(apiUrl, coverPath) } + .map { it.toSManga(apiUrl, coverPath, fetchAllTitles) } fetchAllTitles() @@ -206,7 +206,7 @@ abstract class HeanCms( .substringAfterLast("/") .replace(TIMESTAMP_REGEX, "") - val currentSlug = seriesSlugMap?.get(seriesSlug)?.slug ?: seriesSlug + val currentSlug = seriesSlugMap?.get(seriesSlug)?.slug ?: manga.url.substringAfterLast("/") return "$baseUrl/series/$currentSlug" } @@ -219,7 +219,7 @@ abstract class HeanCms( fetchAllTitles() val seriesDetails = seriesSlugMap?.get(seriesSlug) - val currentSlug = seriesDetails?.slug ?: seriesSlug + val currentSlug = seriesDetails?.slug ?: manga.url.substringAfterLast("/") val currentStatus = seriesDetails?.status ?: manga.status val apiHeaders = headersBuilder() @@ -231,7 +231,7 @@ abstract class HeanCms( override fun mangaDetailsParse(response: Response): SManga { val result = runCatching { response.parseAs() } - val seriesDetails = result.getOrNull()?.toSManga(apiUrl, coverPath) + val seriesDetails = result.getOrNull()?.toSManga(apiUrl, coverPath, fetchAllTitles) ?: throw Exception(intl.urlChangedError(name)) return seriesDetails.apply { diff --git a/multisrc/src/main/java/eu/kanade/tachiyomi/multisrc/heancms/HeanCmsDto.kt b/multisrc/src/main/java/eu/kanade/tachiyomi/multisrc/heancms/HeanCmsDto.kt index 72086cf7c..42b0a49a5 100644 --- a/multisrc/src/main/java/eu/kanade/tachiyomi/multisrc/heancms/HeanCmsDto.kt +++ b/multisrc/src/main/java/eu/kanade/tachiyomi/multisrc/heancms/HeanCmsDto.kt @@ -36,14 +36,15 @@ data class HeanCmsSearchDto( apiUrl: String, coverPath: String, slugMap: Map, + usePermSlug: Boolean, ): SManga = SManga.create().apply { - val slugOnly = slug.replace(HeanCms.TIMESTAMP_REGEX, "") - val thumbnailFileName = slugMap[slugOnly]?.thumbnailFileName + val slug = if (!usePermSlug) slug else slug.replace(HeanCms.TIMESTAMP_REGEX, "") + val thumbnailFileName = slugMap[slug]?.thumbnailFileName title = this@HeanCmsSearchDto.title thumbnail_url = thumbnail?.toAbsoluteThumbnailUrl(apiUrl, coverPath) ?: thumbnailFileName?.toAbsoluteThumbnailUrl(apiUrl, coverPath) - url = "/series/$slugOnly" + url = "/series/$slug" } } @@ -62,8 +63,9 @@ data class HeanCmsSeriesDto( val chapters: List? = emptyList(), ) { - fun toSManga(apiUrl: String, coverPath: String): SManga = SManga.create().apply { + fun toSManga(apiUrl: String, coverPath: String, usePermSlug: Boolean): SManga = SManga.create().apply { val descriptionBody = this@HeanCmsSeriesDto.description?.let(Jsoup::parseBodyFragment) + val slug = if (!usePermSlug) slug else slug.replace(HeanCms.TIMESTAMP_REGEX, "") title = this@HeanCmsSeriesDto.title author = this@HeanCmsSeriesDto.author?.trim() @@ -77,7 +79,7 @@ data class HeanCmsSeriesDto( thumbnail_url = thumbnail.ifEmpty { null } ?.toAbsoluteThumbnailUrl(apiUrl, coverPath) status = this@HeanCmsSeriesDto.status?.toStatus() ?: SManga.UNKNOWN - url = "/series/${slug.replace(HeanCms.TIMESTAMP_REGEX, "")}" + url = "/series/$slug" } } diff --git a/multisrc/src/main/java/eu/kanade/tachiyomi/multisrc/heancms/HeanCmsGenerator.kt b/multisrc/src/main/java/eu/kanade/tachiyomi/multisrc/heancms/HeanCmsGenerator.kt index 840a468aa..3bcd33152 100644 --- a/multisrc/src/main/java/eu/kanade/tachiyomi/multisrc/heancms/HeanCmsGenerator.kt +++ b/multisrc/src/main/java/eu/kanade/tachiyomi/multisrc/heancms/HeanCmsGenerator.kt @@ -9,7 +9,7 @@ class HeanCmsGenerator : ThemeSourceGenerator { override val themeClass = "HeanCms" - override val baseVersionCode: Int = 13 + override val baseVersionCode: Int = 14 override val sources = listOf( SingleLang("Glorious Scan", "https://gloriousscan.com", "pt-BR", overrideVersionCode = 17),