Add pref dynamically to avoid crash

This commit is contained in:
Deep
2021-10-14 16:17:10 -04:00
parent 1b3d6d7077
commit 3cc6e836e8
3 changed files with 10 additions and 6 deletions
@@ -131,6 +131,7 @@ public class BraveMainPreferencesBase
// removePreferenceIfPresent(PREF_USE_CUSTOM_TABS);
removePreferenceIfPresent(PREF_ADVANCED_SECTION);
removePreferenceIfPresent(PREF_PRIVACY);
removePreferenceIfPresent(PREF_BRAVE_VPN_CALLOUT);
updateSearchEnginePreference();
@@ -173,9 +174,10 @@ public class BraveMainPreferencesBase
if (BraveVpnPrefUtils.shouldShowCallout() && !BraveVpnPrefUtils.isSubscriptionPurchase()
&& BraveVpnUtils.isBraveVpnFeatureEnable()) {
findPreference(PREF_BRAVE_VPN_CALLOUT).setOrder(firstSectionOrder);
} else {
removePreferenceIfPresent(PREF_BRAVE_VPN_CALLOUT);
VpnCalloutPreference vpnCalloutPreference = new VpnCalloutPreference(getActivity());
vpnCalloutPreference.setKey(PREF_BRAVE_VPN_CALLOUT);
vpnCalloutPreference.setOrder(firstSectionOrder);
getPreferenceScreen().addPreference(vpnCalloutPreference);
}
findPreference(PREF_FEATURES_SECTION).setOrder(++firstSectionOrder);
@@ -27,6 +27,11 @@ import org.chromium.chrome.browser.vpn.BraveVpnUtils;
import org.chromium.ui.base.DeviceFormFactor;
public class VpnCalloutPreference extends Preference {
public VpnCalloutPreference(Context context) {
super(context);
setLayoutResource(R.layout.vpn_settings_callout_modal_layout);
}
public VpnCalloutPreference(Context context, AttributeSet attrs) {
this(context, attrs, 0);
}
@@ -6,9 +6,6 @@
<PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android"
android:orderingFromXml="false">
<org.chromium.chrome.browser.settings.VpnCalloutPreference
android:key="pref_vpn_callout"
android:order="0"/>
<PreferenceCategory
android:key="features_section"
android:order="1"