various shop improvements

This commit is contained in:
Phillip Thelen 2016-07-29 11:59:56 +02:00
parent f5f5f0012e
commit fcdeb8092b
7 changed files with 117 additions and 21 deletions

View file

@ -48,4 +48,15 @@
android:background="@drawable/rounded_purple_square"
android:paddingLeft="6dp"
android:paddingStart="6dp" />
<TextView
android:id="@+id/unlockView"
android:layout_marginLeft="8dp"
android:layout_marginStart="8dp"
android:layout_width="80dp"
android:layout_height="wrap_content"
tools:text="Description"
android:visibility="gone"
android:maxLines="5"
style="@style/RowText"
android:layout_gravity="center_vertical"/>
</LinearLayout>

View file

@ -352,4 +352,15 @@ To start, which parts of your life do you want to improve?</string>
<string name="timeTravelers">Time Travelers</string>
<string name="seasonalShop">Seasonal Shop</string>
<string name="empty_inbox">You don\'t have any Inbox messages. You can send a user a new message from their public chat messages!</string>
<string name="party_invite">Unlock by inviting friends</string>
<string name="no_gold">Not enough Gold</string>
<string name="no_potion">You don\'t need to buy an health potion</string>
<string name="successful_purchase" formatted="false">%1$s successfully purchased</string>
<string name="purchase_confirmation_title">Confirm purchase</string>
<string name="confirm_purchase_text" formatted="false">Purchase %1$s for %2$s %3$s</string>
<string name="gem">gem</string>
<string name="hourglass">hourglass</string>
<string name="hourglasses">hourglasses</string>
<string name="gold_singular">gold</string>
<string name="gems_plural">gold</string>
</resources>

View file

@ -8,6 +8,8 @@ import android.content.DialogInterface;
import android.support.annotation.NonNull;
import android.support.v4.content.ContextCompat;
import android.support.v7.app.AlertDialog;
import android.text.Spannable;
import android.text.Spanned;
import android.view.Gravity;
import android.view.View;
import android.widget.ImageView;
@ -84,7 +86,7 @@ public class ItemDetailDialog extends AlertDialog {
});
}
public void setDescription(String description) {
public void setDescription(CharSequence description) {
contentTextView.setText(description);
contentTextView.setVisibility(View.VISIBLE);
}
@ -97,6 +99,9 @@ public class ItemDetailDialog extends AlertDialog {
case "gems":
currencyImageView.setImageDrawable(ContextCompat.getDrawable(getContext(), R.drawable.ic_header_gem));
break;
default:
currencyImageView.setImageDrawable(null);
break;
}
}
@ -117,5 +122,4 @@ public class ItemDetailDialog extends AlertDialog {
public void setBuyListener(OnClickListener listener) {
this.setButton(BUTTON_POSITIVE, getContext().getText(R.string.reward_dialog_buy), listener);
}
}

View file

