diff --git a/Habitica/src/main/java/com/habitrpg/android/habitica/models/inventory/QuestContent.java b/Habitica/src/main/java/com/habitrpg/android/habitica/models/inventory/QuestContent.java deleted file mode 100644 index 9e2149c63..000000000 --- a/Habitica/src/main/java/com/habitrpg/android/habitica/models/inventory/QuestContent.java +++ /dev/null @@ -1,165 +0,0 @@ -package com.habitrpg.android.habitica.models.inventory; - -import android.support.annotation.Nullable; - -import io.realm.RealmList; -import io.realm.RealmObject; -import io.realm.annotations.PrimaryKey; - -public class QuestContent extends RealmObject implements Item { - - @PrimaryKey - String key; - String text, notes; - int value, owned; - private String previous; - private int lvl; - private boolean canBuy; - private String category; - @Nullable - private QuestBoss boss; - @Nullable - private QuestDrops drop; - @Nullable - private QuestColors colors; - - RealmList collect; - - public String getPrevious() { - return previous; - } - - public void setPrevious(String previous) { - this.previous = previous; - } - - public int getLvl() { - return lvl; - } - - public void setLvl(int lvl) { - this.lvl = lvl; - } - - public boolean isCanBuy() { - return canBuy; - } - - public void setCanBuy(boolean canBuy) { - this.canBuy = canBuy; - } - - public String getCategory() { - return category; - } - - public void setCategory(String category) { - this.category = category; - } - - public QuestBoss getBoss() { - return boss; - } - - public void setBoss(QuestBoss boss) { - this.boss = boss; - if (boss != null) { - boss.setKey(key); - } - } - - @Nullable - public QuestColors getColors() { - return colors; - } - - public void setColors(QuestColors colors) { - this.colors = colors; - if (colors != null) { - colors.setKey(key); - } - } - - public RealmList getCollect() { - return collect; - } - - public void setCollect(RealmList collect) { - this.collect = collect; - } - - @Override - public String getType() { - return "quests"; - } - - @Override - public String getKey() { - return key; - } - - @Override - public void setOwned(int size) { - owned = size; - } - - @Override - public String getText() { - return text; - } - - @Override - public Integer getOwned() { - return owned; - } - - @Override - public Integer getValue() { - return value; - } - - public void setText(String text) { - this.text = text; - } - - public String getNotes() { - return notes; - } - - public void setValue(Integer value) { - this.value = value; - } - - public void setNotes(String notes) { - this.notes = notes; - } - - public void setKey(String key) { - this.key = key; - } - - @Nullable - public QuestCollect getCollectWithKey(String key) { - for (QuestCollect collect : this.collect) { - if (collect.key.equals(key)) { - return collect; - } - } - return null; - } - - public QuestDrops getDrop() { - return drop; - } - - public void setDrop(QuestDrops drop) { - this.drop = drop; - if (drop != null) { - drop.setKey(key); - } - } - - public boolean isBossQuest() { - return boss != null; - } -} diff --git a/Habitica/src/main/java/com/habitrpg/android/habitica/models/inventory/QuestContent.kt b/Habitica/src/main/java/com/habitrpg/android/habitica/models/inventory/QuestContent.kt new file mode 100644 index 000000000..644e10f96 --- /dev/null +++ b/Habitica/src/main/java/com/habitrpg/android/habitica/models/inventory/QuestContent.kt @@ -0,0 +1,100 @@ +package com.habitrpg.android.habitica.models.inventory + +import java.util.ArrayList + +import io.realm.RealmList +import io.realm.RealmObject +import io.realm.annotations.PrimaryKey + +open class QuestContent : RealmObject(), Item { + + @PrimaryKey + internal var key: String = "" + internal var text: String = "" + var notes: String = "" + internal var value: Int = 0 + internal var owned: Int = 0 + var previous: String? = null + var lvl: Int = 0 + var isCanBuy: Boolean = false + var category: String? = null + var boss: QuestBoss? = null + set(boss) { + field = boss + if (boss != null) { + boss.key = key + } + } + var drop: QuestDrops? = null + set(drop) { + field = drop + if (drop != null) { + drop.key = key + } + } + var colors: QuestColors? = null + set(colors) { + field = colors + if (colors != null) { + colors.key = key + } + } + + var collect: RealmList? = null + + val isBossQuest: Boolean + get() = this.boss != null + + override fun getType(): String { + return "quests" + } + + override fun getKey(): String { + return key + } + + override fun setOwned(size: Int) { + owned = size + } + + override fun getText(): String { + return text + } + + override fun getOwned(): Int? { + return owned + } + + override fun getValue(): Int? { + return value + } + + fun setText(text: String) { + this.text = text + } + + fun setValue(value: Int?) { + this.value = value!! + } + + fun setKey(key: String) { + this.key = key + } + + fun getCollectWithKey(key: String): QuestCollect? { + for (collect in this.collect ?: emptyList()) { + if (collect.key == key) { + return collect + } + } + return null + } + + fun hasGifImage(): Boolean { + val gifImageKeys = listOf("lostMasterclasser4") + if (gifImageKeys.contains(key)) { + return true + } + return false + } +} diff --git a/Habitica/src/main/java/com/habitrpg/android/habitica/ui/fragments/social/TavernDetailFragment.kt b/Habitica/src/main/java/com/habitrpg/android/habitica/ui/fragments/social/TavernDetailFragment.kt index dd3bd4f90..8a0f50a5e 100644 --- a/Habitica/src/main/java/com/habitrpg/android/habitica/ui/fragments/social/TavernDetailFragment.kt +++ b/Habitica/src/main/java/com/habitrpg/android/habitica/ui/fragments/social/TavernDetailFragment.kt @@ -182,7 +182,7 @@ class TavernDetailFragment : BaseFragment() { fun showWorldBossInfoDialog(context: Context, quest: QuestContent) { val alert = HabiticaAlertDialog(context) - val bossName = quest.boss.name ?: "" + val bossName = quest.boss?.name ?: "" alert.setTitle(R.string.world_boss_description_title) alert.setTitleBackgroundColor(quest.colors?.lightColor ?: 0) alert.setSubtitle(context.getString(R.string.world_boss_description_subtitle, bossName)) diff --git a/Habitica/src/main/java/com/habitrpg/android/habitica/ui/fragments/social/party/PartyDetailFragment.kt b/Habitica/src/main/java/com/habitrpg/android/habitica/ui/fragments/social/party/PartyDetailFragment.kt index 97e9bf032..0b00bfbdb 100644 --- a/Habitica/src/main/java/com/habitrpg/android/habitica/ui/fragments/social/party/PartyDetailFragment.kt +++ b/Habitica/src/main/java/com/habitrpg/android/habitica/ui/fragments/social/party/PartyDetailFragment.kt @@ -185,7 +185,11 @@ class PartyDetailFragment : BaseFragment() { } questTitleView?.text = questContent.text DataBindingUtils.loadImage(questScrollImageView, "inventory_quest_scroll_" + questContent.key) - DataBindingUtils.loadImage(questImageView, "quest_" + questContent.key) + if (questContent.hasGifImage()) { + DataBindingUtils.loadImage(questImageView, "quest_" + questContent.key, "gif") + } else { + DataBindingUtils.loadImage(questImageView, "quest_" + questContent.key) + } if (isQuestActive) { questProgressView?.visibility = View.VISIBLE questProgressView?.setData(questContent, quest?.progress) diff --git a/Habitica/src/main/java/com/habitrpg/android/habitica/ui/views/shops/PurchaseDialogQuestContent.kt b/Habitica/src/main/java/com/habitrpg/android/habitica/ui/views/shops/PurchaseDialogQuestContent.kt index 2f44db4a9..9c22c825e 100644 --- a/Habitica/src/main/java/com/habitrpg/android/habitica/ui/views/shops/PurchaseDialogQuestContent.kt +++ b/Habitica/src/main/java/com/habitrpg/android/habitica/ui/views/shops/PurchaseDialogQuestContent.kt @@ -43,14 +43,14 @@ class PurchaseDialogQuestContent : PurchaseDialogContent { if (questContent.isBossQuest) { questTypeTextView.setText(R.string.boss_quest) questCollectView.visibility = View.GONE - bossHealthTextView.text = questContent.boss.hp.toString() - if (questContent.boss.hasRage()) { + bossHealthTextView.text = questContent.boss?.hp.toString() + if (questContent.boss?.hasRage() == true) { rageMeterView.visibility = View.VISIBLE } - questDifficultyView.rating = questContent.boss.str + questDifficultyView.rating = questContent.boss?.str ?: 1f } else { questTypeTextView.setText(R.string.collection_quest) - val collectionList = questContent.collect.map { it.count.toString() + " " + it.text } + val collectionList = questContent.collect?.map { it.count.toString() + " " + it.text } questCollectTextView.text = TextUtils.join(", ", collectionList) bossHealthView.visibility = View.GONE @@ -62,13 +62,13 @@ class PurchaseDialogQuestContent : PurchaseDialogContent { val inflater = context.getSystemService(Context.LAYOUT_INFLATER_SERVICE) as? LayoutInflater - if (questContent.drop != null && questContent.drop.items != null) { - questContent.drop.items - .filterNot { it.isOnlyOwner } - .forEach { addRewardsRow(inflater, it, rewardsList) } + if (questContent.drop != null && questContent.drop?.items != null) { + questContent.drop?.items + ?.filterNot { it.isOnlyOwner } + ?.forEach { addRewardsRow(inflater, it, rewardsList) } var hasOwnerRewards = false - for (item in questContent.drop.items) { + for (item in questContent.drop?.items ?: emptyList()) { if (item.isOnlyOwner) { addRewardsRow(inflater, item, ownerRewardsList) hasOwnerRewards = true @@ -79,23 +79,23 @@ class PurchaseDialogQuestContent : PurchaseDialogContent { ownerRewardsList.visibility = View.GONE } - if (questContent.drop.exp > 0) { + if (questContent.drop?.exp ?: 0 > 0) { val view = inflater?.inflate(R.layout.row_quest_reward_imageview, rewardsList, false) as? ViewGroup val imageView = view?.findViewById(R.id.imageView) imageView?.scaleType = ImageView.ScaleType.CENTER imageView?.setImageBitmap(HabiticaIconsHelper.imageOfExperienceReward()) val titleTextView = view?.findViewById(R.id.titleTextView) - titleTextView?.text = context.getString(R.string.experience_reward, questContent.drop.exp) + titleTextView?.text = context.getString(R.string.experience_reward, questContent.drop?.exp) rewardsList.addView(view) } - if (questContent.drop.gp > 0) { + if (questContent.drop?.gp ?: 0 > 0) { val view = inflater?.inflate(R.layout.row_quest_reward_imageview, rewardsList, false) as? ViewGroup val imageView = view?.findViewById(R.id.imageView) imageView?.scaleType = ImageView.ScaleType.CENTER imageView?.setImageBitmap(HabiticaIconsHelper.imageOfGoldReward()) val titleTextView = view?.findViewById(R.id.titleTextView) - titleTextView?.text = context.getString(R.string.gold_reward, questContent.drop.gp) + titleTextView?.text = context.getString(R.string.gold_reward, questContent.drop?.gp) rewardsList.addView(view) } } diff --git a/Habitica/src/main/java/com/habitrpg/android/habitica/ui/views/social/OldQuestProgressView.kt b/Habitica/src/main/java/com/habitrpg/android/habitica/ui/views/social/OldQuestProgressView.kt index ab89ac06f..07f98e9d0 100644 --- a/Habitica/src/main/java/com/habitrpg/android/habitica/ui/views/social/OldQuestProgressView.kt +++ b/Habitica/src/main/java/com/habitrpg/android/habitica/ui/views/social/OldQuestProgressView.kt @@ -71,13 +71,13 @@ class OldQuestProgressView : LinearLayout { fun setData(quest: QuestContent, progress: QuestProgress?) { collectionContainer.removeAllViews() if (quest.isBossQuest) { - bossNameView.text = quest.boss.name + bossNameView.text = quest.boss?.name if (progress != null) { - bossHealthView.set(progress.hp, quest.boss.hp.toDouble()) + bossHealthView.set(progress.hp, quest.boss?.hp?.toDouble() ?: 0.0) } - if (quest.boss.hasRage()) { + if (quest.boss?.hasRage() == true) { bossRageView.visibility = View.VISIBLE - bossRageView.set(progress?.rage ?: 0.0, quest.boss.rage?.value ?: 0.0) + bossRageView.set(progress?.rage ?: 0.0, quest.boss?.rage?.value ?: 0.0) } else { bossRageView.visibility = View.GONE } diff --git a/Habitica/src/main/java/com/habitrpg/android/habitica/ui/views/social/QuestMenuView.kt b/Habitica/src/main/java/com/habitrpg/android/habitica/ui/views/social/QuestMenuView.kt index 433b25366..2d8596bff 100644 --- a/Habitica/src/main/java/com/habitrpg/android/habitica/ui/views/social/QuestMenuView.kt +++ b/Habitica/src/main/java/com/habitrpg/android/habitica/ui/views/social/QuestMenuView.kt @@ -71,11 +71,11 @@ class QuestMenuView : LinearLayout { fun configure(questContent: QuestContent) { this.questContent = questContent - healthBarView.maxValue = questContent.boss.hp.toDouble() + healthBarView.maxValue = questContent.boss?.hp?.toDouble() ?: 0.0 bottomView.setBackgroundColor(questContent.colors?.darkColor ?: 0) bossArtView.setBackgroundColor(questContent.colors?.mediumColor ?: 0) DataBindingUtils.loadImage(bossArtView, "quest_"+questContent.key) - bossNameView.text = questContent.boss.name + bossNameView.text = questContent.boss?.name } fun configure(user: User) { diff --git a/Habitica/src/main/java/com/habitrpg/android/habitica/ui/views/social/QuestProgressView.kt b/Habitica/src/main/java/com/habitrpg/android/habitica/ui/views/social/QuestProgressView.kt index d83ff597a..4be95a562 100644 --- a/Habitica/src/main/java/com/habitrpg/android/habitica/ui/views/social/QuestProgressView.kt +++ b/Habitica/src/main/java/com/habitrpg/android/habitica/ui/views/social/QuestProgressView.kt @@ -134,15 +134,15 @@ class QuestProgressView : LinearLayout { } collectionContainer.removeAllViews() if (quest.isBossQuest) { - bossNameView.text = quest.boss.name + bossNameView.text = quest.boss?.name bossNameView.visibility = View.VISIBLE bossHealthView.visibility = View.VISIBLE bossHealthView.set(progress.progress?.hp ?: 0.0, quest.boss?.hp?.toDouble() ?: 0.0) - if (quest.boss.hasRage()) { + if (quest.boss?.hasRage() == true) { rageMeterView.visibility = View.VISIBLE bossRageView.visibility = View.VISIBLE - rageMeterView.text = quest.boss.rage?.title + rageMeterView.text = quest.boss?.rage?.title bossRageView.set(progress.progress?.rage ?: 0.0, quest.boss?.rage?.value ?: 0.0) if (progress.hasRageStrikes()) { setupRageStrikeViews()