mirror of
https://github.com/sudoxnym/habitica-android.git
synced 2026-07-13 17:51:57 +00:00
parent
5c22353d2e
commit
6565a7abba
8 changed files with 101 additions and 16 deletions
20
Habitica/res/layout/class_spinner_dropdown_item.xml
Normal file
20
Habitica/res/layout/class_spinner_dropdown_item.xml
Normal file
|
|
@ -0,0 +1,20 @@
|
||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="match_parent"
|
||||||
|
android:minWidth="100dp"
|
||||||
|
android:paddingLeft="12dp"
|
||||||
|
android:paddingRight="12dp"
|
||||||
|
android:paddingTop="4dp"
|
||||||
|
android:paddingBottom="4dp"
|
||||||
|
android:gravity="center_vertical">
|
||||||
|
<ImageView
|
||||||
|
android:id="@+id/classIconView"
|
||||||
|
android:layout_width="32dp"
|
||||||
|
android:layout_height="32dp"
|
||||||
|
android:layout_marginRight="8dp"/>
|
||||||
|
<TextView
|
||||||
|
android:id="@+id/textView"
|
||||||
|
android:layout_width="wrap_content"
|
||||||
|
android:layout_height="wrap_content"/>
|
||||||
|
</LinearLayout>
|
||||||
|
|
@ -11,24 +11,26 @@
|
||||||
android:layout_marginTop="12dp"/>
|
android:layout_marginTop="12dp"/>
|
||||||
<LinearLayout
|
<LinearLayout
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="wrap_content">
|
android:layout_height="wrap_content"
|
||||||
|
android:gravity="center_vertical"
|
||||||
|
android:layout_marginTop="12dp"
|
||||||
|
android:layout_marginBottom="12dp">
|
||||||
<TextView
|
<TextView
|
||||||
android:id="@+id/label"
|
android:id="@+id/label"
|
||||||
android:layout_width="0dp"
|
android:layout_width="0dp"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:layout_weight="1"
|
android:layout_weight="1"
|
||||||
android:textAppearance="?android:attr/textAppearanceMedium"
|
android:textAppearance="?android:attr/textAppearanceMedium"
|
||||||
android:layout_marginLeft="24dp"
|
|
||||||
android:layout_marginRight="24dp"
|
|
||||||
tools:text="Section Header"
|
tools:text="Section Header"
|
||||||
android:layout_marginTop="12dp"
|
android:layout_marginLeft="24dp"
|
||||||
android:layout_marginBottom="12dp" />
|
android:layout_marginRight="24dp" />
|
||||||
<Spinner
|
<Spinner
|
||||||
android:id="@+id/classSelectionSpinner"
|
android:id="@+id/classSelectionSpinner"
|
||||||
android:layout_width="wrap_content"
|
android:layout_width="wrap_content"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:visibility="gone"
|
android:visibility="gone"
|
||||||
android:layout_gravity="bottom"
|
android:layout_gravity="bottom"
|
||||||
|
tools:visibility="visible"
|
||||||
/>
|
/>
|
||||||
</LinearLayout>
|
</LinearLayout>
|
||||||
</LinearLayout>
|
</LinearLayout>
|
||||||
|
|
@ -714,4 +714,5 @@
|
||||||
<string name="allocating_points">Allocating Points</string>
|
<string name="allocating_points">Allocating Points</string>
|
||||||
<string name="class_equipment">Class Equipment</string>
|
<string name="class_equipment">Class Equipment</string>
|
||||||
<string name="equipment_empty">You already have all equipment! More will be released during the Grand Galas, near the solstices and equinoxes.</string>
|
<string name="equipment_empty">You already have all equipment! More will be released during the Grand Galas, near the solstices and equinoxes.</string>
|
||||||
|
<string name="classless">Classless</string>
|
||||||
</resources>
|
</resources>
|
||||||
|
|
|
||||||
|
|
@ -52,10 +52,7 @@ open class ShopItem : RealmObject() {
|
||||||
val isTypeAnimal: Boolean
|
val isTypeAnimal: Boolean
|
||||||
get() = "pets" == purchaseType || "mounts" == purchaseType
|
get() = "pets" == purchaseType || "mounts" == purchaseType
|
||||||
|
|
||||||
fun canBuy(user: User?): Boolean {
|
fun canAfford(user: User?): Boolean {
|
||||||
if (locked) {
|
|
||||||
return false
|
|
||||||
}
|
|
||||||
return when(currency) {
|
return when(currency) {
|
||||||
"gold" -> value <= user?.stats?.getGp() ?: 0.0
|
"gold" -> value <= user?.stats?.getGp() ?: 0.0
|
||||||
"gems" -> value <= user?.balance ?: 0.0 * 4
|
"gems" -> value <= user?.balance ?: 0.0 * 4
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,59 @@
|
||||||
|
package com.habitrpg.android.habitica.ui.adapter.inventory
|
||||||
|
|
||||||
|
import android.content.Context
|
||||||
|
import android.support.v4.content.ContextCompat
|
||||||
|
import android.view.View
|
||||||
|
import android.view.ViewGroup
|
||||||
|
import android.widget.ArrayAdapter
|
||||||
|
import android.widget.ImageView
|
||||||
|
import android.widget.TextView
|
||||||
|
import com.habitrpg.android.habitica.R
|
||||||
|
import com.habitrpg.android.habitica.extensions.inflate
|
||||||
|
import com.habitrpg.android.habitica.models.user.Stats
|
||||||
|
import com.habitrpg.android.habitica.ui.views.HabiticaIconsHelper
|
||||||
|
|
||||||
|
|
||||||
|
class HabiticaClassArrayAdapter(context: Context?, resource: Int, objects: List<CharSequence>?) : ArrayAdapter<CharSequence>(context, resource, R.id.textView, objects) {
|
||||||
|
|
||||||
|
override fun getDropDownView(position: Int, convertView: View?, parent: ViewGroup?): View =
|
||||||
|
getView(position, convertView, parent)
|
||||||
|
|
||||||
|
override fun getView(position: Int, convertView: View?, parent: ViewGroup?): View {
|
||||||
|
val row = convertView ?: parent?.inflate(R.layout.class_spinner_dropdown_item, false)
|
||||||
|
|
||||||
|
val textView: TextView? = row?.findViewById(R.id.textView)
|
||||||
|
val imageView: ImageView? = row?.findViewById(R.id.classIconView)
|
||||||
|
|
||||||
|
when (getItem(position)) {
|
||||||
|
Stats.WARRIOR -> {
|
||||||
|
textView?.text = context.getString(R.string.warrior)
|
||||||
|
textView?.setTextColor(ContextCompat.getColor(context, R.color.red_10))
|
||||||
|
imageView?.setImageBitmap(HabiticaIconsHelper.imageOfWarriorLightBg())
|
||||||
|
}
|
||||||
|
Stats.MAGE -> {
|
||||||
|
textView?.text = context.getString(R.string.mage)
|
||||||
|
textView?.setTextColor(ContextCompat.getColor(context, R.color.blue_10))
|
||||||
|
imageView?.setImageBitmap(HabiticaIconsHelper.imageOfMageLightBg())
|
||||||
|
}
|
||||||
|
Stats.HEALER -> {
|
||||||
|
textView?.text = context.getString(R.string.healer)
|
||||||
|
textView?.setTextColor(ContextCompat.getColor(context, R.color.yellow_10))
|
||||||
|
imageView?.setImageBitmap(HabiticaIconsHelper.imageOfHealerLightBg())
|
||||||
|
}
|
||||||
|
Stats.ROGUE -> {
|
||||||
|
textView?.text = context.getString(R.string.rogue)
|
||||||
|
textView?.setTextColor(ContextCompat.getColor(context, R.color.brand_300))
|
||||||
|
imageView?.setImageBitmap(HabiticaIconsHelper.imageOfRogueLightBg())
|
||||||
|
}
|
||||||
|
else -> {
|
||||||
|
textView?.text = context.getString(R.string.classless)
|
||||||
|
textView?.setTextColor(ContextCompat.getColor(context, R.color.textColorLight))
|
||||||
|
imageView?.setImageBitmap(null)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
return row ?: View(context)
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
@ -10,7 +10,6 @@ import android.text.Html
|
||||||
import android.text.method.LinkMovementMethod
|
import android.text.method.LinkMovementMethod
|
||||||
import android.view.View
|
import android.view.View
|
||||||
import android.view.ViewGroup
|
import android.view.ViewGroup
|
||||||
import android.widget.ArrayAdapter
|
|
||||||
import android.widget.Button
|
import android.widget.Button
|
||||||
import android.widget.ImageView
|
import android.widget.ImageView
|
||||||
import android.widget.TextView
|
import android.widget.TextView
|
||||||
|
|
@ -128,7 +127,7 @@ class ShopRecyclerAdapter : RecyclerView.Adapter<RecyclerView.ViewHolder>() {
|
||||||
val category = obj as ShopCategory
|
val category = obj as ShopCategory
|
||||||
(holder as SectionViewHolder).bind((category).text)
|
(holder as SectionViewHolder).bind((category).text)
|
||||||
if (gearCategories.contains(category)) {
|
if (gearCategories.contains(category)) {
|
||||||
val adapter = ArrayAdapter<CharSequence>(context, android.R.layout.simple_spinner_dropdown_item, gearCategories.map { it.identifier })
|
val adapter = HabiticaClassArrayAdapter(context, R.layout.class_spinner_dropdown_item, gearCategories.map { it.identifier })
|
||||||
holder.spinnerAdapter = adapter
|
holder.spinnerAdapter = adapter
|
||||||
holder.selectedItem = gearCategories.indexOf(category)
|
holder.selectedItem = gearCategories.indexOf(category)
|
||||||
holder.spinnerSelectionChanged = {
|
holder.spinnerSelectionChanged = {
|
||||||
|
|
@ -140,7 +139,7 @@ class ShopRecyclerAdapter : RecyclerView.Adapter<RecyclerView.ViewHolder>() {
|
||||||
}
|
}
|
||||||
ShopItem::class.java -> {
|
ShopItem::class.java -> {
|
||||||
val item = obj as ShopItem
|
val item = obj as ShopItem
|
||||||
(holder as ShopItemViewHolder).bind(item, item.canBuy(user))
|
(holder as ShopItemViewHolder).bind(item, item.canAfford(user))
|
||||||
if (ownedItems.containsKey(item.key)) {
|
if (ownedItems.containsKey(item.key)) {
|
||||||
holder.itemCount = ownedItems[item.key]?.owned ?: 0
|
holder.itemCount = ownedItems[item.key]?.owned ?: 0
|
||||||
}
|
}
|
||||||
|
|
@ -160,7 +159,11 @@ class ShopRecyclerAdapter : RecyclerView.Adapter<RecyclerView.ViewHolder>() {
|
||||||
}
|
}
|
||||||
if (position <= getGearItemCount()) {
|
if (position <= getGearItemCount()) {
|
||||||
return when {
|
return when {
|
||||||
position == 1 -> getSelectedShopCategory()
|
position == 1 -> {
|
||||||
|
val category = getSelectedShopCategory()
|
||||||
|
category?.text = context?.getString(R.string.class_equipment) ?: ""
|
||||||
|
category
|
||||||
|
}
|
||||||
getSelectedShopCategory()?.items?.size ?: 0 <= position-2 -> return context?.getString(R.string.equipment_empty)
|
getSelectedShopCategory()?.items?.size ?: 0 <= position-2 -> return context?.getString(R.string.equipment_empty)
|
||||||
else -> getSelectedShopCategory()?.items?.get(position-2)
|
else -> getSelectedShopCategory()?.items?.get(position-2)
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -61,7 +61,7 @@ public class RewardsRecyclerViewAdapter extends RecyclerView.Adapter<RecyclerVie
|
||||||
((RewardViewHolder)holder).bindHolder(reward, position, reward.getValue() < gold);
|
((RewardViewHolder)holder).bindHolder(reward, position, reward.getValue() < gold);
|
||||||
} else if (inAppRewards != null) {
|
} else if (inAppRewards != null) {
|
||||||
ShopItem item = inAppRewards.get(position-getCustomRewardCount());
|
ShopItem item = inAppRewards.get(position-getCustomRewardCount());
|
||||||
((ShopItemViewHolder)holder).bind(item, item.canBuy(user));
|
((ShopItemViewHolder)holder).bind(item, item.canAfford(user));
|
||||||
((ShopItemViewHolder)holder).setPinned(true);
|
((ShopItemViewHolder)holder).setPinned(true);
|
||||||
((ShopItemViewHolder) holder).hidePinIndicator();
|
((ShopItemViewHolder) holder).hidePinIndicator();
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -113,7 +113,7 @@ public class PurchaseDialog extends AlertDialog {
|
||||||
limitedTextView.setBackgroundColor(ContextCompat.getColor(getContext(), R.color.green_10));
|
limitedTextView.setBackgroundColor(ContextCompat.getColor(getContext(), R.color.green_10));
|
||||||
}
|
}
|
||||||
|
|
||||||
if (shopItem != null && !shopItem.canBuy(user)) {
|
if (shopItem != null && !shopItem.canAfford(user)) {
|
||||||
priceLabel.setCantAfford(true);
|
priceLabel.setCantAfford(true);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -207,7 +207,10 @@ public class PurchaseDialog extends AlertDialog {
|
||||||
void onBuyButtonClicked() {
|
void onBuyButtonClicked() {
|
||||||
final String[] snackbarText = {""};
|
final String[] snackbarText = {""};
|
||||||
if (shopItem.isValid()) {
|
if (shopItem.isValid()) {
|
||||||
if (shopItem.canBuy(user)) {
|
if (shopItem.getLocked()) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (shopItem.canAfford(user)) {
|
||||||
Observable<Void> observable;
|
Observable<Void> observable;
|
||||||
if ((shopIdentifier != null && shopIdentifier.equals(Shop.TIME_TRAVELERS_SHOP)) || "mystery_set".equals(shopItem.getPurchaseType())) {
|
if ((shopIdentifier != null && shopIdentifier.equals(Shop.TIME_TRAVELERS_SHOP)) || "mystery_set".equals(shopItem.getPurchaseType())) {
|
||||||
if (shopItem.getPurchaseType().equals("gear")) {
|
if (shopItem.getPurchaseType().equals("gear")) {
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue