Add link subscription dialog

This commit is contained in:
deeppandya
2022-11-14 23:49:52 -05:00
parent 2c647d479b
commit 031df87c54
9 changed files with 3245 additions and 1 deletions
@@ -0,0 +1,49 @@
/**
* Copyright (c) 2022 The Brave Authors. All rights reserved.
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
*/
package org.chromium.chrome.browser;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Button;
import android.widget.ImageView;
import org.chromium.chrome.R;
import org.chromium.chrome.browser.app.BraveActivity;
import org.chromium.chrome.browser.vpn.utils.BraveVpnPrefUtils;
import org.chromium.chrome.browser.vpn.utils.BraveVpnUtils;
public class LinkVpnSubscriptionDialogFragment
extends BraveDialogFragment implements View.OnClickListener {
@Override
public View onCreateView(
LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
return inflater.inflate(R.layout.fragment_link_subscription_dialog, container, false);
}
@Override
public void onViewCreated(View view, Bundle savedInstanceState) {
BraveVpnPrefUtils.setLinkSubscriptionDialogShown(true);
Button mDoneButton = view.findViewById(R.id.btn_done);
mDoneButton.setOnClickListener(this);
ImageView btnClose = view.findViewById(R.id.modal_close);
btnClose.setOnClickListener(this);
}
@Override
public void onClick(View view) {
if (view.getId() == R.id.btn_done) {
BraveActivity braveActivity = BraveActivity.getBraveActivity();
if (braveActivity != null) {
braveActivity.openNewOrSelectExistingTab(BraveVpnUtils.getBraveAccountUrl());
}
}
dismiss();
}
}
@@ -91,6 +91,7 @@ import org.chromium.chrome.browser.CrossPromotionalModalDialogFragment;
import org.chromium.chrome.browser.DormantUsersEngagementDialogFragment;
import org.chromium.chrome.browser.InternetConnection;
import org.chromium.chrome.browser.LaunchIntentDispatcher;
import org.chromium.chrome.browser.LinkVpnSubscriptionDialogFragment;
import org.chromium.chrome.browser.app.domain.WalletModel;
import org.chromium.chrome.browser.bookmarks.TabBookmarker;
import org.chromium.chrome.browser.brave_news.models.FeedItemsCard;
@@ -966,6 +967,10 @@ public abstract class BraveActivity<C extends ChromeActivityComponent> extends C
BraveVpnUtils.SUBSCRIPTION_PARAM_TEXT, getPackageName());
}
}
if (BraveVpnPrefUtils.isSubscriptionPurchase()
&& !BraveVpnPrefUtils.isLinkSubscriptionDialogShown()) {
showLinkVpnSubscriptionDialog();
}
if (PackageUtils.isFirstInstall(this)
&& (OnboardingPrefManager.getInstance().isDormantUsersEngagementEnabled()
|| getPackageName().equals(BraveConstants.BRAVE_PRODUCTION_PACKAGE_NAME))) {
@@ -1085,6 +1090,14 @@ public abstract class BraveActivity<C extends ChromeActivityComponent> extends C
getSupportFragmentManager(), "BraveVpnCalloutDialogFragment");
}
private void showLinkVpnSubscriptionDialog() {
LinkVpnSubscriptionDialogFragment linkVpnSubscriptionDialogFragment =
new LinkVpnSubscriptionDialogFragment();
linkVpnSubscriptionDialogFragment.setCancelable(false);
linkVpnSubscriptionDialogFragment.show(
getSupportFragmentManager(), "LinkVpnSubscriptionDialogFragment");
}
private void showAdFreeCalloutDialog() {
SharedPreferencesManager.getInstance().writeBoolean(
BravePreferenceKeys.BRAVE_AD_FREE_CALLOUT_DIALOG, false);
@@ -1571,6 +1584,12 @@ public abstract class BraveActivity<C extends ChromeActivityComponent> extends C
@Override
public void onNewIntent(Intent intent) {
super.onNewIntent(intent);
if (intent != null) {
String openUrl = intent.getStringExtra(BraveActivity.OPEN_URL);
if (!TextUtils.isEmpty(openUrl)) {
openNewOrSelectExistingTab(openUrl);
}
}
checkForNotificationData();
}
@@ -308,7 +308,8 @@ public class BraveVpnPreferences extends BravePreferenceFragment implements Brav
}
}
}.start();
findPreference(PREF_LINK_SUBSCRIPTION)
.setEnabled(BraveVpnPrefUtils.isSubscriptionPurchase());
BraveVpnUtils.dismissProgressDialog();
}
@@ -51,6 +51,7 @@ public class BraveVpnPrefUtils {
public static final String PREF_BRAVE_VPN_CLIENT_PRIVATE_KEY = "brave_vpn_client_private_key";
public static final String PREF_SESSION_START_TIME = "brave_vpn_session_start_time";
public static final String PREF_SESSION_END_TIME = "brave_vpn_session_end_time";
private static final String PREF_LINK_SUBSCRIPTION_DIALOG = "link_subscription_dialog";
private static final SharedPreferences mSharedPreferences =
ContextUtils.getAppSharedPreferences();
@@ -75,6 +76,16 @@ public class BraveVpnPrefUtils {
sharedPreferencesEditor.apply();
}
public static boolean isLinkSubscriptionDialogShown() {
return mSharedPreferences.getBoolean(PREF_LINK_SUBSCRIPTION_DIALOG, false);
}
public static void setLinkSubscriptionDialogShown(boolean newValue) {
SharedPreferences.Editor sharedPreferencesEditor = mSharedPreferences.edit();
sharedPreferencesEditor.putBoolean(PREF_LINK_SUBSCRIPTION_DIALOG, newValue);
sharedPreferencesEditor.apply();
}
public static boolean shouldShowCallout() {
return mSharedPreferences.getBoolean(PREF_BRAVE_VPN_CALLOUT, true);
}