This commit is contained in:
Phillip Thelen 2022-07-27 17:05:22 +02:00
parent 3e3d3b11f6
commit de36a0351e
8 changed files with 1275 additions and 1238 deletions

View file

@ -15,7 +15,7 @@
android:orientation="vertical"
android:gravity="center_horizontal"
android:paddingHorizontal="23dp">
<androidx.legacy.widget.Space
<Space
android:layout_width="wrap_content"
android:layout_height="0dp"
android:layout_weight="1" />
@ -63,7 +63,7 @@
android:textColor="@color/text_secondary"
android:layout_marginHorizontal="@dimen/spacing_xlarge"
android:gravity="center"/>
<androidx.legacy.widget.Space
<Space
android:layout_width="wrap_content"
android:layout_height="0dp"
android:layout_weight="1" />

View file

@ -49,8 +49,6 @@
android:textSize="18sp" />
</RelativeLayout>
</androidx.cardview.widget.CardView>
<TextView

View file

@ -31,7 +31,7 @@
android:layout_height="wrap_content"
android:textSize="16sp"/>
</LinearLayout>
<androidx.legacy.widget.Space
<Space
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"/>

View file

@ -30,7 +30,7 @@
android:layout_width="0dp"
android:layout_weight="1"
android:layout_marginBottom="@dimen/spacing_small" />
<androidx.legacy.widget.Space
<Space
android:layout_width="0dp"
android:layout_weight="1"
android:layout_height="wrap_content" />

File diff suppressed because it is too large Load diff

View file

@ -172,11 +172,21 @@ open class ShopItem : RealmObject(), BaseObject {
return item
}
fun fromCustomizationSet(set: CustomizationSet, userSize: String?, hairColor: String?): ShopItem {
fun fromCustomizationSet(
set: CustomizationSet,
additionalSetItems: List<Customization>?,
userSize: String?,
hairColor: String?
): ShopItem {
val item = ShopItem()
var path = ""
for (customization in set.customizations) {
path = path + "," + customization.unlockPath
item.setImageNames.add(customization.getIconName(userSize, hairColor))
}
for (customization in additionalSetItems ?: emptyList()) {
path = path + "," + customization.unlockPath
item.setImageNames.add(customization.getIconName(userSize, hairColor))
}
if (path.isEmpty()) {
item.unlockPath = path
@ -188,9 +198,6 @@ open class ShopItem : RealmObject(), BaseObject {
item.currency = "gems"
item.value = set.price
item.purchaseType = "customizationSet"
set.customizations.forEach {
item.setImageNames.add(it.getIconName(userSize, hairColor))
}
if (set.customizations.firstOrNull()?.type == "background") {
// TODO: Needs a way to be translated.
item.notes = "Get all three Backgrounds in this bundle."

View file

@ -84,6 +84,7 @@ class CustomizationRecyclerViewAdapter() : androidx.recyclerview.widget.Recycler
(holder as SectionFooterViewHolder).bind(obj as CustomizationSet)
val count = min(columnCount, obj.customizations.size)
holder.buttonWidth = (count * 76.dpToPx(holder.itemView.context)) + ((count - 1) * 12.dpToPx(holder.itemView.context))
holder.additionalSetItems = additionalSetItems.filter { it.purchasable && (it.price ?: 0) > 0 }
} else {
(holder as CustomizationViewHolder).bind(customizationList[position] as Customization)
}
@ -125,7 +126,7 @@ class CustomizationRecyclerViewAdapter() : androidx.recyclerview.widget.Recycler
}
}
if (customization.customizationSet != null && customization.customizationSet != lastSet.identifier) {
if (lastSet.hasPurchasable) {
if (lastSet.hasPurchasable && lastSet.price > 0) {
customizationList.add(lastSet)
}
val set = CustomizationSet()
@ -262,6 +263,7 @@ class CustomizationRecyclerViewAdapter() : androidx.recyclerview.widget.Recycler
private val binding = CustomizationSectionFooterBinding.bind(itemView)
var context: Context = itemView.context
private var set: CustomizationSet? = null
var additionalSetItems: List<Customization>? = null
var buttonWidth: Int
get() = binding.purchaseSetButton.width
@ -288,7 +290,7 @@ class CustomizationRecyclerViewAdapter() : androidx.recyclerview.widget.Recycler
override fun onClick(v: View) {
set?.let {
val dialog = PurchaseDialog(itemView.context, HabiticaBaseApplication.userComponent, ShopItem.fromCustomizationSet(it, userSize, hairColor))
val dialog = PurchaseDialog(itemView.context, HabiticaBaseApplication.userComponent, ShopItem.fromCustomizationSet(it, additionalSetItems, userSize, hairColor))
dialog.show()
}
}

View file

@ -2,7 +2,9 @@ package com.habitrpg.android.habitica.ui.views.shops
import android.content.Context
import android.widget.TextView
import com.habitrpg.android.habitica.R
import com.habitrpg.android.habitica.databinding.DialogPurchaseCustomizationBinding
import com.habitrpg.android.habitica.models.shops.ShopItem
import com.habitrpg.common.habitica.extensions.layoutInflater
import com.habitrpg.common.habitica.views.PixelArtView
@ -12,4 +14,25 @@ class PurchaseDialogCustomizationContent(context: Context) : PurchaseDialogConte
get() = binding.imageView
override val titleTextView: TextView
get() = binding.titleTextView
override fun setItem(item: ShopItem) {
super.setItem(item)
if (item.text?.isNotBlank() != true) {
titleTextView.text = buildCustomizationTitle(item)
}
}
private fun buildCustomizationTitle(item: ShopItem): CharSequence? {
val path = item.unlockPath ?: return null
return when {
path.contains("skin") -> context.getString(R.string.avatar_skin_customization)
path.contains("shirt") -> context.getString(R.string.avatar_shirt_customization)
path.contains("color") -> context.getString(R.string.avatar_hair_color_customization)
path.contains("base") -> context.getString(R.string.avatar_hair_style_customization)
path.contains("bangs") -> context.getString(R.string.avatar_bangs_customization)
path.contains("beard") -> context.getString(R.string.avatar_beard_customization)
path.contains("mustache") -> context.getString(R.string.avatar_mustache_customization)
else -> null
}
}
}