Fix loading pets and mounts

This commit is contained in:
Phillip Thelen 2019-08-06 15:14:26 +02:00
parent 21d130a18b
commit c303056ce4
3 changed files with 31 additions and 3 deletions

View file

@ -1,7 +1,5 @@
package com.habitrpg.android.habitica.models.user
import io.realm.RealmMigration
import io.realm.RealmModel
import io.realm.RealmObject
import io.realm.annotations.PrimaryKey
@ -21,4 +19,17 @@ open class OwnedMount : RealmObject(), OwnedObject {
}
var owned = false
override fun equals(other: Any?): Boolean {
return if (other?.javaClass == OwnedMount::class.java) {
this.combinedKey == (other as OwnedMount).combinedKey
} else super.equals(other)
}
override fun hashCode(): Int {
var result = combinedKey.hashCode()
result = 31 * result + userID.hashCode()
result = 31 * result + key.hashCode()
return result
}
}

View file

@ -20,4 +20,17 @@ open class OwnedPet : RealmObject(), OwnedObject {
}
var trained = 0
override fun equals(other: Any?): Boolean {
return if (other?.javaClass == OwnedPet::class.java) {
this.combinedKey == (other as OwnedPet).combinedKey
} else super.equals(other)
}
override fun hashCode(): Int {
var result = combinedKey.hashCode()
result = 31 * result + userID.hashCode()
result = 31 * result + key.hashCode()
return result
}
}

View file

@ -6,6 +6,7 @@ import com.google.gson.JsonDeserializer
import com.google.gson.JsonElement
import com.google.gson.JsonParseException
import com.google.gson.reflect.TypeToken
import com.habitrpg.android.habitica.extensions.getAsString
import com.habitrpg.android.habitica.models.PushDevice
import com.habitrpg.android.habitica.models.QuestAchievement
import com.habitrpg.android.habitica.models.Tag
@ -29,7 +30,10 @@ class UserDeserializer : JsonDeserializer<User> {
val obj = json.asJsonObject
if (obj.has("_id")) {
user.id = obj.get("_id").asString
user.id = obj.getAsString("_id")
}
if (obj.has("_v")) {
user.versionNumber = obj.get("_v").asInt
}
if (obj.has("balance")) {