Improve bottom sheet design and behaviour

This commit is contained in:
Phillip Thelen 2022-05-20 10:51:32 +02:00
parent d6a5eee02c
commit 5256e85641
11 changed files with 68 additions and 36 deletions

View file

@ -5,10 +5,12 @@
android:orientation="vertical">
<View
android:id="@+id/grabber"
android:layout_width="40dp"
android:layout_height="4dp"
android:background="@drawable/layout_rounded_bg_gray"
android:layout_margin="@dimen/spacing_large"
android:layout_width="24dp"
android:layout_height="3dp"
android:background="@drawable/layout_rounded_bg"
android:backgroundTint="@color/offset_background"
android:layout_marginTop="@dimen/spacing_medium"
android:layout_marginBottom="@dimen/spacing_large"
android:layout_gravity="center_horizontal"
/>
<FrameLayout

View file

@ -15,9 +15,16 @@
style="@style/Subheader1"
android:background="@drawable/bottom_sheet_title"
android:padding="8dp"/>
<com.habitrpg.android.habitica.ui.views.PixelArtView
android:id="@+id/icon_view"
android:layout_width="@dimen/shopitem_image_size"
android:layout_height="@dimen/shopitem_image_size"
android:layout_margin="@dimen/spacing_medium"
android:layout_gravity="center"
android:visibility="gone"/>
<LinearLayout
android:id="@+id/menu_items"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"/>
android:orientation="vertical" />
</LinearLayout>

View file

@ -4,7 +4,10 @@
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="wrap_content"
style="@style/BottomMenuItem"
style="@style/HabiticaButton.Purple.Small"
android:background="@drawable/layout_rounded_bg"
android:layout_marginVertical="6dp"
android:layout_marginHorizontal="@dimen/spacing_large"
android:clickable="true"
android:focusable="true">
<TextView

View file

@ -110,7 +110,7 @@
<dimen name="content_inset">21dp</dimen>
<dimen name="header_border_spacing">16dp</dimen>
<dimen name="button_height">53dp</dimen>
<dimen name="button_height">50dp</dimen>
<dimen name="button_height_small">24dp</dimen>
<dimen name="alert_side_padding">26dp</dimen>
<dimen name="downwards_drop_shadow_height">16dp</dimen>

View file

@ -456,7 +456,11 @@
</style>
<style name="BottomMenuItemText">
<item name="android:textSize">@dimen/card_medium_text</item>
<item name="android:textColor">@color/white</item>
<item name="android:textSize">16sp</item>
<item name="android:letterSpacing">0.02</item>
<item name="android:fontFamily">@string/font_family_medium</item>
<item name="android:gravity">center</item>
</style>
<style name="GemPurchaseListItem">

View file

