Squashed commit of the following:

commit b2c0612855b8129ccd5236f8b045f20f4490e02e
Author: Phillip Thelen <viirus@pherth.net>
Date:   Mon Apr 15 13:26:51 2019 +0200

    Fix issues with items and pets

commit 15ae2ee15057522f1407147a389c94ab87591892
Author: Phillip Thelen <viirus@pherth.net>
Date:   Wed Apr 10 12:52:52 2019 +0200

    fix typo

commit 225d096155f5989740454d64025e99418893e0f3
Author: Phillip Thelen <viirus@pherth.net>
Date:   Wed Apr 10 02:20:33 2019 +0200

    fix wacky pets deserialization
This commit is contained in:
Phillip Thelen 2019-04-15 13:29:48 +02:00
parent 22e1e7448e
commit 396ddffc55
13 changed files with 85 additions and 91 deletions

View file

@ -1,7 +1,7 @@
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical" android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_height="wrap_content"
style="@style/BottomMenu"
android:clickable="false">
</LinearLayout>

View file

@ -1,12 +1,16 @@
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical" android:layout_width="match_parent"
xmlns:tools="http://schemas.android.com/tools"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="wrap_content"
style="@style/BottomMenuItem"
android:clickable="true">
android:clickable="true"
android:focusable="true">
<TextView
android:id="@+id/textView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
style="@style/BottomMenuItemText" />
style="@style/BottomMenuItemText"
tools:text="Menu Item"/>
</LinearLayout>

View file

@ -72,7 +72,7 @@
<dimen name="drawer_section_item_text">12sp</dimen>
<dimen name="material_drawer_section_vertical_padding">4dp</dimen>
<dimen name="pet_width">120dp</dimen>
<dimen name="bottom_menu_padding">18dp</dimen>
<dimen name="bottom_menu_padding">28dp</dimen>
<dimen name="pet_image_width">81dp</dimen>
<dimen name="pet_image_height">99dp</dimen>
<dimen name="shop_height">124dp</dimen>

View file

@ -341,12 +341,12 @@
<string name="sectionpremiumPets">Magic Potion</string>
<string name="sectionquestPets">Quest</string>
<string name="sectionspecialPets">Rare</string>
<string name="sectionwhackyPets">Whacky</string>
<string name="sectionwackyPets">Wacky</string>
<string name="sectionmounts">Standard</string>
<string name="sectionpremiumMounts">Magic Potion</string>
<string name="sectionquestMounts">Quest</string>
<string name="sectionspecialMounts">Rare</string>
<string name="sectionwhackyMounts">Whacky</string>
<string name="sectionwackyMounts">Wacky</string>
<string name="world_quest">World Quest</string>
<string name="inn_description">Need a break? Check into Daniels Inn to pause some of Habiticas more difficult game mechanics:\n\n
&#8226; Missed Dailies wont damage you\n

View file

@ -161,6 +161,7 @@
<style name="BottomMenu">
<item name="android:divider">?android:listDivider</item>
<item name="android:showDividers">middle</item>
<item name="android:paddingBottom">@dimen/spacing_medium</item>
</style>
<style name="BottomMenuItem">

View file

