LANraragi: 0.8.8 (#14610)

* LANraragi: 0.8.8 support

Basic fix for API key change while supporting pre-0.8.8. In the future this could be done with the Archive model.
Remove irrelevant draw key.

* LANraragi: Improve var usage

* LANraragi: Consolidate New Only's default value

* LANraragi: Encode the API Key once

* LANraragi: Refactor checkbox + Clear New toggle

Previous behavior was always clear. Now it can be toggled.

* Revert "LANraragi: Encode the API Key once"

This reverts commit 17128421cf7754cffd143a80cebbdf48281112d7.

* LANraragi: Redundant comment
This commit is contained in:
RePod 2022-12-20 11:44:07 -05:00 committed by GitHub
parent fad48f41ad
commit bf5768d256
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 29 additions and 20 deletions

View File

@ -6,7 +6,7 @@ ext {
extName = 'LANraragi'
pkgNameSuffix = 'all.lanraragi'
extClass = '.LANraragiFactory'
extVersionCode = 12
extVersionCode = 13
}
dependencies {

View File

@ -18,7 +18,6 @@ data class ArchivePage(
@Serializable
data class ArchiveSearchResult(
val data: List<Archive>,
val draw: Int,
val recordsFiltered: Int,
val recordsTotal: Int
)

View File

@ -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<SChapter> {
val archive = json.decodeFromString<Archive>(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<Filter<*>>()
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<SManga>()
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<Pair<String?, String>>) :
@ -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
}
}