mirror of
https://github.com/sudoxnym/habitica-android.git
synced 2026-05-20 04:39:04 +00:00
show quest completion modal
This commit is contained in:
parent
c68e4ff12a
commit
a06eefa84e
7 changed files with 215 additions and 0 deletions
65
Habitica/res/layout/dialog_completed_quest_content.xml
Normal file
65
Habitica/res/layout/dialog_completed_quest_content.xml
Normal file
|
|
@ -0,0 +1,65 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<merge 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"
|
||||
android:paddingLeft="@dimen/shopitem_dialog_content_inset"
|
||||
android:paddingRight="@dimen/shopitem_dialog_content_inset"
|
||||
android:gravity="center_horizontal"
|
||||
tools:parentTag="LinearLayout"
|
||||
tools:orientation="vertical">
|
||||
<TextView
|
||||
android:id="@+id/titleTextView"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
style="@style/Headline"
|
||||
tools:text="This is the Title"
|
||||
android:gravity="center"
|
||||
android:layout_marginBottom="4dp"/>
|
||||
|
||||
<TextView
|
||||
android:text="@string/rewards"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginTop="16dp"
|
||||
android:layout_marginBottom="4dp"
|
||||
android:gravity="center_horizontal"
|
||||
/>
|
||||
<LinearLayout
|
||||
android:id="@+id/rewardsList"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:orientation="vertical"/>
|
||||
|
||||
<TextView
|
||||
android:id="@+id/ownerRewardsTitle"
|
||||
android:text="@string/quest_owner_rewards"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginTop="16dp"
|
||||
android:layout_marginBottom="4dp"
|
||||
android:gravity="center_horizontal"
|
||||
/>
|
||||
<LinearLayout
|
||||
android:id="@+id/ownerRewardsList"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:orientation="vertical"/>
|
||||
<com.habitrpg.android.habitica.ui.views.WrapContentDraweeView
|
||||
android:id="@+id/imageView"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginTop="@dimen/spacing_large"
|
||||
android:layout_marginStart="@dimen/spacing_large"
|
||||
android:layout_marginEnd="@dimen/spacing_large"
|
||||
android:layout_marginBottom="@dimen/spacing_large"/>
|
||||
<TextView
|
||||
android:id="@+id/notesTextView"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
style="@style/Body2"
|
||||
android:textColor="@color/black_50_alpha"
|
||||
tools:text="These are the notes"
|
||||
android:gravity="center"/>
|
||||
</merge>
|
||||
|
|
@ -28,6 +28,8 @@ open class Quest : RealmObject() {
|
|||
var participants: RealmList<Member>? = null
|
||||
var rageStrikes: RealmList<QuestRageStrike>? = null
|
||||
|
||||
var completed: String? = null
|
||||
|
||||
fun hasRageStrikes(): Boolean {
|
||||
return rageStrikes?.isNotEmpty() ?: false
|
||||
}
|
||||
|
|
|
|||
|
|
@ -16,6 +16,7 @@ open class QuestContent : RealmObject(), Item {
|
|||
}
|
||||
internal var text: String = ""
|
||||
var notes: String = ""
|
||||
var completion: String = ""
|
||||
internal var value: Int = 0
|
||||
var previous: String? = null
|
||||
var lvl: Int = 0
|
||||
|
|
|
|||
|
|
@ -63,6 +63,7 @@ import com.habitrpg.android.habitica.ui.views.HabiticaSnackbar.SnackbarDisplayTy
|
|||
import com.habitrpg.android.habitica.ui.views.ValueBar
|
||||
import com.habitrpg.android.habitica.ui.views.dialogs.AchievementDialog
|
||||
import com.habitrpg.android.habitica.ui.views.dialogs.HabiticaAlertDialog
|
||||
import com.habitrpg.android.habitica.ui.views.dialogs.QuestCompletedDialog
|
||||
import com.habitrpg.android.habitica.ui.views.yesterdailies.YesterdailyDialog
|
||||
import com.habitrpg.android.habitica.userpicture.BitmapUtils
|
||||
import com.habitrpg.android.habitica.widget.AvatarStatsWidgetProvider
|
||||
|
|
@ -350,6 +351,13 @@ open class MainActivity : BaseActivity(), TutorialView.OnTutorialReaction {
|
|||
val intent = Intent(this, VerifyUsernameActivity::class.java)
|
||||
startActivity(intent)
|
||||
}
|
||||
|
||||
val quest = user?.party?.quest
|
||||
if (quest?.completed?.isNotBlank() == true) {
|
||||
compositeSubscription.add(inventoryRepository.getQuestContent(user?.party?.quest?.completed ?: "").firstElement().subscribe {
|
||||
QuestCompletedDialog.showWithQuest(this, it)
|
||||
})
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -0,0 +1,37 @@
|
|||
package com.habitrpg.android.habitica.ui.views.dialogs
|
||||
|
||||
import android.content.Context
|
||||
import com.habitrpg.android.habitica.R
|
||||
import com.habitrpg.android.habitica.models.inventory.QuestContent
|
||||
|
||||
class QuestCompletedDialog(context: Context) : HabiticaAlertDialog(context) {
|
||||
|
||||
var quest: QuestContent? = null
|
||||
set(value) {
|
||||
field = value
|
||||
if (value == null) return
|
||||
|
||||
val contentView = QuestCompletedDialogContent(context)
|
||||
contentView.setQuestContent(value)
|
||||
setAdditionalContentView(contentView)
|
||||
}
|
||||
|
||||
override fun dismiss() {
|
||||
dialog = null
|
||||
super.dismiss()
|
||||
}
|
||||
|
||||
companion object {
|
||||
private var dialog: QuestCompletedDialog? = null
|
||||
|
||||
fun showWithQuest(context: Context, quest: QuestContent) {
|
||||
if (dialog != null) return
|
||||
|
||||
dialog = QuestCompletedDialog(context)
|
||||
dialog?.quest = quest
|
||||
dialog?.setTitle(R.string.quest_completed)
|
||||
dialog?.addButton(R.string.onwards, isPrimary = true, isDestructive = false)
|
||||
dialog?.enqueue()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,99 @@
|
|||
package com.habitrpg.android.habitica.ui.views.dialogs
|
||||
|
||||
import android.content.Context
|
||||
import android.util.AttributeSet
|
||||
import android.view.Gravity
|
||||
import android.view.LayoutInflater
|
||||
import android.view.View
|
||||
import android.view.ViewGroup
|
||||
import android.widget.ImageView
|
||||
import android.widget.LinearLayout
|
||||
import android.widget.TextView
|
||||
import com.facebook.drawee.view.SimpleDraweeView
|
||||
import com.habitrpg.android.habitica.R
|
||||
import com.habitrpg.android.habitica.databinding.DialogCompletedQuestContentBinding
|
||||
import com.habitrpg.android.habitica.extensions.layoutInflater
|
||||
import com.habitrpg.android.habitica.models.inventory.QuestContent
|
||||
import com.habitrpg.android.habitica.models.inventory.QuestDropItem
|
||||
import com.habitrpg.android.habitica.ui.helpers.DataBindingUtils
|
||||
import com.habitrpg.android.habitica.ui.views.HabiticaIconsHelper
|
||||
|
||||
class QuestCompletedDialogContent : LinearLayout {
|
||||
|
||||
|
||||
private lateinit var binding: DialogCompletedQuestContentBinding
|
||||
|
||||
constructor(context: Context) : super(context) {
|
||||
setupView()
|
||||
}
|
||||
|
||||
constructor(context: Context, attrs: AttributeSet?) : super(context, attrs) {
|
||||
setupView()
|
||||
}
|
||||
|
||||
private fun setupView() {
|
||||
orientation = VERTICAL
|
||||
gravity = Gravity.CENTER
|
||||
|
||||
binding = DialogCompletedQuestContentBinding.inflate(context.layoutInflater, this)
|
||||
}
|
||||
|
||||
fun setQuestContent(questContent: QuestContent) {
|
||||
binding.titleTextView.text = questContent.text
|
||||
binding.notesTextView.text = questContent.completion
|
||||
DataBindingUtils.loadImage(binding.imageView, "quest_" + questContent.key)
|
||||
|
||||
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, binding.rewardsList) }
|
||||
|
||||
var hasOwnerRewards = false
|
||||
for (item in questContent.drop?.items ?: emptyList<QuestDropItem>()) {
|
||||
if (item.isOnlyOwner) {
|
||||
addRewardsRow(inflater, item, binding.ownerRewardsList)
|
||||
hasOwnerRewards = true
|
||||
}
|
||||
}
|
||||
if (!hasOwnerRewards) {
|
||||
binding.ownerRewardsTitle.visibility = View.GONE
|
||||
binding.ownerRewardsList.visibility = View.GONE
|
||||
}
|
||||
|
||||
if (questContent.drop?.exp ?: 0 > 0) {
|
||||
val view = inflater?.inflate(R.layout.row_quest_reward_imageview, binding.rewardsList, false) as? ViewGroup
|
||||
val imageView = view?.findViewById<ImageView>(R.id.imageView)
|
||||
imageView?.scaleType = ImageView.ScaleType.CENTER
|
||||
imageView?.setImageBitmap(HabiticaIconsHelper.imageOfExperienceReward())
|
||||
val titleTextView = view?.findViewById<TextView>(R.id.titleTextView)
|
||||
titleTextView?.text = context.getString(R.string.experience_reward, questContent.drop?.exp)
|
||||
binding.rewardsList.addView(view)
|
||||
}
|
||||
|
||||
if (questContent.drop?.gp ?: 0 > 0) {
|
||||
val view = inflater?.inflate(R.layout.row_quest_reward_imageview, binding.rewardsList, false) as? ViewGroup
|
||||
val imageView = view?.findViewById<ImageView>(R.id.imageView)
|
||||
imageView?.scaleType = ImageView.ScaleType.CENTER
|
||||
imageView?.setImageBitmap(HabiticaIconsHelper.imageOfGoldReward())
|
||||
val titleTextView = view?.findViewById<TextView>(R.id.titleTextView)
|
||||
titleTextView?.text = context.getString(R.string.gold_reward, questContent.drop?.gp)
|
||||
binding.rewardsList.addView(view)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private fun addRewardsRow(inflater: LayoutInflater?, item: QuestDropItem, containerView: ViewGroup?) {
|
||||
val view = inflater?.inflate(R.layout.row_quest_reward, containerView, false) as? ViewGroup
|
||||
val imageView = view?.findViewById(R.id.imageView) as? SimpleDraweeView
|
||||
val titleTextView = view?.findViewById(R.id.titleTextView) as? TextView
|
||||
DataBindingUtils.loadImage(imageView, item.imageName)
|
||||
if (item.count > 1) {
|
||||
titleTextView?.text = context.getString(R.string.quest_reward_count, item.text, item.count)
|
||||
} else {
|
||||
titleTextView?.text = item.text
|
||||
}
|
||||
containerView?.addView(view)
|
||||
}
|
||||
}
|
||||
|
|
@ -62,6 +62,9 @@ class UserDeserializer : JsonDeserializer<User> {
|
|||
user.party?.quest?.RSVPNeeded = quest.RSVPNeeded
|
||||
}
|
||||
}
|
||||
if (obj.getAsJsonObject("party").getAsJsonObject("quest").has("completed")) {
|
||||
user.party?.quest?.completed = obj.getAsJsonObject("party").getAsJsonObject("quest").get("completed").asString
|
||||
}
|
||||
}
|
||||
}
|
||||
if (obj.has("purchased")) {
|
||||
|
|
|
|||
Loading…
Reference in a new issue