@ -35,7 +35,7 @@ class ItemRecyclerAdapter(data: OrderedRealmCollection<OwnedItem>?, autoUpdate:
var hatchingItem: Item? = null
var feedingPet: Pet? = null
var fragment: ItemRecyclerFragment? = null
private var ownedPets: RealmResults<Pet>? = null
private var existingPets: RealmResults<Pet>? = null
var context: Context? = null
var items: Map<String, Item>? = null
set(value) {
@ -65,8 +65,8 @@ class ItemRecyclerAdapter(data: OrderedRealmCollection<OwnedItem>?, autoUpdate:
}
}
fun setOwnedPets(pets: RealmResults<Pet>) {
ownedPets = pets
fun setExistingPets(pets: RealmResults<Pet>) {
existingPets = pets
}
@ -80,14 +80,15 @@ class ItemRecyclerAdapter(data: OrderedRealmCollection<OwnedItem>?, autoUpdate:
var resources: Resources = itemView.resources
private val isPetOwned: Boolean?
private val canHatch: Boolean
get() {
val petKey: String = if (item is Egg) {
item?.key + "-" + hatchingItem?.key
} else {
hatchingItem?.key + "-" + item?.key
}
return ownedPets != null && ownedPets?.where()?.equalTo("key", petKey)?.count() ?: 0 > 0
val pet = existingPets?.where()?.equalTo("key", petKey)?.findFirst()
return pet != null && pet.trained <= 0
}
init {
@ -116,7 +117,7 @@ class ItemRecyclerAdapter(data: OrderedRealmCollection<OwnedItem>?, autoUpdate:
imageName = "Pet_" + type + "_" + item?.key
if (isHatching) {
disabled = this.isPetOwned ?: false
disabled = !this.canHatch
}
}
DataBindingUtils.loadImage(imageView, imageName ?: "head_0")
@ -131,6 +132,7 @@ class ItemRecyclerAdapter(data: OrderedRealmCollection<OwnedItem>?, autoUpdate:
}
override fun onClick(v: View) {
val context = context ?: return
if (!isHatching && !isFeeding) {
val menu = BottomSheetMenu(context)
if (item !is QuestContent && item !is SpecialItem) {
@ -177,7 +179,7 @@ class ItemRecyclerAdapter(data: OrderedRealmCollection<OwnedItem>?, autoUpdate:
}
menu.show()
} else if (isHatching) {
if (this.isPetOwned == true) {
if (!this.canHatch) {
return
}
if (item is Egg) {

View file

@ -1,7 +1,6 @@
package com.habitrpg.android.habitica.ui.adapter.inventory
import android.content.Context
import androidx.recyclerview.widget.RecyclerView
import android.view.View
import android.view.ViewGroup
import android.widget.ProgressBar
@ -29,7 +28,7 @@ class PetDetailRecyclerAdapter(data: OrderedRealmCollection<Pet>?, autoUpdate: B
var itemType: String? = null
var context: Context? = null
private var ownedMounts: RealmResults<Mount>? = null
private var existingMounts: RealmResults<Mount>? = null
private val equipEvents = PublishSubject.create<String>()
fun getEquipFlowable(): Flowable<String> {
@ -46,8 +45,8 @@ class PetDetailRecyclerAdapter(data: OrderedRealmCollection<Pet>?, autoUpdate: B
}
}
fun setOwnedMounts(ownedMounts: RealmResults<Mount>) {
this.ownedMounts = ownedMounts
fun setExistingMounts(existingMounts: RealmResults<Mount>) {
this.existingMounts = existingMounts
notifyDataSetChanged()
}
@ -61,11 +60,11 @@ class PetDetailRecyclerAdapter(data: OrderedRealmCollection<Pet>?, autoUpdate: B
private val isOwned: Boolean
get() = this.animal?.trained ?: 0 > 0
private val isMountOwned: Boolean
private val canRaiseToMount: Boolean
get() {
for (ownedMount in ownedMounts ?: emptyList<Mount>()) {
if (ownedMount.key == animal?.key) {
return true
for (mount in existingMounts ?: emptyList<Mount>()) {
if (mount.key == animal?.key) {
return !mount.owned
}
}
return false
@ -81,10 +80,10 @@ class PetDetailRecyclerAdapter(data: OrderedRealmCollection<Pet>?, autoUpdate: B
this.trainedProgressbar.visibility = if (animal?.animalGroup == "specialPets") View.GONE else View.VISIBLE
this.imageView.alpha = 1.0f
if (this.animal?.trained ?: 0 > 0) {
if (this.isMountOwned) {
this.trainedProgressbar.visibility = View.GONE
} else {
if (this.canRaiseToMount) {
this.trainedProgressbar.progress = animal?.trained ?: 0
} else {
this.trainedProgressbar.visibility = View.GONE
}
DataBindingUtils.loadImage(this.imageView, "Pet-" + itemType + "-" + item.color)
} else {
@ -102,9 +101,10 @@ class PetDetailRecyclerAdapter(data: OrderedRealmCollection<Pet>?, autoUpdate: B
if (!this.isOwned) {
return
}
val context = context ?: return
val menu = BottomSheetMenu(context)
menu.addMenuItem(BottomSheetMenuItem(itemView.resources.getString(R.string.use_animal)))
if (animal?.animalGroup != "specialPets" && !this.isMountOwned) {
if (animal?.animalGroup != "specialPets" && canRaiseToMount) {
menu.addMenuItem(BottomSheetMenuItem(itemView.resources.getString(R.string.feed)))
}
menu.setSelectionRunnable { index ->

View file

@ -192,7 +192,7 @@ class ItemRecyclerFragment : BaseFragment() {
}, RxErrorHandler.handleEmptyError()))
}
compositeSubscription.add(inventoryRepository.getOwnedPets().subscribe(Consumer { adapter?.setOwnedPets(it) }, RxErrorHandler.handleEmptyError()))
compositeSubscription.add(inventoryRepository.getPets().subscribe(Consumer { adapter?.setExistingPets(it) }, RxErrorHandler.handleEmptyError()))
}
private fun openMarket() {

View file

@ -106,7 +106,7 @@ class PetDetailRecyclerFragment : BaseMainFragment() {
private fun loadItems() {
if (animalType.isNotEmpty() && animalGroup.isNotEmpty()) {
compositeSubscription.add(inventoryRepository.getPets(animalType, animalGroup).firstElement().subscribe(Consumer<RealmResults<Pet>> { adapter.updateData(it) }, RxErrorHandler.handleEmptyError()))
compositeSubscription.add(inventoryRepository.getOwnedMounts(animalType, animalGroup).subscribe(Consumer<RealmResults<Mount>> { adapter.setOwnedMounts(it) }, RxErrorHandler.handleEmptyError()))
compositeSubscription.add(inventoryRepository.getMounts(animalType, animalGroup).subscribe(Consumer<RealmResults<Mount>> { adapter.setExistingMounts(it) }, RxErrorHandler.handleEmptyError()))
}
}

View file

@ -164,6 +164,10 @@ class StableRecyclerFragment : BaseFragment() {
}
}
}
if (!((lastAnimal.animalGroup == "premiumPets" || lastAnimal.animalGroup == "specialPets"
|| lastAnimal.animalGroup == "specialMounts" || lastAnimal.animalGroup == "premiumMounts") && lastAnimal.numberOwned == 0)) {
items.add(lastAnimal)
}
Single.just<List<Any>>(items)
}.subscribe(Consumer { items -> adapter?.setItemList(items) }, RxErrorHandler.handleEmptyError()))
}

View file

@ -1,56 +0,0 @@
package com.habitrpg.android.habitica.ui.menu;
import android.content.Context;
import com.google.android.material.bottomsheet.BottomSheetDialog;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.LinearLayout;
import com.habitrpg.android.habitica.R;
public class BottomSheetMenu extends BottomSheetDialog implements View.OnClickListener {
private LayoutInflater inflater;
private Context context;
private LinearLayout contentView;
private BottomSheetMenuSelectionRunnable runnable;
public BottomSheetMenu(Context context) {
super(context);
this.context = context;
this.inflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
this.contentView = (LinearLayout) inflater.inflate(R.layout.menu_bottom_sheet, null);
this.setContentView(this.contentView);
}
public void setSelectionRunnable(BottomSheetMenuSelectionRunnable runnable) {
this.runnable = runnable;
}
public void addMenuItems(BottomSheetMenuItem... menuItems) {
for (BottomSheetMenuItem menuItem : menuItems) {
this.addMenuItem(menuItem);
}
}
public void addMenuItem(BottomSheetMenuItem menuItem) {
View item = menuItem.inflate(this.context, this.inflater, this.contentView);
item.setOnClickListener(this);
this.contentView.addView(item);
}
public void removeMenuItem(Integer index) {
this.contentView.removeViewAt(index);
}
@Override
public void onClick(View v) {
if (this.runnable != null) {
Integer index = this.contentView.indexOfChild(v);
if (index != -1) {
this.runnable.selectedItemAt(index);
this.dismiss();
}
}
}
}

View file

@ -0,0 +1,46 @@
package com.habitrpg.android.habitica.ui.menu
import android.content.Context
import android.view.View
import android.widget.LinearLayout
import com.google.android.material.bottomsheet.BottomSheetDialog
import com.habitrpg.android.habitica.R
class BottomSheetMenu(context: Context) : BottomSheetDialog(context), View.OnClickListener {
private var contentView = layoutInflater.inflate(R.layout.menu_bottom_sheet, null) as LinearLayout
private var runnable: ((Int) -> Unit)? = null
init {
setContentView(contentView)
}
fun setSelectionRunnable(runnable: (Int) -> Unit) {
this.runnable = runnable
}
fun addMenuItems(vararg menuItems: BottomSheetMenuItem) {
for (menuItem in menuItems) {
this.addMenuItem(menuItem)
}
}
fun addMenuItem(menuItem: BottomSheetMenuItem) {
val item = menuItem.inflate(this.context, layoutInflater, this.contentView)
item.setOnClickListener(this)
this.contentView.addView(item)
}
fun removeMenuItem(index: Int) {
this.contentView.removeViewAt(index)
}
override fun onClick(v: View) {
if (this.runnable != null) {
val index = this.contentView.indexOfChild(v)
if (index != -1) {
runnable?.let { it(index) }
this.dismiss()
}
}
}
}

View file

@ -1,7 +0,0 @@
package com.habitrpg.android.habitica.ui.menu;
public interface BottomSheetMenuSelectionRunnable {
void selectedItemAt(Integer index);
}