Update upgrade behaviour for server selection
This commit is contained in:
+15
-4
@@ -21,6 +21,7 @@ import androidx.core.graphics.drawable.DrawableCompat;
|
||||
|
||||
import org.chromium.base.BraveFeatureList;
|
||||
import org.chromium.base.BravePreferenceKeys;
|
||||
import org.chromium.base.Log;
|
||||
import org.chromium.base.supplier.ObservableSupplier;
|
||||
import org.chromium.base.supplier.OneshotSupplier;
|
||||
import org.chromium.base.supplier.Supplier;
|
||||
@@ -58,9 +59,9 @@ import org.chromium.components.embedder_support.util.UrlUtilities;
|
||||
import org.chromium.components.user_prefs.UserPrefs;
|
||||
import org.chromium.ui.modaldialog.ModalDialogManager;
|
||||
|
||||
/**
|
||||
* Brave's extension for TabbedAppMenuPropertiesDelegate
|
||||
*/
|
||||
import java.util.Locale;
|
||||
|
||||
/** Brave's extension for TabbedAppMenuPropertiesDelegate */
|
||||
public class BraveTabbedAppMenuPropertiesDelegate extends TabbedAppMenuPropertiesDelegate {
|
||||
private Menu mMenu;
|
||||
private AppMenuDelegate mAppMenuDelegate;
|
||||
@@ -124,6 +125,10 @@ public class BraveTabbedAppMenuPropertiesDelegate extends TabbedAppMenuPropertie
|
||||
BraveVpnProfileUtils.getInstance().isBraveVPNConnected(mContext));
|
||||
}
|
||||
|
||||
Log.e(
|
||||
"brave_vpn",
|
||||
"BraveVpnPrefUtils.getRegionIsoCode() : "
|
||||
+ BraveVpnPrefUtils.getRegionIsoCode());
|
||||
if (BraveVpnPrefUtils.isSubscriptionPurchase()
|
||||
&& !TextUtils.isEmpty(BraveVpnPrefUtils.getRegionIsoCode())) {
|
||||
String serverLocation = " %s %s";
|
||||
@@ -131,12 +136,18 @@ public class BraveTabbedAppMenuPropertiesDelegate extends TabbedAppMenuPropertie
|
||||
menu.findItem(R.id.request_vpn_location_row_menu_id).getSubMenu();
|
||||
MenuItem vpnLocationSubMenuItem =
|
||||
vpnLocationSubMenu.findItem(R.id.request_vpn_location_id);
|
||||
String isoCode = BraveVpnPrefUtils.getRegionIsoCode();
|
||||
String country =
|
||||
(!BraveVpnPrefUtils.getRegionCountry().equals("")
|
||||
? BraveVpnPrefUtils.getRegionCountry()
|
||||
: new Locale("", isoCode).getDisplayCountry());
|
||||
|
||||
vpnLocationSubMenuItem.setTitle(
|
||||
String.format(
|
||||
serverLocation,
|
||||
BraveVpnUtils.countryCodeToEmoji(
|
||||
BraveVpnPrefUtils.getRegionIsoCode()),
|
||||
BraveVpnPrefUtils.getRegionNamePretty()));
|
||||
country));
|
||||
MenuItem vpnLocationIconSubMenuItem =
|
||||
vpnLocationSubMenu.findItem(R.id.request_vpn_location_icon_id);
|
||||
Drawable drawable = vpnLocationIconSubMenuItem.getIcon();
|
||||
|
||||
@@ -114,10 +114,13 @@ public class VpnServerActivity extends BraveVpnParentActivity {
|
||||
} else {
|
||||
BraveVpnUtils.selectedServerRegion =
|
||||
new BraveVpnServerRegion(
|
||||
region.countryIsoCode,
|
||||
false,
|
||||
city.country,
|
||||
city.continent,
|
||||
position == 0
|
||||
? BraveVpnPrefUtils.PREF_BRAVE_VPN_AUTOMATIC
|
||||
: city.name,
|
||||
? region.countryIsoCode
|
||||
: city.countryIsoCode,
|
||||
position == 0 ? region.name : city.name,
|
||||
position == 0 ? region.namePretty : city.namePretty,
|
||||
position == 0
|
||||
? BraveVpnConstants.REGION_PRECISION_COUNTRY
|
||||
|
||||
+3
-1
@@ -98,6 +98,9 @@ public class VpnServerSelectionActivity extends BraveVpnParentActivity
|
||||
if (mAutomaticSwitch.isChecked()) {
|
||||
BraveVpnUtils.selectedServerRegion =
|
||||
new BraveVpnServerRegion(
|
||||
true,
|
||||
"",
|
||||
"",
|
||||
"",
|
||||
BraveVpnPrefUtils.PREF_BRAVE_VPN_AUTOMATIC,
|
||||
"",
|
||||
@@ -105,7 +108,6 @@ public class VpnServerSelectionActivity extends BraveVpnParentActivity
|
||||
changeServerRegion();
|
||||
}
|
||||
|
||||
BraveVpnPrefUtils.setAutomaticServerSelection(mAutomaticSwitch.isChecked());
|
||||
updateAutomaticSelection(mAutomaticSwitch.isChecked());
|
||||
}
|
||||
});
|
||||
|
||||
@@ -20,6 +20,7 @@ import com.google.android.material.radiobutton.MaterialRadioButton;
|
||||
import org.chromium.brave_vpn.mojom.BraveVpnConstants;
|
||||
import org.chromium.brave_vpn.mojom.Region;
|
||||
import org.chromium.chrome.R;
|
||||
import org.chromium.base.Log;
|
||||
import org.chromium.chrome.browser.vpn.activities.VpnServerActivity.OnCitySelection;
|
||||
import org.chromium.chrome.browser.vpn.utils.BraveVpnPrefUtils;
|
||||
|
||||
@@ -54,24 +55,11 @@ public class VpnServerAdapter extends RecyclerView.Adapter<VpnServerAdapter.View
|
||||
.getQuantityString(
|
||||
R.plurals.server_text, city.serverCount, city.serverCount);
|
||||
holder.cityServerText.setText((position == 0) ? city.name : cityServerText);
|
||||
// boolean isEnabled =
|
||||
// BraveVpnPrefUtils.getRegionName().equals(mRegion.name)
|
||||
// && BraveVpnPrefUtils.getRegionName()
|
||||
// .equals(
|
||||
// position == 0
|
||||
// ? BraveVpnUtils.OPTIMAL_SERVER
|
||||
// : city.name);
|
||||
// boolean isEnabled =
|
||||
// BraveVpnPrefUtils.getRegionPrecision()
|
||||
// .equals(BraveVpnConstants.REGION_PRECISION_CITY)
|
||||
// && BraveVpnPrefUtils.getRegionName()
|
||||
// .equals(
|
||||
// position == 0
|
||||
// ? BraveVpnPrefUtils.PREF_BRAVE_VPN_AUTOMATIC
|
||||
// : city.name);
|
||||
|
||||
// boolean isEnabled =
|
||||
// (BraveVpnPrefUtils.getRegionPrecision().equals(BraveVpnConstants.REGION_PRECISION_COUNTRY) && BraveVpnPrefUtils.getRegionName().equals(mRegion.name) && position == 0) || (BraveVpnPrefUtils.getRegionPrecision().equals(BraveVpnConstants.REGION_PRECISION_CITY) && BraveVpnPrefUtils.getRegionName().equals(city.name));
|
||||
Log.e(
|
||||
"brave_vpn",
|
||||
"BraveVpnPrefUtils.getRegionName() : " + BraveVpnPrefUtils.getRegionName());
|
||||
Log.e("brave_vpn", "mRegion.name : " + mRegion.name);
|
||||
|
||||
boolean isCountryPrecision =
|
||||
BraveVpnPrefUtils.getRegionPrecision()
|
||||
|
||||
@@ -8,22 +8,43 @@ package org.chromium.chrome.browser.vpn.models;
|
||||
import androidx.annotation.NonNull;
|
||||
|
||||
public class BraveVpnServerRegion {
|
||||
private String mCountryIsoCode;
|
||||
private String mRegionName;
|
||||
private String mRegionNamePretty;
|
||||
private String mRegionPrecision;
|
||||
private final boolean mIsAutoSelected;
|
||||
private final String mCountry;
|
||||
private final String mContinent;
|
||||
private final String mCountryIsoCode;
|
||||
private final String mRegionName;
|
||||
private final String mRegionNamePretty;
|
||||
private final String mRegionPrecision;
|
||||
|
||||
public BraveVpnServerRegion(
|
||||
boolean isAutoSelected,
|
||||
String country,
|
||||
String continent,
|
||||
String countryIsoCode,
|
||||
String regionName,
|
||||
String regionNamePretty,
|
||||
String regionPrecision) {
|
||||
this.mIsAutoSelected = isAutoSelected;
|
||||
this.mCountry = country;
|
||||
this.mContinent = continent;
|
||||
this.mCountryIsoCode = countryIsoCode;
|
||||
this.mRegionName = regionName;
|
||||
this.mRegionNamePretty = regionNamePretty;
|
||||
this.mRegionPrecision = regionPrecision;
|
||||
}
|
||||
|
||||
public boolean isAutoSelected() {
|
||||
return mIsAutoSelected;
|
||||
}
|
||||
|
||||
public String getCountry() {
|
||||
return mCountry;
|
||||
}
|
||||
|
||||
public String getContinent() {
|
||||
return mContinent;
|
||||
}
|
||||
|
||||
public String getCountryIsoCode() {
|
||||
return mCountryIsoCode;
|
||||
}
|
||||
@@ -44,7 +65,15 @@ public class BraveVpnServerRegion {
|
||||
@Override
|
||||
public String toString() {
|
||||
return "BraveVpnServerRegion{"
|
||||
+ "mCountryIsoCode='"
|
||||
+ "mIsAutoSelected="
|
||||
+ mIsAutoSelected
|
||||
+ ", mCountry='"
|
||||
+ mCountry
|
||||
+ '\''
|
||||
+ ", mContinent='"
|
||||
+ mContinent
|
||||
+ '\''
|
||||
+ ", mCountryIsoCode='"
|
||||
+ mCountryIsoCode
|
||||
+ '\''
|
||||
+ ", mRegionName='"
|
||||
|
||||
@@ -14,6 +14,7 @@ import android.util.Pair;
|
||||
import androidx.lifecycle.LiveData;
|
||||
import androidx.lifecycle.MutableLiveData;
|
||||
|
||||
import org.chromium.base.Log;
|
||||
import org.chromium.chrome.R;
|
||||
import org.chromium.chrome.browser.billing.InAppPurchaseWrapper;
|
||||
import org.chromium.chrome.browser.billing.PurchaseModel;
|
||||
@@ -88,6 +89,7 @@ public class BraveVpnApiResponseUtils {
|
||||
? region
|
||||
: serverRegion;
|
||||
}
|
||||
Log.e("brave_vpn", "region : " + region);
|
||||
// region =
|
||||
// (braveVpnServerRegion
|
||||
// .getRegionPrecision()
|
||||
|
||||
@@ -1,9 +1,7 @@
|
||||
/**
|
||||
* Copyright (c) 2021 The Brave Authors. All rights reserved.
|
||||
/* Copyright (c) 2021 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 https://mozilla.org/MPL/2.0/.
|
||||
*/
|
||||
* License, v. 2.0. If a copy of the MPL was not distributed with this file,
|
||||
* You can obtain one at https://mozilla.org/MPL/2.0/. */
|
||||
|
||||
package org.chromium.chrome.browser.vpn.utils;
|
||||
|
||||
@@ -30,6 +28,8 @@ public class BraveVpnPrefUtils {
|
||||
private static final String PREF_BRAVE_VPN_PURCHASE_EXPIRY = "brave_vpn_purchase_expiry";
|
||||
private static final String PREF_BRAVE_VPN_SERVER_REGIONS = "brave_vpn_server_regions";
|
||||
private static final String PREF_BRAVE_VPN_SERVER_CHANGE_LOCATION = "server_change_location";
|
||||
private static final String PREF_BRAVE_VPN_SERVER_COUNTRY = "server_country";
|
||||
private static final String PREF_BRAVE_VPN_SERVER_CONTINENT = "server_continent";
|
||||
private static final String PREF_BRAVE_VPN_SERVER_ISO_CODE = "server_iso_code";
|
||||
private static final String PREF_BRAVE_VPN_SERVER_NAME_PRETTY = "server_name_pretty";
|
||||
private static final String PREF_BRAVE_VPN_SERVER_PRECISION = "server_precision";
|
||||
@@ -167,6 +167,28 @@ public class BraveVpnPrefUtils {
|
||||
.writeString(PREF_BRAVE_VPN_SERVER_CHANGE_LOCATION, newValue);
|
||||
}
|
||||
|
||||
public static String getRegionCountry() {
|
||||
String code =
|
||||
ChromeSharedPreferences.getInstance().readString(PREF_BRAVE_VPN_SERVER_COUNTRY, "");
|
||||
return code;
|
||||
}
|
||||
|
||||
public static void setRegionCountry(String newValue) {
|
||||
ChromeSharedPreferences.getInstance().writeString(PREF_BRAVE_VPN_SERVER_COUNTRY, newValue);
|
||||
}
|
||||
|
||||
public static String getRegionContinent() {
|
||||
String code =
|
||||
ChromeSharedPreferences.getInstance()
|
||||
.readString(PREF_BRAVE_VPN_SERVER_CONTINENT, "");
|
||||
return code;
|
||||
}
|
||||
|
||||
public static void setRegionContinent(String newValue) {
|
||||
ChromeSharedPreferences.getInstance()
|
||||
.writeString(PREF_BRAVE_VPN_SERVER_CONTINENT, newValue);
|
||||
}
|
||||
|
||||
public static String getRegionIsoCode() {
|
||||
String code =
|
||||
ChromeSharedPreferences.getInstance()
|
||||
@@ -255,10 +277,13 @@ public class BraveVpnPrefUtils {
|
||||
public static void setPrefModel(BraveVpnPrefModel braveVpnPrefModel) {
|
||||
setHostname(braveVpnPrefModel.getHostname());
|
||||
setHostnameDisplay(braveVpnPrefModel.getHostnameDisplay());
|
||||
setRegionCountry(braveVpnPrefModel.getServerRegion().getCountry());
|
||||
setRegionContinent(braveVpnPrefModel.getServerRegion().getContinent());
|
||||
setRegionIsoCode(braveVpnPrefModel.getServerRegion().getCountryIsoCode());
|
||||
setRegionName(braveVpnPrefModel.getServerRegion().getRegionName());
|
||||
setRegionNamePretty(braveVpnPrefModel.getServerRegion().getRegionNamePretty());
|
||||
setRegionPrecision(braveVpnPrefModel.getServerRegion().getRegionPrecision());
|
||||
setAutomaticServerSelection(braveVpnPrefModel.getServerRegion().isAutoSelected());
|
||||
setPurchaseToken(braveVpnPrefModel.getPurchaseToken());
|
||||
setProductId(braveVpnPrefModel.getProductId());
|
||||
setSubscriberCredential(braveVpnPrefModel.getSubscriberCredential());
|
||||
|
||||
@@ -43,6 +43,7 @@ import org.chromium.gms.ChromiumPlayServicesAvailability;
|
||||
import org.chromium.ui.widget.Toast;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Locale;
|
||||
import java.util.Random;
|
||||
|
||||
public class BraveVpnUtils {
|
||||
@@ -155,9 +156,14 @@ public class BraveVpnUtils {
|
||||
JSONArray timezones = region.getJSONArray("timezones");
|
||||
for (int j = 0; j < timezones.length(); j++) {
|
||||
if (timezones.getString(j).equals(currentTimezone)) {
|
||||
String isoCode = region.getString("country-iso-code");
|
||||
String country = new Locale("", isoCode).getDisplayCountry();
|
||||
BraveVpnServerRegion braveVpnServerRegion =
|
||||
new BraveVpnServerRegion(
|
||||
region.getString("country-iso-code"),
|
||||
true,
|
||||
country,
|
||||
region.getString("continent"),
|
||||
isoCode,
|
||||
region.getString("name"),
|
||||
region.getString("name-pretty"),
|
||||
BraveVpnConstants.REGION_PRECISION_COUNTRY);
|
||||
|
||||
@@ -42,6 +42,7 @@
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_gravity="center_vertical"
|
||||
android:theme="@style/BraveRadioButton"
|
||||
android:layout_marginEnd="16dp" />
|
||||
android:layout_marginEnd="16dp"
|
||||
android:clickable="false" />
|
||||
|
||||
</LinearLayout>
|
||||
|
||||
Reference in New Issue
Block a user