diff --git a/src/all/lanraragi/build.gradle b/src/all/lanraragi/build.gradle index c23bf27bd..6cf8118a9 100644 --- a/src/all/lanraragi/build.gradle +++ b/src/all/lanraragi/build.gradle @@ -6,7 +6,7 @@ ext { extName = 'LANraragi' pkgNameSuffix = 'all.lanraragi' extClass = '.LANraragiFactory' - extVersionCode = 12 + extVersionCode = 13 } dependencies { diff --git a/src/all/lanraragi/src/eu/kanade/tachiyomi/extension/all/lanraragi/LANmodels.kt b/src/all/lanraragi/src/eu/kanade/tachiyomi/extension/all/lanraragi/LANmodels.kt index 16cc32ab0..796247180 100644 --- a/src/all/lanraragi/src/eu/kanade/tachiyomi/extension/all/lanraragi/LANmodels.kt +++ b/src/all/lanraragi/src/eu/kanade/tachiyomi/extension/all/lanraragi/LANmodels.kt @@ -18,7 +18,6 @@ data class ArchivePage( @Serializable data class ArchiveSearchResult( val data: List, - val draw: Int, val recordsFiltered: Int, val recordsTotal: Int ) diff --git a/src/all/lanraragi/src/eu/kanade/tachiyomi/extension/all/lanraragi/LANraragi.kt b/src/all/lanraragi/src/eu/kanade/tachiyomi/extension/all/lanraragi/LANraragi.kt index 3eeed94e5..affa580db 100644 --- a/src/all/lanraragi/src/eu/kanade/tachiyomi/extension/all/lanraragi/LANraragi.kt +++ b/src/all/lanraragi/src/eu/kanade/tachiyomi/extension/all/lanraragi/LANraragi.kt @@ -35,6 +35,7 @@ import uy.kohesive.injekt.Injekt import uy.kohesive.injekt.api.get import java.io.IOException import java.security.MessageDigest +import kotlin.math.max open class LANraragi(private val suffix: String = "") : ConfigurableSource, UnmeteredSource, HttpSource() { override val baseUrl by lazy { getPrefBaseUrl() } @@ -90,9 +91,9 @@ open class LANraragi(private val suffix: String = "") : ConfigurableSource, Unme override fun chapterListParse(response: Response): List { val archive = json.decodeFromString(response.body!!.string()) val uri = getApiUriBuilder("/api/archives/${archive.arcid}/files") - - // Replicate old behavior and unset "isnew" for the archive. - if (archive.isnew == "true") { + val prefClearNew = preferences.getBoolean(NEW_ONLY_KEY, NEW_ONLY_DEFAULT) + + if (archive.isnew == "true" && prefClearNew) { val clearNew = Request.Builder() .url("$baseUrl/api/archives/${archive.arcid}/isnew") .headers(headers) @@ -142,7 +143,7 @@ open class LANraragi(private val suffix: String = "") : ConfigurableSource, Unme override fun latestUpdatesRequest(page: Int): Request { val filters = mutableListOf>() - val prefNewOnly = preferences.getBoolean(NEW_ONLY_KEY, false) + val prefNewOnly = preferences.getBoolean(NEW_ONLY_KEY, NEW_ONLY_DEFAULT) if (prefNewOnly) filters.add(NewArchivesOnly(true)) @@ -201,7 +202,7 @@ open class LANraragi(private val suffix: String = "") : ConfigurableSource, Unme val archives = arrayListOf() lastResultCount = jsonResult.data.size - maxResultCount = if (lastResultCount >= maxResultCount) lastResultCount else maxResultCount + maxResultCount = max(lastResultCount, maxResultCount) lastRecordsFiltered = jsonResult.recordsFiltered totalRecords = jsonResult.recordsTotal @@ -223,7 +224,7 @@ open class LANraragi(private val suffix: String = "") : ConfigurableSource, Unme archives.add(archiveToSManga(it)) } - return MangasPage(archives, currentStart + jsonResult.data.size < jsonResult.recordsFiltered) + return MangasPage(archives, currentStart + lastResultCount < lastRecordsFiltered) } private fun archiveToSManga(archive: Archive) = SManga.create().apply { @@ -281,21 +282,25 @@ open class LANraragi(private val suffix: String = "") : ConfigurableSource, Unme private fun getPrefCustomLabel(): String = preferences.getString(CUSTOM_LABEL_KEY, suffix)!!.ifBlank { suffix } override fun setupPreferenceScreen(screen: androidx.preference.PreferenceScreen) { - val latestNewOnlyPref = androidx.preference.CheckBoxPreference(screen.context).apply { - key = NEW_ONLY_KEY - title = "Latest - New Only" - setDefaultValue(true) + screen.addPreference(screen.editTextPreference(HOSTNAME_KEY, "Hostname", HOSTNAME_DEFAULT, baseUrl, refreshSummary = true)) + screen.addPreference(screen.editTextPreference(APIKEY_KEY, "API Key", "", "Required if No-Fun Mode is enabled.", true)) + screen.addPreference(screen.editTextPreference(CUSTOM_LABEL_KEY, "Custom Label", "", "Show the given label for the source instead of the default.")) + screen.addPreference(screen.checkBoxPreference(CLEAR_NEW_KEY, "Clear New status", CLEAR_NEW_DEFAULT, "Clear an entry's New status when its details are viewed.")) + screen.addPreference(screen.checkBoxPreference(NEW_ONLY_KEY, "Latest - New Only", NEW_ONLY_DEFAULT)) + screen.addPreference(screen.editTextPreference(SORT_BY_NS_KEY, "Latest - Sort by Namespace", SORT_BY_NS_DEFAULT, "Sort by the given namespace for Latest, such as date_added.")) + } + + private fun androidx.preference.PreferenceScreen.checkBoxPreference(key: String, title: String, default: Boolean, summary: String = ""): androidx.preference.CheckBoxPreference { + return androidx.preference.CheckBoxPreference(context).apply { + this.key = key + this.title = title + this.summary = summary + setDefaultValue(default) setOnPreferenceChangeListener { _, newValue -> preferences.edit().putBoolean(this.key, newValue as Boolean).commit() } } - - screen.addPreference(screen.editTextPreference(HOSTNAME_KEY, "Hostname", HOSTNAME_DEFAULT, baseUrl, refreshSummary = true)) - screen.addPreference(screen.editTextPreference(APIKEY_KEY, "API Key", "", "Required if No-Fun Mode is enabled.", true)) - screen.addPreference(screen.editTextPreference(CUSTOM_LABEL_KEY, "Custom Label", "", "Show the given label for the source instead of the default.")) - screen.addPreference(latestNewOnlyPref) - screen.addPreference(screen.editTextPreference(SORT_BY_NS_KEY, "Latest - Sort by Namespace", SORT_BY_NS_DEFAULT, "Sort by the given namespace for Latest, such as date_added.")) } private fun androidx.preference.PreferenceScreen.editTextPreference(key: String, title: String, default: String, summary: String, isPassword: Boolean = false, refreshSummary: Boolean = false): androidx.preference.EditTextPreference { @@ -334,10 +339,12 @@ open class LANraragi(private val suffix: String = "") : ConfigurableSource, Unme // Helper private fun getRandomID(query: String): String { - val searchRandom = client.newCall(GET("$baseUrl/api/search/random?$query", headers)).execute() + val searchRandom = client.newCall(GET("$baseUrl/api/search/random?count=1&$query", headers)).execute() val data = json.parseToJsonElement(searchRandom.body!!.string()).jsonObject["data"] + val archive = data!!.jsonArray.firstOrNull()?.jsonObject - return data!!.jsonArray.firstOrNull()?.jsonObject?.get("id")?.jsonPrimitive?.content ?: "" + // 0.8.2~0.8.7 = id, 0.8.8+ = arcid + return (archive?.get("arcid") ?: archive?.get("id"))?.jsonPrimitive?.content ?: "" } open class UriPartFilter(displayName: String, private val vals: Array>) : @@ -455,8 +462,11 @@ open class LANraragi(private val suffix: String = "") : ConfigurableSource, Unme private const val HOSTNAME_KEY = "hostname" private const val APIKEY_KEY = "apiKey" private const val CUSTOM_LABEL_KEY = "customLabel" + private const val NEW_ONLY_DEFAULT = true private const val NEW_ONLY_KEY = "latestNewOnly" private const val SORT_BY_NS_DEFAULT = "date_added" private const val SORT_BY_NS_KEY = "latestNamespacePref" + private const val CLEAR_NEW_KEY = "clearNew" + private const val CLEAR_NEW_DEFAULT = true } }