Discount badge on Choose plan

This commit is contained in:
Dima-1 2020-04-22 22:04:00 +03:00
parent 74ec8cc43a
commit c66d5601e9
12 changed files with 223 additions and 114 deletions

View file

@ -0,0 +1,8 @@
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android">
<solid android:color="@color/switch_button_active_dark" />
<corners android:radius="3dp" />
<stroke
android:width="1dp"
android:color="@color/active_color_primary_dark" />
</shape>

View file

@ -0,0 +1,8 @@
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android">
<solid android:color="@color/switch_button_active_light" />
<corners android:radius="3dp" />
<stroke
android:width="1dp"
android:color="@color/active_color_primary_light" />
</shape>

View file

@ -16,10 +16,10 @@
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:baselineAligned="false" android:baselineAligned="false"
android:orientation="vertical" android:orientation="vertical"
android:paddingLeft="@dimen/card_padding" android:paddingLeft="@dimen/list_content_padding"
android:paddingRight="@dimen/card_padding" android:paddingRight="@dimen/list_content_padding"
android:paddingEnd="@dimen/card_padding" android:paddingEnd="@dimen/list_content_padding"
android:paddingStart="@dimen/card_padding"> android:paddingStart="@dimen/list_content_padding">
<LinearLayout <LinearLayout
android:layout_width="match_parent" android:layout_width="match_parent"
@ -48,55 +48,48 @@
osmand:typeface="@string/font_roboto_regular" osmand:typeface="@string/font_roboto_regular"
tools:visibility="visible" /> tools:visibility="visible" />
<net.osmand.plus.widgets.TextViewEx
android:id="@+id/description"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textColor="?attr/dialog_text_description_color"
android:textSize="@dimen/default_desc_text_size"
osmand:typeface="@string/font_roboto_regular"
tools:text="$0.62 / month • Save 68%" />
</LinearLayout>
<LinearLayout
android:id="@+id/button_view"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:background="?attr/btn_round_border_2">
<LinearLayout <LinearLayout
android:id="@+id/button"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="wrap_content" android:layout_height="match_parent">
android:background="?attr/selectableItemBackground"
android:gravity="center"
android:orientation="horizontal"
android:padding="@dimen/list_header_padding">
<ProgressBar
android:id="@+id/button_progress"
android:layout_width="@dimen/card_button_progress_size_small"
android:layout_height="@dimen/card_button_progress_size_small"
android:indeterminate="true"
android:visibility="gone" />
<net.osmand.plus.widgets.TextViewEx <net.osmand.plus.widgets.TextViewEx
android:id="@+id/button_title" android:id="@+id/description"
android:layout_width="match_parent" android:layout_width="0dp"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:gravity="center" android:layout_weight="1"
android:letterSpacing="@dimen/text_button_letter_spacing" android:layout_gravity="center"
android:maxWidth="@dimen/dialog_button_ex_max_width" android:textColor="?attr/dialog_text_description_color"
android:minWidth="@dimen/dialog_button_ex_min_width" android:textSize="@dimen/default_desc_text_size"
android:textColor="?attr/color_dialog_buttons" osmand:typeface="@string/font_roboto_regular"
android:textSize="@dimen/text_button_text_size" tools:text="$0.62 / month" />
osmand:typeface="@string/font_roboto_medium"
tools:text="7,99€ / year" />
<LinearLayout
android:id="@+id/button_discount_view"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:background="@drawable/btn_border_bg_light"
android:visibility="gone"
tools:visibility="visible">
<net.osmand.plus.widgets.TextViewEx
android:id="@+id/button_discount_title"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:paddingStart="@dimen/content_padding_small"
android:paddingLeft="@dimen/content_padding_small"
android:paddingEnd="@dimen/content_padding_small"
android:paddingRight="@dimen/content_padding_small"
android:paddingTop="@dimen/subHeaderPadding"
android:paddingBottom="@dimen/subHeaderPadding"
android:gravity="end"
android:letterSpacing="@dimen/text_button_letter_spacing"
android:textColor="@color/text_color_secondary_light"
android:textSize="@dimen/default_desc_text_size"
tools:text="Save 10%"
osmand:typeface="@string/font_roboto_medium" />
</LinearLayout>
</LinearLayout> </LinearLayout>
</LinearLayout> </LinearLayout>
<LinearLayout <LinearLayout
@ -138,7 +131,7 @@
android:id="@+id/div" android:id="@+id/div"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="1dp" android:layout_height="1dp"
android:layout_marginTop="@dimen/content_padding_small" android:layout_marginTop="@dimen/content_padding"
android:background="?attr/wikivoyage_card_divider_color" android:background="?attr/wikivoyage_card_divider_color"
android:visibility="gone" /> android:visibility="gone" />

