mirror of
https://github.com/sudoxnym/habitica-android.git
synced 2026-04-14 19:56:32 +00:00
Improvements to shops
This commit is contained in:
parent
2ddc426d6b
commit
52624c7e7c
5 changed files with 64 additions and 33 deletions
|
|
@ -138,6 +138,7 @@ import java.util.concurrent.TimeUnit;
|
|||
import javax.inject.Inject;
|
||||
|
||||
import butterknife.BindView;
|
||||
import retrofit2.adapter.rxjava.HttpException;
|
||||
import rx.Observable;
|
||||
import rx.functions.Action1;
|
||||
|
||||
|
|
@ -868,26 +869,38 @@ public class MainActivity extends BaseActivity implements Action1<Throwable>, Ha
|
|||
|
||||
@Subscribe
|
||||
public void onEvent(final BuyGemItemCommand event) {
|
||||
Observable<Void> observable;
|
||||
if (event.shopIdentifier.equals(Shop.TIME_TRAVELERS_SHOP)) {
|
||||
if (event.item.purchaseType.equals("gear")) {
|
||||
observable = apiHelper.apiService.purchaseMysterySet(event.item.categoryIdentifier);
|
||||
if (event.item.canBuy(user) || !event.item.getCurrency().equals("gems")) {
|
||||
Observable<Void> observable;
|
||||
if (event.shopIdentifier.equals(Shop.TIME_TRAVELERS_SHOP)) {
|
||||
if (event.item.purchaseType.equals("gear")) {
|
||||
observable = apiHelper.apiService.purchaseMysterySet(event.item.categoryIdentifier);
|
||||
} else {
|
||||
observable = apiHelper.apiService.purchaseHourglassItem(event.item.purchaseType, event.item.key);
|
||||
}
|
||||
} else if (event.item.purchaseType.equals("quests")) {
|
||||
observable = apiHelper.apiService.purchaseQuest(event.item.key);
|
||||
} else {
|
||||
observable = apiHelper.apiService.purchaseHourglassItem(event.item.purchaseType, event.item.key);
|
||||
observable = apiHelper.apiService.purchaseItem(event.item.purchaseType, event.item.key);
|
||||
}
|
||||
observable
|
||||
.compose(apiHelper.configureApiCallObserver())
|
||||
.doOnNext(aVoid -> {
|
||||
showSnackbar(this, floatingMenuWrapper, getString(R.string.successful_purchase, event.item.text), SnackbarDisplayType.NORMAL);
|
||||
})
|
||||
.subscribe(buyResponse -> {
|
||||
apiHelper.retrieveUser(false)
|
||||
.compose(apiHelper.configureApiCallObserver())
|
||||
.subscribe(new HabitRPGUserCallback(this), throwable -> {
|
||||
});
|
||||
}, throwable -> {
|
||||
HttpException error = (HttpException) throwable;
|
||||
if (error.code() == 401 && event.item.getCurrency().equals("gems")) {
|
||||
openGemPurchaseFragment(null);
|
||||
}
|
||||
});
|
||||
} else {
|
||||
observable = apiHelper.apiService.purchaseItem(event.item.purchaseType, event.item.key);
|
||||
openGemPurchaseFragment(null);
|
||||
}
|
||||
observable
|
||||
.compose(apiHelper.configureApiCallObserver())
|
||||
.doOnNext(aVoid -> {
|
||||
showSnackbar(this, floatingMenuWrapper, getString(R.string.successful_purchase, event.item.text), SnackbarDisplayType.NORMAL);
|
||||
})
|
||||
.subscribe(buyResponse -> {
|
||||
apiHelper.retrieveUser(false)
|
||||
.compose(apiHelper.configureApiCallObserver())
|
||||
.subscribe(new HabitRPGUserCallback(this), throwable -> {});
|
||||
}, throwable -> {});
|
||||
}
|
||||
|
||||
@Subscribe
|
||||
|
|
@ -978,7 +991,7 @@ public class MainActivity extends BaseActivity implements Action1<Throwable>, Ha
|
|||
}
|
||||
|
||||
@Subscribe
|
||||
public void onEvent(OpenGemPurchaseFragmentCommand cmd) {
|
||||
public void openGemPurchaseFragment(OpenGemPurchaseFragmentCommand cmd) {
|
||||
drawer.setSelection(MainDrawerBuilder.SIDEBAR_PURCHASE);
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -162,6 +162,10 @@ public class ShopRecyclerAdapter extends RecyclerView.Adapter<RecyclerView.ViewH
|
|||
});
|
||||
}
|
||||
|
||||
private void canBuy() {
|
||||
|
||||
}
|
||||
|
||||
private void buyItem() {
|
||||
BuyGemItemCommand command = new BuyGemItemCommand();
|
||||
command.shopIdentifier = shopIdentifier;
|
||||
|
|
@ -171,6 +175,7 @@ public class ShopRecyclerAdapter extends RecyclerView.Adapter<RecyclerView.ViewH
|
|||
|
||||
public void bind(ShopItem item) {
|
||||
this.item = item;
|
||||
buyButton.setVisibility(View.VISIBLE);
|
||||
titleView.setText(item.getText());
|
||||
descriptionView.setText(Html.fromHtml(item.getNotes()));
|
||||
|
||||
|
|
@ -178,15 +183,12 @@ public class ShopRecyclerAdapter extends RecyclerView.Adapter<RecyclerView.ViewH
|
|||
|
||||
if (item.getUnlockCondition() == null) {
|
||||
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);
|
||||
if (item.getCurrency().equals("gold")) {
|
||||
buyButton.setCompoundDrawablesWithIntrinsicBounds(R.drawable.ic_header_gold, 0, 0, 0);
|
||||
} else if (item.getCurrency().equals("gems")) {
|
||||
buyButton.setCompoundDrawablesWithIntrinsicBounds(R.drawable.ic_header_gem, 0, 0, 0);
|
||||
} else {
|
||||
buyButton.setVisibility(View.GONE);
|
||||
}
|
||||
unlockView.setVisibility(View.GONE);
|
||||
} else {
|
||||
|
|
@ -194,6 +196,10 @@ public class ShopRecyclerAdapter extends RecyclerView.Adapter<RecyclerView.ViewH
|
|||
unlockView.setVisibility(View.VISIBLE);
|
||||
unlockView.setText(item.unlockCondition.readableUnlockConditionId());
|
||||
}
|
||||
|
||||
if (item.getLocked()) {
|
||||
buyButton.setVisibility(View.GONE);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
|||
|
|
@ -3,11 +3,8 @@ 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;
|
||||
|
|
@ -15,7 +12,6 @@ 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;
|
||||
|
|
@ -44,7 +40,7 @@ public class ShopFragment extends BaseFragment {
|
|||
public Shop shop;
|
||||
|
||||
@Inject
|
||||
APIHelper apiHeliper;
|
||||
APIHelper apiHelper;
|
||||
|
||||
@Nullable
|
||||
@Override
|
||||
|
|
@ -104,8 +100,8 @@ public class ShopFragment extends BaseFragment {
|
|||
shopUrl = "seasonal";
|
||||
break;
|
||||
}
|
||||
this.apiHeliper.apiService.fetchShopInventory(shopUrl)
|
||||
.compose(this.apiHeliper.configureApiCallObserver())
|
||||
this.apiHelper.apiService.fetchShopInventory(shopUrl)
|
||||
.compose(this.apiHelper.configureApiCallObserver())
|
||||
.subscribe(shop -> {
|
||||
this.shop = shop;
|
||||
this.adapter.setShop(shop);
|
||||
|
|
|
|||
|
|
@ -75,6 +75,9 @@ public interface ApiService {
|
|||
@POST("user/buy-mystery-set/{key}")
|
||||
Observable<Void> purchaseMysterySet(@Path("key") String itemKey);
|
||||
|
||||
@POST("user/buy-quest/{key}")
|
||||
Observable<Void> purchaseQuest(@Path("key") String key);
|
||||
|
||||
@POST("user/sell/{type}/{key}")
|
||||
Observable<HabitRPGUser> sellItem(@Path("type") String itemType, @Path("key") String itemKey);
|
||||
|
||||
|
|
|
|||
|
|
@ -60,6 +60,9 @@ public class ShopItem {
|
|||
}
|
||||
|
||||
public Boolean getLocked() {
|
||||
if (locked == null) {
|
||||
return false;
|
||||
}
|
||||
return locked;
|
||||
}
|
||||
|
||||
|
|
@ -90,4 +93,14 @@ public class ShopItem {
|
|||
public void setUnlockCondition(ShopItemUnlockCondition unlockCondition) {
|
||||
this.unlockCondition = unlockCondition;
|
||||
}
|
||||
|
||||
public boolean canBuy(HabitRPGUser user) {
|
||||
if (getCurrency().equals("gold")) {
|
||||
return getValue() < user.getStats().getGp();
|
||||
} else if (getCurrency().equals("gems")) {
|
||||
return getValue() < user.getBalance();
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue