Skip to content

Commit

Permalink
Merge pull request #26377 from brave/update_discount_save_text_vpn
Browse files Browse the repository at this point in the history
Update discount save text vpn
  • Loading branch information
deeppandya authored Nov 6, 2024
2 parents e840557 + b719323 commit 42a62bb
Show file tree
Hide file tree
Showing 3 changed files with 114 additions and 98 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -35,28 +35,26 @@
import org.chromium.ui.text.SpanApplier.SpanInfo;

public class VpnPaywallActivity extends BraveVpnParentActivity {
private ProgressBar mMonthlyPlanProgress;
private ProgressBar mYearlyPlanProgress;
private LinearLayout mPlanLayout;
private boolean mShouldShowRestoreMenu;

private ProgressBar mMonthlyPlanProgress;
private LinearLayout mMonthlySelectorLayout;
private TextView mMonthlySubscriptionAmountText;

private ProgressBar mYearlyPlanProgress;
private LinearLayout mYearlySelectorLayout;
private TextView mYearlySubscriptionAmountText;
private TextView mRemovedValueText;
private TextView mYearlyText;

private Button mBtnVpnPlanAction;

enum SelectedPlanType {
YEARLY,
MONTHLY
}
private InAppPurchaseWrapper.SubscriptionType mSelectedPlanType =
InAppPurchaseWrapper.SubscriptionType.YEARLY;

private SelectedPlanType mSelectedPlanType = SelectedPlanType.YEARLY;
private ProductDetails mProductDetails;
private ProductDetails mMonthlyProductDetails;
private ProductDetails mYearlyProductDetails;

@Override
public void onResumeWithNative() {
Expand All @@ -75,11 +73,10 @@ private void initializeViews() {
actionBar.setHomeAsUpIndicator(R.drawable.ic_baseline_close_24);
actionBar.setTitle(getResources().getString(R.string.brave_vpn));

mMonthlyPlanProgress = findViewById(R.id.monthly_plan_progress);

mYearlyPlanProgress = findViewById(R.id.yearly_plan_progress);
mPlanLayout = findViewById(R.id.plan_layout);

mMonthlyPlanProgress = findViewById(R.id.monthly_plan_progress);

mRemovedValueText = findViewById(R.id.removed_value_tv);
mRemovedValueText.setPaintFlags(
mRemovedValueText.getPaintFlags() | Paint.STRIKE_THRU_TEXT_FLAG);
Expand All @@ -89,6 +86,11 @@ private void initializeViews() {
String.format(getResources().getString(R.string.monthly_subscription), ""));
mMonthlySubscriptionAmountText = findViewById(R.id.monthly_subscription_amount_text);
mMonthlySelectorLayout = findViewById(R.id.monthly_selector_layout);
mMonthlySelectorLayout.setOnClickListener(
v -> {
mSelectedPlanType = InAppPurchaseWrapper.SubscriptionType.MONTHLY;
updateSelectedPlanView();
});

TextView trialText = findViewById(R.id.trial_text);
String trialString = getResources().getString(R.string.trial_text);
Expand All @@ -108,8 +110,15 @@ private void initializeViews() {
SPAN_EXCLUSIVE_EXCLUSIVE);
trialText.setText(trialTextSpan);

mYearlyPlanProgress = findViewById(R.id.yearly_plan_progress);
mYearlySubscriptionAmountText = findViewById(R.id.yearly_subscription_amount_text);
mYearlySelectorLayout = findViewById(R.id.yearly_selector_layout);
mYearlySelectorLayout.setOnClickListener(
v -> {
mSelectedPlanType = InAppPurchaseWrapper.SubscriptionType.YEARLY;
updateSelectedPlanView();
});

mYearlyText = findViewById(R.id.yearly_text);

TextView refreshCredentialsButton = findViewById(R.id.refresh_credentials_button);
Expand All @@ -123,10 +132,17 @@ private void initializeViews() {
mBtnVpnPlanAction = findViewById(R.id.vpn_plan_action_button);
mBtnVpnPlanAction.setOnClickListener(
v -> {
if (mProductDetails != null) {
InAppPurchaseWrapper.getInstance()
.initiatePurchase(VpnPaywallActivity.this, mProductDetails);
ProductDetails productDetails = null;
if (mSelectedPlanType == InAppPurchaseWrapper.SubscriptionType.MONTHLY) {
productDetails = mMonthlyProductDetails;
} else if (mSelectedPlanType == InAppPurchaseWrapper.SubscriptionType.YEARLY) {
productDetails = mYearlyProductDetails;
}
if (productDetails == null) {
return;
}
InAppPurchaseWrapper.getInstance()
.initiatePurchase(VpnPaywallActivity.this, productDetails);
});
}

Expand All @@ -150,88 +166,96 @@ private void getMonthlyProductDetails() {
InAppPurchaseWrapper.getInstance()
.getMonthlyProductDetails(InAppPurchaseWrapper.SubscriptionProduct.VPN),
monthlyProductDetails -> {
if (monthlyProductDetails != null) {
runOnUiThread(
new Runnable() {
@Override
public void run() {
mMonthlySelectorLayout.setOnClickListener(
v -> {
mSelectedPlanType = SelectedPlanType.MONTHLY;
mProductDetails = monthlyProductDetails;
updateSelectedPlanView();
});
SpannableString monthlyFormattedPrice =
InAppPurchaseWrapper.getInstance()
.getFormattedProductPrice(
VpnPaywallActivity.this,
monthlyProductDetails,
R.string
.monthly_subscription_amount);
if (monthlyFormattedPrice != null) {
mMonthlySubscriptionAmountText.setText(
monthlyFormattedPrice,
TextView.BufferType.SPANNABLE);
mMonthlyPlanProgress.setVisibility(View.GONE);
}
SpannableString fullPrice =
InAppPurchaseWrapper.getInstance()
.getFormattedFullProductPrice(
VpnPaywallActivity.this,
monthlyProductDetails);
if (fullPrice != null) {
mRemovedValueText.setText(
fullPrice, TextView.BufferType.SPANNABLE);
}
}
});
getYearlyProductDetails(monthlyProductDetails);
}
mMonthlyProductDetails = monthlyProductDetails;
updateMonthlyPlanUI();
getYearlyProductDetails();
});
}

private void getYearlyProductDetails(ProductDetails monthlyProductDetails) {
private void getYearlyProductDetails() {
mYearlyPlanProgress.setVisibility(View.VISIBLE);
LiveDataUtil.observeOnce(
InAppPurchaseWrapper.getInstance()
.getYearlyProductDetails(InAppPurchaseWrapper.SubscriptionProduct.VPN),
yearlyProductDetails -> {
if (yearlyProductDetails != null) {
runOnUiThread(
new Runnable() {
@Override
public void run() {
mYearlySelectorLayout.setOnClickListener(
v -> {
mSelectedPlanType = SelectedPlanType.YEARLY;
mProductDetails = yearlyProductDetails;
updateSelectedPlanView();
});
SpannableString yearlyFormattedPrice =
InAppPurchaseWrapper.getInstance()
.getFormattedProductPrice(
VpnPaywallActivity.this,
yearlyProductDetails,
R.string
.yearly_subscription_amount);
if (yearlyFormattedPrice != null) {
mYearlySubscriptionAmountText.setText(
yearlyFormattedPrice,
TextView.BufferType.SPANNABLE);
mYearlyPlanProgress.setVisibility(View.GONE);
}
}
});
mProductDetails = yearlyProductDetails;
mYearlyProductDetails = yearlyProductDetails;
updateYearlyPlanUI();
});
}

private void updateSelectedPlanView() {
mYearlySelectorLayout.setBackgroundResource(
mSelectedPlanType == InAppPurchaseWrapper.SubscriptionType.YEARLY
? R.drawable.vpn_paywall_selected_bg
: R.drawable.vpn_paywall_bg);
mMonthlySelectorLayout.setBackgroundResource(
mSelectedPlanType == InAppPurchaseWrapper.SubscriptionType.MONTHLY
? R.drawable.vpn_paywall_selected_bg
: R.drawable.vpn_paywall_bg);
}

private void updateMonthlyPlanUI() {
if (mMonthlyProductDetails == null) {
return;
}
runOnUiThread(
new Runnable() {
@Override
public void run() {
SpannableString monthlyFormattedPrice =
InAppPurchaseWrapper.getInstance()
.getFormattedProductPrice(
VpnPaywallActivity.this,
mMonthlyProductDetails,
R.string.monthly_subscription_amount);
if (monthlyFormattedPrice != null) {
mMonthlySubscriptionAmountText.setText(
monthlyFormattedPrice, TextView.BufferType.SPANNABLE);
mMonthlyPlanProgress.setVisibility(View.GONE);
}
SpannableString fullPrice =
InAppPurchaseWrapper.getInstance()
.getFormattedFullProductPrice(
VpnPaywallActivity.this, mMonthlyProductDetails);
if (fullPrice != null) {
mRemovedValueText.setText(fullPrice, TextView.BufferType.SPANNABLE);
}
}
});
}

private void updateYearlyPlanUI() {
if (mYearlyProductDetails == null) {
return;
}
runOnUiThread(
new Runnable() {
@Override
public void run() {
SpannableString yearlyFormattedPrice =
InAppPurchaseWrapper.getInstance()
.getFormattedProductPrice(
VpnPaywallActivity.this,
mYearlyProductDetails,
R.string.yearly_subscription_amount);
if (yearlyFormattedPrice != null) {
mYearlySubscriptionAmountText.setText(
yearlyFormattedPrice, TextView.BufferType.SPANNABLE);
mYearlyPlanProgress.setVisibility(View.GONE);
}
mBtnVpnPlanAction.setEnabled(true);
if (monthlyProductDetails != null) {
String discountText =
if (mMonthlyProductDetails != null) {
String annualSaveText =
getString(
R.string.renew_monthly_save,
R.string.renew_yearly_save,
InAppPurchaseWrapper.getInstance()
.getYearlyDiscountPercentage(
monthlyProductDetails,
yearlyProductDetails));
mMonthlyProductDetails,
mYearlyProductDetails));
String discountText =
getString(R.string.renews_annually)
.concat(" ")
.concat(annualSaveText);
SpannableString discountSpannableString =
SpanApplier.applySpans(
discountText,
Expand All @@ -246,17 +270,6 @@ public void run() {
});
}

private void updateSelectedPlanView() {
mYearlySelectorLayout.setBackgroundResource(
mSelectedPlanType == SelectedPlanType.YEARLY
? R.drawable.vpn_paywall_selected_bg
: R.drawable.vpn_paywall_bg);
mMonthlySelectorLayout.setBackgroundResource(
mSelectedPlanType == SelectedPlanType.MONTHLY
? R.drawable.vpn_paywall_selected_bg
: R.drawable.vpn_paywall_bg);
}

@Override
public boolean onCreateOptionsMenu(Menu menu) {
getMenuInflater().inflate(R.menu.menu_brave_vpn, menu);
Expand Down
2 changes: 1 addition & 1 deletion android/java/res/layout/activity_vpn_paywall.xml
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,7 @@
android:id="@+id/yearly_text"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/renew_monthly_save"
android:text="@string/renews_annually"
android:textColor="@color/primitive_blurple_95"
android:textAlignment="textStart"
style="@style/DefaultRegular"/>
Expand Down
7 changes: 5 additions & 2 deletions browser/ui/android/strings/android_brave_strings.grd
Original file line number Diff line number Diff line change
Expand Up @@ -2342,14 +2342,17 @@ Are you sure you want to do this?
<message name="IDS_RENEWS_MONTHLY" desc="Brave VPN plan text">
Renews monthly
</message>
<message name="IDS_RENEWS_ANNUALLY" desc="Brave VPN plan annually renewal text">
Renews annually
</message>
<message name="IDS_MONTHLY_SUBSCRIPTION_AMOUNT" desc="Brave VPN plan text">
<ph name="MONTHLY_AMOUNT">%1$s</ph> /month
</message>
<message name="IDS_ONE_YEAR" desc="Brave VPN plan text">
One Year
</message>
<message name="IDS_RENEW_MONTHLY_SAVE" desc="Brave VPN plan text">
Renews annually (<ph name="DISCOUNT_TEXT_START">&lt;discount_text&gt;</ph>save <ph name="PERCENTAGE_AMOUNT">%1$d</ph>%%<ph name="DISCOUNT_TEXT_END">&lt;/discount_text&gt;</ph>)
<message name="IDS_RENEW_YEARLY_SAVE" desc="Brave VPN plan text">
(<ph name="DISCOUNT_TEXT_START">&lt;discount_text&gt;</ph>save <ph name="PERCENTAGE_AMOUNT">%1$d</ph>%%<ph name="DISCOUNT_TEXT_END">&lt;/discount_text&gt;</ph>)
</message>
<message name="IDS_YEARLY_SUBSCRIPTION_AMOUNT" desc="Brave VPN plan text">
<ph name="YEARLY_AMOUNT">%1$s</ph> /year
Expand Down

0 comments on commit 42a62bb

Please sign in to comment.