mirror of
https://github.com/sudoxnym/habitica-android.git
synced 2026-04-14 19:56:32 +00:00
add information for purchasing class gear. Fixes #855
This commit is contained in:
parent
acf2596f5f
commit
6e5f609c36
10 changed files with 62 additions and 11 deletions
|
|
@ -2,7 +2,7 @@
|
|||
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:tools="http://schemas.android.com/tools"
|
||||
package="com.habitrpg.android.habitica"
|
||||
android:versionCode="1951"
|
||||
android:versionCode="1952"
|
||||
android:versionName="1.3"
|
||||
android:screenOrientation="portrait"
|
||||
android:installLocation="auto" >
|
||||
|
|
|
|||
|
|
@ -35,7 +35,7 @@
|
|||
android:gravity="center"
|
||||
style="@style/Body1"
|
||||
android:textSize="12sp"
|
||||
android:padding="4dp"
|
||||
android:padding="7dp"
|
||||
android:background="@color/brand_300"
|
||||
android:textColor="@color/white"
|
||||
tools:text="Available until May 6"/>
|
||||
|
|
|
|||
|
|
@ -33,4 +33,15 @@
|
|||
tools:visibility="visible"
|
||||
/>
|
||||
</LinearLayout>
|
||||
<TextView
|
||||
android:id="@+id/headerNotesView"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:gravity="center"
|
||||
android:layout_marginBottom="12dp"
|
||||
android:textSize="12sp"
|
||||
android:textColor="@color/gray_300"
|
||||
android:visibility="gone"
|
||||
tools:visibility="visible"
|
||||
tools:text="@string/class_gear_disclaimer"/>
|
||||
</LinearLayout>
|
||||
|
|
@ -715,4 +715,6 @@
|
|||
<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="classless">Classless</string>
|
||||
<string name="class_equipment_shop_dialog">This item is only available to a specific class.\nYou can change your class from Settings.</string>
|
||||
<string name="class_gear_disclaimer">You can only purchase gear for your current class</string>
|
||||
</resources>
|
||||
|
|
|
|||
|
|
@ -2,4 +2,4 @@ package com.habitrpg.android.habitica.events
|
|||
|
||||
import com.habitrpg.android.habitica.models.shops.ShopItem
|
||||
|
||||
class ShopItemPurchasedEvent(val item: ShopItem)
|
||||
class GearPurchasedEvent(val item: ShopItem)
|
||||
|
|
@ -39,6 +39,8 @@ open class ShopItem : RealmObject() {
|
|||
var path: String? = null
|
||||
var isSuggested: String? = null
|
||||
var pinType: String? = null
|
||||
@SerializedName("klass")
|
||||
var habitClass: String? = null
|
||||
|
||||
val isTypeItem: Boolean
|
||||
get() = "eggs" == purchaseType || "hatchingPotions" == purchaseType || "food" == purchaseType || "armoire" == purchaseType || "potion" == purchaseType
|
||||
|
|
|
|||
|
|
@ -135,6 +135,12 @@ class ShopRecyclerAdapter : RecyclerView.Adapter<RecyclerView.ViewHolder>() {
|
|||
selectedGearCategory = gearCategories[holder.selectedItem].identifier
|
||||
}
|
||||
}
|
||||
if (user?.stats?.habitClass != category.identifier) {
|
||||
holder.notesView?.text = context?.getString(R.string.class_gear_disclaimer)
|
||||
holder.notesView?.visibility = View.VISIBLE
|
||||
} else {
|
||||
holder.notesView?.visibility = View.GONE
|
||||
}
|
||||
}
|
||||
}
|
||||
ShopItem::class.java -> {
|
||||
|
|
|
|||
|
|
@ -9,7 +9,7 @@ import com.habitrpg.android.habitica.R
|
|||
import com.habitrpg.android.habitica.components.AppComponent
|
||||
import com.habitrpg.android.habitica.data.InventoryRepository
|
||||
import com.habitrpg.android.habitica.data.UserRepository
|
||||
import com.habitrpg.android.habitica.events.ShopItemPurchasedEvent
|
||||
import com.habitrpg.android.habitica.events.GearPurchasedEvent
|
||||
import com.habitrpg.android.habitica.helpers.RemoteConfigManager
|
||||
import com.habitrpg.android.habitica.helpers.RxErrorHandler
|
||||
import com.habitrpg.android.habitica.models.shops.Shop
|
||||
|
|
@ -39,6 +39,8 @@ class ShopFragment : BaseFragment() {
|
|||
|
||||
private var layoutManager: GridLayoutManager? = null
|
||||
|
||||
private var gearCategories: MutableList<ShopCategory>? = null
|
||||
|
||||
override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View? {
|
||||
super.onCreateView(inflater, container, savedInstanceState)
|
||||
return inflater.inflate(R.layout.fragment_recyclerview, container, false)
|
||||
|
|
@ -80,11 +82,22 @@ class ShopFragment : BaseFragment() {
|
|||
this.shopIdentifier = savedInstanceState.getString(SHOP_IDENTIFIER_KEY, "")
|
||||
}
|
||||
|
||||
adapter?.selectedGearCategory = user?.stats?.habitClass ?: ""
|
||||
|
||||
if (shop == null) {
|
||||
loadShopInventory()
|
||||
} else {
|
||||
adapter?.setShop(shop, configManager.shopSpriteSuffix())
|
||||
}
|
||||
val categories = gearCategories
|
||||
if (categories != null) {
|
||||
adapter?.gearCategories = categories
|
||||
} else {
|
||||
if (Shop.MARKET == shopIdentifier) {
|
||||
loadMarketGear()
|
||||
}
|
||||
}
|
||||
|
||||
adapter?.user = user
|
||||
|
||||
view.post { setGridSpanCount(view.width) }
|
||||
|
|
@ -115,9 +128,6 @@ class ShopFragment : BaseFragment() {
|
|||
}
|
||||
.subscribe(Action1 {
|
||||
this.shop = it
|
||||
if (Shop.MARKET == shopIdentifier) {
|
||||
loadMarketGear()
|
||||
}
|
||||
this.adapter?.setShop(it, configManager.shopSpriteSuffix())
|
||||
}, RxErrorHandler.handleEmptyError())
|
||||
|
||||
|
|
@ -143,7 +153,7 @@ class ShopFragment : BaseFragment() {
|
|||
shop
|
||||
})
|
||||
.subscribe(Action1 {
|
||||
adapter?.selectedGearCategory = user?.stats?.habitClass ?: ""
|
||||
this.gearCategories = it.categories
|
||||
adapter?.gearCategories = it.categories
|
||||
}, RxErrorHandler.handleEmptyError())
|
||||
}
|
||||
|
|
@ -177,7 +187,7 @@ class ShopFragment : BaseFragment() {
|
|||
}
|
||||
|
||||
@Subscribe
|
||||
fun onItemPurchased(event: ShopItemPurchasedEvent) {
|
||||
fun onItemPurchased(event: GearPurchasedEvent) {
|
||||
loadShopInventory()
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -16,7 +16,7 @@ class SectionViewHolder(itemView: View) : RecyclerView.ViewHolder(itemView) {
|
|||
private val label: TextView by bindView(itemView, R.id.label)
|
||||
private val purchaseSetButton: Button? by bindView(itemView, R.id.purchaseSetButton)
|
||||
private val selectionSpinner: Spinner? by bindView(itemView, R.id.classSelectionSpinner)
|
||||
|
||||
internal val notesView: TextView? by bindView(itemView, R.id.headerNotesView)
|
||||
var context: Context = itemView.context
|
||||
|
||||
var spinnerSelectionChanged: (() -> Unit)? = null
|
||||
|
|
@ -31,7 +31,7 @@ class SectionViewHolder(itemView: View) : RecyclerView.ViewHolder(itemView) {
|
|||
override fun onItemSelected(parent: AdapterView<*>?, view: View?, position: Int, id: Long) {
|
||||
spinnerSelectionChanged?.invoke()
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -15,6 +15,7 @@ import com.habitrpg.android.habitica.R
|
|||
import com.habitrpg.android.habitica.components.AppComponent
|
||||
import com.habitrpg.android.habitica.data.InventoryRepository
|
||||
import com.habitrpg.android.habitica.data.UserRepository
|
||||
import com.habitrpg.android.habitica.events.GearPurchasedEvent
|
||||
import com.habitrpg.android.habitica.events.ShowSnackbarEvent
|
||||
import com.habitrpg.android.habitica.events.commands.OpenGemPurchaseFragmentCommand
|
||||
import com.habitrpg.android.habitica.helpers.RemoteConfigManager
|
||||
|
|
@ -96,6 +97,7 @@ class PurchaseDialog(context: Context, component: AppComponent, val item: ShopIt
|
|||
shopItem.isTypeGear -> {
|
||||
contentView = PurchaseDialogGearContent(context)
|
||||
inventoryRepository.getEquipment(shopItem.key).first().subscribe(Action1<Equipment> { contentView.setEquipment(it) }, RxErrorHandler.handleEmptyError())
|
||||
checkGearClass()
|
||||
}
|
||||
"gems" == shopItem.purchaseType -> contentView = PurchaseDialogGemsContent(context)
|
||||
else -> contentView = PurchaseDialogBaseContent(context)
|
||||
|
|
@ -106,6 +108,18 @@ class PurchaseDialog(context: Context, component: AppComponent, val item: ShopIt
|
|||
setScrollviewSize()
|
||||
}
|
||||
|
||||
private fun checkGearClass() {
|
||||
val user = user ?: return
|
||||
|
||||
if (user.stats.habitClass != shopItem.habitClass) {
|
||||
limitedTextView.text = context.getString(R.string.class_equipment_shop_dialog)
|
||||
limitedTextView.visibility = View.VISIBLE
|
||||
limitedTextView.setBackgroundColor(ContextCompat.getColor(context, R.color.gray_100))
|
||||
} else {
|
||||
limitedTextView.visibility = View.GONE
|
||||
}
|
||||
}
|
||||
|
||||
private val compositeSubscription: CompositeSubscription = CompositeSubscription()
|
||||
var shopIdentifier: String? = null
|
||||
private var user: User? = null
|
||||
|
|
@ -157,6 +171,8 @@ class PurchaseDialog(context: Context, component: AppComponent, val item: ShopIt
|
|||
if (!shopItem.canAfford(user)) {
|
||||
priceLabel.cantAfford = true
|
||||
}
|
||||
|
||||
checkGearClass()
|
||||
}
|
||||
|
||||
override fun dismiss() {
|
||||
|
|
@ -239,6 +255,10 @@ class PurchaseDialog(context: Context, component: AppComponent, val item: ShopIt
|
|||
EventBus.getDefault().post(OpenGemPurchaseFragmentCommand())
|
||||
}
|
||||
}
|
||||
|
||||
if (item.isTypeGear) {
|
||||
EventBus.getDefault().post(GearPurchasedEvent(item))
|
||||
}
|
||||
}
|
||||
} else {
|
||||
when {
|
||||
|
|
|
|||
Loading…
Reference in a new issue