@ -118,31 +118,10 @@ class ItemRecyclerAdapter(val context: Context, val user: User?) : BaseRecyclerV
binding.titleTextView.text = item?.text ?: ownedItem.key
binding.ownedTextView.text = ownedItem.numberOwned.toString()
var disabled = false
val imageName: String?
if (item is QuestContent) {
imageName = "inventory_quest_scroll_" + ownedItem.key
} else if (item is SpecialItem) {
if (item.key == "inventory_present") {
val sdf = SimpleDateFormat("MM", Locale.getDefault())
val month = sdf.format(Date())
imageName = "inventory_present_$month"
} else {
imageName = "shop_" + ownedItem.key
}
} else {
val type = when (ownedItem.itemType) {
"eggs" -> "Egg"
"food" -> "Food"
"hatchingPotions" -> "HatchingPotion"
else -> ""
}
imageName = "Pet_" + type + "_" + ownedItem.key
if (isHatching) {
disabled = !this.canHatch
}
}
val disabled = if (isHatching) {
!this.canHatch
} else false
val imageName = getImageName(item)
binding.imageView.loadImage(imageName)
var alpha = 1.0f
@ -154,10 +133,36 @@ class ItemRecyclerAdapter(val context: Context, val user: User?) : BaseRecyclerV
binding.ownedTextView.alpha = alpha
}
private fun getImageName(
item: Item?,
): String {
return if (item is QuestContent) {
"inventory_quest_scroll_" + item.key
} else if (item is SpecialItem) {
if (item.key == "inventory_present") {
val sdf = SimpleDateFormat("MM", Locale.getDefault())
val month = sdf.format(Date())
"inventory_present_$month"
} else {
"shop_" + item.key
}
} else {
val type = when (item?.type) {
"eggs" -> "Egg"
"food" -> "Food"
"hatchingPotions" -> "HatchingPotion"
else -> ""
}
"Pet_" + type + "_" + item?.key
}
}
override fun onClick(v: View) {
val context = context
if (!isHatching && !isFeeding) {
val menu = BottomSheetMenu(context)
menu.setTitle(item?.text)
menu.setImage(getImageName(item))
if (item !is QuestContent && item !is SpecialItem) {
menu.addMenuItem(BottomSheetMenuItem(resources.getString(R.string.sell, item?.value), true))
}

View file

@ -419,7 +419,9 @@ class TasksFragment : BaseMainFragment<FragmentViewpagerBinding>(), SearchView.O
}
private fun updateBoardDisplay() {
activity?.title = viewModel.ownerTitle
if (viewModel.ownerTitle.isNotBlank()) {
activity?.title = viewModel.ownerTitle
}
val isPersonalBoard = viewModel.isPersonalBoard
bottomNavigation?.canAddTasks = isPersonalBoard
}

View file

@ -3,6 +3,7 @@ package com.habitrpg.android.habitica.ui.menu
import android.content.Context
import android.view.View
import com.habitrpg.android.habitica.databinding.MenuBottomSheetBinding
import com.habitrpg.android.habitica.ui.helpers.loadImage
import com.habitrpg.android.habitica.ui.views.dialogs.HabiticaBottomSheetDialog
class BottomSheetMenu(context: Context) : HabiticaBottomSheetDialog(context), View.OnClickListener {
@ -21,7 +22,12 @@ class BottomSheetMenu(context: Context) : HabiticaBottomSheetDialog(context), Vi
override fun setTitle(title: CharSequence?) {
binding.titleView.text = title
binding.titleView.visibility = View.VISIBLE
grabberVisibility = View.GONE
binding.titleView.background = null
}
fun setImage(url: String) {
binding.iconView.loadImage(url)
binding.iconView.visibility = View.VISIBLE
}
fun addMenuItem(menuItem: BottomSheetMenuItem) {

View file

@ -1,6 +1,7 @@
package com.habitrpg.android.habitica.ui.menu
import android.content.Context
import android.content.res.ColorStateList
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
@ -29,7 +30,7 @@ class BottomSheetMenuItem {
val textView = menuItemView?.findViewById<TextView>(R.id.textView)
textView?.text = this.title
if (this.isDestructive == true) {
textView?.setTextColor(ContextCompat.getColor(context, R.color.red_50))
menuItemView?.backgroundTintList = ColorStateList.valueOf(ContextCompat.getColor(context, R.color.red_10))
}
return menuItemView ?: View(context)
}

View file

@ -51,6 +51,7 @@ class MountViewHolder(parent: ViewGroup, private val equipEvents: PublishSubject
}
val menu = BottomSheetMenu(itemView.context)
menu.setTitle(animal?.text)
menu.setImage("stable_Mount_Icon_" + animal?.animal + "-" + animal?.color)
val hasCurrentMount = currentMount.equals(animal?.key)
val labelId = if (hasCurrentMount) R.string.unequip else R.string.equip

View file

@ -110,6 +110,7 @@ class PetViewHolder(
val context = itemView.context
val menu = BottomSheetMenu(context)
menu.setTitle(animal?.text)
menu.setImage("stable_Pet-${animal?.animal}-${animal?.color}")
val hasCurrentPet = currentPet.equals(animal?.key)
val labelId = if (hasCurrentPet) R.string.unequip else R.string.equip