View file

@ -1,6 +1,5 @@
<?xml version="1.0" encoding="utf-8"?> <?xml version="1.0" encoding="utf-8"?>
<LinearLayout <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:osmand="http://schemas.android.com/apk/res-auto" xmlns:osmand="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools" xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent" android:layout_width="match_parent"
@ -31,7 +30,7 @@
android:background="?attr/selectableItemBackgroundBorderless" android:background="?attr/selectableItemBackgroundBorderless"
android:padding="@dimen/list_content_padding" android:padding="@dimen/list_content_padding"
android:src="@drawable/ic_arrow_back" android:src="@drawable/ic_arrow_back"
android:tint="@color/icon_color_default_light"/> android:tint="@color/icon_color_default_light" />
<net.osmand.plus.widgets.TextViewEx <net.osmand.plus.widgets.TextViewEx
android:id="@+id/title" android:id="@+id/title"
@ -43,7 +42,7 @@
android:textColor="?attr/dialog_title_color" android:textColor="?attr/dialog_title_color"
android:textSize="@dimen/dialog_header_text_size" android:textSize="@dimen/dialog_header_text_size"
osmand:typeface="@string/font_roboto_medium" osmand:typeface="@string/font_roboto_medium"
android:layout_marginStart="@dimen/list_header_padding" /> android:layout_marginStart="@dimen/list_header_padding" />
</LinearLayout> </LinearLayout>
@ -54,8 +53,8 @@
android:layout_marginLeft="@dimen/list_content_padding_large" android:layout_marginLeft="@dimen/list_content_padding_large"
android:layout_marginRight="@dimen/list_content_padding_large" android:layout_marginRight="@dimen/list_content_padding_large"
android:orientation="vertical" android:orientation="vertical"
android:layout_marginStart="@dimen/list_content_padding_large" android:layout_marginStart="@dimen/list_content_padding_large"
android:layout_marginEnd="@dimen/list_content_padding_large"> android:layout_marginEnd="@dimen/list_content_padding_large">
<LinearLayout <LinearLayout
android:id="@+id/info_container" android:id="@+id/info_container"
@ -70,28 +69,48 @@
android:textColor="?attr/dialog_description_color" android:textColor="?attr/dialog_description_color"
android:textSize="@dimen/default_list_text_size" android:textSize="@dimen/default_list_text_size"
osmand:typeface="@string/font_roboto_regular" osmand:typeface="@string/font_roboto_regular"
tools:text="@string/purchase_dialog_travel_description"/> tools:text="@string/purchase_dialog_travel_description" />
</LinearLayout> </LinearLayout>
</LinearLayout> </LinearLayout>
<LinearLayout <LinearLayout
android:id="@+id/cards_container" android:id="@+id/cards_container"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:orientation="vertical"/> android:orientation="vertical" />
<LinearLayout
android:id="@+id/plan_info_container"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="@dimen/list_content_padding"
android:layout_marginRight="@dimen/list_content_padding"
android:layout_marginStart="@dimen/list_content_padding"
android:layout_marginEnd="@dimen/list_content_padding"
android:orientation="vertical">
<net.osmand.plus.widgets.TextViewEx
android:id="@+id/plan_info_description"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textColor="?attr/dialog_description_color"
android:textSize="@dimen/default_desc_text_size"
osmand:typeface="@string/font_roboto_regular"
android:text="@string/osm_live_payment_subscription_management" />
</LinearLayout>
<FrameLayout <FrameLayout
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:layout_marginLeft="@dimen/card_padding" android:layout_marginLeft="@dimen/card_padding"
android:layout_marginRight="@dimen/card_padding" android:layout_marginRight="@dimen/card_padding"
android:layout_marginTop="4dp" android:layout_marginTop="@dimen/list_header_padding"
android:background="?attr/wikivoyage_travel_card_bg" android:background="?attr/wikivoyage_travel_card_bg"
android:layout_marginEnd="@dimen/card_padding" android:layout_marginEnd="@dimen/card_padding"
android:layout_marginStart="@dimen/card_padding"> android:layout_marginStart="@dimen/card_padding">
<net.osmand.plus.widgets.TextViewEx <net.osmand.plus.widgets.TextViewEx
android:id="@+id/button_restore" android:id="@+id/button_restore"
@ -109,8 +128,8 @@
android:textColor="?attr/wikivoyage_active_color" android:textColor="?attr/wikivoyage_active_color"
android:textSize="@dimen/text_button_text_size" android:textSize="@dimen/text_button_text_size"
osmand:typeface="@string/font_roboto_regular" osmand:typeface="@string/font_roboto_regular"
android:paddingStart="@dimen/list_content_padding" android:paddingStart="@dimen/list_content_padding"
android:paddingEnd="@dimen/list_content_padding" /> android:paddingEnd="@dimen/list_content_padding" />
<ProgressBar <ProgressBar
android:id="@+id/progress_bar" android:id="@+id/progress_bar"
@ -132,8 +151,8 @@
android:layout_marginRight="@dimen/card_padding" android:layout_marginRight="@dimen/card_padding"
android:layout_marginTop="4dp" android:layout_marginTop="4dp"
android:background="?attr/wikivoyage_travel_card_bg" android:background="?attr/wikivoyage_travel_card_bg"
android:layout_marginEnd="@dimen/card_padding" android:layout_marginEnd="@dimen/card_padding"
android:layout_marginStart="@dimen/card_padding"> android:layout_marginStart="@dimen/card_padding">
<net.osmand.plus.widgets.TextViewEx <net.osmand.plus.widgets.TextViewEx
android:id="@+id/button_later" android:id="@+id/button_later"
@ -151,8 +170,8 @@
android:textColor="?attr/wikivoyage_active_color" android:textColor="?attr/wikivoyage_active_color"
android:textSize="@dimen/text_button_text_size" android:textSize="@dimen/text_button_text_size"
osmand:typeface="@string/font_roboto_regular" osmand:typeface="@string/font_roboto_regular"
android:paddingStart="@dimen/list_content_padding" android:paddingStart="@dimen/list_content_padding"
android:paddingEnd="@dimen/list_content_padding" /> android:paddingEnd="@dimen/list_content_padding" />
</FrameLayout> </FrameLayout>

