Improve quest shop display? Maybe?

This commit is contained in:
Phillip Thelen 2020-02-04 12:39:36 +01:00
parent deb9d98653
commit fea83fd387
7 changed files with 75 additions and 21 deletions

View file

@ -42,11 +42,13 @@
android:id="@+id/unlockLabel"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="center_horizontal"
android:layout_gravity="center_horizontal"
android:gravity="center"
android:layout_gravity="center"
style="@style/Body1"
android:textSize="11sp"
android:textColor="@color/gray_300"
android:paddingStart="2dp"
android:paddingRight="2dp"
/>
</LinearLayout>
</LinearLayout>

View file

@ -337,6 +337,9 @@
<string name="party_invite">Unlock by inviting friends</string>
<string name="login_incentive">Unlock by logging into Habitica regularly</string>
<string name="create_account">Unlock by creating an account</string>
<string name="party_invite_short">Invite Friends</string>
<string name="login_incentive_short">login into Habitica regularly</string>
<string name="create_account_short">create an account</string>
<string name="successful_purchase">Purchased %1$s</string>
<string name="gold_plural">gold</string>
<string name="chat_message_copied">Message copied to Clipboard</string>
@ -942,4 +945,7 @@
<string name="preference_email_kicked_group">Kicked from group</string>
<string name="preference_email_onboarding">Guidance with setting up your Habitica Account</string>
<string name="skill_unlocks_at">Skill unlocks at level %d</string>
<string name="locked">Locked</string>
<string name="unlock_previous">Finish Quest %d</string>
<string name="unlock_level">Level %d</string>
</resources>

View file

@ -1,5 +1,6 @@
package com.habitrpg.android.habitica.models.shops
import android.content.Context
import android.content.res.Resources
import com.google.gson.annotations.SerializedName
@ -12,6 +13,10 @@ import io.realm.annotations.PrimaryKey
open class ShopItem : RealmObject() {
@PrimaryKey
var key: String = ""
set(value) {
field = value
unlockCondition?.questKey = key
}
var text: String? = ""
var notes: String? = ""
@SerializedName("class")
@ -36,11 +41,20 @@ open class ShopItem : RealmObject() {
var categoryIdentifier: String = ""
var limitedNumberLeft: Int? = null
var unlockCondition: ShopItemUnlockCondition? = null
set(value) {
field = value
if (key.isNotEmpty()) {
field?.questKey = key
}
}
var path: String? = null
var isSuggested: String? = null
var pinType: String? = null
@SerializedName("klass")
var habitClass: String? = null
var previous: String? = null
@SerializedName("lvl")
var level: Int? = null
val isTypeItem: Boolean
get() = "eggs" == purchaseType || "hatchingPotions" == purchaseType || "food" == purchaseType || "armoire" == purchaseType || "potion" == purchaseType
@ -73,6 +87,26 @@ open class ShopItem : RealmObject() {
return this.key.hashCode()
}
fun lockedReason(context: Context): String? {
return when {
unlockCondition != null -> {
unlockCondition?.shortReadableUnlockConditionId()?.let { context.getString(it) }
}
previous != null -> {
try {
val thisNumber = Character.getNumericValue(key.last())
context.getString(R.string.unlock_previous, thisNumber - 1)
} catch (e: NumberFormatException) {
null
}
}
level != null -> {
context.getString(R.string.unlock_level, level ?: 0)
}
else -> null
}
}
companion object {
private const val GEM_FOR_GOLD = "gem"

View file

@ -8,7 +8,8 @@ import io.realm.annotations.PrimaryKey
open class ShopItemUnlockCondition : RealmObject() {
@PrimaryKey
internal var condition: String? = null
var questKey: String? = null
private var condition: String? = null
fun readableUnlockConditionId(): Int = when (this.condition) {
"party invite" -> R.string.party_invite
@ -16,4 +17,11 @@ open class ShopItemUnlockCondition : RealmObject() {
"create account" -> R.string.create_account
else -> R.string.empty
}
fun shortReadableUnlockConditionId(): Int = when (this.condition) {
"party invite" -> R.string.party_invite_short
"login incentive" -> R.string.login_incentive_short
"create account" -> R.string.create_account_short
else -> R.string.empty
}
}

View file

@ -186,7 +186,7 @@ class AuthenticationPreferenceFragment: BasePreferencesFragment() {
val dialog = HabiticaAlertDialog(context)
dialog.setTitle(R.string.delete_account)
dialog.setMessage(deleteMessage)
dialog.addButton(R.string.delete_account_confirmation, true, true) { _, _ ->
dialog.addButton(R.string.delete_account_confirmation, isPrimary = true, isDestructive = true) { _, _ ->
deleteAccount(editText?.text?.toString() ?: "")
}
dialog.addCancelButton()

View file

@ -64,7 +64,11 @@ class ShopItemViewHolder(itemView: View) : RecyclerView.ViewHolder(itemView), Vi
DataBindingUtils.loadImage(this.imageView, item.imageName)
if (item.unlockCondition == null || !item.locked) {
itemDetailIndicator.text = null
itemDetailIndicator.visibility = View.GONE
val lockedReason = item.lockedReason(context)
if (!item.locked) {
priceLabel.text = item.value.toString()
priceLabel.currency = item.currency
if (item.currency == null) {
@ -73,23 +77,19 @@ class ShopItemViewHolder(itemView: View) : RecyclerView.ViewHolder(itemView), Vi
priceLabel.visibility = View.VISIBLE
unlockLabel.visibility = View.GONE
} else {
unlockLabel.setText(item.unlockCondition?.readableUnlockConditionId() ?: 0)
unlockLabel.text = lockedReason
priceLabel.visibility = View.GONE
unlockLabel.visibility = View.VISIBLE
itemDetailIndicator.background = lockedDrawable
itemDetailIndicator.visibility = View.VISIBLE
}
itemDetailIndicator.text = null
itemDetailIndicator.visibility = View.GONE
if (item.isLimited) {
itemDetailIndicator.background = limitedDrawable
itemDetailIndicator.visibility = View.VISIBLE
}
priceLabel.isLocked = item.locked || !canBuy
if (item.locked) {
itemDetailIndicator.background = lockedDrawable
itemDetailIndicator.visibility = View.VISIBLE
}
}
override fun onClick(view: View) {

View file

@ -65,14 +65,6 @@ class PurchaseDialog(context: Context, component: UserComponent?, val item: Shop
set(value) {
field = value
if (shopItem.unlockCondition == null) {
priceLabel.value = shopItem.value.toDouble()
priceLabel.currency = shopItem.currency
} else {
setBuyButtonEnabled(false)
buyLabel.text = shopItem.unlockCondition?.readableUnlockConditionId()?.let { context.getString(it) }
}
if (shopItem.isLimited) {
//TODO: replace with correct date once API is final
limitedTextView.text = context.getString(R.string.available_until, Date().toString())
@ -80,7 +72,19 @@ class PurchaseDialog(context: Context, component: UserComponent?, val item: Shop
limitedTextView.visibility = View.GONE
}
priceLabel.isLocked = shopItem.locked
if (shopItem.lockedReason(context) == null) {
priceLabel.value = shopItem.value.toDouble()
priceLabel.currency = shopItem.currency
} else {
limitedTextView.text = shopItem.lockedReason(context)
}
if (shopItem.locked) {
setBuyButtonEnabled(false)
buyLabel.text = context.getString(R.string.locked)
limitedTextView.visibility = View.VISIBLE
}
priceLabel.isLocked = shopItem.locked || shopItem.lockedReason(context) != null
val contentView: PurchaseDialogContent
when {