add world boss description dialog

This commit is contained in:
Phillip Thelen 2018-02-13 13:01:52 +01:00
parent caa9e959e8
commit 24e0407870
20 changed files with 339 additions and 111 deletions

View file

@ -0,0 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android">
<solid android:color="@color/gray_50" />
<corners android:radius="@dimen/rounded_button_radius"/>
<padding android:left="0dip" android:top="0dip" android:right="0dip" android:bottom="0dip" />
</shape>

View file

@ -0,0 +1,8 @@
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle">
<solid android:color="@color/transparent" />
<stroke
android:width="1dp"
android:color="@color/brand_500"/>
<corners android:radius="6dp" />
</shape>

View file

@ -44,4 +44,10 @@
android:paddingRight="@dimen/spacing_large"
tools:text="This is an example message"
tools:visibility="visible"/>
<FrameLayout
android:id="@+id/contentViewContainer"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:paddingLeft="@dimen/spacing_large"
android:paddingRight="@dimen/spacing_large" />
</LinearLayout>

View file

@ -38,6 +38,7 @@
android:layout_height="wrap_content"
app:title="@string/world_boss"
app:identifier="tavernWorldBoss"
app:hasAdditionalInfo="true"
android:visibility="gone">
<com.habitrpg.android.habitica.ui.views.social.QuestProgressView
android:id="@+id/questProgressView"

View file

@ -58,17 +58,39 @@
android:textColor="@color/white"
android:textSize="12sp"/>
</LinearLayout>
<com.habitrpg.android.habitica.ui.views.ValueBar
android:id="@+id/healthBarView"
<LinearLayout
android:id="@+id/bottomView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center_vertical"
android:orientation="horizontal"
tools:background="@color/brand_50"
android:paddingLeft="@dimen/spacing_medium"
android:paddingRight="@dimen/spacing_large"
android:paddingTop="@dimen/spacing_medium"
android:paddingBottom="@dimen/spacing_small"
app:barForegroundColor="@color/red_100"
app:barBackgroundColor="@color/white_15_alpha"
tools:background="@color/brand_50"/>
android:paddingRight="@dimen/spacing_large">
<com.habitrpg.android.habitica.ui.views.ValueBar
android:id="@+id/healthBarView"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:paddingTop="@dimen/spacing_medium"
android:paddingBottom="@dimen/spacing_small"
app:barForegroundColor="@color/red_100"
app:barBackgroundColor="@color/white_15_alpha"/>
<ImageView
android:id="@+id/pendingDamageIconView"
android:layout_width="18dp"
android:layout_height="18dp"
android:layout_marginLeft="@dimen/spacing_medium"
android:layout_marginRight="@dimen/spacing_small"/>
<TextView
android:id="@+id/pendingDamageTextView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textColor="@color/white"
android:textSize="13sp"
tools:text="+1"
/>
</LinearLayout>
</LinearLayout>
</RelativeLayout>

View file

@ -16,7 +16,7 @@
android:paddingTop="@dimen/spacing_large"
android:paddingBottom="@dimen/spacing_large"
android:paddingLeft="@dimen/spacing_large"
android:paddingRight="@dimen/spacing_large">
android:paddingRight="12dp">
<TextView
android:layout_width="0dp"
android:layout_height="wrap_content"

View file

@ -3,7 +3,7 @@
xmlns:tools="http://schemas.android.com/tools"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent">
android:layout_height="wrap_content">
<View
android:id="@+id/separator"
android:layout_width="match_parent"
@ -14,24 +14,34 @@
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:paddingLeft="@dimen/spacing_large"
android:paddingRight="@dimen/spacing_large">
android:paddingRight="@dimen/spacing_large"
android:gravity="center_vertical">
<TextView
android:id="@+id/titleTextView"
android:layout_width="0dp"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:layout_marginTop="@dimen/spacing_large"
android:layout_marginBottom="@dimen/spacing_large"
android:textSize="16sp"
android:textColor="@color/gray_50"
tools:text="Example"/>
<FrameLayout
android:layout_width="0dp"
android:layout_weight="1"
android:layout_height="18dp"
android:layout_marginLeft="@dimen/spacing_medium"
android:layout_marginRight="@dimen/spacing_medium">
<ImageView
android:id="@+id/infoIconView"
android:layout_width="18dp"
android:layout_height="18dp"
android:layout_gravity="center_vertical|left"/>
</FrameLayout>
<ImageView
android:id="@+id/caretView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:scaleType="center"
android:layout_gravity="center_vertical"
android:layout_marginRight="16dp" />
</LinearLayout>
</merge>