View file

@ -1,7 +1,6 @@
<?xml version="1.0" encoding="utf-8"?> <?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:osmand="http://schemas.android.com/apk/res-auto" xmlns:osmand="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:layout_marginLeft="@dimen/card_padding" android:layout_marginLeft="@dimen/card_padding"
@ -49,7 +48,7 @@
android:layout_marginRight="@dimen/card_padding" android:layout_marginRight="@dimen/card_padding"
android:layout_marginBottom="@dimen/list_header_padding" android:layout_marginBottom="@dimen/list_header_padding"
android:text="@string/osm_live_payment_header" android:text="@string/osm_live_payment_header"
android:textColor="?attr/dialog_text_description_color" android:textColor="@color/preference_category_title"
android:textSize="@dimen/default_desc_text_size" android:textSize="@dimen/default_desc_text_size"
osmand:typeface="@string/font_roboto_regular" osmand:typeface="@string/font_roboto_regular"
android:layout_marginEnd="@dimen/card_padding" android:layout_marginEnd="@dimen/card_padding"
@ -74,7 +73,7 @@
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:layout_marginBottom="2dp" android:layout_marginBottom="2dp"
android:paddingBottom="@dimen/content_padding_small" android:paddingBottom="@dimen/content_padding"
android:orientation="vertical" android:orientation="vertical"
android:visibility="gone" /> android:visibility="gone" />

View file

@ -713,7 +713,7 @@
<string name="osm_live_payment_renews_monthly">Perpanjang tiap bulan</string> <string name="osm_live_payment_renews_monthly">Perpanjang tiap bulan</string>
<string name="osm_live_payment_renews_quarterly">Perpanjang tiap 4 bulan</string> <string name="osm_live_payment_renews_quarterly">Perpanjang tiap 4 bulan</string>
<string name="osm_live_payment_renews_annually">Perpanjang tiap tahun</string> <string name="osm_live_payment_renews_annually">Perpanjang tiap tahun</string>
<string name="default_price_currency_format"/> <string name="default_price_currency_format">%1$.2f %2$s</string>
<string name="osm_live_payment_header">Pilih periode pembayaran yang anda inginkan:</string> <string name="osm_live_payment_header">Pilih periode pembayaran yang anda inginkan:</string>
<string name="osm_live_payment_contribute_descr">Sebagian pendapatan diberikan untuk kontributor OpenStreetMap.</string> <string name="osm_live_payment_contribute_descr">Sebagian pendapatan diberikan untuk kontributor OpenStreetMap.</string>
<string name="powered_by_osmand">Oleh OsmAnd</string> <string name="powered_by_osmand">Oleh OsmAnd</string>