@ -880,6 +880,9 @@ public class MainActivity extends BaseActivity implements Action1<Throwable>, Ha
}
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())
@ -892,7 +895,7 @@ public class MainActivity extends BaseActivity implements Action1<Throwable>, Ha
final String rewardKey = event.Reward.getId();
if (user.getStats().getGp() < event.Reward.getValue()) {
showSnackbar(this, floatingMenuWrapper, "Not enough Gold", SnackbarDisplayType.FAILURE);
showSnackbar(this, floatingMenuWrapper, getString(R.string.no_gold), SnackbarDisplayType.FAILURE);
return;
}
@ -901,7 +904,7 @@ public class MainActivity extends BaseActivity implements Action1<Throwable>, Ha
int maxHp = user.getStats().getMaxHealth();
if (currentHp == maxHp) {
UiUtils.showSnackbar(this, floatingMenuWrapper, "You don't need to buy an health potion", SnackbarDisplayType.FAILURE_BLUE);
UiUtils.showSnackbar(this, floatingMenuWrapper, getString(R.string.no_potion), SnackbarDisplayType.FAILURE_BLUE);
return;
}
}
@ -910,7 +913,7 @@ public class MainActivity extends BaseActivity implements Action1<Throwable>, Ha
apiHelper.apiService.buyItem(event.Reward.getId())
.compose(apiHelper.configureApiCallObserver())
.subscribe(buyResponse -> {
String snackbarMessage = event.Reward.getText() + " successfully purchased!";
String snackbarMessage = getString(R.string.successful_purchase, event.Reward.getText());
if (event.Reward.getId().equals("armoire")) {
if (buyResponse.armoire.get("type").equals("gear")) {

View file

@ -12,6 +12,8 @@ import com.magicmicky.habitrpgwrapper.lib.models.ShopItem;
import org.greenrobot.eventbus.EventBus;
import android.content.Context;
import android.content.DialogInterface;
import android.support.v7.app.AlertDialog;
import android.support.v7.widget.RecyclerView;
import android.text.Html;
import android.text.method.LinkMovementMethod;
@ -112,6 +114,8 @@ public class ShopRecyclerAdapter extends RecyclerView.Adapter<RecyclerView.ViewH
TextView descriptionView;
@BindView(R.id.buyButton)
Button buyButton;
@BindView(R.id.unlockView)
TextView unlockView;
String shopIdentifier;
ShopItem item;
@ -128,7 +132,34 @@ public class ShopRecyclerAdapter extends RecyclerView.Adapter<RecyclerView.ViewH
itemView.setOnClickListener(this);
itemView.setClickable(true);
buyButton.setOnClickListener(view -> this.buyItem());
buyButton.setOnClickListener(view -> {
String currencyString = "";
if (item.getCurrency().equals("gems")) {
if (item.getValue() == 1) {
currencyString = context.getString(R.string.gem);
} else {
currencyString = context.getString(R.string.gems);
}
} else if (item.getCurrency().equals("gold")) {
if (item.getValue() == 1) {
currencyString = context.getString(R.string.gold_singular);
} else {
currencyString = context.getString(R.string.gems_plural);
}
} else if (item.getCurrency().equals("hourglasses")) {
if (item.getValue() == 1) {
currencyString = context.getString(R.string.hourglass);
} else {
currencyString = context.getString(R.string.hourglasses);
}
}
new AlertDialog.Builder(context)
.setTitle(R.string.purchase_confirmation_title)
.setMessage(context.getString(R.string.confirm_purchase_text, item.getText(), item.getValue().toString(), currencyString))
.setPositiveButton(android.R.string.yes, (dialog, which) -> this.buyItem())
.setNegativeButton(android.R.string.no, (dialog, which) -> dialog.dismiss())
.show();
});
}
private void buyItem() {
@ -141,20 +172,27 @@ public class ShopRecyclerAdapter extends RecyclerView.Adapter<RecyclerView.ViewH
public void bind(ShopItem item) {
this.item = item;
titleView.setText(item.getText());
descriptionView.setText(item.getNotes());
descriptionView.setText(Html.fromHtml(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);
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);
}
unlockView.setVisibility(View.GONE);
} else {
buyButton.setVisibility(View.GONE);
unlockView.setVisibility(View.VISIBLE);
unlockView.setText(item.unlockCondition.readableUnlockConditionId());
}
}
@ -162,11 +200,13 @@ public class ShopRecyclerAdapter extends RecyclerView.Adapter<RecyclerView.ViewH
public void onClick(View view) {
ItemDetailDialog dialog = new ItemDetailDialog(context);
dialog.setTitle(item.getText());
dialog.setDescription(item.getNotes());
dialog.setDescription(Html.fromHtml(item.getNotes()));
dialog.setImage(item.getImageName());
dialog.setCurrency(item.getCurrency());
dialog.setValue(item.getValue());
dialog.setBuyListener((clickedDialog, which) -> this.buyItem());
if (item.getUnlockCondition() == null) {
dialog.setCurrency(item.getCurrency());
dialog.setValue(item.getValue());
dialog.setBuyListener((clickedDialog, which) -> this.buyItem());
}
dialog.show();
}
}

View file

@ -13,6 +13,7 @@ public class ShopItem {
public String currency;
public String purchaseType;
public String categoryIdentifier;
public ShopItemUnlockCondition unlockCondition;
public String getKey() {
return key;
@ -81,4 +82,12 @@ public class ShopItem {
public void setPurchaseType(String purchaseType) {
this.purchaseType = purchaseType;
}
public ShopItemUnlockCondition getUnlockCondition() {
return unlockCondition;
}
public void setUnlockCondition(ShopItemUnlockCondition unlockCondition) {
this.unlockCondition = unlockCondition;
}
}

View file

@ -0,0 +1,18 @@
package com.magicmicky.habitrpgwrapper.lib.models;
import com.habitrpg.android.habitica.R;
public class ShopItemUnlockCondition {
String condition;
public int readableUnlockConditionId() {
switch (this.condition) {
case "party invite":
return R.string.party_invite;
default:
return 0;
}
}
}