Manually deserialize saved searches, fix NHentai
This commit is contained in:
parent
3dd10df45e
commit
b67db6a25e
@ -164,7 +164,7 @@ class FullBackupManager(val context: Context) : AbstractBackupManager() {
|
||||
private fun backupSavedSearches(): List<BackupSavedSearch> {
|
||||
return preferences.eh_savedSearches().get().map {
|
||||
val sourceId = it.substringBefore(':').toLong()
|
||||
val content = Json.decodeFromString<JsonSavedSearch>(it.substringAfter(':'))
|
||||
val content = JsonSavedSearch.fromJsonObject(Json.decodeFromString(it.substringAfter(':')))
|
||||
BackupSavedSearch(
|
||||
content.name,
|
||||
content.query,
|
||||
@ -490,7 +490,7 @@ class FullBackupManager(val context: Context) : AbstractBackupManager() {
|
||||
internal fun restoreSavedSearches(backupSavedSearches: List<BackupSavedSearch>) {
|
||||
val currentSavedSearches = preferences.eh_savedSearches().get().map {
|
||||
val sourceId = it.substringBefore(':').toLong()
|
||||
val content = Json.decodeFromString<JsonSavedSearch>(it.substringAfter(':'))
|
||||
val content = JsonSavedSearch.fromJsonObject(Json.decodeFromString(it.substringAfter(':')))
|
||||
BackupSavedSearch(
|
||||
content.name,
|
||||
content.query,
|
||||
|
@ -549,7 +549,7 @@ class LegacyBackupManager(val context: Context, version: Int = CURRENT_VERSION)
|
||||
val newSavedSearches = backupSavedSearches.mapNotNull {
|
||||
try {
|
||||
val id = it.substringBefore(':').toLong()
|
||||
val content = Json.decodeFromString<JsonSavedSearch>(it.substringAfter(':'))
|
||||
val content = JsonSavedSearch.fromJsonObject(Json.decodeFromString(it.substringAfter(':')))
|
||||
id to content
|
||||
} catch (t: RuntimeException) {
|
||||
// Load failed
|
||||
@ -564,7 +564,7 @@ class LegacyBackupManager(val context: Context, version: Int = CURRENT_VERSION)
|
||||
newSavedSearches += preferences.eh_savedSearches().get().mapNotNull {
|
||||
try {
|
||||
val id = it.substringBefore(':').toLong()
|
||||
val content = Json.decodeFromString<JsonSavedSearch>(it.substringAfter(':'))
|
||||
val content = JsonSavedSearch.fromJsonObject(Json.decodeFromString(it.substringAfter(':')))
|
||||
id to content
|
||||
} catch (t: RuntimeException) {
|
||||
// Load failed
|
||||
|
@ -74,7 +74,7 @@ class NHentai(delegate: HttpSource, val context: Context) :
|
||||
}
|
||||
|
||||
jsonResponse.images?.let { images ->
|
||||
coverImageType = images.cover?.type
|
||||
coverImageType = NHentaiSearchMetadata.typeToExtension(images.cover?.type)
|
||||
images.pages.mapNotNull {
|
||||
it.type
|
||||
}.let {
|
||||
@ -127,8 +127,8 @@ class NHentai(delegate: HttpSource, val context: Context) :
|
||||
@Serializable
|
||||
data class JsonPage(
|
||||
@SerialName("t") val type: String? = null,
|
||||
@SerialName("w") val width: String? = null,
|
||||
@SerialName("h") val height: String? = null
|
||||
@SerialName("w") val width: Long? = null,
|
||||
@SerialName("h") val height: Long? = null
|
||||
)
|
||||
|
||||
@Serializable
|
||||
|
@ -461,7 +461,7 @@ open class BrowseSourcePresenter(
|
||||
try {
|
||||
val id = it.substringBefore(':').toLong()
|
||||
if (id != source.id) return@map null
|
||||
val content = Json.decodeFromString<JsonSavedSearch>(it.substringAfter(':'))
|
||||
val content = JsonSavedSearch.fromJsonObject(Json.decodeFromString(it.substringAfter(':')))
|
||||
val originalFilters = source.getFilterList()
|
||||
filterSerializer.deserialize(originalFilters, content.filters)
|
||||
EXHSavedSearch(
|
||||
|
@ -231,7 +231,7 @@ open class IndexPresenter(
|
||||
try {
|
||||
val id = it.substringBefore(':').toLong()
|
||||
if (id != source.id) return@map null
|
||||
val content = Json.decodeFromString<JsonSavedSearch>(it.substringAfter(':'))
|
||||
val content = JsonSavedSearch.fromJsonObject(Json.decodeFromString(it.substringAfter(':')))
|
||||
val originalFilters = source.getFilterList()
|
||||
filterSerializer.deserialize(originalFilters, content.filters)
|
||||
EXHSavedSearch(
|
||||
|
@ -239,7 +239,7 @@ object DebugFunctions {
|
||||
try {
|
||||
val id = it.substringBefore(':').toLong()
|
||||
if (id != source.id) return@mapNotNull null
|
||||
Json.decodeFromString<JsonSavedSearch>(it.substringAfter(':'))
|
||||
JsonSavedSearch.fromJsonObject(Json.decodeFromString(it.substringAfter(':')))
|
||||
} catch (t: RuntimeException) {
|
||||
// Load failed
|
||||
XLog.e("Failed to load saved search!", t)
|
||||
@ -251,7 +251,7 @@ object DebugFunctions {
|
||||
try {
|
||||
val id = it.substringBefore(':').toLong()
|
||||
if (id != newSource.id) return@mapNotNull null
|
||||
Json.decodeFromString<JsonSavedSearch>(it.substringAfter(':'))
|
||||
JsonSavedSearch.fromJsonObject(Json.decodeFromString(it.substringAfter(':')))
|
||||
} catch (t: RuntimeException) {
|
||||
// Load failed
|
||||
XLog.e("Failed to load saved search!", t)
|
||||
@ -278,7 +278,7 @@ object DebugFunctions {
|
||||
try {
|
||||
val id = it.substringBefore(':').toLong()
|
||||
if (id != source.id) return@mapNotNull null
|
||||
Json.decodeFromString<JsonSavedSearch>(it.substringAfter(':'))
|
||||
JsonSavedSearch.fromJsonObject(Json.decodeFromString(it.substringAfter(':')))
|
||||
} catch (t: RuntimeException) {
|
||||
// Load failed
|
||||
XLog.e("Failed to load saved search!", t)
|
||||
@ -290,7 +290,7 @@ object DebugFunctions {
|
||||
try {
|
||||
val id = it.substringBefore(':').toLong()
|
||||
if (id != newSource.id) return@mapNotNull null
|
||||
Json.decodeFromString<JsonSavedSearch>(it.substringAfter(':'))
|
||||
JsonSavedSearch.fromJsonObject(Json.decodeFromString(it.substringAfter(':')))
|
||||
} catch (t: RuntimeException) {
|
||||
// Load failed
|
||||
XLog.e("Failed to load saved search!", t)
|
||||
|
@ -2,10 +2,23 @@ package exh.savedsearches
|
||||
|
||||
import kotlinx.serialization.Serializable
|
||||
import kotlinx.serialization.json.JsonArray
|
||||
import kotlinx.serialization.json.JsonObject
|
||||
import kotlinx.serialization.json.jsonArray
|
||||
import kotlinx.serialization.json.jsonPrimitive
|
||||
|
||||
@Serializable
|
||||
data class JsonSavedSearch(
|
||||
val name: String,
|
||||
val query: String,
|
||||
val filters: JsonArray
|
||||
)
|
||||
) {
|
||||
companion object {
|
||||
fun fromJsonObject(json: JsonObject): JsonSavedSearch {
|
||||
return JsonSavedSearch(
|
||||
json["name"]!!.jsonPrimitive.content,
|
||||
json["query"]!!.jsonPrimitive.content,
|
||||
json["filters"]!!.jsonArray,
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user