View file

@ -0,0 +1,85 @@
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent">
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="@string/world_boss_description_intro"
android:gravity="center_horizontal"
android:layout_marginBottom="@dimen/spacing_large"/>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<View
android:layout_width="@dimen/bullet_size"
android:layout_height="@dimen/bullet_size"
android:layout_marginRight="@dimen/spacing_medium"
android:background="@drawable/layout_rounded_bg_gray_50"
android:layout_marginTop="8dp"/>
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="@string/world_boss_description_1"
android:layout_marginBottom="@dimen/spacing_medium"/>
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<View
android:layout_width="@dimen/bullet_size"
android:layout_height="@dimen/bullet_size"
android:layout_marginRight="@dimen/spacing_medium"
android:background="@drawable/layout_rounded_bg_gray_50"
android:layout_marginTop="8dp"/>
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="@string/world_boss_description_2"
android:layout_marginBottom="@dimen/spacing_medium"/>
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<View
android:layout_width="@dimen/bullet_size"
android:layout_height="@dimen/bullet_size"
android:layout_marginRight="@dimen/spacing_medium"
android:background="@drawable/layout_rounded_bg_gray_50"
android:layout_marginTop="8dp"/>
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="@string/world_boss_description_3"
android:layout_marginBottom="@dimen/spacing_medium"/>
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<View
android:layout_width="@dimen/bullet_size"
android:layout_height="@dimen/bullet_size"
android:layout_marginRight="@dimen/spacing_medium"
android:background="@drawable/layout_rounded_bg_gray_50"
android:layout_marginTop="8dp"/>
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="@string/world_boss_description_4"
android:layout_marginBottom="@dimen/spacing_medium"/>
</LinearLayout>
<TextView
android:id="@+id/worldBossActionPromptView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
tools:text="@string/world_boss_action_prompt"
android:padding="@dimen/spacing_medium"
tools:background="@drawable/rounded_border"
android:gravity="center_horizontal"/>
</LinearLayout>

View file

@ -73,5 +73,6 @@
<attr name="title" />
<attr name="color" format="color" />
<attr name="identifier" />
<attr name="hasAdditionalInfo" format="boolean" />
</declare-styleable>
</resources>

View file

@ -123,5 +123,6 @@
<dimen name="navigation_drawer_width">240dp</dimen>
<dimen name="drawer_padding">16dp</dimen>
<dimen name="snackbar_image_size">46dp</dimen>
<dimen name="bullet_size">6dp</dimen>
</resources>

View file

@ -765,4 +765,13 @@
<string name="insufficientSubscriberGems">You have bought all the Gems you can this month. More become available within the first three days of each month. Thanks for subscribing!</string>
<string name="insufficientSubscriberGemsTitle">Monthly Gem Cap Reached</string>
<string name="chat_message">Chat Message</string>
<string name="world_boss_description_title">The DysHeartener attacks!</string>
<string name="world_boss_description_description">A World Boss is a special event where the whole community works together to take down a powerful monster with their tasks!\nComplete tasks to damage the Boss\nThe Boss wont damage you for missed tasks, but its Rage meter will go up. If the bar fills up, the Boss will attack one of the shopkeepers!\nYou can continue with normal Quest Bosses, damage will apply to both\nCheck the Tavern to see Boss progress and Rage attacks</string>
<string name="world_boss_description_intro">A World Boss is a special event where the whole community works together to take down a powerful monster with their tasks!</string>
<string name="world_boss_description_1">Complete tasks to damage the Boss</string>
<string name="world_boss_description_2">The Boss wont damage you for missed tasks, but its Rage meter will go up. If the bar fills up, the Boss will attack one of the shopkeepers!</string>
<string name="world_boss_description_3">You can continue with normal Quest Bosses, damage will apply to both</string>
<string name="world_boss_description_4">Check the Tavern to see Boss progress and Rage attacks</string>
<string name="world_boss_action_prompt" formatted="false">Defeat the Boss to earn special rewards and save Habitica from %ss Terror!</string>
<string name="world_boss_description_subtitle">%s attacks!</string>
</resources>

View file

