Refactor
This commit is contained in:
parent
e7430dcd5b
commit
dd6c7c07e0
3 changed files with 76 additions and 44 deletions
|
@ -92,6 +92,38 @@
|
||||||
</LinearLayout>
|
</LinearLayout>
|
||||||
</LinearLayout>
|
</LinearLayout>
|
||||||
|
|
||||||
|
<LinearLayout
|
||||||
|
android:id="@+id/button_view"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:layout_gravity="center"
|
||||||
|
android:background="?attr/purchase_dialog_outline_btn_bg">
|
||||||
|
|
||||||
|
<LinearLayout
|
||||||
|
android:id="@+id/button"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:background="?attr/selectableItemBackground"
|
||||||
|
android:gravity="center"
|
||||||
|
android:orientation="horizontal"
|
||||||
|
android:padding="@dimen/list_header_padding">
|
||||||
|
|
||||||
|
<net.osmand.plus.widgets.TextViewEx
|
||||||
|
android:id="@+id/button_title"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:gravity="center"
|
||||||
|
android:letterSpacing="@dimen/text_button_letter_spacing"
|
||||||
|
android:maxWidth="@dimen/dialog_button_ex_max_width"
|
||||||
|
android:minWidth="@dimen/dialog_button_ex_min_width"
|
||||||
|
android:textColor="?attr/color_dialog_buttons"
|
||||||
|
android:textSize="@dimen/text_button_text_size"
|
||||||
|
osmand:typeface="@string/font_roboto_medium"
|
||||||
|
tools:text="7,99€ / year" />
|
||||||
|
|
||||||
|
</LinearLayout>
|
||||||
|
</LinearLayout>
|
||||||
|
|
||||||
<LinearLayout
|
<LinearLayout
|
||||||
android:id="@+id/button_ex_view"
|
android:id="@+id/button_ex_view"
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
|
|
|
@ -6,12 +6,10 @@ import android.app.Dialog;
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.content.DialogInterface;
|
import android.content.DialogInterface;
|
||||||
import android.content.Intent;
|
import android.content.Intent;
|
||||||
import android.content.res.Resources;
|
|
||||||
import android.net.Uri;
|
import android.net.Uri;
|
||||||
import android.os.Build;
|
import android.os.Build;
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
import android.text.TextUtils;
|
import android.text.TextUtils;
|
||||||
import android.util.TypedValue;
|
|
||||||
import android.view.ContextThemeWrapper;
|
import android.view.ContextThemeWrapper;
|
||||||
import android.view.LayoutInflater;
|
import android.view.LayoutInflater;
|
||||||
import android.view.View;
|
import android.view.View;
|
||||||
|
@ -355,7 +353,7 @@ public abstract class ChoosePlanDialogFragment extends BaseOsmAndDialogFragment
|
||||||
osmLiveCardButtonsContainer.removeAllViews();
|
osmLiveCardButtonsContainer.removeAllViews();
|
||||||
View lastBtn = null;
|
View lastBtn = null;
|
||||||
List<InAppSubscription> visibleSubscriptions = purchaseHelper.getLiveUpdates().getVisibleSubscriptions();
|
List<InAppSubscription> visibleSubscriptions = purchaseHelper.getLiveUpdates().getVisibleSubscriptions();
|
||||||
InAppSubscription subscriptionMaxDiscount = null;
|
InAppSubscription maxDiscountSubscription = null;
|
||||||
double maxDiscount = 0;
|
double maxDiscount = 0;
|
||||||
boolean anyPurchased = false;
|
boolean anyPurchased = false;
|
||||||
for (final InAppSubscription s : visibleSubscriptions) {
|
for (final InAppSubscription s : visibleSubscriptions) {
|
||||||
|
@ -364,12 +362,12 @@ public abstract class ChoosePlanDialogFragment extends BaseOsmAndDialogFragment
|
||||||
}
|
}
|
||||||
double discount = s.getDiscountPercent(purchaseHelper.getMonthlyLiveUpdates());
|
double discount = s.getDiscountPercent(purchaseHelper.getMonthlyLiveUpdates());
|
||||||
if (discount > maxDiscount) {
|
if (discount > maxDiscount) {
|
||||||
subscriptionMaxDiscount = s;
|
maxDiscountSubscription = s;
|
||||||
maxDiscount = discount;
|
maxDiscount = discount;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
boolean maxDiscountAction = subscriptionMaxDiscount != null
|
boolean maxDiscountAction = maxDiscountSubscription != null
|
||||||
&& (subscriptionMaxDiscount.getIntroductoryInfo() != null || subscriptionMaxDiscount.isUpgrade());
|
&& (maxDiscountSubscription.getIntroductoryInfo() != null || maxDiscountSubscription.isUpgrade());
|
||||||
for (final InAppSubscription s : visibleSubscriptions) {
|
for (final InAppSubscription s : visibleSubscriptions) {
|
||||||
InAppSubscriptionIntroductoryInfo introductoryInfo = s.getIntroductoryInfo();
|
InAppSubscriptionIntroductoryInfo introductoryInfo = s.getIntroductoryInfo();
|
||||||
boolean hasIntroductoryInfo = introductoryInfo != null;
|
boolean hasIntroductoryInfo = introductoryInfo != null;
|
||||||
|
@ -389,7 +387,11 @@ public abstract class ChoosePlanDialogFragment extends BaseOsmAndDialogFragment
|
||||||
CharSequence priceTitle = hasIntroductoryInfo ?
|
CharSequence priceTitle = hasIntroductoryInfo ?
|
||||||
introductoryInfo.getFormattedDescription(ctx, buttonTitle.getCurrentTextColor()) : s.getPriceWithPeriod(ctx);
|
introductoryInfo.getFormattedDescription(ctx, buttonTitle.getCurrentTextColor()) : s.getPriceWithPeriod(ctx);
|
||||||
title.setText(s.getTitle(ctx));
|
title.setText(s.getTitle(ctx));
|
||||||
description.setText(descriptionText);
|
if (Algorithms.isEmpty(descriptionText.toString())) {
|
||||||
|
description.setVisibility(View.GONE);
|
||||||
|
} else {
|
||||||
|
description.setText(descriptionText);
|
||||||
|
}
|
||||||
buttonTitle.setText(priceTitle);
|
buttonTitle.setText(priceTitle);
|
||||||
buttonView.setVisibility(View.VISIBLE);
|
buttonView.setVisibility(View.VISIBLE);
|
||||||
buttonCancelView.setVisibility(View.GONE);
|
buttonCancelView.setVisibility(View.GONE);
|
||||||
|
@ -437,20 +439,32 @@ public abstract class ChoosePlanDialogFragment extends BaseOsmAndDialogFragment
|
||||||
TextViewEx description = (TextViewEx) button.findViewById(R.id.description);
|
TextViewEx description = (TextViewEx) button.findViewById(R.id.description);
|
||||||
TextViewEx descriptionContribute = (TextViewEx) button.findViewById(R.id.description_contribute);
|
TextViewEx descriptionContribute = (TextViewEx) button.findViewById(R.id.description_contribute);
|
||||||
descriptionContribute.setVisibility(s.isDonationSupported() ? View.VISIBLE : View.GONE);
|
descriptionContribute.setVisibility(s.isDonationSupported() ? View.VISIBLE : View.GONE);
|
||||||
|
|
||||||
|
View buttonView = button.findViewById(R.id.button_view);
|
||||||
View buttonExView = button.findViewById(R.id.button_ex_view);
|
View buttonExView = button.findViewById(R.id.button_ex_view);
|
||||||
|
TextViewEx buttonTitle = (TextViewEx) button.findViewById(R.id.button_title);
|
||||||
TextViewEx buttonExTitle = (TextViewEx) button.findViewById(R.id.button_ex_title);
|
TextViewEx buttonExTitle = (TextViewEx) button.findViewById(R.id.button_ex_title);
|
||||||
if (maxDiscountAction && s.equals(subscriptionMaxDiscount)) {
|
|
||||||
createSolidButton(ctx, buttonExView, buttonExTitle);
|
boolean showSolidButton = !anyPurchased
|
||||||
|
&& (!maxDiscountAction || hasIntroductoryInfo || maxDiscountSubscription.isUpgrade());
|
||||||
|
if (!showSolidButton && hasIntroductoryInfo) {
|
||||||
|
buttonExTitle.setTextColor(buttonTitle.getCurrentTextColor());
|
||||||
}
|
}
|
||||||
|
buttonView.setVisibility(!showSolidButton ? View.VISIBLE : View.GONE);
|
||||||
|
buttonExView.setVisibility(showSolidButton ? View.VISIBLE : View.GONE);
|
||||||
|
View div = button.findViewById(R.id.div);
|
||||||
|
|
||||||
CharSequence priceTitle = hasIntroductoryInfo ?
|
CharSequence priceTitle = hasIntroductoryInfo ?
|
||||||
introductoryInfo.getFormattedDescription(ctx, buttonExTitle.getCurrentTextColor()) : s.getPriceWithPeriod(ctx);
|
introductoryInfo.getFormattedDescription(ctx, buttonExTitle.getCurrentTextColor()) : s.getPriceWithPeriod(ctx);
|
||||||
buttonExTitle.setText(priceTitle);
|
|
||||||
title.setText(s.getTitle(ctx));
|
title.setText(s.getTitle(ctx));
|
||||||
if (Algorithms.isEmpty(descriptionText.toString())) {
|
if (Algorithms.isEmpty(descriptionText.toString())) {
|
||||||
description.setVisibility(View.GONE);
|
description.setVisibility(View.GONE);
|
||||||
} else {
|
} else {
|
||||||
description.setText(descriptionText);
|
description.setText(descriptionText);
|
||||||
}
|
}
|
||||||
|
buttonTitle.setText(priceTitle);
|
||||||
|
buttonExTitle.setText(priceTitle);
|
||||||
|
|
||||||
TextViewEx buttonDiscountTitle = (TextViewEx) button.findViewById(R.id.button_discount_title);
|
TextViewEx buttonDiscountTitle = (TextViewEx) button.findViewById(R.id.button_discount_title);
|
||||||
View buttonDiscountView = button.findViewById(R.id.button_discount_view);
|
View buttonDiscountView = button.findViewById(R.id.button_discount_view);
|
||||||
String discountTitle = s.getDiscountTitle(ctx, purchaseHelper.getMonthlyLiveUpdates());
|
String discountTitle = s.getDiscountTitle(ctx, purchaseHelper.getMonthlyLiveUpdates());
|
||||||
|
@ -458,7 +472,7 @@ public abstract class ChoosePlanDialogFragment extends BaseOsmAndDialogFragment
|
||||||
buttonDiscountTitle.setText(discountTitle);
|
buttonDiscountTitle.setText(discountTitle);
|
||||||
buttonDiscountView.setVisibility(View.VISIBLE);
|
buttonDiscountView.setVisibility(View.VISIBLE);
|
||||||
}
|
}
|
||||||
if (s.equals(subscriptionMaxDiscount)) {
|
if (s.equals(maxDiscountSubscription) || maxDiscountSubscription != null && maxDiscountSubscription.isUpgrade()) {
|
||||||
int saveTextColor = R.color.color_osm_edit_delete;
|
int saveTextColor = R.color.color_osm_edit_delete;
|
||||||
if (hasIntroductoryInfo) {
|
if (hasIntroductoryInfo) {
|
||||||
saveTextColor = R.color.active_buttons_and_links_text_light;
|
saveTextColor = R.color.active_buttons_and_links_text_light;
|
||||||
|
@ -466,21 +480,22 @@ public abstract class ChoosePlanDialogFragment extends BaseOsmAndDialogFragment
|
||||||
ContextCompat.getColor(ctx, R.color.color_osm_edit_delete)));
|
ContextCompat.getColor(ctx, R.color.color_osm_edit_delete)));
|
||||||
}
|
}
|
||||||
buttonDiscountTitle.setTextColor(ContextCompat.getColor(ctx, saveTextColor));
|
buttonDiscountTitle.setTextColor(ContextCompat.getColor(ctx, saveTextColor));
|
||||||
|
}
|
||||||
|
if (!showSolidButton) {
|
||||||
|
buttonView.setOnClickListener(new OnClickListener() {
|
||||||
|
@Override
|
||||||
|
public void onClick(View v) {
|
||||||
|
subscribe(s.getSku());
|
||||||
|
}
|
||||||
|
});
|
||||||
} else {
|
} else {
|
||||||
if (maxDiscountAction) {
|
buttonExView.setOnClickListener(new OnClickListener() {
|
||||||
createOutlineButton(ctx, buttonExView, buttonExTitle);
|
@Override
|
||||||
}
|
public void onClick(View v) {
|
||||||
|
subscribe(s.getSku());
|
||||||
|
}
|
||||||
|
});
|
||||||
}
|
}
|
||||||
if (anyPurchased) {
|
|
||||||
createOutlineButton(ctx, buttonExView, buttonExTitle);
|
|
||||||
}
|
|
||||||
buttonExView.setOnClickListener(new OnClickListener() {
|
|
||||||
@Override
|
|
||||||
public void onClick(View v) {
|
|
||||||
subscribe(s.getSku());
|
|
||||||
}
|
|
||||||
});
|
|
||||||
View div = button.findViewById(R.id.div);
|
|
||||||
div.setVisibility(View.VISIBLE);
|
div.setVisibility(View.VISIBLE);
|
||||||
osmLiveCardButtonsContainer.addView(button);
|
osmLiveCardButtonsContainer.addView(button);
|
||||||
lastBtn = button;
|
lastBtn = button;
|
||||||
|
@ -499,23 +514,6 @@ public abstract class ChoosePlanDialogFragment extends BaseOsmAndDialogFragment
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void createSolidButton(Context ctx, View buttonExView, TextViewEx buttonExTitle) {
|
|
||||||
Resources.Theme theme = ctx.getTheme();
|
|
||||||
TypedValue typedValue = new TypedValue();
|
|
||||||
theme.resolveAttribute(R.attr.wikivoyage_primary_btn_bg, typedValue, true);
|
|
||||||
buttonExView.setBackgroundResource(typedValue.resourceId);
|
|
||||||
buttonExTitle.setTextColor(ContextCompat.getColor(ctx, R.color.active_buttons_and_links_text_light));
|
|
||||||
}
|
|
||||||
|
|
||||||
private void createOutlineButton(Context ctx, View buttonExView, TextViewEx buttonExTitle) {
|
|
||||||
Resources.Theme theme = ctx.getTheme();
|
|
||||||
TypedValue typedValue = new TypedValue();
|
|
||||||
theme.resolveAttribute(R.attr.purchase_dialog_outline_btn_bg, typedValue, true);
|
|
||||||
buttonExView.setBackgroundResource(typedValue.resourceId);
|
|
||||||
theme.resolveAttribute(R.attr.color_dialog_buttons, typedValue, true);
|
|
||||||
buttonExTitle.setTextColor(ContextCompat.getColor(ctx, typedValue.resourceId));
|
|
||||||
}
|
|
||||||
|
|
||||||
private void showDonationSettings() {
|
private void showDonationSettings() {
|
||||||
FragmentActivity activity = getActivity();
|
FragmentActivity activity = getActivity();
|
||||||
if (activity != null) {
|
if (activity != null) {
|
||||||
|
|
|
@ -732,9 +732,6 @@ public class InAppPurchases {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public CharSequence getDescription(@NonNull Context ctx) {
|
public CharSequence getDescription(@NonNull Context ctx) {
|
||||||
if (getMonthlyPriceValue() == getPriceValue()) {
|
|
||||||
return "";
|
|
||||||
}
|
|
||||||
if (getMonthlyPriceValue() == 0) {
|
if (getMonthlyPriceValue() == 0) {
|
||||||
return ctx.getString(R.string.osm_live_payment_month_cost_descr, getDefaultMonthlyPrice(ctx));
|
return ctx.getString(R.string.osm_live_payment_month_cost_descr, getDefaultMonthlyPrice(ctx));
|
||||||
} else {
|
} else {
|
||||||
|
@ -901,6 +898,11 @@ public class InAppPurchases {
|
||||||
public CharSequence getRenewDescription(@NonNull Context ctx) {
|
public CharSequence getRenewDescription(@NonNull Context ctx) {
|
||||||
return ctx.getString(R.string.osm_live_payment_renews_monthly);
|
return ctx.getString(R.string.osm_live_payment_renews_monthly);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public CharSequence getDescription(@NonNull Context ctx) {
|
||||||
|
return "";
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static class InAppPurchaseLiveUpdatesMonthlyFull extends InAppPurchaseLiveUpdatesMonthly {
|
public static class InAppPurchaseLiveUpdatesMonthlyFull extends InAppPurchaseLiveUpdatesMonthly {
|
||||||
|
|
Loading…
Reference in a new issue