mirror of
https://github.com/sudoxnym/habitica-android.git
synced 2026-05-20 04:39:04 +00:00
improve stable handling.
This commit is contained in:
parent
051fed2f72
commit
b136949cd6
5 changed files with 38 additions and 12 deletions
|
|
@ -1,5 +1,8 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<ImageView xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:layout_width="@dimen/pet_image_width" android:layout_height="@dimen/pet_image_height"
|
||||
android:layout_gravity="center">
|
||||
</ImageView>
|
||||
<ImageView android:id="@+id/pet_imageview"
|
||||
android:layout_width="@dimen/pet_image_width" android:layout_height="@dimen/pet_image_height"
|
||||
android:layout_gravity="center" />
|
||||
</FrameLayout>
|
||||
|
|
|
|||
|
|
@ -33,6 +33,7 @@ public class PetDetailRecyclerAdapter extends RecyclerView.Adapter<PetDetailRecy
|
|||
|
||||
private List<Pet> itemList;
|
||||
private HashMap<String, Integer> ownedMapping;
|
||||
private HashMap<String, Boolean> ownedMountMapping;
|
||||
public String itemType;
|
||||
|
||||
public Context context;
|
||||
|
|
@ -47,6 +48,11 @@ public class PetDetailRecyclerAdapter extends RecyclerView.Adapter<PetDetailRecy
|
|||
this.notifyDataSetChanged();
|
||||
}
|
||||
|
||||
public void setOwnedMountsMapping(HashMap<String, Boolean> map) {
|
||||
this.ownedMountMapping = map;
|
||||
this.notifyDataSetChanged();
|
||||
}
|
||||
|
||||
@Override
|
||||
public PetViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
|
||||
|
||||
|
|
@ -94,7 +100,16 @@ public class PetDetailRecyclerAdapter extends RecyclerView.Adapter<PetDetailRecy
|
|||
|
||||
public Boolean isOwned() {
|
||||
if (ownedMapping != null && animal != null) {
|
||||
if (ownedMapping.containsKey(animal.getKey()) && ownedMapping.get(animal.getKey()) > 0) {
|
||||
if (ownedMapping.containsKey(animal.getKey()) && ownedMapping.get(animal.getKey()) != 0) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public Boolean isMountOwned() {
|
||||
if (ownedMountMapping != null && animal != null) {
|
||||
if (ownedMountMapping.containsKey(animal.getKey()) && ownedMountMapping.get(animal.getKey())) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
|
@ -107,7 +122,11 @@ public class PetDetailRecyclerAdapter extends RecyclerView.Adapter<PetDetailRecy
|
|||
this.trainedProgressbar.setVisibility(View.VISIBLE);
|
||||
this.imageView.setAlpha(1.0f);
|
||||
if (this.isOwned()) {
|
||||
this.trainedProgressbar.setProgress(ownedMapping.get(item.getKey()));
|
||||
if (this.isMountOwned()) {
|
||||
this.trainedProgressbar.setVisibility(View.GONE);
|
||||
} else {
|
||||
this.trainedProgressbar.setProgress(ownedMapping.get(item.getKey()));
|
||||
}
|
||||
DataBindingUtils.loadImage(this.imageView, "Pet-" + itemType + "-" + item.getColor());
|
||||
} else {
|
||||
this.trainedProgressbar.setVisibility(View.GONE);
|
||||
|
|
@ -123,7 +142,9 @@ public class PetDetailRecyclerAdapter extends RecyclerView.Adapter<PetDetailRecy
|
|||
}
|
||||
BottomSheetMenu menu = new BottomSheetMenu(context);
|
||||
menu.addMenuItem(new BottomSheetMenuItem(resources.getString(R.string.use_animal)));
|
||||
menu.addMenuItem(new BottomSheetMenuItem(resources.getString(R.string.feed)));
|
||||
if (!this.isMountOwned()) {
|
||||
menu.addMenuItem(new BottomSheetMenuItem(resources.getString(R.string.feed)));
|
||||
}
|
||||
menu.setSelectionRunnable(new BottomSheetMenuSelectionRunnable() {
|
||||
@Override
|
||||
public void selectedItemAt(Integer index) {
|
||||
|
|
|
|||
|
|
@ -111,6 +111,7 @@ public class PetDetailRecyclerFragment extends BaseMainFragment {
|
|||
adapter.setItemList(items);
|
||||
animals = items;
|
||||
adapter.setOwnedMapping(user.getItems().getPets());
|
||||
adapter.setOwnedMountsMapping(user.getItems().getMounts());
|
||||
}
|
||||
};
|
||||
itemsRunnable.run();
|
||||
|
|
@ -127,4 +128,11 @@ public class PetDetailRecyclerFragment extends BaseMainFragment {
|
|||
fragment.show(getFragmentManager(), "feedDialog");
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void updateUserData(HabitRPGUser user) {
|
||||
super.updateUserData(user);
|
||||
adapter.setOwnedMapping(user.getItems().getPets());
|
||||
adapter.setOwnedMountsMapping(user.getItems().getMounts());
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -36,12 +36,6 @@ public class StableFragment extends BaseMainFragment {
|
|||
public void setViewPagerAdapter() {
|
||||
android.support.v4.app.FragmentManager fragmentManager = getChildFragmentManager();
|
||||
|
||||
UserParty party = user.getParty();
|
||||
|
||||
if (party == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
viewPager.setAdapter(new FragmentPagerAdapter(fragmentManager) {
|
||||
|
||||
@Override
|
||||
|
|
|
|||
|
|
@ -5,7 +5,7 @@ buildscript {
|
|||
jcenter()
|
||||
}
|
||||
dependencies {
|
||||
classpath 'com.android.tools.build:gradle:2.0.0-beta7'
|
||||
classpath 'com.android.tools.build:gradle:2.0.0-rc3'
|
||||
classpath 'com.android.databinding:dataBinder:1.0-rc4'
|
||||
classpath 'com.neenbedankt.gradle.plugins:android-apt:1.8'
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue