mirror of
https://github.com/sudoxnym/habitica-android.git
synced 2026-04-14 19:56:32 +00:00
display shops in the app
This commit is contained in:
parent
f68795549a
commit
d29c7b72ca
14 changed files with 770 additions and 36 deletions
51
Habitica/res/layout/row_shopitem.xml
Normal file
51
Habitica/res/layout/row_shopitem.xml
Normal file
|
|
@ -0,0 +1,51 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:bind="http://schemas.android.com/apk/res-auto"
|
||||
xmlns:tools="http://schemas.android.com/tools"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
style="@style/RowWrapper"
|
||||
android:clickable="true"
|
||||
android:background="@android:color/white">
|
||||
<ImageView
|
||||
android:id="@+id/imageView"
|
||||
android:layout_width="@dimen/gear_image_size"
|
||||
android:layout_height="@dimen/gear_image_size"
|
||||
android:scaleType="fitEnd"
|
||||
android:layout_marginRight="@dimen/row_padding"/>
|
||||
<LinearLayout
|
||||
android:layout_width="0dp"
|
||||
android:layout_weight="1"
|
||||
android:layout_height="wrap_content"
|
||||
android:orientation="vertical"
|
||||
android:layout_gravity="center_vertical">
|
||||
<TextView
|
||||
android:id="@+id/titleView"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
tools:text="Title"
|
||||
style="@style/RowTitle" />
|
||||
<TextView
|
||||
android:id="@+id/descriptionView"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
tools:text="Description"
|
||||
android:maxLines="5"
|
||||
style="@style/RowText" />
|
||||
</LinearLayout>
|
||||
|
||||
<Button
|
||||
android:id="@+id/buyButton"
|
||||
android:layout_width="60dp"
|
||||
android:layout_height="45dp"
|
||||
android:layout_marginLeft="8dp"
|
||||
android:layout_marginStart="8dp"
|
||||
android:textColor="@color/white"
|
||||
android:layout_gravity="center_vertical"
|
||||
android:textSize="15sp"
|
||||
android:drawableLeft="@drawable/ic_header_gold"
|
||||
android:drawableStart="@drawable/ic_header_gold"
|
||||
android:background="@drawable/rounded_purple_square"
|
||||
android:paddingLeft="6dp"
|
||||
android:paddingStart="6dp" />
|
||||
</LinearLayout>
|
||||
|
|
@ -16,4 +16,5 @@
|
|||
<string name="sidebar.news">News</string>
|
||||
<string name="sidebar.settings">Settings</string>
|
||||
<string name="sidebar.about">About</string>
|
||||
<string name="sidebar_shops">Shops</string>
|
||||
</resources>
|
||||
|
|
|
|||
|
|
@ -348,4 +348,7 @@ To start, which parts of your life do you want to improve?</string>
|
|||
<string name="change_class_confirmation">Are you sure you want to change your class? This will cost 3 gems.</string>
|
||||
<string name="leaderMessage" formatted="false">Message from %1$s</string>
|
||||
<string name="confirm">Confirm</string>
|
||||
<string name="market">Market</string>
|
||||
<string name="timeTravelers">Time Travelers</string>
|
||||
<string name="seasonalShop">Seasonal Shop</string>
|
||||
</resources>
|
||||
|
|
|
|||
|
|
@ -25,6 +25,8 @@ import com.habitrpg.android.habitica.ui.fragments.inventory.equipment.EquipmentD
|
|||
import com.habitrpg.android.habitica.ui.fragments.inventory.equipment.EquipmentOverviewFragment;
|
||||
import com.habitrpg.android.habitica.ui.fragments.inventory.items.ItemRecyclerFragment;
|
||||
import com.habitrpg.android.habitica.ui.fragments.inventory.items.ItemsFragment;
|
||||
import com.habitrpg.android.habitica.ui.fragments.inventory.shops.ShopFragment;
|
||||
import com.habitrpg.android.habitica.ui.fragments.inventory.shops.ShopsFragment;
|
||||
import com.habitrpg.android.habitica.ui.fragments.inventory.stable.MountDetailRecyclerFragment;
|
||||
import com.habitrpg.android.habitica.ui.fragments.inventory.stable.PetDetailRecyclerFragment;
|
||||
import com.habitrpg.android.habitica.ui.fragments.inventory.stable.StableFragment;
|
||||
|
|
@ -150,4 +152,8 @@ public interface AppComponent {
|
|||
void inject(InboxFragment inboxFragment);
|
||||
|
||||
void inject(InboxMessageListFragment inboxMessageListFragment);
|
||||
|
||||
void inject(ShopsFragment shopsFragment);
|
||||
|
||||
void inject(ShopFragment shopFragment);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -0,0 +1,232 @@
|
|||
package com.habitrpg.android.habitica.ui.adapter.inventory;
|
||||
|
||||
import com.habitrpg.android.habitica.R;
|
||||
import com.habitrpg.android.habitica.databinding.ItemItemBinding;
|
||||
import com.habitrpg.android.habitica.events.ReloadContentEvent;
|
||||
import com.habitrpg.android.habitica.ui.helpers.DataBindingUtils;
|
||||
import com.habitrpg.android.habitica.ui.viewHolders.SectionViewHolder;
|
||||
import com.magicmicky.habitrpgwrapper.lib.models.Shop;
|
||||
import com.magicmicky.habitrpgwrapper.lib.models.ShopCategory;
|
||||
import com.magicmicky.habitrpgwrapper.lib.models.ShopItem;
|
||||
|
||||
import org.greenrobot.eventbus.EventBus;
|
||||
|
||||
import android.content.Context;
|
||||
import android.content.res.Resources;
|
||||
import android.databinding.DataBindingUtil;
|
||||
import android.support.annotation.NonNull;
|
||||
import android.support.v4.content.ContextCompat;
|
||||
import android.support.v7.app.AlertDialog;
|
||||
import android.support.v7.widget.RecyclerView;
|
||||
import android.view.Gravity;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
import android.widget.Button;
|
||||
import android.widget.ImageView;
|
||||
import android.widget.LinearLayout;
|
||||
import android.widget.TextView;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import butterknife.BindView;
|
||||
import butterknife.ButterKnife;
|
||||
|
||||
public class ShopRecyclerAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder> {
|
||||
|
||||
private List<Object> items;
|
||||
|
||||
public void setShop(Shop shop) {
|
||||
items = new ArrayList<>();
|
||||
for (ShopCategory category : shop.categories) {
|
||||
if (category.items != null && category.items.size() > 0) {
|
||||
items.add(category);
|
||||
for (ShopItem item : category.items) {
|
||||
items.add(item);
|
||||
}
|
||||
}
|
||||
}
|
||||
notifyDataSetChanged();
|
||||
}
|
||||
|
||||
@Override
|
||||
public RecyclerView.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
|
||||
if (viewType == 0) {
|
||||
View view = LayoutInflater.from(parent.getContext())
|
||||
.inflate(R.layout.customization_section_header, parent, false);
|
||||
|
||||
return new SectionViewHolder(view);
|
||||
} else {
|
||||
View view = LayoutInflater.from(parent.getContext())
|
||||
.inflate(R.layout.row_shopitem, parent, false);
|
||||
|
||||
return new ItemViewHolder(view);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onBindViewHolder(RecyclerView.ViewHolder holder, int position) {
|
||||
Object obj = this.items.get(position);
|
||||
if (obj.getClass().equals(ShopCategory.class)) {
|
||||
((SectionViewHolder) holder).bind(((ShopCategory) obj).getText());
|
||||
} else {
|
||||
((ItemViewHolder) holder).bind((ShopItem) items.get(position));
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getItemViewType(int position) {
|
||||
if (this.items.get(position).getClass().equals(ShopCategory.class)) {
|
||||
return 0;
|
||||
} else {
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getItemCount() {
|
||||
return items != null ? items.size() : 0;
|
||||
}
|
||||
|
||||
static class ItemViewHolder extends RecyclerView.ViewHolder implements View.OnClickListener {
|
||||
|
||||
@BindView(R.id.imageView)
|
||||
ImageView imageView;
|
||||
@BindView(R.id.titleView)
|
||||
TextView titleView;
|
||||
@BindView(R.id.descriptionView)
|
||||
TextView descriptionView;
|
||||
@BindView(R.id.buyButton)
|
||||
Button buyButton;
|
||||
|
||||
ShopItem item;
|
||||
|
||||
Context context;
|
||||
|
||||
public ItemViewHolder(View itemView) {
|
||||
super(itemView);
|
||||
|
||||
context = itemView.getContext();
|
||||
|
||||
ButterKnife.bind(this, itemView);
|
||||
|
||||
itemView.setOnClickListener(this);
|
||||
itemView.setClickable(true);
|
||||
}
|
||||
|
||||
public void bind(ShopItem item) {
|
||||
this.item = item;
|
||||
titleView.setText(item.getText());
|
||||
descriptionView.setText(item.getNotes());
|
||||
|
||||
DataBindingUtils.loadImage(this.imageView, item.getImageName());
|
||||
|
||||
buyButton.setText(item.getValue().toString());
|
||||
switch (item.getCurrency()) {
|
||||
case "gold":
|
||||
buyButton.setCompoundDrawablesWithIntrinsicBounds(R.drawable.ic_header_gold, 0, 0, 0);
|
||||
break;
|
||||
case "gems":
|
||||
buyButton.setCompoundDrawablesWithIntrinsicBounds(R.drawable.ic_header_gem, 0, 0, 0);
|
||||
break;
|
||||
default:
|
||||
buyButton.setVisibility(View.GONE);
|
||||
}
|
||||
}
|
||||
|
||||
@NonNull
|
||||
private LinearLayout createContentViewForGearDialog() {
|
||||
String content = this.item.getNotes();
|
||||
|
||||
// External ContentView
|
||||
LinearLayout contentViewLayout = new LinearLayout(context);
|
||||
contentViewLayout.setOrientation(LinearLayout.VERTICAL);
|
||||
|
||||
// Gear Image
|
||||
ImageView gearImageView = new ImageView(context);
|
||||
LinearLayout.LayoutParams gearImageLayoutParams = new LinearLayout.LayoutParams(
|
||||
LinearLayout.LayoutParams.WRAP_CONTENT, LinearLayout.LayoutParams.WRAP_CONTENT);
|
||||
|
||||
gearImageLayoutParams.gravity = Gravity.CENTER_HORIZONTAL | Gravity.CENTER_VERTICAL;
|
||||
gearImageLayoutParams.setMargins(0, 0, 0, 20);
|
||||
gearImageView.setMinimumWidth(200);
|
||||
gearImageView.setMinimumHeight(200);
|
||||
gearImageView.setLayoutParams(gearImageLayoutParams);
|
||||
DataBindingUtils.loadImage(gearImageView, item.getImageName());
|
||||
|
||||
// Gear Description
|
||||
TextView contentTextView = new TextView(context, null);
|
||||
contentTextView.setPadding(16, 0, 16, 0);
|
||||
if (!content.isEmpty()) {
|
||||
contentTextView.setText(content);
|
||||
}
|
||||
|
||||
// GoldPrice View
|
||||
LinearLayout goldPriceLayout = new LinearLayout(context);
|
||||
goldPriceLayout.setGravity(Gravity.CENTER_HORIZONTAL);
|
||||
LinearLayout.LayoutParams goldPriceLayoutParams = new LinearLayout.LayoutParams(
|
||||
LinearLayout.LayoutParams.WRAP_CONTENT, LinearLayout.LayoutParams.WRAP_CONTENT);
|
||||
goldPriceLayoutParams.setMargins(0, 0, 0, 16);
|
||||
goldPriceLayoutParams.gravity = Gravity.CENTER_HORIZONTAL | Gravity.CENTER_VERTICAL;
|
||||
|
||||
goldPriceLayout.setOrientation(LinearLayout.HORIZONTAL);
|
||||
goldPriceLayout.setLayoutParams(goldPriceLayoutParams);
|
||||
goldPriceLayout.setGravity(Gravity.CENTER_HORIZONTAL | Gravity.CENTER_VERTICAL);
|
||||
|
||||
// Price View
|
||||
TextView priceTextView = new TextView(context);
|
||||
priceTextView.setText(item.getValue().toString());
|
||||
priceTextView.setPadding(10, 0, 0, 0);
|
||||
|
||||
ImageView currency = new ImageView(context);
|
||||
switch (item.getCurrency()) {
|
||||
case "gold":
|
||||
currency.setImageDrawable(ContextCompat.getDrawable(context, R.drawable.ic_header_gold));
|
||||
break;
|
||||
case "gems":
|
||||
currency.setImageDrawable(ContextCompat.getDrawable(context, R.drawable.ic_header_gem));
|
||||
break;
|
||||
default:
|
||||
buyButton.setVisibility(View.GONE);
|
||||
}
|
||||
currency.setMinimumHeight(50);
|
||||
currency.setMinimumWidth(50);
|
||||
currency.setPadding(0, 0, 5, 0);
|
||||
|
||||
goldPriceLayout.addView(currency);
|
||||
goldPriceLayout.addView(priceTextView);
|
||||
|
||||
if (gearImageView.getDrawable() != null) {
|
||||
contentViewLayout.addView(gearImageView);
|
||||
}
|
||||
contentViewLayout.setGravity(Gravity.CENTER_VERTICAL);
|
||||
|
||||
contentViewLayout.addView(goldPriceLayout);
|
||||
|
||||
if (!content.isEmpty()) {
|
||||
contentViewLayout.addView(contentTextView);
|
||||
}
|
||||
|
||||
return contentViewLayout;
|
||||
}
|
||||
|
||||
private AlertDialog createDialog(LinearLayout contentViewForDialog) {
|
||||
return new AlertDialog.Builder(context)
|
||||
.setPositiveButton(R.string.reward_dialog_buy, (dialog, which) -> {
|
||||
})
|
||||
.setTitle(this.item.getText())
|
||||
.setView(contentViewForDialog)
|
||||
.setNegativeButton(R.string.reward_dialog_dismiss, (dialog, which) -> {
|
||||
dialog.dismiss();
|
||||
}).create();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onClick(View view) {
|
||||
AlertDialog dialog = createDialog(createContentViewForGearDialog());
|
||||
dialog.show();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -5,6 +5,7 @@ import com.habitrpg.android.habitica.ui.activities.MainActivity;
|
|||
import com.habitrpg.android.habitica.ui.fragments.inventory.stable.MountDetailRecyclerFragment;
|
||||
import com.habitrpg.android.habitica.ui.fragments.inventory.stable.PetDetailRecyclerFragment;
|
||||
import com.habitrpg.android.habitica.ui.helpers.DataBindingUtils;
|
||||
import com.habitrpg.android.habitica.ui.viewHolders.SectionViewHolder;
|
||||
import com.magicmicky.habitrpgwrapper.lib.models.inventory.Animal;
|
||||
|
||||
import android.content.Context;
|
||||
|
|
@ -138,31 +139,4 @@ public class StableRecyclerAdapter extends RecyclerView.Adapter<RecyclerView.Vie
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
class SectionViewHolder extends RecyclerView.ViewHolder {
|
||||
|
||||
@BindView(R.id.label)
|
||||
TextView label;
|
||||
|
||||
@BindView(R.id.purchaseSetButton)
|
||||
Button purchaseSetButton;
|
||||
|
||||
Context context;
|
||||
|
||||
public SectionViewHolder(View itemView) {
|
||||
super(itemView);
|
||||
context = itemView.getContext();
|
||||
ButterKnife.bind(this, itemView);
|
||||
this.purchaseSetButton.setVisibility(View.GONE);
|
||||
}
|
||||
|
||||
public void bind(String title) {
|
||||
try {
|
||||
Integer stringID = context.getResources().getIdentifier("section" + title, "string", context.getPackageName());
|
||||
this.label.setText(context.getString(stringID));
|
||||
} catch (Exception e) {
|
||||
this.label.setText(title);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -0,0 +1,125 @@
|
|||
package com.habitrpg.android.habitica.ui.fragments.inventory.shops;
|
||||
|
||||
import com.habitrpg.android.habitica.APIHelper;
|
||||
import com.habitrpg.android.habitica.R;
|
||||
import com.habitrpg.android.habitica.components.AppComponent;
|
||||
import com.habitrpg.android.habitica.ui.activities.MainActivity;
|
||||
import com.habitrpg.android.habitica.ui.adapter.inventory.ShopRecyclerAdapter;
|
||||
import com.habitrpg.android.habitica.ui.adapter.inventory.StableRecyclerAdapter;
|
||||
import com.habitrpg.android.habitica.ui.fragments.BaseFragment;
|
||||
import com.habitrpg.android.habitica.ui.helpers.MarginDecoration;
|
||||
import com.habitrpg.android.habitica.ui.helpers.RecyclerViewEmptySupport;
|
||||
import com.habitrpg.android.habitica.ui.menu.DividerItemDecoration;
|
||||
import com.magicmicky.habitrpgwrapper.lib.models.HabitRPGUser;
|
||||
import com.magicmicky.habitrpgwrapper.lib.models.Shop;
|
||||
|
||||
import android.os.Bundle;
|
||||
import android.support.annotation.Nullable;
|
||||
import android.support.v7.widget.GridLayoutManager;
|
||||
import android.support.v7.widget.LinearLayoutManager;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
import android.widget.TextView;
|
||||
|
||||
import javax.inject.Inject;
|
||||
|
||||
import butterknife.BindView;
|
||||
import butterknife.ButterKnife;
|
||||
|
||||
public class ShopFragment extends BaseFragment {
|
||||
private static final String SHOP_IDENTIFIER_KEY = "SHOP_IDENTIFIER_KEY";
|
||||
|
||||
@BindView(R.id.recyclerView)
|
||||
public RecyclerViewEmptySupport recyclerView;
|
||||
@BindView(R.id.empty_view)
|
||||
public TextView emptyView;
|
||||
|
||||
private View view;
|
||||
public ShopRecyclerAdapter adapter;
|
||||
|
||||
public String shopIdentifier;
|
||||
public HabitRPGUser user;
|
||||
|
||||
public Shop shop;
|
||||
|
||||
@Inject
|
||||
APIHelper apiHeliper;
|
||||
|
||||
@Nullable
|
||||
@Override
|
||||
public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
|
||||
super.onCreateView(inflater, container, savedInstanceState);
|
||||
boolean setupViews = false;
|
||||
if (view == null) {
|
||||
view = inflater.inflate(R.layout.fragment_recyclerview, container, false);
|
||||
setupViews = true;
|
||||
}
|
||||
|
||||
unbinder = ButterKnife.bind(this, view);
|
||||
|
||||
if (setupViews) {
|
||||
recyclerView.addItemDecoration(new DividerItemDecoration(getActivity(), DividerItemDecoration.VERTICAL_LIST));
|
||||
}
|
||||
|
||||
|
||||
adapter = (ShopRecyclerAdapter) recyclerView.getAdapter();
|
||||
if (adapter == null) {
|
||||
adapter = new ShopRecyclerAdapter();
|
||||
recyclerView.setAdapter(adapter);
|
||||
}
|
||||
LinearLayoutManager layoutManager = (LinearLayoutManager) recyclerView.getLayoutManager();
|
||||
if (layoutManager == null) {
|
||||
layoutManager = new LinearLayoutManager(getContext());
|
||||
|
||||
recyclerView.setLayoutManager(layoutManager);
|
||||
}
|
||||
|
||||
if (savedInstanceState != null) {
|
||||
this.shopIdentifier = savedInstanceState.getString(SHOP_IDENTIFIER_KEY, "");
|
||||
}
|
||||
|
||||
if (shop == null) {
|
||||
loadShopInventory();
|
||||
} else {
|
||||
adapter.setShop(shop);
|
||||
}
|
||||
|
||||
return view;
|
||||
}
|
||||
|
||||
private void loadShopInventory() {
|
||||
String shopUrl = "";
|
||||
switch (this.shopIdentifier) {
|
||||
case Shop.MARKET:
|
||||
shopUrl = "market";
|
||||
break;
|
||||
case Shop.QUEST_SHOP:
|
||||
shopUrl = "quests";
|
||||
break;
|
||||
case Shop.TIME_TRAVELERS_SHOP:
|
||||
shopUrl = "time-travelers";
|
||||
break;
|
||||
case Shop.SEASONAL_SHOP:
|
||||
shopUrl = "seasonal";
|
||||
break;
|
||||
}
|
||||
this.apiHeliper.apiService.fetchShopInventory(shopUrl)
|
||||
.compose(this.apiHeliper.configureApiCallObserver())
|
||||
.subscribe(shop -> {
|
||||
this.shop = shop;
|
||||
this.adapter.setShop(shop);
|
||||
}, throwable -> {});
|
||||
}
|
||||
|
||||
@Override
|
||||
public void injectFragment(AppComponent component) {
|
||||
component.inject(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onSaveInstanceState(Bundle outState) {
|
||||
super.onSaveInstanceState(outState);
|
||||
outState.putString(SHOP_IDENTIFIER_KEY, this.shopIdentifier);
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,99 @@
|
|||
package com.habitrpg.android.habitica.ui.fragments.inventory.shops;
|
||||
|
||||
import com.habitrpg.android.habitica.R;
|
||||
import com.habitrpg.android.habitica.components.AppComponent;
|
||||
import com.habitrpg.android.habitica.ui.fragments.BaseMainFragment;
|
||||
import com.magicmicky.habitrpgwrapper.lib.models.Shop;
|
||||
|
||||
import android.os.Bundle;
|
||||
import android.support.v4.app.Fragment;
|
||||
import android.support.v4.app.FragmentPagerAdapter;
|
||||
import android.support.v4.view.ViewPager;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
|
||||
public class ShopsFragment extends BaseMainFragment {
|
||||
|
||||
public ViewPager viewPager;
|
||||
|
||||
@Override
|
||||
public View onCreateView(LayoutInflater inflater, ViewGroup container,
|
||||
Bundle savedInstanceState) {
|
||||
this.usesTabLayout = true;
|
||||
super.onCreateView(inflater, container, savedInstanceState);
|
||||
View v = inflater.inflate(R.layout.fragment_viewpager, container, false);
|
||||
|
||||
viewPager = (ViewPager) v.findViewById(R.id.view_pager);
|
||||
|
||||
viewPager.setCurrentItem(0);
|
||||
|
||||
setViewPagerAdapter();
|
||||
|
||||
return v;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void injectFragment(AppComponent component) {
|
||||
component.inject(this);
|
||||
}
|
||||
|
||||
public void setViewPagerAdapter() {
|
||||
android.support.v4.app.FragmentManager fragmentManager = getChildFragmentManager();
|
||||
|
||||
viewPager.setAdapter(new FragmentPagerAdapter(fragmentManager) {
|
||||
|
||||
@Override
|
||||
public Fragment getItem(int position) {
|
||||
|
||||
ShopFragment fragment = new ShopFragment();
|
||||
|
||||
switch (position) {
|
||||
case 0: {
|
||||
fragment.shopIdentifier = Shop.MARKET;
|
||||
break;
|
||||
}
|
||||
case 1: {
|
||||
fragment.shopIdentifier = Shop.QUEST_SHOP;
|
||||
break;
|
||||
}
|
||||
case 2: {
|
||||
fragment.shopIdentifier = Shop.TIME_TRAVELERS_SHOP;
|
||||
break;
|
||||
}
|
||||
case 3: {
|
||||
fragment.shopIdentifier = Shop.SEASONAL_SHOP;
|
||||
break;
|
||||
}
|
||||
}
|
||||
fragment.user = ShopsFragment.this.user;
|
||||
|
||||
return fragment;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getCount() {
|
||||
return 4;
|
||||
}
|
||||
|
||||
@Override
|
||||
public CharSequence getPageTitle(int position) {
|
||||
switch (position) {
|
||||
case 0:
|
||||
return activity.getString(R.string.market);
|
||||
case 1:
|
||||
return activity.getString(R.string.quests);
|
||||
case 2:
|
||||
return activity.getString(R.string.timeTravelers);
|
||||
case 3:
|
||||
return activity.getString(R.string.seasonalShop);
|
||||
}
|
||||
return "";
|
||||
}
|
||||
});
|
||||
|
||||
if (tabLayout != null && viewPager != null) {
|
||||
tabLayout.setupWithViewPager(viewPager);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -11,6 +11,7 @@ import com.habitrpg.android.habitica.ui.fragments.faq.FAQOverviewFragment;
|
|||
import com.habitrpg.android.habitica.ui.fragments.inventory.customization.AvatarOverviewFragment;
|
||||
import com.habitrpg.android.habitica.ui.fragments.inventory.equipment.EquipmentOverviewFragment;
|
||||
import com.habitrpg.android.habitica.ui.fragments.inventory.items.ItemsFragment;
|
||||
import com.habitrpg.android.habitica.ui.fragments.inventory.shops.ShopsFragment;
|
||||
import com.habitrpg.android.habitica.ui.fragments.inventory.stable.StableFragment;
|
||||
import com.habitrpg.android.habitica.ui.fragments.skills.SkillsFragment;
|
||||
import com.habitrpg.android.habitica.ui.fragments.social.GuildsOverviewFragment;
|
||||
|
|
@ -37,15 +38,16 @@ public class MainDrawerBuilder {
|
|||
public static final int SIDEBAR_TAVERN = 3;
|
||||
public static final int SIDEBAR_PARTY = 4;
|
||||
public static final int SIDEBAR_GUILDS = 5;
|
||||
public static final int SIDEBAR_AVATAR = 6;
|
||||
public static final int SIDEBAR_EQUIPMENT = 7;
|
||||
public static final int SIDEBAR_ITEMS = 8;
|
||||
public static final int SIDEBAR_STABLE = 9;
|
||||
public static final int SIDEBAR_PURCHASE = 10;
|
||||
public static final int SIDEBAR_NEWS = 11;
|
||||
public static final int SIDEBAR_SETTINGS = 12;
|
||||
public static final int SIDEBAR_HELP = 13;
|
||||
public static final int SIDEBAR_ABOUT = 14;
|
||||
public static final int SIDEBAR_SHOPS = 6;
|
||||
public static final int SIDEBAR_AVATAR = 7;
|
||||
public static final int SIDEBAR_EQUIPMENT = 8;
|
||||
public static final int SIDEBAR_ITEMS = 9;
|
||||
public static final int SIDEBAR_STABLE = 10;
|
||||
public static final int SIDEBAR_PURCHASE = 11;
|
||||
public static final int SIDEBAR_NEWS = 12;
|
||||
public static final int SIDEBAR_SETTINGS = 13;
|
||||
public static final int SIDEBAR_HELP = 14;
|
||||
public static final int SIDEBAR_ABOUT = 15;
|
||||
|
||||
public static AccountHeaderBuilder CreateDefaultAccountHeader(final Activity activity) {
|
||||
return new AccountHeaderBuilder()
|
||||
|
|
@ -80,6 +82,7 @@ public class MainDrawerBuilder {
|
|||
new PrimaryDrawerItem().withName(activity.getString(R.string.sidebar_guilds)).withIdentifier(SIDEBAR_GUILDS),
|
||||
|
||||
new SectionIconDrawerItem().withName(activity.getString(R.string.sidebar_section_inventory).toUpperCase()),
|
||||
new PrimaryDrawerItem().withName(activity.getString(R.string.sidebar_shops)).withIdentifier(SIDEBAR_SHOPS),
|
||||
new PrimaryDrawerItem().withName(activity.getString(R.string.sidebar_avatar)).withIdentifier(SIDEBAR_AVATAR),
|
||||
new PrimaryDrawerItem().withName(activity.getString(R.string.sidebar_equipment)).withIdentifier(SIDEBAR_EQUIPMENT),
|
||||
new PrimaryDrawerItem().withName(activity.getString(R.string.sidebar_items)).withIdentifier(SIDEBAR_ITEMS),
|
||||
|
|
@ -124,6 +127,10 @@ public class MainDrawerBuilder {
|
|||
fragment = new TavernFragment();
|
||||
break;
|
||||
}
|
||||
case SIDEBAR_SHOPS: {
|
||||
fragment = new ShopsFragment();
|
||||
break;
|
||||
}
|
||||
case SIDEBAR_AVATAR: {
|
||||
fragment = new AvatarOverviewFragment();
|
||||
break;
|
||||
|
|
|
|||
|
|
@ -0,0 +1,39 @@
|
|||
package com.habitrpg.android.habitica.ui.viewHolders;
|
||||
|
||||
import com.habitrpg.android.habitica.R;
|
||||
|
||||
import android.content.Context;
|
||||
import android.support.v7.widget.RecyclerView;
|
||||
import android.view.View;
|
||||
import android.widget.Button;
|
||||
import android.widget.TextView;
|
||||
|
||||
import butterknife.BindView;
|
||||
import butterknife.ButterKnife;
|
||||
|
||||
public class SectionViewHolder extends RecyclerView.ViewHolder {
|
||||
|
||||
@BindView(R.id.label)
|
||||
TextView label;
|
||||
|
||||
@BindView(R.id.purchaseSetButton)
|
||||
Button purchaseSetButton;
|
||||
|
||||
Context context;
|
||||
|
||||
public SectionViewHolder(View itemView) {
|
||||
super(itemView);
|
||||
context = itemView.getContext();
|
||||
ButterKnife.bind(this, itemView);
|
||||
this.purchaseSetButton.setVisibility(View.GONE);
|
||||
}
|
||||
|
||||
public void bind(String title) {
|
||||
try {
|
||||
Integer stringID = context.getResources().getIdentifier("section" + title, "string", context.getPackageName());
|
||||
this.label.setText(context.getString(stringID));
|
||||
} catch (Exception e) {
|
||||
this.label.setText(title);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -9,6 +9,7 @@ import com.magicmicky.habitrpgwrapper.lib.models.PostChatMessageResult;
|
|||
import com.magicmicky.habitrpgwrapper.lib.models.PurchaseValidationRequest;
|
||||
import com.magicmicky.habitrpgwrapper.lib.models.PurchaseValidationResult;
|
||||
import com.magicmicky.habitrpgwrapper.lib.models.Quest;
|
||||
import com.magicmicky.habitrpgwrapper.lib.models.Shop;
|
||||
import com.magicmicky.habitrpgwrapper.lib.models.Status;
|
||||
import com.magicmicky.habitrpgwrapper.lib.models.Tag;
|
||||
import com.magicmicky.habitrpgwrapper.lib.models.TaskDirectionData;
|
||||
|
|
@ -220,6 +221,9 @@ public interface ApiService {
|
|||
@POST("members/send-private-message")
|
||||
Observable<PostChatMessageResult> postPrivateMessage(@Body HashMap<String, String> messageDetails);
|
||||
|
||||
@GET("shops/{identifier}")
|
||||
Observable<Shop> fetchShopInventory(@Path("identifier") String identifier);
|
||||
|
||||
//DEBUG: These calls only work on a local development server
|
||||
|
||||
@POST("debug/add-ten-gems")
|
||||
|
|
|
|||
|
|
@ -0,0 +1,57 @@
|
|||
package com.magicmicky.habitrpgwrapper.lib.models;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public class Shop {
|
||||
|
||||
public static final String MARKET = "market";
|
||||
public static final String QUEST_SHOP = "questShop";
|
||||
public static final String TIME_TRAVELERS_SHOP = "timeTravelersShop";
|
||||
public static final String SEASONAL_SHOP = "seasonalShop";
|
||||
public String identifier;
|
||||
public String text;
|
||||
public String notes;
|
||||
public String imageName;
|
||||
|
||||
public List<ShopCategory> categories;
|
||||
|
||||
public String getIdentifier() {
|
||||
return identifier;
|
||||
}
|
||||
|
||||
public void setIdentifier(String identifier) {
|
||||
this.identifier = identifier;
|
||||
}
|
||||
|
||||
public String getText() {
|
||||
return text;
|
||||
}
|
||||
|
||||
public void setText(String text) {
|
||||
this.text = text;
|
||||
}
|
||||
|
||||
public String getNotes() {
|
||||
return notes;
|
||||
}
|
||||
|
||||
public void setNotes(String notes) {
|
||||
this.notes = notes;
|
||||
}
|
||||
|
||||
public String getImageName() {
|
||||
return imageName;
|
||||
}
|
||||
|
||||
public void setImageName(String imageName) {
|
||||
this.imageName = imageName;
|
||||
}
|
||||
|
||||
public List<ShopCategory> getCategories() {
|
||||
return categories;
|
||||
}
|
||||
|
||||
public void setCategories(List<ShopCategory> categories) {
|
||||
this.categories = categories;
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,53 @@
|
|||
package com.magicmicky.habitrpgwrapper.lib.models;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public class ShopCategory {
|
||||
|
||||
public String identifier;
|
||||
public String text;
|
||||
public String notes;
|
||||
public Boolean purchaseAll;
|
||||
|
||||
public List<ShopItem> items;
|
||||
|
||||
public String getIdentifier() {
|
||||
return identifier;
|
||||
}
|
||||
|
||||
public void setIdentifier(String identifier) {
|
||||
this.identifier = identifier;
|
||||
}
|
||||
|
||||
public String getText() {
|
||||
return text;
|
||||
}
|
||||
|
||||
public void setText(String text) {
|
||||
this.text = text;
|
||||
}
|
||||
|
||||
public String getNotes() {
|
||||
return notes;
|
||||
}
|
||||
|
||||
public void setNotes(String notes) {
|
||||
this.notes = notes;
|
||||
}
|
||||
|
||||
public Boolean getPurchaseAll() {
|
||||
return purchaseAll;
|
||||
}
|
||||
|
||||
public void setPurchaseAll(Boolean purchaseAll) {
|
||||
this.purchaseAll = purchaseAll;
|
||||
}
|
||||
|
||||
public List<ShopItem> getItems() {
|
||||
return items;
|
||||
}
|
||||
|
||||
public void setItems(List<ShopItem> items) {
|
||||
this.items = items;
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,83 @@
|
|||
package com.magicmicky.habitrpgwrapper.lib.models;
|
||||
|
||||
import com.google.gson.annotations.SerializedName;
|
||||
|
||||
public class ShopItem {
|
||||
|
||||
public String key;
|
||||
public String text;
|
||||
public String notes;
|
||||
@SerializedName("class") public String imageName;
|
||||
public Integer value;
|
||||
public Boolean locked;
|
||||
public String currency;
|
||||
public String purchaseType;
|
||||
|
||||
public String getKey() {
|
||||
return key;
|
||||
}
|
||||
|
||||
public void setKey(String key) {
|
||||
this.key = key;
|
||||
}
|
||||
|
||||
public String getText() {
|
||||
return text;
|
||||
}
|
||||
|
||||
public void setText(String text) {
|
||||
this.text = text;
|
||||
}
|
||||
|
||||
public String getNotes() {
|
||||
return notes;
|
||||
}
|
||||
|
||||
public void setNotes(String notes) {
|
||||
this.notes = notes;
|
||||
}
|
||||
|
||||
public String getImageName() {
|
||||
if (imageName != null) {
|
||||
return imageName;
|
||||
} else {
|
||||
return "shop_"+key;
|
||||
}
|
||||
}
|
||||
|
||||
public void setImageName(String imageName) {
|
||||
this.imageName = imageName;
|
||||
}
|
||||
|
||||
public Integer getValue() {
|
||||
return value;
|
||||
}
|
||||
|
||||
public void setValue(Integer value) {
|
||||
this.value = value;
|
||||
}
|
||||
|
||||
public Boolean getLocked() {
|
||||
return locked;
|
||||
}
|
||||
|
||||
public void setLocked(Boolean locked) {
|
||||
this.locked = locked;
|
||||
}
|
||||
|
||||
public String getCurrency() {
|
||||
return currency;
|
||||
}
|
||||
|
||||
public void setCurrency(String currency) {
|
||||
this.currency = currency;
|
||||
}
|
||||
|
||||
public String getPurchaseType() {
|
||||
return purchaseType;
|
||||
}
|
||||
|
||||
public void setPurchaseType(String purchaseType) {
|
||||
this.purchaseType = purchaseType;
|
||||
}
|
||||
}
|
||||
Loading…
Reference in a new issue