[android] Implemented free trial period ui for yearly all pass subscription

This commit is contained in:
Александр Зацепин 2020-07-15 14:05:21 +03:00 committed by Arsentiy Milchakov
parent 1adb44d49e
commit bf19c3320f
5 changed files with 86 additions and 12 deletions

View file

@ -125,6 +125,27 @@
app:buttonBackground="@drawable/button_secondary_transparent"
app:buttonTextColor="@color/white_primary"
app:progressColor="@color/base_accent" />
<Button
android:id="@+id/free_trial_button"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="@dimen/margin_double_and_half"
android:background="@drawable/button_accent"
android:text="@string/guides_trial_cta_button"
android:textColor="@color/white_primary"
android:textSize="@dimen/text_size_body_3"
android:visibility="gone"
tools:visibility="visible"/>
<TextView
android:id="@+id/free_trial_mesage"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="@dimen/margin_base"
android:text="@string/guides_trial_message"
android:textColor="@color/white_primary"
android:textSize="@dimen/text_size_body_4"
android:visibility="gone"
tools:visibility="visible"/>
<TextView
android:id="@+id/restore_purchase_btn"
android:layout_width="wrap_content"

View file

@ -115,6 +115,29 @@
app:buttonBackground="@drawable/button_secondary_transparent"
app:buttonTextColor="@color/white_primary"
app:progressColor="@color/base_accent" />
<Button
android:id="@+id/free_trial_button"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginStart="@dimen/margin_base_plus"
android:layout_marginTop="@dimen/margin_double_and_half"
android:layout_marginEnd="@dimen/margin_base_plus"
android:background="@drawable/button_accent"
android:text="@string/guides_trial_cta_button"
android:textColor="@color/white_primary"
android:textSize="@dimen/text_size_body_3"
android:visibility="gone"
tools:visibility="visible"/>
<TextView
android:id="@+id/free_trial_mesage"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="@dimen/margin_base"
android:text="@string/guides_trial_message"
android:textColor="@color/white_primary"
android:textSize="@dimen/text_size_body_4"
android:visibility="gone"
tools:visibility="visible"/>
<TextView
android:id="@+id/restore_purchase_btn"
android:layout_width="wrap_content"

View file

@ -2,7 +2,9 @@ package com.mapswithme.maps.purchase;
import android.os.Parcel;
import android.os.Parcelable;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
class ProductDetails implements Parcelable
{
@ -13,19 +15,22 @@ class ProductDetails implements Parcelable
private final String mCurrencyCode;
@NonNull
private final String mTitle;
@Nullable
private final String mFreeTrialPeriod;
ProductDetails(@NonNull String productId, float price, @NonNull String currencyCode, @NonNull
String title)
ProductDetails(@NonNull String productId, float price, @NonNull String currencyCode,
@NonNull String title, @Nullable String freeTrialPeriod)
{
mProductId = productId;
mPrice = price;
mCurrencyCode = currencyCode;
mTitle = title;
mFreeTrialPeriod = freeTrialPeriod;
}
private ProductDetails(Parcel in)
{
this(in.readString(), in.readFloat(), in.readString(), in.readString());
this(in.readString(), in.readFloat(), in.readString(), in.readString(), in.readString());
}
float getPrice()
@ -51,6 +56,12 @@ class ProductDetails implements Parcelable
return mTitle;
}
@Nullable
String getFreeTrialPeriod()
{
return mFreeTrialPeriod;
}
public static final Creator<ProductDetails> CREATOR = new Creator<ProductDetails>()
{
@Override
@ -79,5 +90,6 @@ class ProductDetails implements Parcelable
dest.writeFloat(mPrice);
dest.writeString(mCurrencyCode);
dest.writeString(mTitle);
dest.writeString(mFreeTrialPeriod);
}
}

View file

@ -81,7 +81,8 @@ public class PurchaseUtils
{
float price = normalizePrice(skuDetails.getPriceAmountMicros());
String currencyCode = skuDetails.getPriceCurrencyCode();
return new ProductDetails(skuDetails.getSku(), price, currencyCode, skuDetails.getTitle());
return new ProductDetails(skuDetails.getSku(), price, currencyCode, skuDetails.getTitle(),
skuDetails.getFreeTrialPeriod());
}
@NonNull

View file

@ -1,25 +1,34 @@
package com.mapswithme.maps.purchase;
import android.text.TextUtils;
import android.view.View;
import android.widget.TextView;
import androidx.annotation.CallSuper;
import androidx.annotation.NonNull;
import com.mapswithme.maps.R;
import com.mapswithme.maps.widget.SubscriptionButton;
import com.mapswithme.util.UiUtils;
import com.mapswithme.util.Utils;
import java.util.List;
class TwoButtonsSubscriptionFragmentDelegate extends SubscriptionFragmentDelegate
{
@SuppressWarnings("NullableProblems")
@SuppressWarnings("NotNullFieldNotInitialized")
@NonNull
private SubscriptionButton mYearlyButton;
@SuppressWarnings("NullableProblems")
@SuppressWarnings("NotNullFieldNotInitialized")
@NonNull
private SubscriptionButton mMonthlyButton;
@NonNull
private PurchaseUtils.Period mSelectedPeriod = PurchaseUtils.Period.P1Y;
@SuppressWarnings("NotNullFieldNotInitialized")
@NonNull
private View mFreeTrialButton;
@SuppressWarnings("NotNullFieldNotInitialized")
@NonNull
private TextView mFreeTrialMessage;
TwoButtonsSubscriptionFragmentDelegate(@NonNull AbstractBookmarkSubscriptionFragment fragment)
{
@ -32,13 +41,12 @@ class TwoButtonsSubscriptionFragmentDelegate extends SubscriptionFragmentDelegat
{
super.onCreateView(root);
mYearlyButton = root.findViewById(R.id.annual_button);
mYearlyButton.setOnClickListener(v -> {
onSubscriptionButtonClicked(PurchaseUtils.Period.P1Y);
});
mYearlyButton.setOnClickListener(v -> onSubscriptionButtonClicked(PurchaseUtils.Period.P1Y));
mMonthlyButton = root.findViewById(R.id.monthly_button);
mMonthlyButton.setOnClickListener(v -> {
onSubscriptionButtonClicked(PurchaseUtils.Period.P1M);
});
mMonthlyButton.setOnClickListener(v -> onSubscriptionButtonClicked(PurchaseUtils.Period.P1M));
mFreeTrialButton = root.findViewById(R.id.free_trial_button);
mFreeTrialButton.setOnClickListener(v -> onSubscriptionButtonClicked(PurchaseUtils.Period.P1Y));
mFreeTrialMessage = root.findViewById(R.id.free_trial_mesage);
}
private void onSubscriptionButtonClicked(@NonNull PurchaseUtils.Period period)
@ -75,6 +83,15 @@ class TwoButtonsSubscriptionFragmentDelegate extends SubscriptionFragmentDelegat
private void updatePaymentButtons()
{
ProductDetails details = getFragment().getProductDetailsForPeriod(PurchaseUtils.Period.P1Y);
if (!TextUtils.isEmpty(details.getFreeTrialPeriod()))
{
UiUtils.hide(mYearlyButton, mMonthlyButton);
UiUtils.show(mFreeTrialButton, mFreeTrialMessage);
String price = Utils.formatCurrencyString(details.getPrice(), details.getCurrencyCode());
mFreeTrialMessage.setText(getFragment().getString(R.string.guides_trial_message, price));
return;
}
updateYearlyButton();
updateMonthlyButton();
}