design tweaks

This commit is contained in:
Phillip Thelen 2023-08-21 11:36:20 +02:00
parent fe98f6960a
commit 6935dcf980
4 changed files with 59 additions and 50 deletions

View file

@ -29,5 +29,6 @@
style="@style/Body2"
android:gravity="center_horizontal"
android:textColor="@color/text_ternary"
android:maxWidth="300dp"
android:layout_marginTop="2dp"/>
</LinearLayout>

View file

@ -125,9 +125,6 @@ class ItemRecyclerFragment : BaseFragment<FragmentItemsBinding>(), SwipeRefreshL
layoutManager = androidx.recyclerview.widget.LinearLayoutManager(context)
binding?.recyclerView?.layoutManager = layoutManager
activity?.let {
binding?.recyclerView?.addItemDecoration(androidx.recyclerview.widget.DividerItemDecoration(it, androidx.recyclerview.widget.DividerItemDecoration.VERTICAL))
}
binding?.recyclerView?.itemAnimator = SafeDefaultItemAnimator()
userViewModel.user.observeOnce(this) {
@ -155,54 +152,54 @@ class ItemRecyclerFragment : BaseFragment<FragmentItemsBinding>(), SwipeRefreshL
adapter = ItemRecyclerAdapter(context)
}
binding?.recyclerView?.adapter = adapter
adapter?.onUseSpecialItem = { onSpecialItemSelected(it) }
adapter?.onSellItem = {
lifecycleScope.launchCatching {
inventoryRepository.sellItem(it)
}
}
adapter?.onUseSpecialItem = { onSpecialItemSelected(it) }
adapter?.onSellItem = {
lifecycleScope.launchCatching {
inventoryRepository.sellItem(it)
}
adapter?.onQuestInvitation = {
lifecycleScope.launchCatching {
inventoryRepository.inviteToQuest(it)
MainNavigationController.navigate(R.id.partyFragment)
}
}
adapter?.onQuestInvitation = {
lifecycleScope.launchCatching {
inventoryRepository.inviteToQuest(it)
MainNavigationController.navigate(R.id.partyFragment)
}
adapter?.onOpenMysteryItem = {
lifecycleScope.launchCatching {
val item = inventoryRepository.openMysteryItem(user) ?: return@launchCatching
val activity = activity as? MainActivity
if (activity != null) {
val dialog = OpenedMysteryitemDialog(activity)
dialog.isCelebratory = true
dialog.setTitle(R.string.mystery_item_title)
dialog.binding.iconView.loadImage("shop_${item.key}")
dialog.binding.titleView.text = item.text
dialog.binding.descriptionView.text = item.notes
dialog.addButton(R.string.equip, true) { _, _ ->
lifecycleScope.launchCatching {
item.key?.let { mysteryItem -> inventoryRepository.equip("equipped", mysteryItem) }
}
}
adapter?.onOpenMysteryItem = {
lifecycleScope.launchCatching {
val item = inventoryRepository.openMysteryItem(user) ?: return@launchCatching
val activity = activity as? MainActivity
if (activity != null) {
val dialog = OpenedMysteryitemDialog(activity)
dialog.isCelebratory = true
dialog.setTitle(R.string.mystery_item_title)
dialog.binding.iconView.loadImage("shop_${item.key}")
dialog.binding.titleView.text = item.text
dialog.binding.descriptionView.text = item.notes
dialog.addButton(R.string.equip, true) { _, _ ->
lifecycleScope.launchCatching {
item.key?.let { mysteryItem -> inventoryRepository.equip("equipped", mysteryItem) }
}
dialog.addCloseButton()
dialog.enqueue()
}
dialog.addCloseButton()
dialog.enqueue()
}
}
adapter?.onStartHatching = { showHatchingDialog(it) }
adapter?.onHatchPet = { pet, egg -> hatchPet(pet, egg) }
adapter?.onCreateNewParty = { createNewParty() }
adapter?.itemType = itemType ?: ""
adapter?.itemText = (if (itemType == "hatchingPotions") context?.getString(R.string.potions) else itemTypeText) ?: ""
adapter?.onOpenShop = {
Analytics.sendEvent("Items CTA tap", EventCategory.BEHAVIOUR, HitType.EVENT, mapOf(
"area" to "bottom",
"type" to (itemType ?: "")
))
if (itemType == "quests") {
MainNavigationController.navigate(R.id.questShopFragment)
} else {
openMarket()
}
}
adapter?.onStartHatching = { showHatchingDialog(it) }
adapter?.onHatchPet = { pet, egg -> hatchPet(pet, egg) }
adapter?.onCreateNewParty = { createNewParty() }
adapter?.itemType = itemType ?: ""
adapter?.itemText = (if (itemType == "hatchingPotions") context?.getString(R.string.potions) else itemTypeText) ?: ""
adapter?.onOpenShop = {
Analytics.sendEvent("Items CTA tap", EventCategory.BEHAVIOUR, HitType.EVENT, mapOf(
"area" to "bottom",
"type" to (itemType ?: "")
))
if (itemType == "quests") {
MainNavigationController.navigate(R.id.questShopFragment)
} else {
openMarket()
}
}
}

View file

@ -2,12 +2,24 @@ package com.habitrpg.common.habitica.extensions
import android.text.SpannableStringBuilder
import android.text.Spanned
import android.text.TextPaint
import android.text.method.LinkMovementMethod
import android.text.style.ClickableSpan
import android.text.style.URLSpan
import android.view.View
import android.widget.TextView
class HabiticaClickableSpan(val onClick: () -> Unit): ClickableSpan() {
override fun onClick(widget: View) {
onClick(widget)
}
override fun updateDrawState(ds: TextPaint) {
super.updateDrawState(ds)
ds.isUnderlineText = false
}
}
fun TextView.handleUrlClicks(onClicked: ((String) -> Unit)? = null) {
// create span builder and replaces current text with it
text = SpannableStringBuilder.valueOf(text).apply {
@ -15,10 +27,8 @@ fun TextView.handleUrlClicks(onClicked: ((String) -> Unit)? = null) {
getSpans(0, length, URLSpan::class.java).forEach {
// add new clickable span at the same position
setSpan(
object : ClickableSpan() {
override fun onClick(widget: View) {
onClicked?.invoke(it.url)
}
HabiticaClickableSpan {
onClicked?.invoke(it.url)
},
getSpanStart(it),
getSpanEnd(it),

View file

@ -29,9 +29,10 @@
<TextView
android:id="@+id/emptyViewDescription"
android:layout_width="wrap_content"
android:maxWidth="300dp"
android:layout_height="wrap_content"
android:gravity="center"
android:textSize="16sp"
android:textSize="14sp"
android:textColor="@color/text_ternary"
tools:text="No Items" />
</LinearLayout>