mirror of
https://github.com/tachiyomiorg/tachiyomi.git
synced 2024-12-22 22:01:51 +01:00
Exclude backup empty fields
This commit is contained in:
parent
f4d12ba622
commit
b418169c20
@ -3,8 +3,10 @@ package eu.kanade.tachiyomi.data.backup
|
||||
import com.github.salomonbrys.kotson.fromJson
|
||||
import com.google.gson.*
|
||||
import com.google.gson.stream.JsonReader
|
||||
import eu.kanade.tachiyomi.data.backup.serializer.BooleanSerializer
|
||||
import eu.kanade.tachiyomi.data.backup.serializer.IdExclusion
|
||||
import eu.kanade.tachiyomi.data.backup.serializer.IntegerSerializer
|
||||
import eu.kanade.tachiyomi.data.backup.serializer.LongSerializer
|
||||
import eu.kanade.tachiyomi.data.database.DatabaseHelper
|
||||
import eu.kanade.tachiyomi.data.database.models.*
|
||||
import java.io.*
|
||||
@ -42,7 +44,9 @@ class BackupManager(private val db: DatabaseHelper) {
|
||||
|
||||
@Suppress("PLATFORM_CLASS_MAPPED_TO_KOTLIN")
|
||||
private val gson = GsonBuilder()
|
||||
.registerTypeAdapter(Integer::class.java, IntegerSerializer())
|
||||
.registerTypeAdapter(java.lang.Integer::class.java, IntegerSerializer())
|
||||
.registerTypeAdapter(java.lang.Boolean::class.java, BooleanSerializer())
|
||||
.registerTypeAdapter(java.lang.Long::class.java, LongSerializer())
|
||||
.setExclusionStrategies(IdExclusion())
|
||||
.create()
|
||||
|
||||
|
@ -0,0 +1,16 @@
|
||||
package eu.kanade.tachiyomi.data.backup.serializer
|
||||
|
||||
import com.google.gson.JsonElement
|
||||
import com.google.gson.JsonPrimitive
|
||||
import com.google.gson.JsonSerializationContext
|
||||
import com.google.gson.JsonSerializer
|
||||
import java.lang.reflect.Type
|
||||
|
||||
class BooleanSerializer : JsonSerializer<Boolean> {
|
||||
|
||||
override fun serialize(value: Boolean?, type: Type, context: JsonSerializationContext): JsonElement? {
|
||||
if (value != null && value != false)
|
||||
return JsonPrimitive(value)
|
||||
return null
|
||||
}
|
||||
}
|
@ -2,10 +2,10 @@ package eu.kanade.tachiyomi.data.backup.serializer
|
||||
|
||||
import com.google.gson.ExclusionStrategy
|
||||
import com.google.gson.FieldAttributes
|
||||
import eu.kanade.tachiyomi.data.database.models.Category
|
||||
import eu.kanade.tachiyomi.data.database.models.Chapter
|
||||
import eu.kanade.tachiyomi.data.database.models.Manga
|
||||
import eu.kanade.tachiyomi.data.database.models.MangaSync
|
||||
import eu.kanade.tachiyomi.data.database.models.CategoryImpl
|
||||
import eu.kanade.tachiyomi.data.database.models.ChapterImpl
|
||||
import eu.kanade.tachiyomi.data.database.models.MangaImpl
|
||||
import eu.kanade.tachiyomi.data.database.models.MangaSyncImpl
|
||||
|
||||
class IdExclusion : ExclusionStrategy {
|
||||
|
||||
@ -15,10 +15,10 @@ class IdExclusion : ExclusionStrategy {
|
||||
private val syncExclusions = listOf("id", "manga_id", "update")
|
||||
|
||||
override fun shouldSkipField(f: FieldAttributes) = when (f.declaringClass) {
|
||||
Manga::class.java -> mangaExclusions.contains(f.name)
|
||||
Chapter::class.java -> chapterExclusions.contains(f.name)
|
||||
MangaSync::class.java -> syncExclusions.contains(f.name)
|
||||
Category::class.java -> categoryExclusions.contains(f.name)
|
||||
MangaImpl::class.java -> mangaExclusions.contains(f.name)
|
||||
ChapterImpl::class.java -> chapterExclusions.contains(f.name)
|
||||
MangaSyncImpl::class.java -> syncExclusions.contains(f.name)
|
||||
CategoryImpl::class.java -> categoryExclusions.contains(f.name)
|
||||
else -> false
|
||||
}
|
||||
|
||||
|
@ -0,0 +1,16 @@
|
||||
package eu.kanade.tachiyomi.data.backup.serializer
|
||||
|
||||
import com.google.gson.JsonElement
|
||||
import com.google.gson.JsonPrimitive
|
||||
import com.google.gson.JsonSerializationContext
|
||||
import com.google.gson.JsonSerializer
|
||||
import java.lang.reflect.Type
|
||||
|
||||
class LongSerializer : JsonSerializer<Long> {
|
||||
|
||||
override fun serialize(value: Long?, type: Type, context: JsonSerializationContext): JsonElement? {
|
||||
if (value != null && value !== 0L)
|
||||
return JsonPrimitive(value)
|
||||
return null
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user