Enable pinning of background shop items

# Conflicts:
#	Habitica/src/main/java/com/habitrpg/android/habitica/models/shops/ShopItem.kt
This commit is contained in:
Hafiz 2022-06-15 12:22:54 -04:00 committed by Phillip Thelen
parent ec20a0fc52
commit dce7cbc450
5 changed files with 28 additions and 3 deletions

View file

@ -22,8 +22,8 @@
android:paddingEnd="8dp">
<ImageView
android:id="@+id/pin_icon"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_width="@dimen/shopitem_status_size"
android:layout_height="@dimen/shopitem_status_size"
android:layout_marginEnd="6dp"/>
<TextView
android:id="@+id/pin_text"

View file

@ -176,7 +176,7 @@ class UserRepositoryImpl(
}
override fun unlockPath(customization: Customization): Flowable<UnlockResponse> {
return unlockPath(customization.path, customization.price ?: 0)
return unlockPath(customization.unlockPath, customization.price ?: 0)
}
override fun runCron() {

View file

@ -78,6 +78,18 @@ open class Customization : RealmObject(), BaseObject {
}
val path: String
get() {
var path = if (type == "background") "backgrounds" else type
if (this.customizationSet != null) {
path = path + "." + this.customizationSet
} else if (this.category != null) {
path = path + "." + this.category
}
path = "$path.$identifier"
return path
}
val unlockPath: String
get() {
var path = type
if (this.category != null) {

View file

@ -41,6 +41,7 @@ class CustomizationRecyclerViewAdapter() : androidx.recyclerview.widget.Recycler
}
var ownedCustomizations: List<String> = listOf()
private var pinnedItemKeys: List<String> = ArrayList()
private val selectCustomizationEvents = PublishSubject.create<Customization>()
@ -143,6 +144,11 @@ class CustomizationRecyclerViewAdapter() : androidx.recyclerview.widget.Recycler
return selectCustomizationEvents.toFlowable(BackpressureStrategy.DROP)
}
fun setPinnedItemKeys(pinnedItemKeys: List<String>) {
this.pinnedItemKeys = pinnedItemKeys
if (customizationList.size > 0) this.notifyDataSetChanged()
}
internal inner class CustomizationViewHolder(itemView: View) : androidx.recyclerview.widget.RecyclerView.ViewHolder(itemView), View.OnClickListener {
private val binding = CustomizationGridItemBinding.bind(itemView)
@ -194,6 +200,7 @@ class CustomizationRecyclerViewAdapter() : androidx.recyclerview.widget.Recycler
} else {
customization?.let {
val dialog = PurchaseDialog(itemView.context, HabiticaBaseApplication.userComponent, ShopItem.fromCustomization(it, userSize, hairColor))
if (it.type == "background") dialog.isPinned = pinnedItemKeys.contains(ShopItem.fromCustomization(it, userSize, hairColor).key)
dialog.show()
}
}

View file

@ -87,6 +87,12 @@ class AvatarCustomizationFragment :
.subscribe({ }, RxErrorHandler.handleEmptyError())
)
compositeSubscription.add(
this.inventoryRepository.getInAppRewards()
.map { rewards -> rewards.map { it.key } }
.subscribe({ adapter.setPinnedItemKeys(it) }, RxErrorHandler.handleEmptyError())
)
return super.onCreateView(inflater, container, savedInstanceState)
}