Fix background display

This commit is contained in:
Phillip Thelen 2020-04-03 17:45:19 +02:00
parent 675c8cfbb8
commit 68cd8829ba
7 changed files with 111 additions and 212 deletions

View file

@ -4,10 +4,11 @@
android:layout_height="wrap_content">
<com.facebook.drawee.view.SimpleDraweeView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_width="@dimen/avatar_width"
android:layout_height="@dimen/avatar_height"
android:id="@+id/imageView"
android:layout_gravity="center_horizontal" />
android:layout_gravity="center_horizontal"
android:scaleType="center"/>
<LinearLayout
android:orientation="horizontal"

View file

@ -141,7 +141,7 @@ class UserRepositoryImpl(localRepository: UserLocalRepository, apiClient: ApiCli
copiedUser.preferences = unlockResponse.preferences
copiedUser.purchased = unlockResponse.purchased
copiedUser.items = unlockResponse.items
copiedUser.balance = copiedUser.balance - customization.price / 4.0
copiedUser.balance = copiedUser.balance - (customization.price ?: 0) / 4.0
localRepository.saveUser(copiedUser)
}
}

View file

@ -1,200 +0,0 @@
package com.habitrpg.android.habitica.models.inventory;
import androidx.annotation.Nullable;
import java.util.Date;
import io.realm.RealmObject;
import io.realm.annotations.PrimaryKey;
public class Customization extends RealmObject {
@PrimaryKey
private String id;
private String identifier, category, type, notes, customizationSet, customizationSetName, text;
private boolean purchased, isBuyable;
private Integer price, setPrice;
private Date availableFrom, availableUntil;
private void updateID() {
this.id = this.identifier + "_" + this.type + "_" + this.category;
}
public String getId() {
return this.id;
}
public void setId(String id) {
this.id = id;
}
@Nullable
public String getIdentifier() {
return this.identifier;
}
public void setIdentifier(String identifier) {
this.identifier = identifier;
this.updateID();
}
@Nullable
public String getCategory() {
return this.category;
}
public void setCategory(String category) {
this.category = category;
this.updateID();
}
@Nullable
public String getType() {
return this.type;
}
public void setType(String type) {
this.type = type;
this.updateID();
}
public String getNotes() {
return this.notes;
}
public void setNotes(String notes) {
this.notes = notes;
}
public String getCustomizationSet() {
return this.customizationSet;
}
public void setCustomizationSet(String customizationSet) {
this.customizationSet = customizationSet;
}
public String getCustomizationSetName() {
return this.customizationSetName;
}
public void setCustomizationSetName(@Nullable String customizationSetName) {
this.customizationSetName = customizationSetName;
}
public String getText() {
return this.text;
}
public void setText(String text) {
this.text = text;
}
@SuppressWarnings("RedundantIfStatement")
public boolean getPurchasable() {
Date today = new Date();
if (this.availableFrom != null && !this.availableFrom.before(today)) {
//Not released yet
return false;
}
if (this.availableUntil != null && !this.availableUntil.after(today)) {
//Discontinued
return false;
}
return true;
}
public boolean getPurchased() {
return this.purchased;
}
public void setPurchased(boolean purchased) {
this.purchased = purchased;
}
public Integer getPrice() {
return this.price;
}
public void setPrice(Integer price) {
this.price = price;
}
public Integer getSetPrice() {
return this.setPrice;
}
public void setSetPrice(Integer setPrice) {
this.setPrice = setPrice;
}
public Date getAvailableFrom() {
return this.availableFrom;
}
public void setAvailableFrom(Date availableFrom) {
this.availableFrom = availableFrom;
}
public Date getAvailableUntil() {
return this.availableUntil;
}
public void setAvailableUntil(Date availableUntil) {
this.availableUntil = availableUntil;
}
public String getImageName(String userSize, String hairColor) {
switch (this.type) {
case "skin":
return "skin_" + this.identifier;
case "shirt":
return userSize + "_shirt_" + this.identifier;
case "hair":
if (this.identifier.equals("0")) {
return "head_0";
}
switch (this.category) {
case "color":
return "hair_bangs_1_" + this.identifier;
case "flower":
return "hair_flower_" + this.identifier;
default:
return "hair_" + this.category + "_" + this.identifier + "_" + hairColor;
}
case "background":
return "background_" + this.identifier;
case "chair":
return "chair_" + identifier;
}
return "";
}
public boolean isUsable() {
return this.price == null || this.price == 0 || this.purchased;
}
public String getPath() {
String path = this.type;
if (this.category != null) {
path = path + "." + this.category;
}
path = path + "." + this.identifier;
return path;
}
public boolean getIsBuyable() {
return isBuyable;
}
public void setIsBuyable(boolean buyable) {
isBuyable = buyable;
}
}