View file

@ -103,6 +103,7 @@
<attr name="wikivoyage_secondary_btn_bg" format="reference"/> <attr name="wikivoyage_secondary_btn_bg" format="reference"/>
<attr name="wikivoyage_primary_btn_bg" format="reference"/> <attr name="wikivoyage_primary_btn_bg" format="reference"/>
<attr name="purchase_dialog_shadow_btn_bg" format="reference"/> <attr name="purchase_dialog_shadow_btn_bg" format="reference"/>
<attr name="purchase_dialog_outline_btn_bg" format="reference"/>
<attr name="bottom_nav_shadow" format="reference"/> <attr name="bottom_nav_shadow" format="reference"/>

View file

@ -461,7 +461,8 @@
<color name="profile_icon_color_inactive">#727272</color> <color name="profile_icon_color_inactive">#727272</color>
<color name="switch_button_active">#1A237BFF</color> <color name="switch_button_active_light">#1A237BFF</color>
<color name="switch_button_active_dark">#1AD28521</color>
<color name="switch_button_active_stroke">#80237BFF</color> <color name="switch_button_active_stroke">#80237BFF</color>
<color name="empty_hint_bg">#80000000</color> <color name="empty_hint_bg">#80000000</color>

View file

@ -11,6 +11,8 @@
Thx - Hardy Thx - Hardy
--> -->
<string name="osm_live_payment_subscription_management">Payment will be charged to your Google Play account at the confirmation of purchase.\n\nSubscription automatically renews unless it is canceled before the renewal date. Your account will be charged for renewal period(month/three month/year) only on the renewal date.\n\nYou can manage and cancel your subscriptions by going to your Google Play settings.</string>
<string name="ltr_or_rtl_combine_via_slash_with_space">%1$s / %2$s</string>
<string name="custom_color">Custom color</string> <string name="custom_color">Custom color</string>
<string name="lang_lmo">Lombard</string> <string name="lang_lmo">Lombard</string>
<string name="lang_an">Aragonese</string> <string name="lang_an">Aragonese</string>
@ -715,7 +717,7 @@
<string name="osm_live_payment_annual_title">Annually</string> <string name="osm_live_payment_annual_title">Annually</string>
<string name="osm_live_payment_month_cost_descr">%1$s / month</string> <string name="osm_live_payment_month_cost_descr">%1$s / month</string>
<string name="osm_live_payment_month_cost_descr_ex">%1$.2f %2$s / month</string> <string name="osm_live_payment_month_cost_descr_ex">%1$.2f %2$s / month</string>
<string name="osm_live_payment_discount_descr">Save %1$s.</string> <string name="osm_live_payment_discount_descr">Save %1$s</string>
<string name="osm_live_payment_current_subscription">Current subscription</string> <string name="osm_live_payment_current_subscription">Current subscription</string>
<string name="osm_live_payment_renews_monthly">Renews monthly</string> <string name="osm_live_payment_renews_monthly">Renews monthly</string>
<string name="osm_live_payment_renews_quarterly">Renews quarterly</string> <string name="osm_live_payment_renews_quarterly">Renews quarterly</string>

View file

