Fix time travelers shop display. Fixes #862

This commit is contained in:
Phillip Thelen 2019-04-19 13:05:31 +02:00
parent 5bfef43cdb
commit d0b56baef5
4 changed files with 42 additions and 9 deletions

View file

@ -890,4 +890,5 @@
<string name="report_explanation">**Only** report a post that violates the [Community Guidelines](https://habitica.com/static/community-guidelines) and/or [Terms of Service](https://habitica.com/static/terms). Inappropriately reporting a post may give you an infraction.</string>
<string name="report_message_title">Report %s for violation:</string>
<string name="reason_for_report">Reason for report (optional)</string>
<string name="mystery_sets">Mystery Sets</string>
</resources>

View file

@ -43,7 +43,7 @@ class ShopFragment : BaseFragment() {
@Inject
lateinit var configManager: RemoteConfigManager
private var layoutManager: androidx.recyclerview.widget.GridLayoutManager? = null
private var layoutManager: GridLayoutManager? = null
private var gearCategories: MutableList<ShopCategory>? = null
@ -71,8 +71,8 @@ class ShopFragment : BaseFragment() {
}
if (recyclerView.layoutManager == null) {
layoutManager = androidx.recyclerview.widget.GridLayoutManager(context, 2)
layoutManager?.spanSizeLookup = object : androidx.recyclerview.widget.GridLayoutManager.SpanSizeLookup() {
layoutManager = GridLayoutManager(context, 2)
layoutManager?.spanSizeLookup = object : GridLayoutManager.SpanSizeLookup() {
override fun getSpanSize(position: Int): Int {
return if (adapter?.getItemViewType(position) ?: 0 < 3) {
layoutManager?.spanCount ?: 1
@ -140,7 +140,11 @@ class ShopFragment : BaseFragment() {
shop1.categories.add(specialCategory)
}
}
shop1
if (shop1.identifier == Shop.TIME_TRAVELERS_SHOP) {
formatTimeTravelersShop(shop1)
} else {
shop1
}
}
.subscribe(Consumer {
this.shop = it
@ -158,6 +162,29 @@ class ShopFragment : BaseFragment() {
.subscribe(Consumer { adapter?.setPinnedItemKeys(it) }, RxErrorHandler.handleEmptyError()))
}
private fun formatTimeTravelersShop(shop: Shop): Shop {
val newCategories = mutableListOf<ShopCategory>()
for (category in shop.categories) {
if (category.identifier == "pets" || category.identifier == "mounts") {
newCategories.add(category)
} else {
val newCategory = newCategories.find { it.identifier == "mystery_sets" } ?: ShopCategory()
if (newCategory.identifier.isEmpty()) {
newCategory.identifier = "mystery_sets"
newCategory.text = getString(R.string.mystery_sets)
newCategories.add(newCategory)
}
val item = category.items.firstOrNull() ?: continue
item.key = category.identifier
item.text = category.text
item.imageName = "shop_set_mystery_${item.key}"
newCategory.items.add(item)
}
}
shop.categories = newCategories
return shop
}
private fun loadMarketGear() {
compositeSubscription.add(inventoryRepository.retrieveMarketGear()
.zipWith(inventoryRepository.getOwnedEquipment().map { equipment -> equipment.map { it.key } }, BiFunction<Shop, List<String?>, Shop> { shop, equipment ->

View file

@ -111,7 +111,7 @@ class PurchaseDialog(context: Context, component: AppComponent?, val item: ShopI
return
}
if (shopItem.habitClass != "special" && user.stats?.habitClass != shopItem.habitClass) {
if (shopItem.habitClass != null && shopItem.habitClass != "special" && 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))

View file

@ -34,19 +34,24 @@ internal class PurchaseDialogGearContent : PurchaseDialogContent {
}
fun setEquipment(equipment: Equipment) {
if (equipment.isManaged) {
if (equipment.isValid) {
configureFieldsForValue(strLabel, strValueTextView, equipment.str)
configureFieldsForValue(perLabel, perValueTextView, equipment.per)
configureFieldsForValue(conLabel, conValueTextView, equipment.con)
configureFieldsForValue(intLabel, intValueTextView, equipment._int)
} else {
configureFieldsForValue(strLabel, strValueTextView, 0)
configureFieldsForValue(perLabel, perValueTextView, 0)
configureFieldsForValue(conLabel, conValueTextView, 0)
configureFieldsForValue(intLabel, intValueTextView, 0)
}
}
private fun configureFieldsForValue(labelView: TextView?, valueTextView: TextView?, value: Int) {
valueTextView!!.text = "+" + value
valueTextView?.text = "+$value"
if (value == 0) {
labelView!!.setTextColor(ContextCompat.getColor(context, R.color.gray_400))
valueTextView.setTextColor(ContextCompat.getColor(context, R.color.gray_400))
labelView?.setTextColor(ContextCompat.getColor(context, R.color.gray_400))
valueTextView?.setTextColor(ContextCompat.getColor(context, R.color.gray_400))
}
}
}