View file

@ -0,0 +1,89 @@
package com.habitrpg.android.habitica.models.inventory
import io.realm.RealmObject
import io.realm.annotations.PrimaryKey
import java.util.*
open class Customization : RealmObject() {
@PrimaryKey
var id: String? = null
var identifier: String? = null
set(value) {
field = value
updateID()
}
var category: String? = null
set(value) {
field = value
updateID()
}
var type: String? = null
set(value) {
field = value
updateID()
}
var notes: String? = null
var customizationSet: String? = null
var customizationSetName: String? = null
var text: String? = null
var purchased = false
var isBuyable = false
var price: Int? = null
var setPrice: Int? = null
var availableFrom: Date? = null
var availableUntil: Date? = null
private fun updateID() {
id = identifier + "_" + type + "_" + this.category
}
//Not released yet
val purchasable: Boolean
get() {
val today = Date()
if (availableFrom != null && !availableFrom!!.before(today)) { //Not released yet
return false
}
return !(availableUntil != null && !availableUntil!!.after(today))
}
fun getIconName(userSize: String?, hairColor: String?): String {
return if (type == "background") {
"background_$identifier"
} else {
getImageName(userSize, hairColor)
}
}
fun getImageName(userSize: String?, hairColor: String?): String {
when (type) {
"skin" -> return "skin_$identifier"
"shirt" -> return userSize + "_shirt_" + identifier
"hair" -> {
return if (identifier == "0") {
"head_0"
} else when (this.category) {
"color" -> "hair_bangs_1_$identifier"
"flower" -> "hair_flower_$identifier"
else -> "hair_" + this.category + "_" + identifier + "_" + hairColor
}
}
"background" -> return "background_$identifier"
"chair" -> return "chair_$identifier"
}
return ""
}
val isUsable: Boolean
get() = price == null || price == 0 || purchased
val path: String
get() {
var path = type
if (this.category != null) {
path = path + "." + this.category
}
path = path + "." + identifier
return path
}
}

View file

@ -1,6 +1,7 @@
package com.habitrpg.android.habitica.ui.adapter
import android.content.Context
import android.view.Gravity
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
@ -138,17 +139,25 @@ class CustomizationRecyclerViewAdapter : androidx.recyclerview.widget.RecyclerVi
fun bind(customization: Customization) {
this.customization = customization
if (customization.customizationSet?.contains("timeTravel") == true) {
DataBindingUtils.loadImage(binding.imageView, customization.getImageName(userSize, hairColor), imageFormat = "gif")
} else {
DataBindingUtils.loadImage(binding.imageView, customization.getImageName(userSize, hairColor))
DataBindingUtils.loadImage(binding.imageView, customization.getIconName(userSize, hairColor))
if (customization.type == "background") {
val params = (binding.imageView.layoutParams as? LinearLayout.LayoutParams)?.apply {
gravity = Gravity.CENTER
}
binding.imageView.layoutParams = params
}
if (customization.isUsable) {
binding.buyButton.visibility = View.GONE
} else {
binding.buyButton.visibility = View.VISIBLE
binding.priceLabel.currency = "gems"
binding.priceLabel.value = customization.price.toDouble()
if (customization.customizationSet?.contains("timeTravel") == true) {
binding.priceLabel.currency = "hourglasses"
} else {
binding.priceLabel.currency = "gems"
}
binding.priceLabel.value = customization.price?.toDouble() ?: 0.0
}
if (activeCustomization == customization.identifier) {

View file

@ -138,7 +138,7 @@ class AvatarCustomizationFragment : BaseMainFragment() {
this.updateActiveCustomization(user)
if (adapter.customizationList.size != 0) {
val ownedCustomizations = ArrayList<String>()
user.purchased?.customizations?.filter { it.type == this.type }?.mapTo(ownedCustomizations) { it.id }
user.purchased?.customizations?.filter { it.type == this.type }?.mapTo(ownedCustomizations) { it.id ?: "" }
adapter.updateOwnership(ownedCustomizations)
} else {
this.loadCustomizations()

View file

@ -54,7 +54,7 @@ class CustomizationDeserializer : JsonDeserializer<List<Customization>> {
if (jsonObject.has(customization.customizationSet)) {
val nestedObject = jsonObject.get(customization.customizationSet).asJsonObject
if (nestedObject.has(customization.identifier)) {
customizations.add(this.parseBackground(customization, customization.customizationSet, customization.identifier, nestedObject.get(customization.identifier).asJsonObject))
customizations.add(this.parseBackground(customization, customization.customizationSet ?: "", customization.identifier, nestedObject.get(customization.identifier).asJsonObject))
nestedObject.remove(customization.identifier)
}
}