@ -246,6 +246,7 @@
<item name="wikivoyage_primary_btn_bg">@drawable/wikivoyage_primary_btn_bg_light</item> <item name="wikivoyage_primary_btn_bg">@drawable/wikivoyage_primary_btn_bg_light</item>
<item name="purchase_dialog_active_card_bg">@drawable/dialog_active_card_bg_light</item> <item name="purchase_dialog_active_card_bg">@drawable/dialog_active_card_bg_light</item>
<item name="purchase_dialog_shadow_btn_bg">@drawable/purchase_dialog_shadow_btn_bg_light</item> <item name="purchase_dialog_shadow_btn_bg">@drawable/purchase_dialog_shadow_btn_bg_light</item>
<item name="purchase_dialog_outline_btn_bg">@drawable/purchase_dialog_outline_btn_bg_light</item>
<item name="bottom_nav_shadow">@drawable/bg_bottom_bar_shadow_with_line_day</item> <item name="bottom_nav_shadow">@drawable/bg_bottom_bar_shadow_with_line_day</item>
@ -512,6 +513,7 @@
<item name="wikivoyage_primary_btn_bg">@drawable/wikivoyage_primary_btn_bg_dark</item> <item name="wikivoyage_primary_btn_bg">@drawable/wikivoyage_primary_btn_bg_dark</item>
<item name="purchase_dialog_active_card_bg">@drawable/dialog_active_card_bg_dark</item> <item name="purchase_dialog_active_card_bg">@drawable/dialog_active_card_bg_dark</item>
<item name="purchase_dialog_shadow_btn_bg">@drawable/purchase_dialog_shadow_btn_bg_dark</item> <item name="purchase_dialog_shadow_btn_bg">@drawable/purchase_dialog_shadow_btn_bg_dark</item>
<item name="purchase_dialog_outline_btn_bg">@drawable/purchase_dialog_outline_btn_bg_dark</item>
<item name="bottom_nav_shadow">@drawable/bg_bottom_bar_shadow_with_line_night</item> <item name="bottom_nav_shadow">@drawable/bg_bottom_bar_shadow_with_line_night</item>

View file

