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