mirror of
https://github.com/sudoxnym/habitica-android.git
synced 2026-05-19 20:29:02 +00:00
show confirmation when selling items
This commit is contained in:
parent
75bad46e09
commit
89ab3fc360
5 changed files with 41 additions and 10 deletions
|
|
@ -268,6 +268,7 @@
|
|||
<string name="armoireFood_new">You rummage in the Armoire and find food. What\'s that doing in here?</string>
|
||||
<string name="armoireExp">You wrestle with the Armoire and gain Experience. Take that!</string>
|
||||
<string name="sell">Sell (%d Gold)</string>
|
||||
<string name="sell_confirmation_title">Are you sure you want to sell this %s?</string>
|
||||
<string name="sell_no_price">Sell</string>
|
||||
<string name="hatch_with_potion">Hatch with potion</string>
|
||||
<string name="hatch_egg">Hatch with egg</string>
|
||||
|
|
|
|||
|
|
@ -497,7 +497,12 @@ class RealmInventoryLocalRepository(realm: Realm) :
|
|||
}
|
||||
val stats = updatedUser.stats
|
||||
if (stats != null) {
|
||||
user.stats = stats
|
||||
user.stats?.apply {
|
||||
hp = stats.hp
|
||||
mp = stats.mp
|
||||
exp = stats.exp
|
||||
gp = stats.gp
|
||||
}
|
||||
}
|
||||
}
|
||||
return user
|
||||
|
|
|
|||
|
|
@ -50,7 +50,7 @@ class ItemRecyclerAdapter(val context: Context) :
|
|||
notifyDataSetChanged()
|
||||
}
|
||||
|
||||
var onSellItem: ((OwnedItem) -> Unit)? = null
|
||||
var onSellItem: ((Item, OwnedItem) -> Unit)? = null
|
||||
var onQuestInvitation: ((QuestContent) -> Unit)? = null
|
||||
var onOpenMysteryItem: ((Item) -> Unit)? = null
|
||||
var onStartHatching: ((Item) -> Unit)? = null
|
||||
|
|
@ -276,6 +276,7 @@ class ItemRecyclerAdapter(val context: Context) :
|
|||
if (!(selectedItem is QuestContent || selectedItem is SpecialItem || ownedItem?.itemType == "special") && index == 0) {
|
||||
ownedItem?.let { selectedOwnedItem ->
|
||||
onSellItem?.invoke(
|
||||
selectedItem,
|
||||
selectedOwnedItem,
|
||||
)
|
||||
}
|
||||
|
|
|
|||
|
|
@ -11,6 +11,7 @@ import com.habitrpg.android.habitica.data.InventoryRepository
|
|||
import com.habitrpg.android.habitica.data.SocialRepository
|
||||
import com.habitrpg.android.habitica.data.UserRepository
|
||||
import com.habitrpg.android.habitica.databinding.FragmentItemsDialogBinding
|
||||
import com.habitrpg.android.habitica.extensions.addCancelButton
|
||||
import com.habitrpg.android.habitica.extensions.addCloseButton
|
||||
import com.habitrpg.android.habitica.helpers.Analytics
|
||||
import com.habitrpg.android.habitica.helpers.EventCategory
|
||||
|
|
@ -24,6 +25,7 @@ import com.habitrpg.android.habitica.models.inventory.Item
|
|||
import com.habitrpg.android.habitica.models.inventory.Pet
|
||||
import com.habitrpg.android.habitica.models.inventory.QuestContent
|
||||
import com.habitrpg.android.habitica.models.inventory.SpecialItem
|
||||
import com.habitrpg.android.habitica.models.user.OwnedItem
|
||||
import com.habitrpg.android.habitica.models.user.OwnedPet
|
||||
import com.habitrpg.android.habitica.models.user.User
|
||||
import com.habitrpg.android.habitica.ui.activities.MainActivity
|
||||
|
|
@ -31,6 +33,7 @@ import com.habitrpg.android.habitica.ui.adapter.inventory.ItemRecyclerAdapter
|
|||
import com.habitrpg.android.habitica.ui.fragments.BaseDialogFragment
|
||||
import com.habitrpg.android.habitica.ui.helpers.SafeDefaultItemAnimator
|
||||
import com.habitrpg.android.habitica.ui.viewmodels.MainUserViewModel
|
||||
import com.habitrpg.android.habitica.ui.views.dialogs.HabiticaAlertDialog
|
||||
import com.habitrpg.android.habitica.ui.views.dialogs.OpenedMysteryitemDialog
|
||||
import com.habitrpg.common.habitica.extensions.loadImage
|
||||
import com.habitrpg.common.habitica.extensions.observeOnce
|
||||
|
|
@ -214,10 +217,8 @@ class ItemDialogFragment : BaseDialogFragment<FragmentItemsDialogBinding>() {
|
|||
adapter?.feedingPet = this.feedingPet
|
||||
}
|
||||
binding?.recyclerView?.adapter = adapter
|
||||
adapter?.onSellItem = {
|
||||
lifecycleScope.launchCatching {
|
||||
inventoryRepository.sellItem(it)
|
||||
}
|
||||
adapter?.onSellItem = { item, ownedItem ->
|
||||
showSellItemConfirmation(item, ownedItem)
|
||||
}
|
||||
adapter?.onQuestInvitation = {
|
||||
lifecycleScope.launchCatching {
|
||||
|
|
@ -368,6 +369,18 @@ class ItemDialogFragment : BaseDialogFragment<FragmentItemsDialogBinding>() {
|
|||
MainNavigationController.navigate(R.id.marketFragment)
|
||||
}
|
||||
|
||||
private fun showSellItemConfirmation(item: Item, ownedItem: OwnedItem) {
|
||||
val dialog = HabiticaAlertDialog(requireContext())
|
||||
dialog.setTitle(getString(R.string.sell_confirmation_title, item.text))
|
||||
dialog.addButton(getString(R.string.sell, item.value), isPrimary = true, isDestructive = true) { _, _ ->
|
||||
lifecycleScope.launchCatching {
|
||||
inventoryRepository.sellItem(ownedItem)
|
||||
}
|
||||
}
|
||||
dialog.addCancelButton()
|
||||
dialog.show()
|
||||
}
|
||||
|
||||
companion object {
|
||||
private const val ITEM_TYPE_KEY = "CLASS_TYPE_KEY"
|
||||
}
|
||||
|
|
|
|||
|
|
@ -15,6 +15,7 @@ import com.habitrpg.android.habitica.data.InventoryRepository
|
|||
import com.habitrpg.android.habitica.data.SocialRepository
|
||||
import com.habitrpg.android.habitica.data.UserRepository
|
||||
import com.habitrpg.android.habitica.databinding.FragmentItemsBinding
|
||||
import com.habitrpg.android.habitica.extensions.addCancelButton
|
||||
import com.habitrpg.android.habitica.extensions.addCloseButton
|
||||
import com.habitrpg.android.habitica.helpers.Analytics
|
||||
import com.habitrpg.android.habitica.helpers.EventCategory
|
||||
|
|
@ -171,10 +172,8 @@ class ItemRecyclerFragment :
|
|||
binding?.recyclerView?.adapter = adapter
|
||||
}
|
||||
adapter?.onUseSpecialItem = { onSpecialItemSelected(it) }
|
||||
adapter?.onSellItem = {
|
||||
lifecycleScope.launchCatching {
|
||||
inventoryRepository.sellItem(it)
|
||||
}
|
||||
adapter?.onSellItem = { item, ownedItem ->
|
||||
showSellItemConfirmation(item, ownedItem)
|
||||
}
|
||||
adapter?.onQuestInvitation = {
|
||||
lifecycleScope.launchCatching {
|
||||
|
|
@ -395,6 +394,18 @@ class ItemRecyclerFragment :
|
|||
loadItems()
|
||||
}
|
||||
|
||||
private fun showSellItemConfirmation(item: Item, ownedItem: OwnedItem) {
|
||||
val dialog = HabiticaAlertDialog(requireContext())
|
||||
dialog.setTitle(getString(R.string.sell_confirmation_title, item.text))
|
||||
dialog.addButton(getString(R.string.sell, item.value), isPrimary = true, isDestructive = true) { _, _ ->
|
||||
lifecycleScope.launchCatching {
|
||||
inventoryRepository.sellItem(ownedItem)
|
||||
}
|
||||
}
|
||||
dialog.addCancelButton()
|
||||
dialog.show()
|
||||
}
|
||||
|
||||
companion object {
|
||||
private const val ITEM_TYPE_KEY = "CLASS_TYPE_KEY"
|
||||
private const val ITEM_TYPE_TEXT_KEY = "CLASS_TYPE_TEXT_KEY"
|
||||
|
|
|
|||
Loading…
Reference in a new issue