@ -6,10 +6,12 @@ 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;
@ -37,6 +39,7 @@ import net.osmand.plus.OsmandApplication;
import net.osmand.plus.OsmandPlugin; import net.osmand.plus.OsmandPlugin;
import net.osmand.plus.OsmandSettings; import net.osmand.plus.OsmandSettings;
import net.osmand.plus.R; import net.osmand.plus.R;
import net.osmand.plus.UiUtilities;
import net.osmand.plus.Version; import net.osmand.plus.Version;
import net.osmand.plus.activities.MapActivity; import net.osmand.plus.activities.MapActivity;
import net.osmand.plus.base.BaseOsmAndDialogFragment; import net.osmand.plus.base.BaseOsmAndDialogFragment;
@ -352,18 +355,21 @@ 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();
boolean anyPurchasedOrIntroducted = false; boolean anyPurchased = false;
for (final InAppSubscription s : visibleSubscriptions) { for (final InAppSubscription s : visibleSubscriptions) {
if (s.isPurchased() || s.getIntroductoryInfo() != null) { if (s.isPurchased()) {
anyPurchasedOrIntroducted = true; anyPurchased = true;
break; break;
} }
} }
InAppSubscription subscriptionMaxDiscount = purchaseHelper.getLiveUpdates()
.getSubscriptionWithMaxDiscount(purchaseHelper.getMonthlyLiveUpdates());
boolean maxDiscountAction = subscriptionMaxDiscount != null
&& (subscriptionMaxDiscount.getIntroductoryInfo() != null || subscriptionMaxDiscount.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;
CharSequence descriptionText = hasIntroductoryInfo ? CharSequence descriptionText = s.getDescription(ctx);
introductoryInfo.getDescriptionTitle(ctx) : s.getDescription(ctx, purchaseHelper.getMonthlyLiveUpdates());
if (s.isPurchased()) { if (s.isPurchased()) {
View buttonPurchased = inflate(R.layout.purchase_dialog_card_button_active_ex, osmLiveCardButtonsContainer); View buttonPurchased = inflate(R.layout.purchase_dialog_card_button_active_ex, osmLiveCardButtonsContainer);
TextViewEx title = (TextViewEx) buttonPurchased.findViewById(R.id.title); TextViewEx title = (TextViewEx) buttonPurchased.findViewById(R.id.title);
@ -377,7 +383,7 @@ public abstract class ChoosePlanDialogFragment extends BaseOsmAndDialogFragment
AppCompatImageView rightImage = (AppCompatImageView) buttonPurchased.findViewById(R.id.right_image); AppCompatImageView rightImage = (AppCompatImageView) buttonPurchased.findViewById(R.id.right_image);
CharSequence priceTitle = hasIntroductoryInfo ? CharSequence priceTitle = hasIntroductoryInfo ?
introductoryInfo.getFormattedDescription(ctx, buttonTitle.getCurrentTextColor()) : s.getPrice(ctx); introductoryInfo.getFormattedDescription(ctx, buttonTitle.getCurrentTextColor()) : s.getPriceWithPeriod(ctx);
title.setText(s.getTitle(ctx)); title.setText(s.getTitle(ctx));
description.setText(descriptionText); description.setText(descriptionText);
buttonTitle.setText(priceTitle); buttonTitle.setText(priceTitle);
@ -421,45 +427,56 @@ public abstract class ChoosePlanDialogFragment extends BaseOsmAndDialogFragment
rightImage.setVisibility(View.VISIBLE); rightImage.setVisibility(View.VISIBLE);
osmLiveCardButtonsContainer.addView(buttonCancel); osmLiveCardButtonsContainer.addView(buttonCancel);
lastBtn = buttonCancel; lastBtn = buttonCancel;
} else { } else {
View button = inflate(R.layout.purchase_dialog_card_button_ex, osmLiveCardButtonsContainer); View button = inflate(R.layout.purchase_dialog_card_button_ex, osmLiveCardButtonsContainer);
TextViewEx title = (TextViewEx) button.findViewById(R.id.title); TextViewEx title = (TextViewEx) button.findViewById(R.id.title);
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);
boolean showSolidButton = !anyPurchasedOrIntroducted || hasIntroductoryInfo; if (maxDiscountAction && s.equals(subscriptionMaxDiscount)) {
buttonView.setVisibility(!showSolidButton ? View.VISIBLE : View.GONE); createSolidButton(ctx, buttonExView, buttonExTitle);
buttonExView.setVisibility(showSolidButton ? View.VISIBLE : View.GONE);
View div = button.findViewById(R.id.div);
CharSequence priceTitle = hasIntroductoryInfo ?
introductoryInfo.getFormattedDescription(ctx, buttonExTitle.getCurrentTextColor()) : s.getPrice(ctx);
title.setText(s.getTitle(ctx));
description.setText(descriptionText);
buttonTitle.setText(priceTitle);
buttonExTitle.setText(priceTitle);
if (!showSolidButton) {
buttonView.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
subscribe(s.getSku());
}
});
} else {
buttonExView.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
subscribe(s.getSku());
}
});
} }
CharSequence priceTitle = hasIntroductoryInfo ?
introductoryInfo.getFormattedDescription(ctx, buttonExTitle.getCurrentTextColor()) : s.getPriceWithPeriod(ctx);
buttonExTitle.setText(priceTitle);
title.setText(s.getTitle(ctx));
if (Algorithms.isEmpty(descriptionText.toString())) {
description.setVisibility(View.GONE);
} else {
description.setText(descriptionText);
}
TextViewEx buttonDiscountTitle = (TextViewEx) button.findViewById(R.id.button_discount_title);
View buttonDiscountView = button.findViewById(R.id.button_discount_view);
String discountTitle = s.getDiscountTitle(ctx, purchaseHelper.getMonthlyLiveUpdates());
if (!Algorithms.isEmpty(discountTitle)) {
buttonDiscountTitle.setText(discountTitle);
buttonDiscountView.setVisibility(View.VISIBLE);
}
if (s.equals(subscriptionMaxDiscount)) {
int saveTextColor = R.color.color_osm_edit_delete;
if (hasIntroductoryInfo) {
saveTextColor = R.color.active_buttons_and_links_text_light;
AndroidUtils.setBackground(buttonDiscountView, UiUtilities.tintDrawable(buttonDiscountView.getBackground(),
ContextCompat.getColor(ctx, R.color.color_osm_edit_delete)));
}
buttonDiscountTitle.setTextColor(ContextCompat.getColor(ctx, saveTextColor));
} else {
if (maxDiscountAction) {
createOutlineButton(ctx, buttonExView, buttonExTitle);
}
}
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;
@ -478,6 +495,23 @@ 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) {

View file

@ -258,6 +258,20 @@ public class InAppPurchases {
} }
return null; return null;
} }
@Nullable
public InAppSubscription getSubscriptionWithMaxDiscount(@Nullable InAppSubscription monthlyLiveUpdates) {
double maxDiscount = 0;
InAppSubscription subscriptionWithMaxDiscount = null;
for (InAppSubscription s : getAllSubscriptions()) {
double discount = s.getDiscountPercent(monthlyLiveUpdates);
if (discount > maxDiscount) {
subscriptionWithMaxDiscount = s;
maxDiscount = discount;
}
}
return subscriptionWithMaxDiscount;
}
} }
public static class LiveUpdatesInAppPurchasesFree extends InAppSubscriptionList { public static class LiveUpdatesInAppPurchasesFree extends InAppSubscriptionList {
@ -677,6 +691,10 @@ public class InAppPurchases {
return s; return s;
} }
public boolean isUpgrade() {
return upgrade;
}
public boolean isAnyPurchased() { public boolean isAnyPurchased() {
if (isPurchased()) { if (isPurchased()) {
return true; return true;
@ -728,6 +746,9 @@ 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 {
@ -740,12 +761,6 @@ public class InAppPurchases {
} }
} }
public CharSequence getDescription(@NonNull Context ctx, @Nullable InAppSubscription monthlyLiveUpdates) {
CharSequence descr = getDescription(ctx);
int discountPercent = getDiscountPercent(monthlyLiveUpdates);
return discountPercent > 0 ? ctx.getString(R.string.price_and_discount, descr, discountPercent + "%") : descr;
}
public CharSequence getRenewDescription(@NonNull Context ctx) { public CharSequence getRenewDescription(@NonNull Context ctx) {
return ""; return "";
} }
@ -753,7 +768,12 @@ public class InAppPurchases {
@Nullable @Nullable
protected abstract InAppSubscription newInstance(@NonNull String sku); protected abstract InAppSubscription newInstance(@NonNull String sku);
public int getDiscountPercent(@Nullable InAppSubscription monthlyLiveUpdates) { public String getDiscountTitle(@NonNull Context ctx, @Nullable InAppSubscription monthlyLiveUpdates) {
int discountPercent = getDiscountPercent(monthlyLiveUpdates);
return discountPercent > 0 ? ctx.getString(R.string.osm_live_payment_discount_descr, discountPercent + "%") : "";
}
int getDiscountPercent(@Nullable InAppSubscription monthlyLiveUpdates) {
double monthlyPriceValue = getMonthlyPriceValue(); double monthlyPriceValue = getMonthlyPriceValue();
if (monthlyLiveUpdates != null) { if (monthlyLiveUpdates != null) {
double regularMonthlyPrice = monthlyLiveUpdates.getPriceValue(); double regularMonthlyPrice = monthlyLiveUpdates.getPriceValue();
@ -768,6 +788,10 @@ public class InAppPurchases {
} }
return 0; return 0;
} }
public String getPriceWithPeriod(Context ctx) {
return getPrice(ctx);
}
} }
public static class InAppPurchaseFullVersion extends InAppPurchase { public static class InAppPurchaseFullVersion extends InAppPurchase {
@ -881,6 +905,12 @@ public class InAppPurchases {
return ctx.getString(R.string.osm_live_payment_monthly_title); return ctx.getString(R.string.osm_live_payment_monthly_title);
} }
@Override
public String getPriceWithPeriod(Context ctx) {
return ctx.getString(R.string.ltr_or_rtl_combine_via_slash_with_space, getPrice(ctx),
ctx.getString(R.string.month).toLowerCase());
}
@Override @Override
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);
@ -956,6 +986,12 @@ public class InAppPurchases {
return ctx.getString(R.string.osm_live_payment_3_months_title); return ctx.getString(R.string.osm_live_payment_3_months_title);
} }
@Override
public String getPriceWithPeriod(Context ctx) {
return ctx.getString(R.string.ltr_or_rtl_combine_via_slash_with_space, getPrice(ctx),
ctx.getString(R.string.months_3).toLowerCase());
}
@Override @Override
public CharSequence getRenewDescription(@NonNull Context ctx) { public CharSequence getRenewDescription(@NonNull Context ctx) {
return ctx.getString(R.string.osm_live_payment_renews_quarterly); return ctx.getString(R.string.osm_live_payment_renews_quarterly);
@ -1031,6 +1067,12 @@ public class InAppPurchases {
return ctx.getString(R.string.osm_live_payment_annual_title); return ctx.getString(R.string.osm_live_payment_annual_title);
} }
@Override
public String getPriceWithPeriod(Context ctx) {
return ctx.getString(R.string.ltr_or_rtl_combine_via_slash_with_space, getPrice(ctx),
ctx.getString(R.string.year).toLowerCase());
}
@Override @Override
public CharSequence getRenewDescription(@NonNull Context ctx) { public CharSequence getRenewDescription(@NonNull Context ctx) {
return ctx.getString(R.string.osm_live_payment_renews_annually); return ctx.getString(R.string.osm_live_payment_renews_annually);