Improve empty states for shop categories

This commit is contained in:
Phillip Thelen 2024-05-16 17:55:18 +02:00
parent 5ad7ea11fd
commit 91dd28d4ec
6 changed files with 85 additions and 4 deletions

View file

@ -0,0 +1,33 @@
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical"
android:layout_gravity="center"
android:padding="17dp"
android:background="@drawable/layout_rounded_bg_window"
android:gravity="center_horizontal"
android:layout_marginHorizontal="20dp">
<TextView
android:id="@+id/title_view"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
style="@style/Body1"
android:textColor="?textColorPrimary"
tools:text="Test Title"
android:layout_marginBottom="3dp"/>
<TextView
android:id="@+id/description_view"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:maxWidth="300dp"
style="@style/Body2"
android:gravity="center_horizontal"
android:textColor="?textColorSecondary"
tools:text="Test Description"/>
</LinearLayout>
</FrameLayout>

View file

@ -1515,6 +1515,11 @@
<string name="summer">Summer</string>
<string name="fall">Fall</string>
<string name="animal_tails">Animal Tails</string>
<string name="you_own_all_items">You own all of these items</string>
<string name="try_on_next_month">You can try them on by customizing your avatar. Be sure to check back later for next months options!</string>
<string name="try_on_next_season">You can try them on by customizing your avatar. Be sure to check back later for next seasons options!</string>
<string name="try_on_customize">"You can try them on by customizing your avatar. "</string>
<string name="try_on_equipment">"You can try them on by Equipment. Be sure to check back later for next months options! "</string>
<plurals name="you_x_others">
<item quantity="zero">You</item>

View file

@ -0,0 +1,19 @@
package com.habitrpg.android.habitica.models.shops
import android.content.Context
import com.habitrpg.android.habitica.R
class EmptyShopCategory(categoryIdentifier: String, context: Context?) {
val title: String = context?.getString(R.string.you_own_all_items) ?: ""
val description: String
init {
val stringId = when (categoryIdentifier) {
"background" -> R.string.try_on_next_month
"color" -> R.string.try_on_next_season
"skin" -> R.string.try_on_next_season
"mystery_sets" -> R.string.try_on_equipment
else -> R.string.try_on_customize
}
description = context?.getString(stringId) ?: ""
}
}

View file

@ -14,12 +14,14 @@ 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.android.habitica.models.shops.EmptyShopCategory
import com.habitrpg.android.habitica.models.shops.Shop
import com.habitrpg.android.habitica.models.shops.ShopCategory
import com.habitrpg.android.habitica.models.shops.ShopItem
import com.habitrpg.android.habitica.models.user.OwnedItem
import com.habitrpg.android.habitica.models.user.User
import com.habitrpg.android.habitica.ui.activities.MainActivity
import com.habitrpg.android.habitica.ui.viewHolders.EmptyShopSectionViewHolder
import com.habitrpg.android.habitica.ui.viewHolders.SectionViewHolder
import com.habitrpg.android.habitica.ui.viewHolders.ShopItemViewHolder
import com.habitrpg.android.habitica.ui.views.getTranslatedClassName
@ -89,8 +91,11 @@ class ShopRecyclerAdapter : androidx.recyclerview.widget.RecyclerView.Adapter<Vi
items.clear()
items.add(shop)
for (category in shop.categories) {
if (category.items.size > 0) {
items.add(category)
items.add(category)
if (category.items.isEmpty()) {
items.add(EmptyShopCategory(category.identifier, context))
} else {
for (item in category.items) {
item.categoryIdentifier = category.identifier
items.add(item)
@ -115,6 +120,7 @@ class ShopRecyclerAdapter : androidx.recyclerview.widget.RecyclerView.Adapter<Vi
}
viewHolder
}
4 -> EmptyShopSectionViewHolder(parent.inflate(R.layout.shop_section_empty))
else -> {
val view = parent.inflate(R.layout.row_shopitem)
@ -212,6 +218,8 @@ class ShopRecyclerAdapter : androidx.recyclerview.widget.RecyclerView.Adapter<Vi
itemHolder.isCompleted = completedQuests.contains(obj.key)
}
is EmptyShopCategory -> (holder as? EmptyShopSectionViewHolder)?.bind(obj)
is String -> (holder as? EmptyStateViewHolder)?.text = obj
is Pair<*, *> ->
(holder as? ArmoireGearViewHolder)?.bind(
@ -264,7 +272,8 @@ class ShopRecyclerAdapter : androidx.recyclerview.widget.RecyclerView.Adapter<Vi
is Shop -> 0
is ShopCategory -> 1
is Pair<*, *> -> 3
is ShopItem -> 4
is EmptyShopCategory -> 4
is ShopItem -> 5
else -> 2
}

View file

@ -176,7 +176,7 @@ open class ShopFragment : BaseMainFragment<FragmentRefreshRecyclerviewBinding>()
layoutManager?.spanSizeLookup =
object : GridLayoutManager.SpanSizeLookup() {
override fun getSpanSize(position: Int): Int {
return if ((adapter?.getItemViewType(position) ?: 0) < 4) {
return if ((adapter?.getItemViewType(position) ?: 0) < 5) {
layoutManager?.spanCount ?: 1
} else {
1

View file

@ -0,0 +1,15 @@
package com.habitrpg.android.habitica.ui.viewHolders
import android.view.View
import androidx.recyclerview.widget.RecyclerView
import com.habitrpg.android.habitica.databinding.ShopSectionEmptyBinding
import com.habitrpg.android.habitica.models.shops.EmptyShopCategory
class EmptyShopSectionViewHolder(itemView: View) : RecyclerView.ViewHolder(itemView) {
private val binding = ShopSectionEmptyBinding.bind(itemView)
fun bind(emptyShopCategory: EmptyShopCategory) {
binding.titleView.text = emptyShopCategory.title
binding.descriptionView.text = emptyShopCategory.description
}
}