Merge branch 'brave_vpn_radio_server_selection_radiobutton_fix'
This commit is contained in:
+15
-6
@@ -20,6 +20,7 @@ import com.wireguard.android.backend.GoBackend;
|
||||
import com.wireguard.crypto.KeyPair;
|
||||
|
||||
import org.chromium.base.Log;
|
||||
import org.chromium.base.ThreadUtils;
|
||||
import org.chromium.base.supplier.OneshotSupplier;
|
||||
import org.chromium.chrome.R;
|
||||
import org.chromium.chrome.browser.billing.InAppPurchaseWrapper;
|
||||
@@ -28,7 +29,6 @@ import org.chromium.chrome.browser.init.ActivityProfileProvider;
|
||||
import org.chromium.chrome.browser.init.AsyncInitializationActivity;
|
||||
import org.chromium.chrome.browser.profiles.ProfileProvider;
|
||||
import org.chromium.chrome.browser.util.LiveDataUtil;
|
||||
import org.chromium.chrome.browser.util.TabUtils;
|
||||
import org.chromium.chrome.browser.vpn.BraveVpnNativeWorker;
|
||||
import org.chromium.chrome.browser.vpn.BraveVpnObserver;
|
||||
import org.chromium.chrome.browser.vpn.models.BraveVpnPrefModel;
|
||||
@@ -39,8 +39,10 @@ import org.chromium.chrome.browser.vpn.utils.BraveVpnProfileUtils;
|
||||
import org.chromium.chrome.browser.vpn.utils.BraveVpnUtils;
|
||||
import org.chromium.chrome.browser.vpn.wireguard.WireguardConfigUtils;
|
||||
|
||||
public abstract class BraveVpnParentActivity
|
||||
extends AsyncInitializationActivity implements BraveVpnObserver {
|
||||
import java.util.concurrent.CompletableFuture;
|
||||
|
||||
public abstract class BraveVpnParentActivity extends AsyncInitializationActivity
|
||||
implements BraveVpnObserver {
|
||||
private static final String TAG = "BraveVPN";
|
||||
public boolean mIsVerification;
|
||||
protected BraveVpnPrefModel mBraveVpnPrefModel;
|
||||
@@ -265,8 +267,16 @@ public abstract class BraveVpnParentActivity
|
||||
braveVpnWireguardProfileCredentials.getClientId());
|
||||
mBraveVpnPrefModel.setApiAuthToken(
|
||||
braveVpnWireguardProfileCredentials.getApiAuthToken());
|
||||
BraveVpnPrefUtils.setPrefModel(mBraveVpnPrefModel);
|
||||
|
||||
CompletableFuture<Void> awaitPrefDone = new CompletableFuture<Void>();
|
||||
ThreadUtils.postOnUiThread(
|
||||
() -> {
|
||||
try {
|
||||
BraveVpnPrefUtils.setPrefModel(mBraveVpnPrefModel);
|
||||
} finally {
|
||||
awaitPrefDone.complete(null);
|
||||
}
|
||||
});
|
||||
awaitPrefDone.get();
|
||||
BraveVpnUtils.dismissProgressDialog();
|
||||
Intent intent = GoBackend.VpnService.prepare(BraveVpnParentActivity.this);
|
||||
if (intent != null) {
|
||||
@@ -274,7 +284,6 @@ public abstract class BraveVpnParentActivity
|
||||
return;
|
||||
}
|
||||
BraveVpnProfileUtils.getInstance().startVpn(BraveVpnParentActivity.this);
|
||||
TabUtils.bringChromeTabbedActivityToTheTop(BraveVpnParentActivity.this);
|
||||
} catch (Exception e) {
|
||||
BraveVpnUtils.dismissProgressDialog();
|
||||
Log.e(TAG, e.getMessage());
|
||||
|
||||
+32
@@ -57,6 +57,7 @@ public class VpnServerSelectionActivity extends BraveVpnParentActivity
|
||||
|
||||
private void initVpnService() {
|
||||
if (mServiceHandler != null) {
|
||||
mServiceHandler.close();
|
||||
mServiceHandler = null;
|
||||
}
|
||||
mServiceHandler =
|
||||
@@ -69,6 +70,10 @@ public class VpnServerSelectionActivity extends BraveVpnParentActivity
|
||||
void onServerRegionClick(Region region);
|
||||
}
|
||||
|
||||
public interface OnQuickServerSelection {
|
||||
void onQuickServerSelect(Region region);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onOptionsItemSelected(MenuItem item) {
|
||||
if (item.getItemId() == android.R.id.home) {
|
||||
@@ -169,6 +174,24 @@ public class VpnServerSelectionActivity extends BraveVpnParentActivity
|
||||
VpnServerSelectionActivity.this, region);
|
||||
}
|
||||
});
|
||||
mBraveVpnServerSelectionAdapter.setOnQuickServerSelection(
|
||||
new OnQuickServerSelection() {
|
||||
@Override
|
||||
public void onQuickServerSelect(Region region) {
|
||||
BraveVpnUtils.selectedRegion = region;
|
||||
BraveVpnUtils.selectedServerRegion =
|
||||
new BraveVpnServerRegion(
|
||||
false,
|
||||
region.country,
|
||||
region.continent,
|
||||
region.countryIsoCode,
|
||||
region.name,
|
||||
region.namePretty,
|
||||
BraveVpnConstants
|
||||
.REGION_PRECISION_COUNTRY);
|
||||
changeServerRegion();
|
||||
}
|
||||
});
|
||||
mServerRegionList.setAdapter(mBraveVpnServerSelectionAdapter);
|
||||
boolean isAutomatic = BraveVpnPrefUtils.isAutomaticServerSelection();
|
||||
updateAutomaticSelection(isAutomatic);
|
||||
@@ -218,4 +241,13 @@ public class VpnServerSelectionActivity extends BraveVpnParentActivity
|
||||
|
||||
@Override
|
||||
public void updateProfileView() {}
|
||||
|
||||
@Override
|
||||
protected void onDestroy() {
|
||||
super.onDestroy();
|
||||
if (mServiceHandler != null) {
|
||||
mServiceHandler.close();
|
||||
mServiceHandler = null;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+51
-2
@@ -19,6 +19,7 @@ import com.google.android.material.radiobutton.MaterialRadioButton;
|
||||
|
||||
import org.chromium.brave_vpn.mojom.Region;
|
||||
import org.chromium.chrome.R;
|
||||
import org.chromium.chrome.browser.vpn.activities.VpnServerSelectionActivity.OnQuickServerSelection;
|
||||
import org.chromium.chrome.browser.vpn.activities.VpnServerSelectionActivity.OnServerRegionSelection;
|
||||
import org.chromium.chrome.browser.vpn.utils.BraveVpnPrefUtils;
|
||||
import org.chromium.chrome.browser.vpn.utils.BraveVpnUtils;
|
||||
@@ -31,6 +32,8 @@ public class BraveVpnServerSelectionAdapter
|
||||
private final Context mContext;
|
||||
private List<Region> mRegions = new ArrayList<>();
|
||||
private OnServerRegionSelection mOnServerRegionSelection;
|
||||
private OnQuickServerSelection mOnQuickServerSelection;
|
||||
private Region mActiveRegion;
|
||||
|
||||
public BraveVpnServerSelectionAdapter(Context context) {
|
||||
this.mContext = context;
|
||||
@@ -45,6 +48,28 @@ public class BraveVpnServerSelectionAdapter
|
||||
return new ViewHolder(listItem);
|
||||
}
|
||||
|
||||
private static enum CheckedState {
|
||||
SET_CHECKED,
|
||||
SET_UNCHECKED,
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onBindViewHolder(
|
||||
@NonNull ViewHolder holder, int position, @NonNull List<Object> payloads) {
|
||||
if (payloads.isEmpty()) {
|
||||
onBindViewHolder(holder, position);
|
||||
return;
|
||||
}
|
||||
Object isCheckedObj = payloads.get(0);
|
||||
if (isCheckedObj instanceof CheckedState) {
|
||||
boolean isChecked = ((CheckedState) isCheckedObj) == CheckedState.SET_CHECKED;
|
||||
holder.serverRadioButton.setChecked(isChecked);
|
||||
if (isChecked) {
|
||||
mActiveRegion = mRegions.get(position);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onBindViewHolder(@NonNull ViewHolder holder, int position) {
|
||||
final Region region = mRegions.get(position);
|
||||
@@ -62,8 +87,28 @@ public class BraveVpnServerSelectionAdapter
|
||||
.getQuantityString(
|
||||
R.plurals.server_text, region.serverCount, region.serverCount);
|
||||
holder.cityServerText.setText(cityText.concat(serverText));
|
||||
holder.serverRadioButton.setChecked(
|
||||
BraveVpnPrefUtils.getRegionIsoCode().equals(region.countryIsoCode));
|
||||
boolean isChecked = BraveVpnPrefUtils.getRegionIsoCode().equals(region.countryIsoCode);
|
||||
holder.serverRadioButton.setChecked(isChecked);
|
||||
if (isChecked) {
|
||||
mActiveRegion = region;
|
||||
}
|
||||
holder.serverRadioButton.setOnClickListener(
|
||||
new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
if (region == mActiveRegion) {
|
||||
return;
|
||||
}
|
||||
mOnQuickServerSelection.onQuickServerSelect(region);
|
||||
if (mActiveRegion != null) {
|
||||
notifyItemChanged(
|
||||
mRegions.indexOf(mActiveRegion),
|
||||
CheckedState.SET_UNCHECKED);
|
||||
}
|
||||
notifyItemChanged(
|
||||
holder.getBindingAdapterPosition(), CheckedState.SET_CHECKED);
|
||||
}
|
||||
});
|
||||
holder.serverSelectionItemLayout.setOnClickListener(
|
||||
new View.OnClickListener() {
|
||||
@Override
|
||||
@@ -87,6 +132,10 @@ public class BraveVpnServerSelectionAdapter
|
||||
this.mOnServerRegionSelection = onServerRegionSelection;
|
||||
}
|
||||
|
||||
public void setOnQuickServerSelection(OnQuickServerSelection onQuickServerSelection) {
|
||||
this.mOnQuickServerSelection = onQuickServerSelection;
|
||||
}
|
||||
|
||||
public static class ViewHolder extends RecyclerView.ViewHolder {
|
||||
public LinearLayout serverSelectionItemLayout;
|
||||
public TextView serverIconText;
|
||||
|
||||
@@ -11,6 +11,7 @@ import org.chromium.chrome.browser.preferences.BravePref;
|
||||
import org.chromium.chrome.browser.preferences.ChromeSharedPreferences;
|
||||
import org.chromium.chrome.browser.profiles.ProfileManager;
|
||||
import org.chromium.chrome.browser.vpn.models.BraveVpnPrefModel;
|
||||
import org.chromium.components.prefs.PrefService;
|
||||
import org.chromium.components.user_prefs.UserPrefs;
|
||||
|
||||
import java.util.Collections;
|
||||
@@ -125,13 +126,15 @@ public class BraveVpnPrefUtils {
|
||||
}
|
||||
|
||||
public static void setPurchaseToken(String value) {
|
||||
if (value == null) {
|
||||
return;
|
||||
}
|
||||
ChromeSharedPreferences.getInstance().writeString(PREF_BRAVE_VPN_PURCHASE_TOKEN, value);
|
||||
UserPrefs.get(ProfileManager.getLastUsedRegularProfile())
|
||||
.setString(BravePref.BRAVE_VPN_PURCHASE_TOKEN_ANDROID, value);
|
||||
UserPrefs.get(ProfileManager.getLastUsedRegularProfile())
|
||||
.setString(
|
||||
BravePref.BRAVE_VPN_PACKAGE_ANDROID,
|
||||
ContextUtils.getApplicationContext().getPackageName());
|
||||
PrefService prefSvc = UserPrefs.get(ProfileManager.getLastUsedRegularProfile());
|
||||
prefSvc.setString(BravePref.BRAVE_VPN_PURCHASE_TOKEN_ANDROID, value);
|
||||
prefSvc.setString(
|
||||
BravePref.BRAVE_VPN_PACKAGE_ANDROID,
|
||||
ContextUtils.getApplicationContext().getPackageName());
|
||||
}
|
||||
|
||||
public static String getPurchaseToken() {
|
||||
@@ -139,6 +142,9 @@ public class BraveVpnPrefUtils {
|
||||
}
|
||||
|
||||
public static void setProductId(String value) {
|
||||
if (value == null) {
|
||||
return;
|
||||
}
|
||||
ChromeSharedPreferences.getInstance().writeString(PREF_BRAVE_VPN_PRODUCT_ID, value);
|
||||
UserPrefs.get(ProfileManager.getLastUsedRegularProfile())
|
||||
.setString(BravePref.BRAVE_VPN_PRODUCT_ID_ANDROID, value);
|
||||
|
||||
Reference in New Issue
Block a user