mirror of
https://github.com/sudoxnym/habitica-android.git
synced 2026-07-14 10:11:58 +00:00
Improve empty states
This commit is contained in:
parent
d4c410ba6f
commit
8ab3f22ba2
7 changed files with 71 additions and 9 deletions
|
|
@ -4,7 +4,7 @@
|
|||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content">
|
||||
<LinearLayout
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:orientation="vertical"
|
||||
android:layout_gravity="center"
|
||||
|
|
|
|||
|
|
@ -729,7 +729,7 @@ Die Quest-Schriftrolle wird an den Quest-Besitzer zurückgegeben.</string>
|
|||
<string name="complete">Erledigen</string>
|
||||
<string name="reject">Ablehnen</string>
|
||||
<string name="accept">Akzeptieren</string>
|
||||
<string name="equip_automatically">Neue Ausrüstung automatisch anziehen</string>
|
||||
<string name="equip_automatically">Neues automatisch anziehen</string>
|
||||
<string name="leave_challenges">Herausforderung verlassen</string>
|
||||
<string name="keep_challenges">Herausforderungen behalten</string>
|
||||
<string name="inviteFriendDescription">Du hast einen Freund oder Freunde eingeladen, die Dich auf Deinem Abenteuer begleiten!</string>
|
||||
|
|
|
|||
|
|
@ -1527,6 +1527,8 @@
|
|||
<string name="warriors">Warriors</string>
|
||||
<string name="mages">Mages</string>
|
||||
<string name="customization_shop">Customization Shop</string>
|
||||
<string name="equipment">Equipment</string>
|
||||
<string name="customizing_your_avatar">customizing your avatar</string>
|
||||
|
||||
<plurals name="you_x_others">
|
||||
<item quantity="zero">You</item>
|
||||
|
|
|
|||
|
|
@ -1,11 +1,15 @@
|
|||
package com.habitrpg.android.habitica.models.shops
|
||||
|
||||
import android.content.Context
|
||||
import android.text.Spannable
|
||||
import android.text.SpannableString
|
||||
import android.text.style.ForegroundColorSpan
|
||||
import androidx.core.content.ContextCompat
|
||||
import com.habitrpg.android.habitica.R
|
||||
|
||||
class EmptyShopCategory(categoryIdentifier: String, context: Context?) {
|
||||
class EmptyShopCategory(val categoryIdentifier: String, context: Context?) {
|
||||
val title: String = context?.getString(R.string.you_own_all_items) ?: ""
|
||||
val description: String
|
||||
val description: Spannable
|
||||
init {
|
||||
val stringId = when (categoryIdentifier) {
|
||||
"backgrounds" -> R.string.try_on_next_month
|
||||
|
|
@ -14,6 +18,19 @@ class EmptyShopCategory(categoryIdentifier: String, context: Context?) {
|
|||
"mystery_sets" -> R.string.try_on_equipment
|
||||
else -> R.string.try_on_customize
|
||||
}
|
||||
description = context?.getString(stringId) ?: ""
|
||||
if (context != null) {
|
||||
val descriptionString = context.getString(stringId)
|
||||
val words = listOf(context.getString(R.string.equipment), context.getString(R.string.customizing_your_avatar))
|
||||
val spannable = SpannableString(descriptionString)
|
||||
for (word in words) {
|
||||
val index = spannable.indexOf(word)
|
||||
if (index >= 0) {
|
||||
spannable.setSpan(ForegroundColorSpan(ContextCompat.getColor(context, R.color.brand_400)), index, index + word.length, Spannable.SPAN_INCLUSIVE_EXCLUSIVE)
|
||||
}
|
||||
}
|
||||
description = spannable
|
||||
} else {
|
||||
description = SpannableString("")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -42,6 +42,7 @@ class ShopRecyclerAdapter : androidx.recyclerview.widget.RecyclerView.Adapter<Vi
|
|||
var armoireItem: ShopItem? = null
|
||||
|
||||
var changeClassEvents: ((String) -> Unit)? = null
|
||||
var emptySectionClickedEvents: ((String) -> Unit)? = null
|
||||
|
||||
var shopSpriteSuffix: String? = null
|
||||
set(value) {
|
||||
|
|
@ -93,7 +94,6 @@ class ShopRecyclerAdapter : androidx.recyclerview.widget.RecyclerView.Adapter<Vi
|
|||
items.add(category)
|
||||
if (category.items.isEmpty()) {
|
||||
items.add(EmptyShopCategory(category.identifier, context))
|
||||
|
||||
} else {
|
||||
for (item in category.items) {
|
||||
item.categoryIdentifier = category.identifier
|
||||
|
|
@ -217,7 +217,12 @@ class ShopRecyclerAdapter : androidx.recyclerview.widget.RecyclerView.Adapter<Vi
|
|||
itemHolder.isCompleted = completedQuests.contains(obj.key)
|
||||
}
|
||||
|
||||
is EmptyShopCategory -> (holder as? EmptyShopSectionViewHolder)?.bind(obj)
|
||||
is EmptyShopCategory -> {
|
||||
(holder as? EmptyShopSectionViewHolder)?.bind(obj)
|
||||
(holder as? EmptyShopSectionViewHolder)?.onClicked = {
|
||||
emptySectionClickedEvents?.invoke(obj.categoryIdentifier)
|
||||
}
|
||||
}
|
||||
|
||||
is String -> (holder as? EmptyStateViewHolder)?.text = obj
|
||||
is Pair<*, *> ->
|
||||
|
|
|
|||
|
|
@ -9,6 +9,7 @@ import androidx.compose.foundation.layout.Row
|
|||
import androidx.compose.runtime.mutableStateOf
|
||||
import androidx.compose.ui.platform.ComposeView
|
||||
import androidx.compose.ui.unit.dp
|
||||
import androidx.core.os.bundleOf
|
||||
import androidx.lifecycle.lifecycleScope
|
||||
import androidx.recyclerview.widget.GridLayoutManager
|
||||
import com.habitrpg.android.habitica.R
|
||||
|
|
@ -23,7 +24,6 @@ import com.habitrpg.android.habitica.helpers.HitType
|
|||
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.social.Group
|
||||
import com.habitrpg.android.habitica.ui.adapter.inventory.ShopRecyclerAdapter
|
||||
import com.habitrpg.android.habitica.ui.fragments.BaseMainFragment
|
||||
import com.habitrpg.android.habitica.ui.fragments.purchases.EventOutcomeSubscriptionBottomSheetFragment
|
||||
|
|
@ -36,10 +36,10 @@ import com.habitrpg.android.habitica.ui.views.dialogs.HabiticaProgressDialog
|
|||
import com.habitrpg.android.habitica.ui.views.insufficientCurrency.InsufficientGemsDialog
|
||||
import com.habitrpg.android.habitica.ui.views.shops.PurchaseDialog
|
||||
import com.habitrpg.common.habitica.helpers.ExceptionHandler
|
||||
import com.habitrpg.common.habitica.helpers.MainNavigationController
|
||||
import com.habitrpg.common.habitica.helpers.RecyclerViewState
|
||||
import com.habitrpg.common.habitica.helpers.launchCatching
|
||||
import kotlinx.coroutines.Dispatchers
|
||||
import kotlinx.coroutines.flow.filter
|
||||
import kotlinx.coroutines.flow.firstOrNull
|
||||
import kotlinx.coroutines.flow.map
|
||||
import kotlinx.coroutines.launch
|
||||
|
|
@ -160,6 +160,34 @@ open class ShopFragment : BaseMainFragment<FragmentRefreshRecyclerviewBinding>()
|
|||
adapter?.changeClassEvents = {
|
||||
showClassChangeDialog(it)
|
||||
}
|
||||
adapter?.emptySectionClickedEvents = {
|
||||
if (shopIdentifier == Shop.CUSTOMIZATIONS) {
|
||||
var navigationID = R.id.ComposeAvatarCustomizationFragment
|
||||
var type = ""
|
||||
var category: String? = null
|
||||
if (it == "color") {
|
||||
type = "hair"
|
||||
category = "color"
|
||||
} else if (it == "facialHair") {
|
||||
type = "hair"
|
||||
category = "beard"
|
||||
} else if (it == "base") {
|
||||
type = "hair"
|
||||
category = "base"
|
||||
} else if (it == "animalEars") {
|
||||
navigationID = R.id.composeAvatarEquipmentFragment
|
||||
category = "headAccessory"
|
||||
} else if (it == "animalTails") {
|
||||
navigationID = R.id.composeAvatarEquipmentFragment
|
||||
category = "back"
|
||||
} else if (it == "backgrounds") {
|
||||
category = "background"
|
||||
}
|
||||
MainNavigationController.navigate(navigationID, bundleOf("category" to category, "type" to type))
|
||||
} else if (shopIdentifier == Shop.TIME_TRAVELERS_SHOP) {
|
||||
MainNavigationController.navigate(R.id.equipmentOverviewFragment)
|
||||
}
|
||||
}
|
||||
|
||||
lifecycleScope.launchCatching {
|
||||
inventoryRepository.getInAppReward("armoire").collect {
|
||||
|
|
@ -337,9 +365,11 @@ open class ShopFragment : BaseMainFragment<FragmentRefreshRecyclerviewBinding>()
|
|||
specialCategory.items.add(ShopItem.makeFortifyItem(context?.resources))
|
||||
newShop.categories.add(specialCategory)
|
||||
}
|
||||
|
||||
Shop.TIME_TRAVELERS_SHOP -> {
|
||||
formatTimeTravelersShop(newShop)
|
||||
}
|
||||
|
||||
Shop.SEASONAL_SHOP -> {
|
||||
newShop.categories.sortWith(
|
||||
compareBy<ShopCategory> { it.items.firstOrNull()?.currency != "gold" }
|
||||
|
|
|
|||
|
|
@ -8,6 +8,14 @@ import com.habitrpg.android.habitica.models.shops.EmptyShopCategory
|
|||
class EmptyShopSectionViewHolder(itemView: View) : RecyclerView.ViewHolder(itemView) {
|
||||
private val binding = ShopSectionEmptyBinding.bind(itemView)
|
||||
|
||||
var onClicked: (() -> Unit)? = null
|
||||
|
||||
init {
|
||||
binding.root.setOnClickListener {
|
||||
onClicked?.invoke()
|
||||
}
|
||||
}
|
||||
|
||||
fun bind(emptyShopCategory: EmptyShopCategory) {
|
||||
binding.titleView.text = emptyShopCategory.title
|
||||
binding.descriptionView.text = emptyShopCategory.description
|
||||
|
|
|
|||
Loading…
Reference in a new issue