Fix opening mystery item

This commit is contained in:
Phillip Thelen 2020-11-10 17:15:19 +01:00
parent e710e6782b
commit 3c1907f58d
3 changed files with 7 additions and 8 deletions

View file

@ -242,12 +242,13 @@ class RealmInventoryLocalRepository(realm: Realm) : RealmContentLocalRepository(
return
}
val item = realm.where(OwnedItem::class.java).equalTo("combinedKey", "${user.id}specialinventory_present").findFirst()
val liveUser = getLiveObject(user)
executeTransaction {
if (item != null && item.isValid) {
item.numberOwned = item.numberOwned - 1
}
if (user.isValid) {
user.purchased?.plan?.mysteryItemCount = (user.purchased?.plan?.mysteryItemCount ?: 0) - 1
if (liveUser?.isValid == true) {
liveUser.purchased?.plan?.mysteryItemCount = (user.purchased?.plan?.mysteryItemCount ?: 0) - 1
}
}
}

View file

@ -27,7 +27,7 @@ import org.greenrobot.eventbus.EventBus
import java.text.SimpleDateFormat
import java.util.*
class ItemRecyclerAdapter(data: OrderedRealmCollection<OwnedItem>?, autoUpdate: Boolean, val context: Context) : BaseRecyclerViewAdapter<OwnedItem, ItemRecyclerAdapter.ItemViewHolder>() {
class ItemRecyclerAdapter(val context: Context) : BaseRecyclerViewAdapter<OwnedItem, ItemRecyclerAdapter.ItemViewHolder>() {
var isHatching: Boolean = false
var isFeeding: Boolean = false
@ -67,10 +67,8 @@ class ItemRecyclerAdapter(data: OrderedRealmCollection<OwnedItem>?, autoUpdate:
}
override fun onBindViewHolder(holder: ItemViewHolder, position: Int) {
data?.let {
val ownedItem = it[position]
holder.bind(ownedItem, items?.get(ownedItem.key))
}
val ownedItem = data[position]
holder.bind(ownedItem, items?.get(ownedItem.key))
}
fun setExistingPets(pets: RealmResults<Pet>) {

View file

@ -73,7 +73,7 @@ class ItemRecyclerFragment : BaseFragment<FragmentItemsBinding>(), SwipeRefreshL
adapter = binding?.recyclerView?.adapter as? ItemRecyclerAdapter
if (adapter == null) {
context?.let {
adapter = ItemRecyclerAdapter(null, true, context)
adapter = ItemRecyclerAdapter(context)
adapter?.isHatching = this.isHatching
adapter?.isFeeding = this.isFeeding
adapter?.fragment = this