Skip to content

Commit

Permalink
improve shop display state
Browse files Browse the repository at this point in the history
  • Loading branch information
phillipthelen committed Aug 29, 2023
1 parent eb6fa95 commit 5259232
Show file tree
Hide file tree
Showing 11 changed files with 35 additions and 20 deletions.
Binary file added Habitica/res/drawable-hdpi/shop_locked.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added Habitica/res/drawable-xhdpi/shop_locked.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added Habitica/res/drawable-xxhdpi/shop_locked.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 2 additions & 0 deletions Habitica/res/layout/row_shopitem.xml
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,8 @@
tools:visibility="visible"
android:gravity="center"
android:scaleType="center"
android:tintMode="multiply"
app:tint="@color/text_dimmed"
android:textColor="@color/white" />
</LinearLayout>
<TextView
Expand Down
Binary file added Habitica/res/shop_locked.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
8 changes: 4 additions & 4 deletions Habitica/res/values/styles.xml
Original file line number Diff line number Diff line change
Expand Up @@ -1012,12 +1012,12 @@
</style>

<style name="CountLabel">
<item name="android:background">@drawable/pill_bg_gray_300</item>
<item name="android:paddingStart">4dp</item>
<item name="android:paddingEnd">4dp</item>
<item name="android:background">@drawable/pill_bg_gray</item>
<item name="android:paddingStart">2dp</item>
<item name="android:paddingEnd">2dp</item>
<item name="android:minWidth">24dp</item>
<item name="android:gravity">center</item>
<item name="android:textColor">@color/white</item>
<item name="android:textColor">@color/text_quad</item>
<item name="android:textSize">12sp</item>
<item name="android:textStyle">bold</item>
</style>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ import com.habitrpg.android.habitica.extensions.inflate
import com.habitrpg.android.habitica.helpers.Analytics
import com.habitrpg.android.habitica.helpers.EventCategory
import com.habitrpg.android.habitica.helpers.HitType
import com.habitrpg.common.habitica.helpers.MainNavigationController
import com.habitrpg.android.habitica.models.shops.Shop
import com.habitrpg.android.habitica.models.shops.ShopCategory
import com.habitrpg.android.habitica.models.shops.ShopItem
Expand All @@ -27,9 +26,11 @@ import com.habitrpg.android.habitica.ui.views.getTranslatedClassName
import com.habitrpg.android.habitica.ui.views.insufficientCurrency.InsufficientGemsDialog
import com.habitrpg.common.habitica.extensions.fromHtml
import com.habitrpg.common.habitica.extensions.loadImage
import com.habitrpg.common.habitica.helpers.MainNavigationController

class ShopRecyclerAdapter : androidx.recyclerview.widget.RecyclerView.Adapter<ViewHolder>() {

var completedQuests: List<String?> = emptyList()
var armoireCount: Int = 0
var onNeedsRefresh: (() -> Unit)? = null
var onShowPurchaseDialog: ((ShopItem, Boolean) -> Unit)? = null
Expand Down Expand Up @@ -177,6 +178,7 @@ class ShopRecyclerAdapter : androidx.recyclerview.widget.RecyclerView.Adapter<Vi
val numberOwned = ownedItems[obj.key + "-" + obj.purchaseType]?.numberOwned ?: 0
itemHolder.bind(obj, obj.canAfford(user, 1), numberOwned)
itemHolder.isPinned = pinnedItemKeys.contains(obj.key)
itemHolder.isCompleted = completedQuests.contains(obj.key)
}
is String -> (holder as? EmptyStateViewHolder)?.text = obj
is Pair<*, *> -> (holder as? ArmoireGearViewHolder)?.bind(obj.first as? String ?: "", obj.second as? Int ?: 0)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,9 @@ import android.os.Bundle
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import androidx.lifecycle.lifecycleScope
import com.habitrpg.android.habitica.models.shops.Shop
import com.habitrpg.common.habitica.helpers.launchCatching
import dagger.hilt.android.AndroidEntryPoint

@AndroidEntryPoint
Expand All @@ -17,4 +19,14 @@ class QuestShopFragment : ShopFragment() {
shopIdentifier = Shop.QUEST_SHOP
return super.onCreateView(inflater, container, savedInstanceState)
}