@ -177,6 +177,7 @@ class NavigationDrawerFragment : DialogFragment() {
subscriptions?.add(userRepository.getUser().subscribe(Action1 {
setUsername(it.profile.name)
avatarView.setAvatar(it)
questMenuView.configure(it)
}, RxErrorHandler.handleEmptyError()))
messagesButton.setOnClickListener { setSelection(SIDEBAR_INBOX) }

View file

@ -1,13 +1,16 @@
package com.habitrpg.android.habitica.ui.fragments.social
import android.content.Context
import android.content.Intent
import android.graphics.Bitmap
import android.graphics.PorterDuff
import android.graphics.Shader
import android.graphics.drawable.BitmapDrawable
import android.net.Uri
import android.os.Build
import android.os.Bundle
import android.support.v4.content.ContextCompat
import android.support.v7.app.AlertDialog
import android.util.Log
import android.view.Gravity
import android.view.LayoutInflater
@ -15,6 +18,7 @@ import android.view.View
import android.view.ViewGroup
import android.widget.FrameLayout
import android.widget.ImageView
import android.widget.TextView
import com.habitrpg.android.habitica.R
import com.habitrpg.android.habitica.components.AppComponent
@ -38,16 +42,19 @@ import com.habitrpg.android.habitica.data.InventoryRepository
import com.habitrpg.android.habitica.data.SocialRepository
import com.habitrpg.android.habitica.events.commands.OpenMenuItemCommand
import com.habitrpg.android.habitica.extensions.backgroundCompat
import com.habitrpg.android.habitica.extensions.layoutInflater
import com.habitrpg.android.habitica.extensions.notNull
import com.habitrpg.android.habitica.helpers.RemoteConfigManager
import com.habitrpg.android.habitica.models.members.PlayerTier
import com.habitrpg.android.habitica.models.social.Group
import com.habitrpg.android.habitica.ui.fragments.NavigationDrawerFragment
import com.habitrpg.android.habitica.ui.helpers.DataBindingUtils
import com.habitrpg.android.habitica.ui.views.HabiticaAlertDialog
import com.habitrpg.android.habitica.ui.views.social.UsernameLabel
import kotlinx.android.synthetic.main.shop_header.*
import kotlinx.android.synthetic.main.fragment_tavern_detail.*
import org.greenrobot.eventbus.EventBus
import org.w3c.dom.Text
import rx.Observable
import rx.android.schedulers.AndroidSchedulers
import rx.functions.Action1
@ -155,6 +162,33 @@ class TavernDetailFragment : BaseFragment() {
reportButton.setOnClickListener {
EventBus.getDefault().post(OpenMenuItemCommand(NavigationDrawerFragment.SIDEBAR_ABOUT))
}
worldBossSection.infoIconView.setOnClickListener {
showWorldBossInfoDialog()
}
}
private fun showWorldBossInfoDialog() {
context.notNull { val alert = HabiticaAlertDialog(it)
val quest = questProgressView.quest
val bossName = quest?.boss?.name ?: ""
alert.setTitle(R.string.world_boss_description_title)
alert.setTitleBackgroundColor(quest?.colors?.mediumColor ?: 0)
alert.setSubtitle(it.getString(R.string.world_boss_description_subtitle, bossName))
alert.setAdditionalContentView(R.layout.world_boss_description_view)
val descriptionView = alert.getContentView()
val promptView: TextView? = descriptionView?.findViewById(R.id.worldBossActionPromptView)
promptView?.text = it.getString(R.string.world_boss_action_prompt, bossName)
promptView?.setTextColor(quest?.colors?.mediumColor ?: 0)
val background = ContextCompat.getDrawable(it, R.drawable.rounded_border)
background?.setColorFilter(quest?.colors?.extraLightColor ?: 0, PorterDuff.Mode.MULTIPLY)
promptView?.backgroundCompat = background
alert.setButton(AlertDialog.BUTTON_POSITIVE, it.getString(R.string.close), { dialog, _ ->
dialog.dismiss()
})
alert.show() }
}
private fun updatePausedState() {

View file

@ -19,6 +19,7 @@ class CollapsibleSectionView(context: Context?, attrs: AttributeSet?) : LinearLa
private val titleView: LinearLayout by bindView(R.id.title_view)
private val titleLabel: TextView by bindView(R.id.titleTextView)
private val caretView: ImageView by bindView(R.id.caretView)
public val infoIconView: ImageView by bindView(R.id.infoIconView)
private var preferences: SharedPreferences? = null
private val padding = context?.resources?.getDimension(R.dimen.spacing_large)?.toInt() ?: 0
@ -49,9 +50,7 @@ class CollapsibleSectionView(context: Context?, attrs: AttributeSet?) : LinearLa
return (separatorView.background as? ColorDrawable)?.color ?: 0
}
set(value) {
if (value != null) {
separatorView.setBackgroundColor(value)
}
separatorView.setBackgroundColor(value)
}
private fun showViews() {
@ -123,6 +122,12 @@ class CollapsibleSectionView(context: Context?, attrs: AttributeSet?) : LinearLa
caretColor = color
titleLabel.setTextColor(color)
}
if (attributes?.getBoolean(R.styleable.CollapsibleSectionView_hasAdditionalInfo, false) == true) {
infoIconView.setImageBitmap(HabiticaIconsHelper.imageOfInfoIcon())
} else {
infoIconView.visibility = View.GONE
}
}
override fun onAttachedToWindow() {

View file

@ -1,19 +1,16 @@
package com.habitrpg.android.habitica.ui.views
import android.content.Context
import android.os.Bundle
import android.support.v4.content.ContextCompat
import android.support.v7.app.AlertDialog
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import android.widget.LinearLayout
import android.widget.TextView
import com.habitrpg.android.habitica.R
import com.habitrpg.android.habitica.extensions.bindView
/**
* Created by phillip on 01.02.18.
*/
import com.habitrpg.android.habitica.extensions.layoutInflater
open class HabiticaAlertDialog(context: Context) : AlertDialog(context) {
@ -21,6 +18,7 @@ open class HabiticaAlertDialog(context: Context) : AlertDialog(context) {
private val titleTextView: TextView by bindView(view, R.id.titleTextView)
private val subtitleTextView: TextView by bindView(view, R.id.subtitleTextView)
private val messageTextView: TextView by bindView(view, R.id.messageTextView)
private val contentViewContainer: ViewGroup by bindView(view, R.id.contentViewContainer)
init {
setView(view)
@ -38,6 +36,10 @@ open class HabiticaAlertDialog(context: Context) : AlertDialog(context) {
titleTextView.setBackgroundColor(ContextCompat.getColor(context, colorId))
}
fun setTitleBackgroundColor(color: Int) {
titleTextView.setBackgroundColor(color)
}
fun setSubtitle(subtitle: CharSequence?) {
if (subtitle != null) {
subtitleTextView.visibility = View.VISIBLE
@ -63,4 +65,27 @@ open class HabiticaAlertDialog(context: Context) : AlertDialog(context) {
fun setMessage(messageId: Int) {
setMessage(context.getString(messageId))
}
fun setAdditionalContentView(layoutResID: Int) {
val inflater = context.layoutInflater
setAdditionalContentView(inflater.inflate(layoutResID, contentViewContainer, false))
}
fun setAdditionalContentView(view: View?) {
contentViewContainer.removeAllViewsInLayout()
if (view != null) {
contentViewContainer.visibility = View.VISIBLE
} else {
contentViewContainer.visibility = View.GONE
}
contentViewContainer.addView(view)
}
fun getContentView(): View? {
return if (contentViewContainer.childCount > 0) {
contentViewContainer.getChildAt(0)
} else {
null
}
}
}

View file

@ -19,6 +19,7 @@ import com.habitrpg.android.habitica.extensions.backgroundCompat
import com.habitrpg.android.habitica.extensions.bindView
import com.habitrpg.android.habitica.models.inventory.Quest
import com.habitrpg.android.habitica.models.inventory.QuestContent
import com.habitrpg.android.habitica.models.user.User
import com.habitrpg.android.habitica.ui.helpers.DataBindingUtils
import com.habitrpg.android.habitica.ui.views.HabiticaIconsHelper
import com.habitrpg.android.habitica.ui.views.ValueBar
@ -31,6 +32,9 @@ class QuestMenuView : LinearLayout {
private val healthBarView: ValueBar by bindView(R.id.healthBarView)
private val topView: LinearLayout by bindView(R.id.topView)
private val closeButton: AppCompatImageButton by bindView(R.id.closeButton)
private val bottomView: ViewGroup by bindView(R.id.bottomView)
private val pendingDamageIconView: ImageView by bindView(R.id.pendingDamageIconView)
private val pendingDamageTextView: TextView by bindView(R.id.pendingDamageTextView)
private var questContent: QuestContent? = null
@ -49,6 +53,8 @@ class QuestMenuView : LinearLayout {
healthBarView.setIcon(HabiticaIconsHelper.imageOfHeartDarkBg())
healthBarView.setLabelVisibility(View.GONE)
pendingDamageIconView.setImageBitmap(HabiticaIconsHelper.imageOfDamage())
closeButton.setOnClickListener {
hideBossArt()
val preferences = context.getSharedPreferences("collapsible_sections", 0)
@ -65,12 +71,19 @@ class QuestMenuView : LinearLayout {
fun configure(questContent: QuestContent) {
this.questContent = questContent
healthBarView.maxValue = questContent.boss.hp.toDouble()
healthBarView.setBackgroundColor(questContent.colors?.darkColor ?: 0)
bottomView.setBackgroundColor(questContent.colors?.darkColor ?: 0)
bossArtView.setBackgroundColor(questContent.colors?.mediumColor ?: 0)
DataBindingUtils.loadImage(bossArtView, "quest_"+questContent?.key)
DataBindingUtils.loadImage(bossArtView, "quest_"+questContent.key)
bossNameView.text = questContent.boss.name
}
fun configure(user: User) {
val party = user.party
val quest = party.quest
val progress = quest.progress
pendingDamageTextView.text = String.format("%.01f", (user.party?.quest?.progress?.up ?: 0))
}
fun hideBossArt() {
topView.orientation = LinearLayout.HORIZONTAL
topView.setBackgroundColor(questContent?.colors?.mediumColor ?: 0)

View file

@ -1,82 +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.JsonObject;
import com.google.gson.JsonParseException;
import com.habitrpg.android.habitica.models.inventory.Quest;
import com.habitrpg.android.habitica.models.inventory.QuestMember;
import com.habitrpg.android.habitica.models.inventory.QuestProgress;
import com.habitrpg.android.habitica.models.inventory.QuestProgressCollect;
import java.lang.reflect.Type;
import java.util.Map;
import io.realm.RealmList;
public class QuestDeserializer implements JsonDeserializer<Quest> {
@Override
public Quest deserialize(JsonElement json, Type typeOfT, JsonDeserializationContext context) throws JsonParseException {
JsonObject obj = json.getAsJsonObject();
Quest quest = new Quest();
if (obj.has("key") && !obj.get("key").isJsonNull()) {
quest.setKey(obj.get("key").getAsString());
} else {
return quest;
}
if (obj.has("active")) {
quest.setActive(obj.get("active").getAsBoolean());
}
if (obj.has("leader")) {
quest.setLeader(obj.get("leader").getAsString());
}
if (obj.has("RSVPNeeded")) {
quest.setRSVPNeeded(obj.get("RSVPNeeded").getAsBoolean());
}
if (obj.has("progress")) {
QuestProgress progress = new QuestProgress();
progress.setKey(quest.getKey());
JsonObject progressObj = obj.get("progress").getAsJsonObject();
if (progressObj.has("hp")) {
progress.setHp(progressObj.get("hp").getAsInt());
}
if (progressObj.has("rage")) {
progress.setRage(progressObj.get("rage").getAsInt());
}
if (progressObj.has("up")) {
progress.setUp(progressObj.get("up").getAsInt());
}
if (progressObj.has("down")) {
progress.setDown(progressObj.get("down").getAsInt());
}
if (progressObj.has("collect")) {
progress.setCollect(new RealmList<>());
for (Map.Entry<String, JsonElement> entry : progressObj.get("collect").getAsJsonObject().entrySet()) {
QuestProgressCollect collect = new QuestProgressCollect();
collect.key = entry.getKey();
collect.count = entry.getValue().getAsInt();
progress.getCollect().add(collect);
}
}
quest.setProgress(progress);
}
if (obj.has("members")) {
RealmList<QuestMember> members = new RealmList<>();
for (Map.Entry<String, JsonElement> entry : obj.get("members").getAsJsonObject().entrySet()) {
QuestMember member = new QuestMember();
member.key = entry.getKey();
if (entry.getValue().isJsonNull()) {
member.isParticipating = null;
} else {
member.isParticipating = entry.getValue().getAsBoolean();
}
members.add(member);
}
quest.setMembers(members);
}
return quest;
}
}

View file

@ -0,0 +1,82 @@
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.JsonObject
import com.google.gson.JsonParseException
import com.habitrpg.android.habitica.models.inventory.Quest
import com.habitrpg.android.habitica.models.inventory.QuestMember
import com.habitrpg.android.habitica.models.inventory.QuestProgress
import com.habitrpg.android.habitica.models.inventory.QuestProgressCollect
import java.lang.reflect.Type
import io.realm.RealmList
class QuestDeserializer : JsonDeserializer<Quest> {
@Throws(JsonParseException::class)
override fun deserialize(json: JsonElement, typeOfT: Type, context: JsonDeserializationContext): Quest {
val obj = json.asJsonObject
val quest = Quest()
if (obj.has("progress")) {
val progress = QuestProgress()
progress.key = quest.key
val progressObj = obj.getAsJsonObject("progress")
if (progressObj.has("hp")) {
progress.hp = progressObj.get("hp").asDouble
}
if (progressObj.has("rage")) {
progress.rage = progressObj.get("rage").asDouble
}
if (progressObj.has("up")) {
progress.up = progressObj.get("up").asFloat
}
if (progressObj.has("down")) {
progress.down = progressObj.get("down").asFloat
}
if (progressObj.has("collect")) {
progress.collect = RealmList()
for ((key, value) in progressObj.getAsJsonObject("collect").entrySet()) {
val collect = QuestProgressCollect()
collect.key = key
collect.count = value.asInt
progress.collect?.add(collect)
}
}
quest.progress = progress
}
if (obj.has("key") && !obj.get("key").isJsonNull) {
quest.key = obj.get("key").asString
} else {
return quest
}
if (obj.has("active")) {
quest.active = obj.get("active").asBoolean
}
if (obj.has("leader")) {
quest.leader = obj.get("leader").asString
}
if (obj.has("RSVPNeeded")) {
quest.RSVPNeeded = obj.get("RSVPNeeded").asBoolean
}
if (obj.has("members")) {
val members = RealmList<QuestMember>()
for ((key, value) in obj.getAsJsonObject("members").entrySet()) {
val member = QuestMember()
member.key = key
if (value.isJsonNull) {
member.isParticipating = null
} else {
member.isParticipating = value.asBoolean
}
members.add(member)
}
quest.members = members
}
return quest
}
}

View file

@ -50,7 +50,7 @@ class UserDeserializer : JsonDeserializer<User> {
user.party = context.deserialize(obj.get("party"), UserParty::class.java)
if (user.party != null && user.party.quest != null) {
user.party.quest.id = user.id
if (!obj.get("party").asJsonObject.get("quest").asJsonObject.has("RSVPNeeded")) {
if (!obj.getAsJsonObject("party").getAsJsonObject("quest").has("RSVPNeeded")) {
val realm = Realm.getDefaultInstance()
val quest = realm.where(Quest::class.java).equalTo("id", user.id).findFirst()
if (quest != null && quest.isValid) {
@ -91,9 +91,9 @@ class UserDeserializer : JsonDeserializer<User> {
}
if (obj.has("purchased")) {
user.purchased = context.deserialize(obj.get("purchased"), Purchases::class.java)
if (obj.get("purchased").asJsonObject.has("plan")) {
if (obj.get("purchased").asJsonObject.get("plan").asJsonObject.has("mysteryItems")) {
user.purchased.plan.mysteryItemCount = obj.get("purchased").asJsonObject.get("plan").asJsonObject.get("mysteryItems").asJsonArray.size()
if (obj.getAsJsonObject("purchased").has("plan")) {
if (obj.getAsJsonObject("purchased").getAsJsonObject("plan").has("mysteryItems")) {
user.purchased.plan.mysteryItemCount = obj.getAsJsonObject("purchased").getAsJsonObject("plan").getAsJsonArray("mysteryItems").size()
}
}
}

View file

@ -27,6 +27,7 @@ class WorldStateSerialization: JsonDeserializer<WorldState> {
if (progressObj.has("rage")) {
progress.rage = progressObj["rage"].asDouble
}
state.progress = progress
}
if (worldBossObject.has("extra")) {
val extra = worldBossObject["extra"].asJsonObject