mirror of
https://github.com/sudoxnym/habitica-android.git
synced 2026-07-18 03:52:23 +00:00
start building new purchase dialog
This commit is contained in:
parent
cd3a8b5d43
commit
31baca2d26
9 changed files with 287 additions and 20 deletions
|
|
@ -1,8 +1,11 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<merge xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:tools="http://schemas.android.com/tools"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="36dp"
|
||||
android:gravity="center_vertical">
|
||||
android:gravity="center_vertical"
|
||||
tools:parentTag="LinearLayout"
|
||||
tools:orientation="horizontal">
|
||||
<TextView
|
||||
android:id="@+id/hourglassTextView"
|
||||
android:drawableLeft="@drawable/currency_hourglass"
|
||||
|
|
|
|||
101
Habitica/res/layout/dialog_purchase_shopitem.xml
Normal file
101
Habitica/res/layout/dialog_purchase_shopitem.xml
Normal file
|
|
@ -0,0 +1,101 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:tools="http://schemas.android.com/tools"
|
||||
android:orientation="vertical"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:background="@color/white">
|
||||
|
||||
<LinearLayout
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:paddingLeft="16dp"
|
||||
android:paddingRight="16dp"
|
||||
android:paddingTop="12dp"
|
||||
android:paddingBottom="12dp"
|
||||
android:background="@color/gray_700">
|
||||
<TextView
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_weight="1"
|
||||
android:maxLines="1"
|
||||
android:text="@string/your_balance"
|
||||
android:layout_gravity="center_vertical"/>
|
||||
<com.habitrpg.android.habitica.ui.views.CurrencyView
|
||||
android:id="@+id/currencyView"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content" />
|
||||
</LinearLayout>
|
||||
<TextView
|
||||
android:id="@+id/limitedTextView"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:gravity="center"
|
||||
style="@style/Body1"
|
||||
android:textSize="12sp"
|
||||
android:padding="4dp"
|
||||
android:background="@color/brand_300"
|
||||
android:textColor="@color/white"
|
||||
tools:text="Available until May 6"/>
|
||||
<FrameLayout
|
||||
android:id="@+id/content_container"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:minHeight="100dp"/>
|
||||
<View
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="1dp"
|
||||
android:background="@color/gray_600"/>
|
||||
<RelativeLayout
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:paddingLeft="12dp"
|
||||
android:paddingRight="12dp"
|
||||
android:paddingTop="8dp"
|
||||
android:paddingBottom="8dp">
|
||||
<ImageButton
|
||||
android:id="@+id/pinButton"
|
||||
android:layout_width="40dp"
|
||||
android:layout_height="40dp"
|
||||
android:layout_alignParentLeft="true"
|
||||
android:layout_centerVertical="true"/>
|
||||
<LinearLayout
|
||||
android:id="@+id/buyButton"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="40dp"
|
||||
android:gravity="center"
|
||||
android:background="@drawable/layout_rounded_bg_gray_700"
|
||||
android:layout_alignParentRight="true"
|
||||
android:paddingLeft="16dp"
|
||||
android:paddingRight="16dp">
|
||||
<TextView
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="@string/reward.dialog.buy"
|
||||
android:textAllCaps="true"
|
||||
android:textColor="@color/brand_300"
|
||||
style="@style/Body1" />
|
||||
<ImageView
|
||||
android:id="@+id/currency_icon_view"
|
||||
android:layout_width="@dimen/currency_icon_size"
|
||||
android:layout_height="@dimen/currency_icon_size"
|
||||
tools:src="@drawable/currency_gem" />
|
||||
<TextView
|
||||
android:id="@+id/priceLabel"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
tools:text="10"
|
||||
tools:textColor="@color/good_10"
|
||||
style="@style/Body1" />
|
||||
</LinearLayout>
|
||||
<Button
|
||||
android:id="@+id/closeButton"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="40dp"
|
||||
style="@style/Base.Widget.AppCompat.Button.Borderless.Colored"
|
||||
android:text="@string/close"
|
||||
android:layout_toLeftOf="@id/buyButton"
|
||||
android:layout_marginRight="12dp"/>
|
||||
|
||||
</RelativeLayout>
|
||||
</LinearLayout>
|
||||
|
|
@ -113,4 +113,5 @@
|
|||
<dimen name="shopitem_status_size">24dp</dimen>
|
||||
<dimen name="shopitem_image_size">68dp</dimen>
|
||||
<dimen name="shop_scene_height">186dp</dimen>
|
||||
<dimen name="currency_icon_size">24dp</dimen>
|
||||
</resources>
|
||||
|
|
|
|||
|
|
@ -627,4 +627,6 @@
|
|||
<string name="thousand_abbrev">k</string>
|
||||
<string name="million_abbrev">m</string>
|
||||
<string name="billion_abbrev">b</string>
|
||||
<string name="your_balance">Your balance:</string>
|
||||
<string name="available_until" formatted="false">Available until %s</string>
|
||||
</resources>
|
||||
|
|
|
|||
|
|
@ -83,6 +83,7 @@ import com.habitrpg.android.habitica.ui.fragments.social.party.PartyInviteFragme
|
|||
import com.habitrpg.android.habitica.ui.fragments.social.party.PartyMemberListFragment;
|
||||
import com.habitrpg.android.habitica.ui.fragments.tasks.TaskRecyclerViewFragment;
|
||||
import com.habitrpg.android.habitica.ui.fragments.tasks.TasksFragment;
|
||||
import com.habitrpg.android.habitica.ui.views.shops.PurchaseDialog;
|
||||
import com.habitrpg.android.habitica.ui.views.tasks.TaskFilterDialog;
|
||||
import com.habitrpg.android.habitica.widget.AvatarStatsWidgetProvider;
|
||||
import com.habitrpg.android.habitica.widget.BaseWidgetProvider;
|
||||
|
|
@ -274,4 +275,6 @@ public interface AppComponent {
|
|||
void inject(PartyDetailFragment partyDetailFragment);
|
||||
|
||||
void inject(QuestDetailFragment questDetailFragment);
|
||||
|
||||
void inject(PurchaseDialog purchaseDialog);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,13 +1,18 @@
|
|||
package com.habitrpg.android.habitica.interactors;
|
||||
|
||||
import android.content.Context;
|
||||
import android.support.v4.content.ContextCompat;
|
||||
import android.support.v4.util.Pair;
|
||||
import android.support.v7.app.AppCompatActivity;
|
||||
import android.text.SpannableString;
|
||||
import android.text.SpannableStringBuilder;
|
||||
import android.text.style.DynamicDrawableSpan;
|
||||
import android.text.style.ImageSpan;
|
||||
import android.view.Gravity;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
import android.widget.LinearLayout;
|
||||
import android.widget.TextView;
|
||||
|
||||
import com.habitrpg.android.habitica.R;
|
||||
import com.habitrpg.android.habitica.data.UserRepository;
|
||||
|
|
@ -48,15 +53,58 @@ public class NotifyUserUseCase extends UseCase<NotifyUserUseCase.RequestValues,
|
|||
.flatMap(aVoid -> userRepository.retrieveUser(false))
|
||||
.map(User::getStats);
|
||||
} else {
|
||||
Pair<SpannableStringBuilder, SnackbarDisplayType> pair = getNotificationAndAddStatsToUser(requestValues.context, requestValues.xp, requestValues.hp, requestValues.gold, requestValues.mp);
|
||||
showSnackbar(requestValues.context, requestValues.snackbarTargetView, pair.first, pair.second);
|
||||
Pair<View, SnackbarDisplayType> pair = getNotificationAndAddStatsToUser(requestValues.context, requestValues.xp, requestValues.hp, requestValues.gold, requestValues.mp);
|
||||
showSnackbar(requestValues.context, requestValues.snackbarTargetView, null, null, pair.first, pair.second);
|
||||
return Observable.just(stats);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
public static Pair<SpannableStringBuilder, SnackbarDisplayType> getNotificationAndAddStatsToUser(Context context, double xp, double hp, double gold, double mp){
|
||||
public static Pair<View, SnackbarDisplayType> getNotificationAndAddStatsToUser(Context context, double xp, double hp, double gold, double mp){
|
||||
|
||||
SnackbarDisplayType displayType = SnackbarDisplayType.NORMAL;
|
||||
|
||||
LinearLayout container = new LinearLayout(context);
|
||||
container.setOrientation(LinearLayout.HORIZONTAL);
|
||||
|
||||
if (xp > 0) {
|
||||
container.addView(createTextView(context, " + "+String.valueOf(round(xp, 2)), R.drawable.ic_header_exp));
|
||||
}
|
||||
if (hp != 0) {
|
||||
displayType = SnackbarDisplayType.FAILURE;
|
||||
container.addView(createTextView(context, " - "+String.valueOf(Math.abs(round(hp, 2))), R.drawable.ic_header_heart));
|
||||
}
|
||||
if (gold != 0) {
|
||||
if (gold > 0) {
|
||||
container.addView(createTextView(context, " + "+String.valueOf(round(gold, 2)), R.drawable.currency_gold));
|
||||
} else if (gold < 0) {
|
||||
displayType = SnackbarDisplayType.FAILURE;
|
||||
container.addView(createTextView(context, " - "+String.valueOf(Math.abs(round(gold, 2))), R.drawable.currency_gold));
|
||||
}
|
||||
}
|
||||
if (mp > 0) {
|
||||
container.addView(createTextView(context, " + "+String.valueOf(round(mp, 2)), R.drawable.ic_header_magic));
|
||||
}
|
||||
|
||||
int padding = (int) context.getResources().getDimension(R.dimen.spacing_medium);
|
||||
for (int index = 1 ; index < container.getChildCount() ; index++) {
|
||||
View view = container.getChildAt(index);
|
||||
view.setPadding(padding, 0, 0, 0);
|
||||
}
|
||||
|
||||
return new Pair<>(container, displayType);
|
||||
}
|
||||
|
||||
private static View createTextView(Context context, String text, int icon) {
|
||||
TextView textView = new TextView(context);
|
||||
textView.setCompoundDrawablesWithIntrinsicBounds(icon, 0, 0, 0);
|
||||
textView.setText(text);
|
||||
textView.setGravity(Gravity.CENTER_VERTICAL);
|
||||
textView.setTextColor(ContextCompat.getColor(context, R.color.white));
|
||||
return textView;
|
||||
}
|
||||
|
||||
public static Pair<SpannableStringBuilder, SnackbarDisplayType> getNotificationAndAddStatsToUserAsText(Context context, double xp, double hp, double gold, double mp) {
|
||||
SpannableStringBuilder builder = new SpannableStringBuilder();
|
||||
SnackbarDisplayType displayType = SnackbarDisplayType.NORMAL;
|
||||
|
||||
|
|
@ -83,7 +131,7 @@ public class NotifyUserUseCase extends UseCase<NotifyUserUseCase.RequestValues,
|
|||
return new Pair<>(builder, displayType);
|
||||
}
|
||||
|
||||
public static final class RequestValues implements UseCase.RequestValues {
|
||||
public static final class RequestValues implements UseCase.RequestValues {
|
||||
|
||||
private AppCompatActivity context;
|
||||
private ViewGroup snackbarTargetView;
|
||||
|
|
|
|||
|
|
@ -30,6 +30,7 @@ import com.facebook.imagepipeline.datasource.BaseBitmapDataSubscriber;
|
|||
import com.facebook.imagepipeline.image.CloseableImage;
|
||||
import com.facebook.imagepipeline.request.ImageRequest;
|
||||
import com.facebook.imagepipeline.request.ImageRequestBuilder;
|
||||
import com.habitrpg.android.habitica.HabiticaBaseApplication;
|
||||
import com.habitrpg.android.habitica.R;
|
||||
import com.habitrpg.android.habitica.events.commands.BuyGemItemCommand;
|
||||
import com.habitrpg.android.habitica.helpers.TiledBitmapPostProcessor;
|
||||
|
|
@ -39,6 +40,7 @@ import com.habitrpg.android.habitica.models.shops.ShopItem;
|
|||
import com.habitrpg.android.habitica.ui.ItemDetailDialog;
|
||||
import com.habitrpg.android.habitica.ui.helpers.DataBindingUtils;
|
||||
import com.habitrpg.android.habitica.ui.viewHolders.SectionViewHolder;
|
||||
import com.habitrpg.android.habitica.ui.views.shops.PurchaseDialog;
|
||||
|
||||
import org.greenrobot.eventbus.EventBus;
|
||||
|
||||
|
|
@ -215,15 +217,7 @@ public class ShopRecyclerAdapter extends RecyclerView.Adapter<RecyclerView.ViewH
|
|||
|
||||
@Override
|
||||
public void onClick(View view) {
|
||||
ItemDetailDialog dialog = new ItemDetailDialog(context);
|
||||
dialog.setTitle(item.getText());
|
||||
dialog.setDescription(Html.fromHtml(item.getNotes()));
|
||||
dialog.setImage(item.getImageName());
|
||||
if (item.getUnlockCondition() == null) {
|
||||
dialog.setCurrency(item.getCurrency());
|
||||
dialog.setValue(item.getValue());
|
||||
dialog.setBuyListener((clickedDialog, which) -> this.buyItem());
|
||||
}
|
||||
PurchaseDialog dialog = new PurchaseDialog(context, HabiticaBaseApplication.getComponent(), item);
|
||||
dialog.show();
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -86,11 +86,11 @@ public class ShopsFragment extends BaseMainFragment {
|
|||
fragment.shopIdentifier = Shop.QUEST_SHOP;
|
||||
break;
|
||||
}
|
||||
//case 2: {
|
||||
// fragment.shopIdentifier = Shop.TIME_TRAVELERS_SHOP;
|
||||
// break;
|
||||
//}
|
||||
case 2: {
|
||||
fragment.shopIdentifier = Shop.TIME_TRAVELERS_SHOP;
|
||||
break;
|
||||
}
|
||||
case 3: {
|
||||
fragment.shopIdentifier = Shop.SEASONAL_SHOP;
|
||||
break;
|
||||
}
|
||||
|
|
@ -112,9 +112,9 @@ public class ShopsFragment extends BaseMainFragment {
|
|||
return activity.getString(R.string.market);
|
||||
case 1:
|
||||
return activity.getString(R.string.quests);
|
||||
//case 2:
|
||||
// return activity.getString(R.string.timeTravelers);
|
||||
case 2:
|
||||
return activity.getString(R.string.timeTravelers);
|
||||
case 3:
|
||||
return activity.getString(R.string.seasonalShop);
|
||||
}
|
||||
return "";
|
||||
|
|
|
|||
|
|
@ -0,0 +1,115 @@
|
|||
package com.habitrpg.android.habitica.ui.views.shops;
|
||||
|
||||
import android.app.AlertDialog;
|
||||
import android.content.Context;
|
||||
import android.support.v4.content.ContextCompat;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
import android.widget.ImageView;
|
||||
import android.widget.TextView;
|
||||
|
||||
import com.habitrpg.android.habitica.R;
|
||||
import com.habitrpg.android.habitica.components.AppComponent;
|
||||
import com.habitrpg.android.habitica.data.UserRepository;
|
||||
import com.habitrpg.android.habitica.helpers.RxErrorHandler;
|
||||
import com.habitrpg.android.habitica.models.shops.ShopItem;
|
||||
import com.habitrpg.android.habitica.models.user.User;
|
||||
import com.habitrpg.android.habitica.ui.helpers.DataBindingUtils;
|
||||
import com.habitrpg.android.habitica.ui.views.CurrencyView;
|
||||
|
||||
import java.util.Date;
|
||||
|
||||
import javax.inject.Inject;
|
||||
|
||||
import butterknife.BindView;
|
||||
import butterknife.ButterKnife;
|
||||
import butterknife.OnClick;
|
||||
|
||||
/**
|
||||
* Created by phillip on 21.07.17.
|
||||
*/
|
||||
|
||||
public class PurchaseDialog extends AlertDialog {
|
||||
|
||||
@Inject
|
||||
UserRepository userRepository;
|
||||
|
||||
@BindView(R.id.currencyView)
|
||||
CurrencyView currencyView;
|
||||
@BindView(R.id.limitedTextView)
|
||||
TextView limitedTextView;
|
||||
@BindView(R.id.priceLabel)
|
||||
TextView priceLabel;
|
||||
@BindView(R.id.currency_icon_view)
|
||||
ImageView currencyIconView;
|
||||
@BindView(R.id.buyButton)
|
||||
View buyButton;
|
||||
private ShopItem shopItem;
|
||||
|
||||
public PurchaseDialog(Context context, AppComponent component, ShopItem item) {
|
||||
super(context);
|
||||
|
||||
component.inject(this);
|
||||
|
||||
LayoutInflater inflater = LayoutInflater.from(context);
|
||||
View view = inflater.inflate(R.layout.dialog_purchase_shopitem, null);
|
||||
ButterKnife.bind(this, view);
|
||||
setView(view);
|
||||
|
||||
setShopItem(item);
|
||||
|
||||
userRepository.getUser().subscribe(this::setUser, RxErrorHandler.handleEmptyError());
|
||||
}
|
||||
|
||||
private void setUser(User user) {
|
||||
currencyView.setGold(user.getStats().getGp());
|
||||
currencyView.setGems(user.getGemCount());
|
||||
currencyView.setHourglasses(user.getHourglassCount());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void dismiss() {
|
||||
userRepository.close();
|
||||
super.dismiss();
|
||||
}
|
||||
|
||||
private void setShopItem(ShopItem item) {
|
||||
this.shopItem = item;
|
||||
|
||||
buyButton.setVisibility(View.VISIBLE);
|
||||
|
||||
if (item.getUnlockCondition() == null) {
|
||||
priceLabel.setText(item.getValue().toString());
|
||||
if (item.getCurrency().equals("gold")) {
|
||||
currencyIconView.setImageResource(R.drawable.currency_gold);
|
||||
priceLabel.setTextColor(ContextCompat.getColor(getContext(), R.color.gold));
|
||||
} else if (item.getCurrency().equals("gems")) {
|
||||
currencyIconView.setImageResource(R.drawable.currency_gem);
|
||||
priceLabel.setTextColor(ContextCompat.getColor(getContext(), R.color.good_10));
|
||||
} else {
|
||||
buyButton.setVisibility(View.GONE);
|
||||
}
|
||||
} else {
|
||||
buyButton.setVisibility(View.GONE);
|
||||
}
|
||||
|
||||
if (item.isLimited()) {
|
||||
//TODO: replace with correct date once API is final
|
||||
limitedTextView.setText(getContext().getString(R.string.available_until, new Date().toString()));
|
||||
} else {
|
||||
limitedTextView.setVisibility(View.GONE);
|
||||
}
|
||||
|
||||
if (item.getLocked()) {
|
||||
priceLabel.setTextColor(ContextCompat.getColor(getContext(), R.color.gray_300));
|
||||
currencyIconView.setAlpha(0.5f);
|
||||
} else {
|
||||
currencyIconView.setAlpha(1.0f);
|
||||
}
|
||||
}
|
||||
|
||||
@OnClick(R.id.closeButton)
|
||||
public void onCloseClicked() {
|
||||
dismiss();
|
||||
}
|
||||
}
|
||||
Loading…
Reference in a new issue