override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
super.onViewCreated(view, savedInstanceState)

lifecycleScope.launchCatching {
userRepository.getQuestAchievements().collect {
adapter?.completedQuests = it.map { it.questKey }
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ import com.habitrpg.android.habitica.databinding.RowShopitemBinding
import com.habitrpg.android.habitica.models.shops.ShopItem
import com.habitrpg.android.habitica.ui.views.HabiticaIconsHelper
import com.habitrpg.common.habitica.extensions.dpToPx
import com.habitrpg.common.habitica.extensions.isUsingNightModeResources
import com.habitrpg.common.habitica.extensions.loadImage

class ShopItemViewHolder(itemView: View) : RecyclerView.ViewHolder(itemView), View.OnClickListener {
Expand Down Expand Up @@ -66,28 +65,28 @@ class ShopItemViewHolder(itemView: View) : RecyclerView.ViewHolder(itemView), Vi
binding.priceLabel.visibility = View.GONE
binding.unlockLabel.visibility = View.VISIBLE
}
val isLimited = item.isLimited || item.event?.end != null
if (numberOwned > 0) {
binding.itemDetailIndicator.text = numberOwned.toString()
binding.itemDetailIndicator.background = if (context.isUsingNightModeResources()) {
BitmapDrawable(context.resources, HabiticaIconsHelper.imageOfItemIndicatorNumberDark(item.isLimited || item.event?.end != null))
} else {
BitmapDrawable(context.resources, HabiticaIconsHelper.imageOfItemIndicatorNumber(item.isLimited || item.event?.end != null))
}
binding.itemDetailIndicator.background =
AppCompatResources.getDrawable(context, R.drawable.pill_bg_gray)
binding.itemDetailIndicator.visibility = View.VISIBLE
}
if (item.locked) {
binding.itemDetailIndicator.background = AppCompatResources.getDrawable(context, R.drawable.shop_locked)
binding.itemDetailIndicator.visibility = View.VISIBLE
} else if (item.locked) {
binding.itemDetailIndicator.background = if (context.isUsingNightModeResources()) {
BitmapDrawable(context.resources, HabiticaIconsHelper.imageOfItemIndicatorLockedDark(item.isLimited || item.event?.end != null))
} else if (isLimited) {
if (numberOwned == 0) {
binding.itemDetailIndicator.background = BitmapDrawable(context.resources, HabiticaIconsHelper.imageOfItemIndicatorLimited())
} else {
BitmapDrawable(context.resources, HabiticaIconsHelper.imageOfItemIndicatorLocked(item.isLimited || item.event?.end != null))
binding.itemDetailIndicator.background = AppCompatResources.getDrawable(context, R.drawable.pill_bg_purple_300)
}
binding.itemDetailIndicator.visibility = View.VISIBLE
} else if (item.isLimited || item.event?.end != null) {
binding.itemDetailIndicator.background = BitmapDrawable(context.resources, HabiticaIconsHelper.imageOfItemIndicatorLimited())
binding.itemDetailIndicator.visibility = View.VISIBLE
}

if (item.key == "gem" && item.limitedNumberLeft == -1) {
binding.itemDetailIndicator.background = AppCompatResources.getDrawable(context, R.drawable.item_indicator_subscribe)
binding.itemDetailIndicator.visibility = View.VISIBLE
}

if (binding.itemDetailIndicator.visibility == View.VISIBLE) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -234,7 +234,7 @@ public static Bitmap imageOfPinnedItem() {
if (imageOfPinnedItem != null)
return imageOfPinnedItem;

int size = scaleSize(16);
int size = scaleSize(14);
imageOfPinnedItem = Bitmap.createBitmap(size, size, Bitmap.Config.ARGB_8888);
Canvas canvas = new Canvas(imageOfPinnedItem);
canvas.scale(displayDensity, displayDensity);
Expand Down
2 changes: 1 addition & 1 deletion version.properties
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
NAME=4.3
CODE=6381
CODE=6391

0 comments on commit 5259232

Please sign in to comment.