mirror of
https://github.com/sudoxnym/habitica-android.git
synced 2026-07-31 19:20:34 +00:00
Fix Stable display
This commit is contained in:
parent
2746d2e9c2
commit
6d5f8658e5
21 changed files with 173 additions and 197 deletions
|
|
@ -50,4 +50,6 @@ public interface InventoryRepository extends ContentRepository {
|
|||
Observable<User> sellItem(User user, Item item);
|
||||
|
||||
Observable<Items> equipGear(User user, String equipment, boolean asCostume);
|
||||
|
||||
Observable<RealmResults<Mount>> getOwnedMounts(String animalType, String animalGroup);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -147,4 +147,9 @@ public class InventoryRepositoryImpl extends ContentRepositoryImpl<InventoryLoca
|
|||
});
|
||||
});
|
||||
}
|
||||
|
||||
@Override
|
||||
public Observable<RealmResults<Mount>> getOwnedMounts(String animalType, String animalGroup) {
|
||||
return localRepository.getOwnedMounts(animalType, animalGroup);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -39,4 +39,6 @@ public interface InventoryLocalRepository extends ContentLocalRepository {
|
|||
void changeOwnedCount(String type, String key, int amountToAdd);
|
||||
|
||||
Observable<Item> getItem(String type, String key);
|
||||
|
||||
Observable<RealmResults<Mount>> getOwnedMounts(String animalType, String animalGroup);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -16,6 +16,7 @@ import java.util.List;
|
|||
import io.realm.Realm;
|
||||
import io.realm.RealmObject;
|
||||
import io.realm.RealmResults;
|
||||
import io.realm.Sort;
|
||||
import rx.Observable;
|
||||
|
||||
|
||||
|
|
@ -104,7 +105,8 @@ public class RealmInventoryLocalRepository extends RealmContentLocalRepository i
|
|||
|
||||
@Override
|
||||
public Observable<RealmResults<Mount>> getMounts() {
|
||||
return realm.where(Mount.class).findAll()
|
||||
return realm.where(Mount.class)
|
||||
.findAllSorted("animalGroup", Sort.ASCENDING, "animal", Sort.ASCENDING)
|
||||
.asObservable()
|
||||
.filter(RealmResults::isLoaded);
|
||||
}
|
||||
|
|
@ -112,8 +114,8 @@ public class RealmInventoryLocalRepository extends RealmContentLocalRepository i
|
|||
@Override
|
||||
public Observable<RealmResults<Mount>> getMounts(String type, String group) {
|
||||
return realm.where(Mount.class)
|
||||
.equalTo("group", group)
|
||||
.equalTo("type", type)
|
||||
.equalTo("animalGroup", group)
|
||||
.equalTo("animal", type)
|
||||
.findAll()
|
||||
.asObservable()
|
||||
.filter(RealmResults::isLoaded);
|
||||
|
|
@ -121,7 +123,8 @@ public class RealmInventoryLocalRepository extends RealmContentLocalRepository i
|
|||
|
||||
@Override
|
||||
public Observable<RealmResults<Pet>> getPets() {
|
||||
return realm.where(Pet.class).findAll()
|
||||
return realm.where(Pet.class)
|
||||
.findAllSorted("animalGroup", Sort.ASCENDING, "animal", Sort.ASCENDING)
|
||||
.asObservable()
|
||||
.filter(RealmResults::isLoaded);
|
||||
}
|
||||
|
|
@ -129,8 +132,8 @@ public class RealmInventoryLocalRepository extends RealmContentLocalRepository i
|
|||
@Override
|
||||
public Observable<RealmResults<Pet>> getPets(String type, String group) {
|
||||
return realm.where(Pet.class)
|
||||
.equalTo("group", group)
|
||||
.equalTo("type", type)
|
||||
.equalTo("animalGroup", group)
|
||||
.equalTo("animal", type)
|
||||
.findAll()
|
||||
.asObservable()
|
||||
.filter(RealmResults::isLoaded);
|
||||
|
|
@ -165,4 +168,15 @@ public class RealmInventoryLocalRepository extends RealmContentLocalRepository i
|
|||
.filter(realmObject -> realmObject.isLoaded())
|
||||
.cast(Item.class);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Observable<RealmResults<Mount>> getOwnedMounts(String animalType, String animalGroup) {
|
||||
return realm.where(Mount.class)
|
||||
.equalTo("animalGroup", animalGroup)
|
||||
.equalTo("animal", animalType)
|
||||
.equalTo("owned", true)
|
||||
.findAll()
|
||||
.asObservable()
|
||||
.filter(RealmResults::isLoaded);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -11,5 +11,4 @@ public class Skill extends RealmObject {
|
|||
public String key;
|
||||
public String text, notes, target, habitClass;
|
||||
public Integer mana, lvl;
|
||||
public boolean isSpecialItem;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -30,13 +30,13 @@ public interface Animal {
|
|||
|
||||
public void setColorText(String colorText);
|
||||
|
||||
public Boolean getPremium();
|
||||
public boolean getPremium();
|
||||
|
||||
public void setPremium(Boolean premium);
|
||||
public void setPremium(boolean premium);
|
||||
|
||||
public Boolean getLimited();
|
||||
public boolean getLimited();
|
||||
|
||||
public void setLimited(Boolean limited);
|
||||
public void setLimited(boolean limited);
|
||||
|
||||
public Integer getNumberOwned();
|
||||
|
||||
|
|
|
|||
|
|
@ -1,15 +1,18 @@
|
|||
package com.habitrpg.android.habitica.models.inventory;
|
||||
|
||||
import io.realm.RealmObject;
|
||||
import io.realm.annotations.Ignore;
|
||||
import io.realm.annotations.PrimaryKey;
|
||||
|
||||
public class Mount extends RealmObject implements Animal {
|
||||
|
||||
Boolean owned;
|
||||
boolean owned;
|
||||
@PrimaryKey
|
||||
String key;
|
||||
String animal, color, animalGroup, animalText, colorText;
|
||||
Boolean premium, limited;
|
||||
boolean premium, limited;
|
||||
|
||||
@Ignore
|
||||
Integer numberOwned;
|
||||
|
||||
public String getKey() {
|
||||
|
|
@ -21,6 +24,9 @@ public class Mount extends RealmObject implements Animal {
|
|||
}
|
||||
|
||||
public String getAnimal() {
|
||||
if (animal == null) {
|
||||
return key.split("-")[0];
|
||||
}
|
||||
return animal;
|
||||
}
|
||||
|
||||
|
|
@ -29,6 +35,9 @@ public class Mount extends RealmObject implements Animal {
|
|||
}
|
||||
|
||||
public String getColor() {
|
||||
if (color == null) {
|
||||
return key.split("-")[1];
|
||||
}
|
||||
return color;
|
||||
}
|
||||
|
||||
|
|
@ -37,6 +46,9 @@ public class Mount extends RealmObject implements Animal {
|
|||
}
|
||||
|
||||
public String getAnimalGroup() {
|
||||
if (animalGroup == null) {
|
||||
return "";
|
||||
}
|
||||
return animalGroup;
|
||||
}
|
||||
|
||||
|
|
@ -66,19 +78,19 @@ public class Mount extends RealmObject implements Animal {
|
|||
this.colorText = colorText;
|
||||
}
|
||||
|
||||
public Boolean getPremium() {
|
||||
public boolean getPremium() {
|
||||
return premium;
|
||||
}
|
||||
|
||||
public void setPremium(Boolean premium) {
|
||||
public void setPremium(boolean premium) {
|
||||
this.premium = premium;
|
||||
}
|
||||
|
||||
public Boolean getLimited() {
|
||||
public boolean getLimited() {
|
||||
return limited;
|
||||
}
|
||||
|
||||
public void setLimited(Boolean limited) {
|
||||
public void setLimited(boolean limited) {
|
||||
this.limited = limited;
|
||||
}
|
||||
|
||||
|
|
@ -93,11 +105,11 @@ public class Mount extends RealmObject implements Animal {
|
|||
this.numberOwned = numberOwned;
|
||||
}
|
||||
|
||||
public Boolean getOwned() {
|
||||
public boolean getOwned() {
|
||||
return owned;
|
||||
}
|
||||
|
||||
public void setOwned(Boolean owned) {
|
||||
public void setOwned(boolean owned) {
|
||||
this.owned = owned;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -2,6 +2,7 @@ package com.habitrpg.android.habitica.models.inventory;
|
|||
|
||||
|
||||
import io.realm.RealmObject;
|
||||
import io.realm.annotations.Ignore;
|
||||
import io.realm.annotations.PrimaryKey;
|
||||
|
||||
public class Pet extends RealmObject implements Animal{
|
||||
|
|
@ -10,9 +11,10 @@ public class Pet extends RealmObject implements Animal{
|
|||
@PrimaryKey
|
||||
String key;
|
||||
String animal, color, animalGroup, animalText, colorText;
|
||||
Boolean premium, limited;
|
||||
boolean premium, limited;
|
||||
|
||||
Integer numberOwned;
|
||||
@Ignore
|
||||
private Integer numberOwned;
|
||||
|
||||
public String getKey() {
|
||||
return key;
|
||||
|
|
@ -23,6 +25,9 @@ public class Pet extends RealmObject implements Animal{
|
|||
}
|
||||
|
||||
public String getAnimal() {
|
||||
if (animal == null) {
|
||||
return getKey().split("-")[0];
|
||||
}
|
||||
return animal;
|
||||
}
|
||||
|
||||
|
|
@ -31,6 +36,9 @@ public class Pet extends RealmObject implements Animal{
|
|||
}
|
||||
|
||||
public String getColor() {
|
||||
if (color == null) {
|
||||
return getKey().split("-")[1];
|
||||
}
|
||||
return color;
|
||||
}
|
||||
|
||||
|
|
@ -39,6 +47,9 @@ public class Pet extends RealmObject implements Animal{
|
|||
}
|
||||
|
||||
public String getAnimalGroup() {
|
||||
if (animalGroup == null) {
|
||||
return "";
|
||||
}
|
||||
return animalGroup;
|
||||
}
|
||||
|
||||
|
|
@ -68,19 +79,19 @@ public class Pet extends RealmObject implements Animal{
|
|||
this.colorText = colorText;
|
||||
}
|
||||
|
||||
public Boolean getPremium() {
|
||||
public boolean getPremium() {
|
||||
return premium;
|
||||
}
|
||||
|
||||
public void setPremium(Boolean premium) {
|
||||
public void setPremium(boolean premium) {
|
||||
this.premium = premium;
|
||||
}
|
||||
|
||||
public Boolean getLimited() {
|
||||
public boolean getLimited() {
|
||||
return limited;
|
||||
}
|
||||
|
||||
public void setLimited(Boolean limited) {
|
||||
public void setLimited(boolean limited) {
|
||||
this.limited = limited;
|
||||
}
|
||||
|
||||
|
|
@ -95,6 +106,9 @@ public class Pet extends RealmObject implements Animal{
|
|||
this.numberOwned = numberOwned;
|
||||
}
|
||||
public Integer getTrained() {
|
||||
if (trained == null) {
|
||||
return 0;
|
||||
}
|
||||
return trained;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -90,7 +90,7 @@ public class SkillsRecyclerViewAdapter extends RecyclerView.Adapter<SkillsRecycl
|
|||
skillNameTextView.setText(skill.text);
|
||||
skillNotesTextView.setText(skill.notes);
|
||||
|
||||
if (skill.isSpecialItem) {
|
||||
if ("special".equals(skill.habitClass)) {
|
||||
priceButton.setText(R.string.skill_transformation_use);
|
||||
|
||||
priceButton.setCompoundDrawables(null, null, null, null);
|
||||
|
|
|
|||
|
|
@ -2,6 +2,7 @@ package com.habitrpg.android.habitica.ui.adapter.inventory;
|
|||
|
||||
import android.content.Context;
|
||||
import android.content.res.Resources;
|
||||
import android.support.annotation.Nullable;
|
||||
import android.support.v7.widget.CardView;
|
||||
import android.support.v7.widget.RecyclerView;
|
||||
import android.view.LayoutInflater;
|
||||
|
|
@ -19,27 +20,18 @@ import com.habitrpg.android.habitica.ui.menu.BottomSheetMenuItem;
|
|||
|
||||
import org.greenrobot.eventbus.EventBus;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
|
||||
import butterknife.BindView;
|
||||
import butterknife.ButterKnife;
|
||||
import io.realm.OrderedRealmCollection;
|
||||
import io.realm.RealmRecyclerViewAdapter;
|
||||
|
||||
public class MountDetailRecyclerAdapter extends RecyclerView.Adapter<MountDetailRecyclerAdapter.MountViewHolder> {
|
||||
public class MountDetailRecyclerAdapter extends RealmRecyclerViewAdapter<Mount, MountDetailRecyclerAdapter.MountViewHolder> {
|
||||
|
||||
public String itemType;
|
||||
public Context context;
|
||||
private List<Mount> itemList;
|
||||
private HashMap<String, Boolean> ownedMapping;
|
||||
|
||||
public void setItemList(List<Mount> itemList) {
|
||||
this.itemList = itemList;
|
||||
this.notifyDataSetChanged();
|
||||
}
|
||||
|
||||
public void setOwnedMapping(HashMap<String, Boolean> map) {
|
||||
this.ownedMapping = map;
|
||||
this.notifyDataSetChanged();
|
||||
public MountDetailRecyclerAdapter(@Nullable OrderedRealmCollection<Mount> data, boolean autoUpdate) {
|
||||
super(data, autoUpdate);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
@ -53,12 +45,9 @@ public class MountDetailRecyclerAdapter extends RecyclerView.Adapter<MountDetail
|
|||
|
||||
@Override
|
||||
public void onBindViewHolder(MountViewHolder holder, int position) {
|
||||
holder.bind(this.itemList.get(position));
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getItemCount() {
|
||||
return itemList == null ? 0 : itemList.size();
|
||||
if (getData() != null) {
|
||||
holder.bind(this.getData().get(position));
|
||||
}
|
||||
}
|
||||
|
||||
class MountViewHolder extends RecyclerView.ViewHolder implements View.OnClickListener {
|
||||
|
|
@ -78,7 +67,7 @@ public class MountDetailRecyclerAdapter extends RecyclerView.Adapter<MountDetail
|
|||
|
||||
Resources resources;
|
||||
|
||||
public MountViewHolder(View itemView) {
|
||||
MountViewHolder(View itemView) {
|
||||
super(itemView);
|
||||
ButterKnife.bind(this, itemView);
|
||||
|
||||
|
|
@ -87,21 +76,12 @@ public class MountDetailRecyclerAdapter extends RecyclerView.Adapter<MountDetail
|
|||
itemView.setOnClickListener(this);
|
||||
}
|
||||
|
||||
Boolean isOwned() {
|
||||
if (ownedMapping != null && animal != null) {
|
||||
if (ownedMapping.containsKey(animal.getKey()) && ownedMapping.get(animal.getKey())) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public void bind(Mount item) {
|
||||
animal = item;
|
||||
titleView.setText(item.getColorText());
|
||||
ownedTextView.setVisibility(View.GONE);
|
||||
this.imageView.setAlpha(1.0f);
|
||||
if (this.isOwned()) {
|
||||
if (this.animal.getOwned()) {
|
||||
DataBindingUtils.loadImage(this.imageView, "Mount_Icon_" + itemType + "-" + item.getColor());
|
||||
} else {
|
||||
DataBindingUtils.loadImage(this.imageView, "PixelPaw");
|
||||
|
|
@ -111,7 +91,7 @@ public class MountDetailRecyclerAdapter extends RecyclerView.Adapter<MountDetail
|
|||
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
if (!this.isOwned()) {
|
||||
if (!this.animal.getOwned()) {
|
||||
return;
|
||||
}
|
||||
BottomSheetMenu menu = new BottomSheetMenu(context);
|
||||
|
|
|
|||
|
|
@ -2,6 +2,7 @@ package com.habitrpg.android.habitica.ui.adapter.inventory;
|
|||
|
||||
import android.content.Context;
|
||||
import android.content.res.Resources;
|
||||
import android.support.annotation.Nullable;
|
||||
import android.support.v7.widget.CardView;
|
||||
import android.support.v7.widget.RecyclerView;
|
||||
import android.view.LayoutInflater;
|
||||
|
|
@ -14,6 +15,7 @@ import com.facebook.drawee.view.SimpleDraweeView;
|
|||
import com.habitrpg.android.habitica.R;
|
||||
import com.habitrpg.android.habitica.events.commands.EquipCommand;
|
||||
import com.habitrpg.android.habitica.events.commands.FeedCommand;
|
||||
import com.habitrpg.android.habitica.models.inventory.Mount;
|
||||
import com.habitrpg.android.habitica.models.inventory.Pet;
|
||||
import com.habitrpg.android.habitica.ui.helpers.DataBindingUtils;
|
||||
import com.habitrpg.android.habitica.ui.menu.BottomSheetMenu;
|
||||
|
|
@ -21,34 +23,22 @@ import com.habitrpg.android.habitica.ui.menu.BottomSheetMenuItem;
|
|||
|
||||
import org.greenrobot.eventbus.EventBus;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
|
||||
import butterknife.BindView;
|
||||
import butterknife.ButterKnife;
|
||||
import io.realm.OrderedRealmCollection;
|
||||
import io.realm.RealmRecyclerViewAdapter;
|
||||
import io.realm.RealmResults;
|
||||
|
||||
public class PetDetailRecyclerAdapter extends RecyclerView.Adapter<PetDetailRecyclerAdapter.PetViewHolder> {
|
||||
public class PetDetailRecyclerAdapter extends RealmRecyclerViewAdapter<Pet, PetDetailRecyclerAdapter.PetViewHolder> {
|
||||
|
||||
public String itemType;
|
||||
public Context context;
|
||||
private List<Pet> itemList;
|
||||
private HashMap<String, Integer> ownedMapping;
|
||||
private HashMap<String, Boolean> ownedMountMapping;
|
||||
private RealmResults<Mount> ownedMounts;
|
||||
|
||||
public void setItemList(List<Pet> itemList) {
|
||||
this.itemList = itemList;
|
||||
this.notifyDataSetChanged();
|
||||
public PetDetailRecyclerAdapter(@Nullable OrderedRealmCollection<Pet> data, boolean autoUpdate) {
|
||||
super(data, autoUpdate);
|
||||
}
|
||||
|
||||
public void setOwnedMapping(HashMap<String, Integer> map) {
|
||||
this.ownedMapping = map;
|
||||
this.notifyDataSetChanged();
|
||||
}
|
||||
|
||||
public void setOwnedMountsMapping(HashMap<String, Boolean> map) {
|
||||
this.ownedMountMapping = map;
|
||||
this.notifyDataSetChanged();
|
||||
}
|
||||
|
||||
@Override
|
||||
public PetViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
|
||||
|
|
@ -61,12 +51,14 @@ public class PetDetailRecyclerAdapter extends RecyclerView.Adapter<PetDetailRecy
|
|||
|
||||
@Override
|
||||
public void onBindViewHolder(PetViewHolder holder, int position) {
|
||||
holder.bind(this.itemList.get(position));
|
||||
if (getData() != null) {
|
||||
holder.bind(this.getData().get(position));
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getItemCount() {
|
||||
return itemList == null ? 0 : itemList.size();
|
||||
public void setOwnedMounts(RealmResults<Mount> ownedMounts) {
|
||||
this.ownedMounts = ownedMounts;
|
||||
notifyDataSetChanged();
|
||||
}
|
||||
|
||||
class PetViewHolder extends RecyclerView.ViewHolder implements View.OnClickListener {
|
||||
|
|
@ -95,46 +87,21 @@ public class PetDetailRecyclerAdapter extends RecyclerView.Adapter<PetDetailRecy
|
|||
itemView.setOnClickListener(this);
|
||||
}
|
||||
|
||||
public int getOwnedStatus() {
|
||||
if (ownedMapping != null && animal != null) {
|
||||
if (ownedMapping.containsKey(animal.getKey())) {
|
||||
return ownedMapping.get(animal.getKey());
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
public boolean isOwned() {
|
||||
return this.getOwnedStatus() > 0;
|
||||
}
|
||||
|
||||
public Boolean isMountOwned() {
|
||||
if (animal.getAnimalGroup().equals("specialPets")) {
|
||||
return false;
|
||||
}
|
||||
if (ownedMountMapping != null && animal != null) {
|
||||
if (ownedMountMapping.get(animal.getKey()) != null) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public void bind(Pet item) {
|
||||
this.animal = item;
|
||||
this.titleView.setText(item.getColorText());
|
||||
this.trainedProgressbar.setVisibility(animal.getAnimalGroup().equals("specialPets") ? View.GONE : View.VISIBLE);
|
||||
this.imageView.setAlpha(1.0f);
|
||||
if (this.getOwnedStatus() > 0) {
|
||||
if (this.animal.getTrained() > 0) {
|
||||
if (this.isMountOwned()) {
|
||||
this.trainedProgressbar.setVisibility(View.GONE);
|
||||
} else {
|
||||
this.trainedProgressbar.setProgress(ownedMapping.get(item.getKey()));
|
||||
this.trainedProgressbar.setProgress(this.animal.getTrained());
|
||||
}
|
||||
DataBindingUtils.loadImage(this.imageView, "Pet-" + itemType + "-" + item.getColor());
|
||||
} else {
|
||||
this.trainedProgressbar.setVisibility(View.GONE);
|
||||
if (this.getOwnedStatus() == 0) {
|
||||
if (this.animal.getTrained() == 0) {
|
||||
DataBindingUtils.loadImage(this.imageView, "PixelPaw");
|
||||
} else {
|
||||
DataBindingUtils.loadImage(this.imageView, "Pet-" + itemType + "-" + item.getColor());
|
||||
|
|
@ -167,5 +134,18 @@ public class PetDetailRecyclerAdapter extends RecyclerView.Adapter<PetDetailRecy
|
|||
});
|
||||
menu.show();
|
||||
}
|
||||
|
||||
private boolean isOwned() {
|
||||
return this.animal.getTrained() > 0;
|
||||
}
|
||||
|
||||
public boolean isMountOwned() {
|
||||
for (Mount ownedMount : ownedMounts) {
|
||||
if (ownedMount.getKey().equals(animal.getKey())) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -105,7 +105,7 @@ public class StableRecyclerAdapter extends RecyclerView.Adapter<RecyclerView.Vie
|
|||
ownedTextView.setVisibility(View.VISIBLE);
|
||||
this.imageView.setAlpha(1.0f);
|
||||
if (animal.getNumberOwned() > 0) {
|
||||
this.ownedTextView.setText(animal.getNumberOwned().toString());
|
||||
this.ownedTextView.setText(String.valueOf(animal.getNumberOwned()));
|
||||
if (itemType.equals("pets")) {
|
||||
DataBindingUtils.loadImage(this.imageView, "Pet-" + item.getKey());
|
||||
} else {
|
||||
|
|
|
|||
|
|
@ -11,6 +11,7 @@ import android.view.ViewGroup;
|
|||
import com.habitrpg.android.habitica.R;
|
||||
import com.habitrpg.android.habitica.components.AppComponent;
|
||||
import com.habitrpg.android.habitica.data.InventoryRepository;
|
||||
import com.habitrpg.android.habitica.helpers.ReactiveErrorHandler;
|
||||
import com.habitrpg.android.habitica.models.inventory.Mount;
|
||||
import com.habitrpg.android.habitica.ui.adapter.inventory.MountDetailRecyclerAdapter;
|
||||
import com.habitrpg.android.habitica.ui.fragments.BaseMainFragment;
|
||||
|
|
@ -30,13 +31,12 @@ public class MountDetailRecyclerFragment extends BaseMainFragment {
|
|||
public MountDetailRecyclerAdapter adapter;
|
||||
public String animalType;
|
||||
public String animalGroup;
|
||||
public List<Mount> animals;
|
||||
GridLayoutManager layoutManager = null;
|
||||
|
||||
private View view;
|
||||
|
||||
@Override
|
||||
public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
|
||||
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
|
||||
this.usesTabLayout = false;
|
||||
super.onCreateView(inflater, container, savedInstanceState);
|
||||
if (view == null) {
|
||||
|
|
@ -44,15 +44,13 @@ public class MountDetailRecyclerFragment extends BaseMainFragment {
|
|||
|
||||
recyclerView = (RecyclerView) view.findViewById(R.id.recyclerView);
|
||||
|
||||
android.support.v4.app.FragmentActivity context = getActivity();
|
||||
|
||||
layoutManager = new GridLayoutManager(getActivity(), 2);
|
||||
recyclerView.setLayoutManager(layoutManager);
|
||||
recyclerView.addItemDecoration(new MarginDecoration(getActivity()));
|
||||
|
||||
adapter = (MountDetailRecyclerAdapter) recyclerView.getAdapter();
|
||||
if (adapter == null) {
|
||||
adapter = new MountDetailRecyclerAdapter();
|
||||
adapter = new MountDetailRecyclerAdapter(null, true);
|
||||
adapter.context = this.getActivity();
|
||||
adapter.itemType = this.animalType;
|
||||
recyclerView.setAdapter(adapter);
|
||||
|
|
@ -106,10 +104,7 @@ public class MountDetailRecyclerFragment extends BaseMainFragment {
|
|||
}
|
||||
|
||||
private void loadItems() {
|
||||
inventoryRepository.getMounts().subscribe(mounts -> {
|
||||
adapter.setItemList(mounts);
|
||||
animals = mounts;
|
||||
});
|
||||
inventoryRepository.getMounts(animalType, animalGroup).first().subscribe(adapter::updateData, ReactiveErrorHandler.handleEmptyError());
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
|||
|
|
@ -13,7 +13,6 @@ import com.habitrpg.android.habitica.components.AppComponent;
|
|||
import com.habitrpg.android.habitica.data.InventoryRepository;
|
||||
import com.habitrpg.android.habitica.events.commands.FeedCommand;
|
||||
import com.habitrpg.android.habitica.helpers.ReactiveErrorHandler;
|
||||
import com.habitrpg.android.habitica.models.inventory.Pet;
|
||||
import com.habitrpg.android.habitica.models.user.User;
|
||||
import com.habitrpg.android.habitica.ui.adapter.inventory.PetDetailRecyclerAdapter;
|
||||
import com.habitrpg.android.habitica.ui.fragments.BaseMainFragment;
|
||||
|
|
@ -22,8 +21,6 @@ import com.habitrpg.android.habitica.ui.helpers.MarginDecoration;
|
|||
|
||||
import org.greenrobot.eventbus.Subscribe;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import javax.inject.Inject;
|
||||
|
||||
public class PetDetailRecyclerFragment extends BaseMainFragment {
|
||||
|
|
@ -36,13 +33,12 @@ public class PetDetailRecyclerFragment extends BaseMainFragment {
|
|||
public PetDetailRecyclerAdapter adapter;
|
||||
public String animalType;
|
||||
public String animalGroup;
|
||||
public List<Pet> animals;
|
||||
GridLayoutManager layoutManager = null;
|
||||
|
||||
private View view;
|
||||
|
||||
@Override
|
||||
public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
|
||||
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
|
||||
this.usesTabLayout = false;
|
||||
super.onCreateView(inflater, container, savedInstanceState);
|
||||
if (view == null) {
|
||||
|
|
@ -50,15 +46,13 @@ public class PetDetailRecyclerFragment extends BaseMainFragment {
|
|||
|
||||
recyclerView = (RecyclerView) view.findViewById(R.id.recyclerView);
|
||||
|
||||
android.support.v4.app.FragmentActivity context = getActivity();
|
||||
|
||||
layoutManager = new GridLayoutManager(getActivity(), 2);
|
||||
recyclerView.setLayoutManager(layoutManager);
|
||||
recyclerView.addItemDecoration(new MarginDecoration(getActivity()));
|
||||
|
||||
adapter = (PetDetailRecyclerAdapter) recyclerView.getAdapter();
|
||||
if (adapter == null) {
|
||||
adapter = new PetDetailRecyclerAdapter();
|
||||
adapter = new PetDetailRecyclerAdapter(null, true);
|
||||
adapter.context = this.getActivity();
|
||||
adapter.itemType = this.animalType;
|
||||
recyclerView.setAdapter(adapter);
|
||||
|
|
@ -111,10 +105,8 @@ public class PetDetailRecyclerFragment extends BaseMainFragment {
|
|||
}
|
||||
|
||||
private void loadItems() {
|
||||
inventoryRepository.getPets(animalType, animalGroup).subscribe(pets -> {
|
||||
adapter.setItemList(pets);
|
||||
animals = pets;
|
||||
}, ReactiveErrorHandler.handleEmptyError());
|
||||
inventoryRepository.getPets(animalType, animalGroup).first().subscribe(adapter::updateData, ReactiveErrorHandler.handleEmptyError());
|
||||
inventoryRepository.getOwnedMounts(animalType, animalGroup).subscribe(adapter::setOwnedMounts, ReactiveErrorHandler.handleEmptyError());
|
||||
}
|
||||
|
||||
@Subscribe
|
||||
|
|
|
|||
|
|
@ -15,6 +15,8 @@ import com.habitrpg.android.habitica.events.ContentReloadedEvent;
|
|||
import com.habitrpg.android.habitica.events.ReloadContentEvent;
|
||||
import com.habitrpg.android.habitica.helpers.ReactiveErrorHandler;
|
||||
import com.habitrpg.android.habitica.models.inventory.Animal;
|
||||
import com.habitrpg.android.habitica.models.inventory.Mount;
|
||||
import com.habitrpg.android.habitica.models.inventory.Pet;
|
||||
import com.habitrpg.android.habitica.models.user.User;
|
||||
import com.habitrpg.android.habitica.ui.activities.MainActivity;
|
||||
import com.habitrpg.android.habitica.ui.adapter.inventory.StableRecyclerAdapter;
|
||||
|
|
@ -141,16 +143,14 @@ public class StableRecyclerFragment extends BaseFragment {
|
|||
Observable<? extends Animal> observable;
|
||||
|
||||
if ("pets".equals(itemType)) {
|
||||
observable = inventoryRepository.getPets().flatMap(Observable::from);
|
||||
observable = inventoryRepository.getPets().first().flatMap(Observable::from);
|
||||
} else {
|
||||
observable = inventoryRepository.getMounts().flatMap(Observable::from);
|
||||
observable = inventoryRepository.getMounts().first().flatMap(Observable::from);
|
||||
}
|
||||
|
||||
observable.toList().flatMap(unsortedAnimals -> {
|
||||
List<Object> items = new ArrayList<>();
|
||||
if (unsortedAnimals.size() == 0) {
|
||||
ReloadContentEvent event = new ReloadContentEvent();
|
||||
EventBus.getDefault().post(event);
|
||||
return Observable.just(items);
|
||||
}
|
||||
String lastSectionTitle = "";
|
||||
|
|
@ -175,18 +175,14 @@ public class StableRecyclerFragment extends BaseFragment {
|
|||
if (user != null && user.getItems() != null) {
|
||||
switch (itemType) {
|
||||
case "pets":
|
||||
if (user.getItems().getPets() != null) {
|
||||
if (lastAnimal.getNumberOwned() == 0) {
|
||||
lastAnimal.setColor(animal.getColor());
|
||||
}
|
||||
Pet pet = (Pet) animal;
|
||||
if (pet.getTrained() > 0) {
|
||||
lastAnimal.setNumberOwned(lastAnimal.getNumberOwned() + 1);
|
||||
}
|
||||
break;
|
||||
case "mounts":
|
||||
if (user.getItems().getMounts() != null) {
|
||||
if (lastAnimal.getNumberOwned() == 0) {
|
||||
lastAnimal.setColor(animal.getColor());
|
||||
}
|
||||
Mount mount = (Mount) animal;
|
||||
if (mount.getOwned()) {
|
||||
lastAnimal.setNumberOwned(lastAnimal.getNumberOwned() + 1);
|
||||
}
|
||||
break;
|
||||
|
|
@ -194,9 +190,6 @@ public class StableRecyclerFragment extends BaseFragment {
|
|||
}
|
||||
}
|
||||
return Observable.just(items);
|
||||
})
|
||||
.subscribeOn(Schedulers.io())
|
||||
.observeOn(AndroidSchedulers.mainThread())
|
||||
.subscribe(items -> adapter.setItemList(items), ReactiveErrorHandler.handleEmptyError());
|
||||
}).subscribe(items -> adapter.setItemList(items), ReactiveErrorHandler.handleEmptyError());
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -112,7 +112,7 @@ public class SkillsFragment extends BaseMainFragment {
|
|||
public void onEvent(UseSkillCommand command) {
|
||||
Skill skill = command.skill;
|
||||
|
||||
if (skill.isSpecialItem) {
|
||||
if ("special".equals(skill.habitClass)) {
|
||||
selectedSkill = skill;
|
||||
Intent intent = new Intent(activity, SkillMemberActivity.class);
|
||||
startActivityForResult(intent, MEMBER_SELECTION_ACTIVITY);
|
||||
|
|
@ -129,7 +129,7 @@ public class SkillsFragment extends BaseMainFragment {
|
|||
removeProgressDialog();
|
||||
adapter.setMana(response.user.getStats().mp);
|
||||
StringBuilder message = new StringBuilder();
|
||||
if (usedSkill.isSpecialItem) {
|
||||
if ("special".equals(usedSkill.habitClass)) {
|
||||
message.append(getContext().getString(R.string.used_skill_without_mana, usedSkill.text));
|
||||
} else {
|
||||
message.append(getContext().getString(R.string.used_skill, usedSkill.text, usedSkill.mana));
|
||||
|
|
|
|||
|
|
@ -19,22 +19,14 @@ import com.habitrpg.android.habitica.models.inventory.Equipment;
|
|||
import com.habitrpg.android.habitica.models.inventory.Mount;
|
||||
import com.habitrpg.android.habitica.models.inventory.Pet;
|
||||
import com.habitrpg.android.habitica.models.inventory.QuestContent;
|
||||
import com.raizlabs.android.dbflow.runtime.TransactionManager;
|
||||
import com.raizlabs.android.dbflow.runtime.transaction.process.ProcessModelInfo;
|
||||
import com.raizlabs.android.dbflow.runtime.transaction.process.SaveModelTransaction;
|
||||
import com.raizlabs.android.dbflow.sql.language.Select;
|
||||
import com.raizlabs.android.dbflow.structure.BaseModel;
|
||||
|
||||
import java.lang.reflect.Type;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import javax.inject.Inject;
|
||||
|
||||
import io.realm.RealmList;
|
||||
import io.realm.RealmObject;
|
||||
|
||||
public class ContentDeserializer implements JsonDeserializer<ContentResult> {
|
||||
|
||||
|
|
@ -81,31 +73,37 @@ public class ContentDeserializer implements JsonDeserializer<ContentResult> {
|
|||
for (HatchingPotion potion : result.hatchingPotions) {
|
||||
String key = egg.getKey() + "-" + potion.getKey();
|
||||
if (pets.containsKey(key)) {
|
||||
pets.put(key, this.populatePet(pets.get(key), egg, potion));
|
||||
pets.put(key, this.populatePet(pets.get(key), egg, potion, "pets"));
|
||||
}
|
||||
if (specialPets.containsKey(key)) {
|
||||
specialPets.put(key, this.populatePet(specialPets.get(key), egg, potion));
|
||||
specialPets.put(key, this.populatePet(specialPets.get(key), egg, potion, "specialPets"));
|
||||
}
|
||||
if (premiumPets.containsKey(key)) {
|
||||
premiumPets.put(key, this.populatePet(premiumPets.get(key), egg, potion));
|
||||
premiumPets.put(key, this.populatePet(premiumPets.get(key), egg, potion, "premiumPets"));
|
||||
}
|
||||
if (questPets.containsKey(key)) {
|
||||
questPets.put(key, this.populatePet(questPets.get(key), egg, potion));
|
||||
questPets.put(key, this.populatePet(questPets.get(key), egg, potion, "questPets"));
|
||||
}
|
||||
if (mounts.containsKey(key)) {
|
||||
mounts.put(key, this.popupateMount(mounts.get(key), egg, potion));
|
||||
mounts.put(key, this.populateMount(mounts.get(key), egg, potion, "mounts"));
|
||||
}
|
||||
if (specialMounts.containsKey(key)) {
|
||||
specialMounts.put(key, this.popupateMount(specialMounts.get(key), egg, potion));
|
||||
specialMounts.put(key, this.populateMount(specialMounts.get(key), egg, potion, "specialMounts"));
|
||||
}
|
||||
if (premiumMounts.containsKey(key)) {
|
||||
premiumMounts.put(key, this.popupateMount(premiumMounts.get(key), egg, potion));
|
||||
premiumMounts.put(key, this.populateMount(premiumMounts.get(key), egg, potion, "premiumMounts"));
|
||||
}
|
||||
if (questMounts.containsKey(key)) {
|
||||
questMounts.put(key, this.popupateMount(questMounts.get(key), egg, potion));
|
||||
questMounts.put(key, this.populateMount(questMounts.get(key), egg, potion, "questMounts"));
|
||||
}
|
||||
}
|
||||
}
|
||||
for (Pet pet : specialPets.values()) {
|
||||
pet.setAnimalGroup("specialMounts");
|
||||
}
|
||||
for (Mount mount : specialMounts.values()) {
|
||||
mount.setAnimalGroup("specialMounts");
|
||||
}
|
||||
|
||||
result.pets = new RealmList<>();
|
||||
result.pets.addAll(pets.values());
|
||||
|
|
@ -122,17 +120,6 @@ public class ContentDeserializer implements JsonDeserializer<ContentResult> {
|
|||
result.spells = context.deserialize(object.get("spells"), new TypeToken<List<Skill>>() {
|
||||
}.getType());
|
||||
|
||||
List<String> spellKeys = new ArrayList<>();
|
||||
for (Skill skill : result.spells) {
|
||||
spellKeys.add(skill.key);
|
||||
}
|
||||
/*List<Skill> oldSkills = new Select().from(Skill.class).queryList();
|
||||
for (Skill skill : oldSkills) {
|
||||
if (!spellKeys.contains(skill.key)) {
|
||||
skill.delete();
|
||||
}
|
||||
}*/
|
||||
|
||||
result.appearances = context.deserialize(object.get("appearances"), new TypeToken<RealmList<Customization>>() {
|
||||
}.getType());
|
||||
result.backgrounds = context.deserialize(object.get("backgrounds"), new TypeToken<RealmList<Customization>>() {
|
||||
|
|
@ -144,19 +131,21 @@ public class ContentDeserializer implements JsonDeserializer<ContentResult> {
|
|||
return result;
|
||||
}
|
||||
|
||||
private Mount popupateMount(Mount mount, Egg egg, HatchingPotion potion) {
|
||||
private Mount populateMount(Mount mount, Egg egg, HatchingPotion potion, String group) {
|
||||
mount.setAnimalText(egg.getMountText());
|
||||
mount.setColorText(potion.getText());
|
||||
mount.setLimited(potion.getLimited());
|
||||
mount.setPremium(potion.getPremium());
|
||||
mount.setAnimalGroup(group);
|
||||
return mount;
|
||||
}
|
||||
|
||||
private Pet populatePet(Pet pet, Egg egg, HatchingPotion potion) {
|
||||
private Pet populatePet(Pet pet, Egg egg, HatchingPotion potion, String group) {
|
||||
pet.setAnimalText(egg.getText());
|
||||
pet.setColorText(potion.getText());
|
||||
pet.setLimited(potion.getLimited());
|
||||
pet.setPremium(potion.getPremium());
|
||||
pet.setAnimalGroup(group);
|
||||
return pet;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -36,9 +36,10 @@ public class MountListDeserializer implements JsonDeserializer<RealmList<Mount>>
|
|||
}
|
||||
|
||||
for (Map.Entry<String, JsonElement> entry : json.getAsJsonObject().entrySet()) {
|
||||
Mount mount;
|
||||
mount = new Mount();
|
||||
Mount mount = new Mount();
|
||||
mount.setKey(entry.getKey());
|
||||
mount.setAnimal(entry.getKey().split("-")[0]);
|
||||
mount.setColor(entry.getKey().split("-")[1]);
|
||||
if (entry.getValue().isJsonNull()) {
|
||||
mount.setOwned(false);
|
||||
} else {
|
||||
|
|
|
|||
|
|
@ -24,11 +24,12 @@ public class MountMapDeserializer implements JsonDeserializer<HashMap<String, Mo
|
|||
JsonObject object = json.getAsJsonObject();
|
||||
|
||||
Realm realm = Realm.getDefaultInstance();
|
||||
List<Pet> existingItems = realm.copyFromRealm(realm.where(Pet.class).findAll());
|
||||
List<Mount> existingItems = realm.copyFromRealm(realm.where(Mount.class).findAll());
|
||||
realm.close();
|
||||
|
||||
for (Pet mount : existingItems) {
|
||||
for (Mount mount : existingItems) {
|
||||
if (object.has(mount.getKey())) {
|
||||
vals.put(mount.getKey(), mount);
|
||||
object.remove(mount.getKey());
|
||||
}
|
||||
}
|
||||
|
|
@ -37,7 +38,6 @@ public class MountMapDeserializer implements JsonDeserializer<HashMap<String, Mo
|
|||
Mount mount;
|
||||
mount = new Mount();
|
||||
mount.setKey(entry.getKey());
|
||||
mount.setKey(entry.getKey());
|
||||
mount.setAnimal(entry.getKey().split("-")[0]);
|
||||
mount.setColor(entry.getKey().split("-")[1]);
|
||||
vals.put(mount.getKey(), mount);
|
||||
|
|
|
|||
|
|
@ -38,17 +38,14 @@ public class PetListDeserializer implements JsonDeserializer<RealmList<Pet>> {
|
|||
}
|
||||
|
||||
for (Map.Entry<String, JsonElement> entry : json.getAsJsonObject().entrySet()) {
|
||||
Pet pet;
|
||||
if (entry.getValue().isJsonObject()) {
|
||||
pet = context.deserialize(entry.getValue(), Food.class);
|
||||
Pet pet = new Pet();
|
||||
pet.setKey(entry.getKey());
|
||||
pet.setAnimal(entry.getKey().split("-")[0]);
|
||||
pet.setColor(entry.getKey().split("-")[1]);
|
||||
if (entry.getValue().isJsonNull()) {
|
||||
pet.setTrained(0);
|
||||
} else {
|
||||
pet = new Pet();
|
||||
pet.setKey(entry.getKey());
|
||||
if (entry.getValue().isJsonNull()) {
|
||||
pet.setTrained(0);
|
||||
} else {
|
||||
pet.setTrained(entry.getValue().getAsInt());
|
||||
}
|
||||
pet.setTrained(entry.getValue().getAsInt());
|
||||
}
|
||||
vals.add(pet);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -23,12 +23,13 @@ public class PetMapDeserializer implements JsonDeserializer<HashMap<String, Pet>
|
|||
JsonObject object = json.getAsJsonObject();
|
||||
|
||||
Realm realm = Realm.getDefaultInstance();
|
||||
List<Mount> existingItems = realm.copyFromRealm(realm.where(Mount.class).findAll());
|
||||
List<Pet> existingItems = realm.copyFromRealm(realm.where(Pet.class).findAll());
|
||||
realm.close();
|
||||
|
||||
for (Mount mount : existingItems) {
|
||||
if (object.has(mount.getKey())) {
|
||||
object.remove(mount.getKey());
|
||||
for (Pet pet : existingItems) {
|
||||
if (object.has(pet.getKey())) {
|
||||
vals.put(pet.getKey(), pet);
|
||||
object.remove(pet.getKey());
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue