mirror of
https://github.com/sudoxnym/habitica-android.git
synced 2026-07-13 17:51:57 +00:00
Extend existing setAvatar method and use Map<LayerType, String>
This commit is contained in:
parent
491e7f33f9
commit
f89cd4284e
4 changed files with 19 additions and 8 deletions
|
|
@ -35,6 +35,7 @@ class AvatarView : FrameLayout {
|
||||||
private var showPet = true
|
private var showPet = true
|
||||||
private var showSleeping = true
|
private var showSleeping = true
|
||||||
private var hasBackground: Boolean = false
|
private var hasBackground: Boolean = false
|
||||||
|
private var preview: Map<LayerType, String>? = null
|
||||||
private var backgroundForPurchase: String? = null
|
private var backgroundForPurchase: String? = null
|
||||||
private var hasMount: Boolean = false
|
private var hasMount: Boolean = false
|
||||||
private var hasPet: Boolean = false
|
private var hasPet: Boolean = false
|
||||||
|
|
@ -204,8 +205,9 @@ class AvatarView : FrameLayout {
|
||||||
}
|
}
|
||||||
|
|
||||||
var backgroundName = avatar.preferences?.background
|
var backgroundName = avatar.preferences?.background
|
||||||
if (backgroundForPurchase != null) {
|
// if (backgroundForPurchase != null) {
|
||||||
layerMap[LayerType.BACKGROUND] = backgroundForPurchase
|
if (preview != null) {
|
||||||
|
layerMap[preview?.keys?.first()] = preview?.values?.first()
|
||||||
if (resetHasAttributes) hasBackground = true
|
if (resetHasAttributes) hasBackground = true
|
||||||
} else if (showBackground && backgroundName?.isNotEmpty() == true) {
|
} else if (showBackground && backgroundName?.isNotEmpty() == true) {
|
||||||
backgroundName = substituteOrReturn(spriteSubstitutions["backgrounds"], backgroundName)
|
backgroundName = substituteOrReturn(spriteSubstitutions["backgrounds"], backgroundName)
|
||||||
|
|
@ -422,9 +424,10 @@ class AvatarView : FrameLayout {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fun setAvatar(avatar: Avatar) {
|
fun setAvatar(avatar: Avatar, preview: Map<LayerType, String>? = null) {
|
||||||
val oldUser = this.avatar
|
val oldUser = this.avatar
|
||||||
this.avatar = avatar
|
this.avatar = avatar
|
||||||
|
preview?.let { this.preview = preview }
|
||||||
|
|
||||||
var equals = false
|
var equals = false
|
||||||
if (oldUser != null) {
|
if (oldUser != null) {
|
||||||
|
|
|
||||||
|
|
@ -23,7 +23,8 @@ import com.habitrpg.android.habitica.ui.views.shops.PurchaseDialog
|
||||||
import io.reactivex.rxjava3.core.BackpressureStrategy
|
import io.reactivex.rxjava3.core.BackpressureStrategy
|
||||||
import io.reactivex.rxjava3.core.Flowable
|
import io.reactivex.rxjava3.core.Flowable
|
||||||
import io.reactivex.rxjava3.subjects.PublishSubject
|
import io.reactivex.rxjava3.subjects.PublishSubject
|
||||||
import java.util.Date
|
import java.util.*
|
||||||
|
import kotlin.collections.ArrayList
|
||||||
|
|
||||||
class CustomizationRecyclerViewAdapter() : androidx.recyclerview.widget.RecyclerView.Adapter<androidx.recyclerview.widget.RecyclerView.ViewHolder>() {
|
class CustomizationRecyclerViewAdapter() : androidx.recyclerview.widget.RecyclerView.Adapter<androidx.recyclerview.widget.RecyclerView.ViewHolder>() {
|
||||||
|
|
||||||
|
|
@ -200,7 +201,9 @@ class CustomizationRecyclerViewAdapter() : androidx.recyclerview.widget.Recycler
|
||||||
if (customization?.type == "background" && avatar != null){
|
if (customization?.type == "background" && avatar != null){
|
||||||
val alert = HabiticaAlertDialog(context = itemView.context)
|
val alert = HabiticaAlertDialog(context = itemView.context)
|
||||||
val purchasedCustomizationView: View = LayoutInflater.from(itemView.context).inflate(R.layout.purchased_equip_dialog, null)
|
val purchasedCustomizationView: View = LayoutInflater.from(itemView.context).inflate(R.layout.purchased_equip_dialog, null)
|
||||||
purchasedCustomizationView.findViewById<AvatarView>(R.id.avatar_view).setAvatarWithSelectedBackground(avatar!!, customization?.let { ShopItem.fromCustomization(it, userSize, hairColor).imageName })
|
val layerMap = EnumMap<AvatarView.LayerType, String>(AvatarView.LayerType::class.java)
|
||||||
|
layerMap[AvatarView.LayerType.BACKGROUND] = customization?.let { ShopItem.fromCustomization(it, userSize, hairColor).imageName }
|
||||||
|
purchasedCustomizationView.findViewById<AvatarView>(R.id.avatar_view).setAvatar(avatar!!, layerMap)
|
||||||
alert.setAdditionalContentView(purchasedCustomizationView)
|
alert.setAdditionalContentView(purchasedCustomizationView)
|
||||||
alert.addButton(R.string.equip, true) { _, _ ->
|
alert.addButton(R.string.equip, true) { _, _ ->
|
||||||
customization?.let {
|
customization?.let {
|
||||||
|
|
|
||||||
|
|
@ -288,7 +288,7 @@ class PurchaseDialog(context: Context, component: UserComponent?, val item: Shop
|
||||||
setLimitedTextView()
|
setLimitedTextView()
|
||||||
|
|
||||||
if (additionalContentView is PurchaseDialogBackgroundContent) {
|
if (additionalContentView is PurchaseDialogBackgroundContent) {
|
||||||
(additionalContentView as PurchaseDialogBackgroundContent).setAvatarWithBackgroundForPurchase(userRepository.getUnmanagedCopy(user), shopItem)
|
(additionalContentView as PurchaseDialogBackgroundContent).setAvatarWithBackgroundPreview(userRepository.getUnmanagedCopy(user), shopItem)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -6,7 +6,9 @@ import com.habitrpg.android.habitica.databinding.PurchaseDialogBackgroundBinding
|
||||||
import com.habitrpg.android.habitica.extensions.layoutInflater
|
import com.habitrpg.android.habitica.extensions.layoutInflater
|
||||||
import com.habitrpg.android.habitica.models.Avatar
|
import com.habitrpg.android.habitica.models.Avatar
|
||||||
import com.habitrpg.android.habitica.models.shops.ShopItem
|
import com.habitrpg.android.habitica.models.shops.ShopItem
|
||||||
|
import com.habitrpg.android.habitica.ui.AvatarView
|
||||||
import com.habitrpg.android.habitica.ui.views.PixelArtView
|
import com.habitrpg.android.habitica.ui.views.PixelArtView
|
||||||
|
import java.util.*
|
||||||
|
|
||||||
class PurchaseDialogBackgroundContent(context: Context) : PurchaseDialogContent(context) {
|
class PurchaseDialogBackgroundContent(context: Context) : PurchaseDialogContent(context) {
|
||||||
val binding = PurchaseDialogBackgroundBinding.inflate(context.layoutInflater, this)
|
val binding = PurchaseDialogBackgroundBinding.inflate(context.layoutInflater, this)
|
||||||
|
|
@ -20,7 +22,10 @@ class PurchaseDialogBackgroundContent(context: Context) : PurchaseDialogContent(
|
||||||
binding.notesTextView.text = item.notes
|
binding.notesTextView.text = item.notes
|
||||||
}
|
}
|
||||||
|
|
||||||
fun setAvatarWithBackgroundForPurchase(avatar: Avatar, item: ShopItem) {
|
fun setAvatarWithBackgroundPreview(avatar: Avatar, item: ShopItem) {
|
||||||
binding.avatarView.setAvatarWithSelectedBackground(avatar, item.imageName)
|
val layerMap = EnumMap<AvatarView.LayerType, String>(AvatarView.LayerType::class.java)
|
||||||
|
layerMap[AvatarView.LayerType.BACKGROUND] = item.imageName
|
||||||
|
|
||||||
|
binding.avatarView.setAvatar(avatar, layerMap)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue