mirror of
https://github.com/sudoxnym/habitica-android.git
synced 2026-05-19 20:29:02 +00:00
Fix content mapping
This commit is contained in:
parent
e40e768888
commit
fa02797e64
5 changed files with 39 additions and 58 deletions
|
|
@ -149,8 +149,8 @@ android {
|
|||
buildConfigField "String", "TESTING_LEVEL", "\"production\""
|
||||
multiDexEnabled true
|
||||
|
||||
versionCode 2169
|
||||
versionName "2.0"
|
||||
versionCode 2174
|
||||
versionName "2.0.1"
|
||||
}
|
||||
|
||||
lintOptions {
|
||||
|
|
|
|||
|
|
@ -13,9 +13,9 @@ open class RealmContentLocalRepository(realm: Realm) : RealmBaseLocalRepository(
|
|||
|
||||
override fun saveContent(contentResult: ContentResult) {
|
||||
realm.executeTransactionAsync { realm1 ->
|
||||
realm1.insertOrUpdate(contentResult.potion)
|
||||
realm1.insertOrUpdate(contentResult.armoire)
|
||||
realm1.insertOrUpdate(contentResult.gear.flat)
|
||||
contentResult.potion?.let { realm1.insertOrUpdate(it) }
|
||||
contentResult.armoire?.let { realm1.insertOrUpdate(it) }
|
||||
contentResult.gear?.flat?.let { realm1.insertOrUpdate(it) }
|
||||
|
||||
realm1.insertOrUpdate(contentResult.quests)
|
||||
realm1.insertOrUpdate(contentResult.eggs)
|
||||
|
|
|
|||
|
|
@ -1,45 +0,0 @@
|
|||
package com.habitrpg.android.habitica.models;
|
||||
|
||||
import com.habitrpg.android.habitica.models.inventory.Customization;
|
||||
import com.habitrpg.android.habitica.models.inventory.Egg;
|
||||
import com.habitrpg.android.habitica.models.inventory.Equipment;
|
||||
import com.habitrpg.android.habitica.models.inventory.Food;
|
||||
import com.habitrpg.android.habitica.models.inventory.HatchingPotion;
|
||||
import com.habitrpg.android.habitica.models.inventory.Mount;
|
||||
import com.habitrpg.android.habitica.models.inventory.Pet;
|
||||
import com.habitrpg.android.habitica.models.inventory.QuestContent;
|
||||
import com.habitrpg.android.habitica.models.inventory.SpecialItem;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import io.realm.RealmList;
|
||||
|
||||
/**
|
||||
* Created by Negue on 15.07.2015.
|
||||
*/
|
||||
public class ContentResult {
|
||||
|
||||
public Equipment potion;
|
||||
|
||||
public Equipment armoire;
|
||||
|
||||
public ContentGear gear;
|
||||
|
||||
public RealmList<QuestContent> quests;
|
||||
public RealmList<Egg> eggs;
|
||||
public RealmList<Food> food;
|
||||
public RealmList<HatchingPotion> hatchingPotions;
|
||||
|
||||
public RealmList<Pet> pets;
|
||||
|
||||
public RealmList<Mount> mounts;
|
||||
|
||||
public List<Skill> spells;
|
||||
|
||||
public RealmList<Customization> appearances;
|
||||
public RealmList<Customization> backgrounds;
|
||||
|
||||
public RealmList<FAQArticle> faq;
|
||||
public RealmList<SpecialItem> special;
|
||||
}
|
||||
|
||||
|
|
@ -0,0 +1,34 @@
|
|||
package com.habitrpg.android.habitica.models
|
||||
|
||||
import com.habitrpg.android.habitica.models.inventory.*
|
||||
import io.realm.RealmList
|
||||
|
||||
/**
|
||||
* Created by Negue on 15.07.2015.
|
||||
*/
|
||||
class ContentResult {
|
||||
|
||||
var potion: Equipment? = null
|
||||
|
||||
var armoire: Equipment? = null
|
||||
|
||||
var gear: ContentGear? = null
|
||||
|
||||
var quests = RealmList<QuestContent>()
|
||||
var eggs = RealmList<Egg>()
|
||||
var food = RealmList<Food>()
|
||||
var hatchingPotions = RealmList<HatchingPotion>()
|
||||
|
||||
var pets = RealmList<Pet>()
|
||||
|
||||
var mounts = RealmList<Mount>()
|
||||
|
||||
var spells = RealmList<Skill>()
|
||||
|
||||
var appearances = RealmList<Customization>()
|
||||
var backgrounds = RealmList<Customization>()
|
||||
|
||||
var faq = RealmList<FAQArticle>()
|
||||
var special = RealmList<SpecialItem>()
|
||||
}
|
||||
|
||||
|
|
@ -14,7 +14,6 @@ import com.habitrpg.android.habitica.models.Skill
|
|||
import com.habitrpg.android.habitica.models.inventory.*
|
||||
import io.realm.RealmList
|
||||
import java.lang.reflect.Type
|
||||
import java.util.*
|
||||
|
||||
class ContentDeserializer : JsonDeserializer<ContentResult> {
|
||||
|
||||
|
|
@ -29,25 +28,20 @@ class ContentDeserializer : JsonDeserializer<ContentResult> {
|
|||
result.armoire = context.deserialize(obj.get("armoire"), Equipment::class.java)
|
||||
result.gear = context.deserialize(obj.get("gear"), ContentGear::class.java)
|
||||
|
||||
result.quests = RealmList()
|
||||
for (entry in obj.get("quests").asJsonObject.entrySet()) {
|
||||
result.quests.add(context.deserialize(entry.value, QuestContent::class.java))
|
||||
result.quests.forEach { it.key = it.key }
|
||||
}
|
||||
result.eggs = RealmList()
|
||||
for (entry in obj.get("eggs").asJsonObject.entrySet()) {
|
||||
result.eggs.add(context.deserialize(entry.value, Egg::class.java))
|
||||
}
|
||||
result.food = RealmList()
|
||||
for (entry in obj.get("food").asJsonObject.entrySet()) {
|
||||
result.food.add(context.deserialize(entry.value, Food::class.java))
|
||||
}
|
||||
result.hatchingPotions = RealmList()
|
||||
for (entry in obj.get("hatchingPotions").asJsonObject.entrySet()) {
|
||||
result.hatchingPotions.add(context.deserialize(entry.value, HatchingPotion::class.java))
|
||||
}
|
||||
|
||||
result.pets = RealmList()
|
||||
val pets = obj.getAsJsonObject("petInfo")
|
||||
for (key in pets.keySet()) {
|
||||
val pet = Pet()
|
||||
|
|
@ -67,7 +61,6 @@ class ContentDeserializer : JsonDeserializer<ContentResult> {
|
|||
result.pets.add(pet)
|
||||
}
|
||||
|
||||
result.mounts = RealmList()
|
||||
val mounts = obj.getAsJsonObject("mountInfo")
|
||||
for (key in mounts.keySet()) {
|
||||
val mount = Mount()
|
||||
|
|
@ -85,7 +78,6 @@ class ContentDeserializer : JsonDeserializer<ContentResult> {
|
|||
}
|
||||
result.mounts.add(mount)
|
||||
}
|
||||
result.spells = ArrayList<Skill>()
|
||||
for ((classname, value) in obj.getAsJsonObject("spells").entrySet()) {
|
||||
val classObject = value.asJsonObject
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue