data handling improvements

This commit is contained in:
Phillip Thelen 2021-06-08 16:53:41 +02:00
parent eb2333667b
commit 077d23b380
5 changed files with 2 additions and 55 deletions

View file

@ -20,7 +20,7 @@ import java.util.*
object GSonFactoryCreator { object GSonFactoryCreator {
fun create(): GsonConverterFactory { fun create(): GsonConverterFactory {
val skillListType = object : TypeToken<List<Skill?>?>() {}.type val skillListType = object : TypeToken<List<Skill>?>() {}.type
val taskTagClassListType = object : TypeToken<RealmList<Tag?>?>() {}.type val taskTagClassListType = object : TypeToken<RealmList<Tag?>?>() {}.type
val customizationListType = object : TypeToken<RealmList<Customization?>?>() {}.type val customizationListType = object : TypeToken<RealmList<Customization?>?>() {}.type
val tutorialStepListType = object : TypeToken<RealmList<TutorialStep?>?>() {}.type val tutorialStepListType = object : TypeToken<RealmList<TutorialStep?>?>() {}.type
@ -34,7 +34,7 @@ object GSonFactoryCreator {
val ownedItemListType = object : TypeToken<RealmList<OwnedItem?>?>() {}.type val ownedItemListType = object : TypeToken<RealmList<OwnedItem?>?>() {}.type
val ownedPetListType = object : TypeToken<RealmList<OwnedPet?>?>() {}.type val ownedPetListType = object : TypeToken<RealmList<OwnedPet?>?>() {}.type
val ownedMountListType = object : TypeToken<RealmList<OwnedMount?>?>() {}.type val ownedMountListType = object : TypeToken<RealmList<OwnedMount?>?>() {}.type
val achievementsListType = object : TypeToken<List<Achievement?>?>() {}.type val achievementsListType = object : TypeToken<List<Achievement>?>() {}.type
val gson = GsonBuilder() val gson = GsonBuilder()
.registerTypeAdapter(taskTagClassListType, TaskTagDeserializer()) .registerTypeAdapter(taskTagClassListType, TaskTagDeserializer())
@ -57,7 +57,6 @@ object GSonFactoryCreator {
.registerTypeAdapter(Challenge::class.java, ChallengeDeserializer()) .registerTypeAdapter(Challenge::class.java, ChallengeDeserializer())
.registerTypeAdapter(User::class.java, UserDeserializer()) .registerTypeAdapter(User::class.java, UserDeserializer())
.registerTypeAdapter(questCollectListType, QuestCollectDeserializer()) .registerTypeAdapter(questCollectListType, QuestCollectDeserializer())
.registerTypeAdapter(chatMessageListType, ChatMessageListDeserializer())
.registerTypeAdapter(challengeListType, ChallengeListDeserializer()) .registerTypeAdapter(challengeListType, ChallengeListDeserializer())
.registerTypeAdapter(challengeRealmListType, ChallengeListDeserializer()) .registerTypeAdapter(challengeRealmListType, ChallengeListDeserializer())
.registerTypeAdapter(questDropItemListType, QuestDropItemsListSerialization()) .registerTypeAdapter(questDropItemListType, QuestDropItemsListSerialization())

View file

@ -41,16 +41,6 @@ open class ChecklistItem : RealmObject, BaseMainObject, Parcelable {
this.completed = item.completed this.completed = item.completed
} }
override fun equals(other: Any?): Boolean {
return if (other?.javaClass == ChecklistItem::class.java && this.id != null) {
this.id == (other as? ChecklistItem)?.id
} else super.equals(other)
}
override fun hashCode(): Int {
return id?.hashCode() ?: 0
}
override fun describeContents(): Int { override fun describeContents(): Int {
return 0 return 0
} }

View file

@ -18,16 +18,6 @@ open class RemindersItem : RealmObject, Parcelable {
//Use to store task type before a task is created //Use to store task type before a task is created
var type: String? = null var type: String? = null
override fun equals(other: Any?): Boolean {
return if (other?.javaClass == RemindersItem::class.java) {
this.id == (other as? RemindersItem)?.id
} else super.equals(other)
}
override fun hashCode(): Int {
return id?.hashCode() ?: 0
}
override fun describeContents(): Int { override fun describeContents(): Int {
return 0 return 0
} }

View file

@ -29,8 +29,6 @@ import javax.inject.Inject
open class ShopFragment : BaseMainFragment<FragmentRecyclerviewBinding>() { open class ShopFragment : BaseMainFragment<FragmentRecyclerviewBinding>() {
internal val currencyView: CurrencyViews by lazy { internal val currencyView: CurrencyViews by lazy {
val view = CurrencyViews(context) val view = CurrencyViews(context)
view view

View file

@ -1,30 +0,0 @@
package com.habitrpg.android.habitica.utils
import com.google.gson.JsonDeserializationContext
import com.google.gson.JsonDeserializer
import com.google.gson.JsonElement
import com.google.gson.JsonParseException
import com.habitrpg.android.habitica.models.social.ChatMessage
import java.lang.reflect.Type
import io.realm.RealmList
class ChatMessageListDeserializer : JsonDeserializer<RealmList<ChatMessage>> {
@Throws(JsonParseException::class)
override fun deserialize(json: JsonElement, typeOfT: Type, context: JsonDeserializationContext): RealmList<ChatMessage> {
val messages = RealmList<ChatMessage>()
if (json.isJsonArray) {
json.asJsonArray.mapTo(messages) { context.deserialize(it, ChatMessage::class.java) }
} else {
for ((_, value) in json.asJsonObject.entrySet()) {
messages.add(context.deserialize(value, ChatMessage::class.java))
}
}
//Make sure the messageId is set for all likes
messages.forEach { it.id = it.id }
return messages
}
}