diff --git a/Habitica/src/main/java/com/habitrpg/android/habitica/ui/AvatarView.kt b/Habitica/src/main/java/com/habitrpg/android/habitica/ui/AvatarView.kt index 28ed8bbf2..eca5d87f3 100644 --- a/Habitica/src/main/java/com/habitrpg/android/habitica/ui/AvatarView.kt +++ b/Habitica/src/main/java/com/habitrpg/android/habitica/ui/AvatarView.kt @@ -35,6 +35,7 @@ class AvatarView : FrameLayout { private var showPet = true private var showSleeping = true private var hasBackground: Boolean = false + private var backgroundForPurchase: String? = null private var hasMount: Boolean = false private var hasPet: Boolean = false private val imageViewHolder = mutableListOf() @@ -203,7 +204,10 @@ class AvatarView : FrameLayout { } var backgroundName = avatar.preferences?.background - if (showBackground && backgroundName?.isNotEmpty() == true) { + if (backgroundForPurchase != null) { + layerMap[LayerType.BACKGROUND] = backgroundForPurchase + if (resetHasAttributes) hasBackground = true + } else if (showBackground && backgroundName?.isNotEmpty() == true) { backgroundName = substituteOrReturn(spriteSubstitutions["backgrounds"], backgroundName) layerMap[LayerType.BACKGROUND] = "background_$backgroundName" if (resetHasAttributes) hasBackground = true @@ -433,6 +437,22 @@ class AvatarView : FrameLayout { } } + fun setAvatarWithBackgroundForPurchase(avatar: Avatar, backgroundForPurchase: String?) { + val oldUser = this.avatar + this.avatar = avatar + this.backgroundForPurchase = backgroundForPurchase + + var equals = false + if (oldUser != null) { + val newLayerMap = getLayerMap(avatar, false) + + equals = currentLayers == newLayerMap + } + if (!equals) { + invalidate() + } + } + private fun initAvatarRectMatrix() { if (avatarRectF == null) { val srcRect = originalRect diff --git a/Habitica/src/main/java/com/habitrpg/android/habitica/ui/views/shops/PurchaseDialog.kt b/Habitica/src/main/java/com/habitrpg/android/habitica/ui/views/shops/PurchaseDialog.kt index 485a332c5..0db1c8218 100644 --- a/Habitica/src/main/java/com/habitrpg/android/habitica/ui/views/shops/PurchaseDialog.kt +++ b/Habitica/src/main/java/com/habitrpg/android/habitica/ui/views/shops/PurchaseDialog.kt @@ -288,7 +288,7 @@ class PurchaseDialog(context: Context, component: UserComponent?, val item: Shop setLimitedTextView() if (additionalContentView is PurchaseDialogBackgroundContent) { - (additionalContentView as PurchaseDialogBackgroundContent).setAvatar(userRepository.getUnmanagedCopy(user)) + (additionalContentView as PurchaseDialogBackgroundContent).setAvatarWithBackgroundForPurchase(userRepository.getUnmanagedCopy(user), shopItem) } } diff --git a/Habitica/src/main/java/com/habitrpg/android/habitica/ui/views/shops/PurchaseDialogBackgroundContent.kt b/Habitica/src/main/java/com/habitrpg/android/habitica/ui/views/shops/PurchaseDialogBackgroundContent.kt index ad457a3f3..0c5de89b7 100644 --- a/Habitica/src/main/java/com/habitrpg/android/habitica/ui/views/shops/PurchaseDialogBackgroundContent.kt +++ b/Habitica/src/main/java/com/habitrpg/android/habitica/ui/views/shops/PurchaseDialogBackgroundContent.kt @@ -20,7 +20,7 @@ class PurchaseDialogBackgroundContent(context: Context) : PurchaseDialogContent( binding.notesTextView.text = item.notes } - fun setAvatar(avatar: Avatar) { - binding.avatarView.setAvatar(avatar) + fun setAvatarWithBackgroundForPurchase(avatar: Avatar, item: ShopItem) { + binding.avatarView.setAvatarWithBackgroundForPurchase(avatar, item.imageName) } }