Skip to content

Commit

Permalink
Update annual discount text behaviour
Browse files Browse the repository at this point in the history
  • Loading branch information
deeppandya committed Nov 5, 2024
1 parent 2935367 commit b719323
Show file tree
Hide file tree
Showing 3 changed files with 83 additions and 77 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,6 @@ public class VpnPaywallActivity extends BraveVpnParentActivity {
private LinearLayout mMonthlySelectorLayout;
private TextView mMonthlySubscriptionAmountText;


private ProgressBar mYearlyPlanProgress;
private LinearLayout mYearlySelectorLayout;
private TextView mYearlySubscriptionAmountText;
Expand All @@ -53,7 +52,7 @@ public class VpnPaywallActivity extends BraveVpnParentActivity {

private InAppPurchaseWrapper.SubscriptionType mSelectedPlanType =
InAppPurchaseWrapper.SubscriptionType.YEARLY;

private ProductDetails mMonthlyProductDetails;
private ProductDetails mYearlyProductDetails;

Expand Down Expand Up @@ -88,10 +87,10 @@ private void initializeViews() {
mMonthlySubscriptionAmountText = findViewById(R.id.monthly_subscription_amount_text);
mMonthlySelectorLayout = findViewById(R.id.monthly_selector_layout);
mMonthlySelectorLayout.setOnClickListener(
v -> {
mSelectedPlanType = InAppPurchaseWrapper.SubscriptionType.MONTHLY;
updateSelectedPlanView();
});
v -> {
mSelectedPlanType = InAppPurchaseWrapper.SubscriptionType.MONTHLY;
updateSelectedPlanView();
});

TextView trialText = findViewById(R.id.trial_text);
String trialString = getResources().getString(R.string.trial_text);
Expand All @@ -114,6 +113,12 @@ private void initializeViews() {
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 @@ -130,15 +135,14 @@ private void initializeViews() {
ProductDetails productDetails = null;
if (mSelectedPlanType == InAppPurchaseWrapper.SubscriptionType.MONTHLY) {
productDetails = mMonthlyProductDetails;
} else if (mSelectedPlanType
== InAppPurchaseWrapper.SubscriptionType.YEARLY) {
} else if (mSelectedPlanType == InAppPurchaseWrapper.SubscriptionType.YEARLY) {
productDetails = mYearlyProductDetails;
}
if (productDetails == null) {
return;
}
InAppPurchaseWrapper.getInstance()
.initiatePurchase(VpnPaywallActivity.this, productDetails);
.initiatePurchase(VpnPaywallActivity.this, productDetails);
});
}

Expand All @@ -152,6 +156,7 @@ public void finishNativeInitialization() {
verifySubscription();

getMonthlyProductDetails();
updateSelectedPlanView();
}

private void getMonthlyProductDetails() {
Expand Down Expand Up @@ -193,78 +198,76 @@ 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);
}
}
});
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 (mMonthlyProductDetails != null) {
String discountText =
getString(
R.string.renew_monthly_save,
InAppPurchaseWrapper.getInstance()
.getYearlyDiscountPercentage(
mMonthlyProductDetails,
mYearlyProductDetails));
SpannableString discountSpannableString =
SpanApplier.applySpans(
discountText,
new SpanInfo(
"<discount_text>",
"</discount_text>",
new StyleSpan(android.graphics.Typeface.BOLD),
new UnderlineSpan()));
mYearlyText.setText(discountSpannableString);
}
}
});
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 (mMonthlyProductDetails != null) {
String annualSaveText =
getString(
R.string.renew_yearly_save,
InAppPurchaseWrapper.getInstance()
.getYearlyDiscountPercentage(
mMonthlyProductDetails,
mYearlyProductDetails));
String discountText =
getString(R.string.renews_annually)
.concat(" ")
.concat(annualSaveText);
SpannableString discountSpannableString =
SpanApplier.applySpans(
discountText,
new SpanInfo(
"<discount_text>",
"</discount_text>",
new StyleSpan(android.graphics.Typeface.BOLD),
new UnderlineSpan()));
mYearlyText.setText(discountSpannableString);
}
}
});
}

@Override
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 b719323

Please sign in to comment.