Don't forget proxy settings when disabling proxy (#5471)
This commit is contained in:
parent
b860ee33d0
commit
bf95bf172d
@ -67,6 +67,7 @@ public class ProxyDialog {
|
|||||||
.setView(content)
|
.setView(content)
|
||||||
.setNegativeButton(R.string.cancel_label, null)
|
.setNegativeButton(R.string.cancel_label, null)
|
||||||
.setPositiveButton(R.string.proxy_test_label, null)
|
.setPositiveButton(R.string.proxy_test_label, null)
|
||||||
|
.setNeutralButton(R.string.reset, null)
|
||||||
.show();
|
.show();
|
||||||
// To prevent cancelling the dialog on button click
|
// To prevent cancelling the dialog on button click
|
||||||
dialog.getButton(AlertDialog.BUTTON_POSITIVE).setOnClickListener((view) -> {
|
dialog.getButton(AlertDialog.BUTTON_POSITIVE).setOnClickListener((view) -> {
|
||||||
@ -75,36 +76,19 @@ public class ProxyDialog {
|
|||||||
test();
|
test();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
String type = (String) spType.getSelectedItem();
|
setProxyConfig();
|
||||||
ProxyConfig proxy;
|
|
||||||
if (Proxy.Type.valueOf(type) == Proxy.Type.DIRECT) {
|
|
||||||
proxy = ProxyConfig.direct();
|
|
||||||
} else {
|
|
||||||
String host = etHost.getText().toString();
|
|
||||||
String port = etPort.getText().toString();
|
|
||||||
String username = etUsername.getText().toString();
|
|
||||||
if (TextUtils.isEmpty(username)) {
|
|
||||||
username = null;
|
|
||||||
}
|
|
||||||
String password = etPassword.getText().toString();
|
|
||||||
if (TextUtils.isEmpty(password)) {
|
|
||||||
password = null;
|
|
||||||
}
|
|
||||||
int portValue = 0;
|
|
||||||
if (!TextUtils.isEmpty(port)) {
|
|
||||||
portValue = Integer.parseInt(port);
|
|
||||||
}
|
|
||||||
if (Proxy.Type.valueOf(type) == Proxy.Type.SOCKS) {
|
|
||||||
proxy = ProxyConfig.socks(host, portValue, username, password);
|
|
||||||
} else {
|
|
||||||
proxy = ProxyConfig.http(host, portValue, username, password);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
UserPreferences.setProxyConfig(proxy);
|
|
||||||
AntennapodHttpClient.reinit();
|
AntennapodHttpClient.reinit();
|
||||||
dialog.dismiss();
|
dialog.dismiss();
|
||||||
});
|
});
|
||||||
|
|
||||||
|
dialog.getButton(AlertDialog.BUTTON_NEUTRAL).setOnClickListener((view) -> {
|
||||||
|
etHost.getText().clear();
|
||||||
|
etPort.getText().clear();
|
||||||
|
etUsername.getText().clear();
|
||||||
|
etPassword.getText().clear();
|
||||||
|
setProxyConfig();
|
||||||
|
});
|
||||||
|
|
||||||
List<String> types = new ArrayList<>();
|
List<String> types = new ArrayList<>();
|
||||||
types.add(Proxy.Type.DIRECT.name());
|
types.add(Proxy.Type.DIRECT.name());
|
||||||
types.add(Proxy.Type.HTTP.name());
|
types.add(Proxy.Type.HTTP.name());
|
||||||
@ -144,6 +128,11 @@ public class ProxyDialog {
|
|||||||
spType.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
|
spType.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
|
||||||
@Override
|
@Override
|
||||||
public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {
|
public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {
|
||||||
|
if (position == 0) {
|
||||||
|
dialog.getButton(AlertDialog.BUTTON_NEUTRAL).setVisibility(View.GONE);
|
||||||
|
} else {
|
||||||
|
dialog.getButton(AlertDialog.BUTTON_NEUTRAL).setVisibility(View.VISIBLE);
|
||||||
|
}
|
||||||
enableSettings(position > 0);
|
enableSettings(position > 0);
|
||||||
setTestRequired(position > 0);
|
setTestRequired(position > 0);
|
||||||
}
|
}
|
||||||
@ -158,6 +147,35 @@ public class ProxyDialog {
|
|||||||
return dialog;
|
return dialog;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void setProxyConfig() {
|
||||||
|
String type = (String) spType.getSelectedItem();
|
||||||
|
ProxyConfig proxy;
|
||||||
|
if (Proxy.Type.valueOf(type) == Proxy.Type.DIRECT) {
|
||||||
|
proxy = ProxyConfig.direct();
|
||||||
|
} else {
|
||||||
|
String host = etHost.getText().toString();
|
||||||
|
String port = etPort.getText().toString();
|
||||||
|
String username = etUsername.getText().toString();
|
||||||
|
if (TextUtils.isEmpty(username)) {
|
||||||
|
username = null;
|
||||||
|
}
|
||||||
|
String password = etPassword.getText().toString();
|
||||||
|
if (TextUtils.isEmpty(password)) {
|
||||||
|
password = null;
|
||||||
|
}
|
||||||
|
int portValue = 0;
|
||||||
|
if (!TextUtils.isEmpty(port)) {
|
||||||
|
portValue = Integer.parseInt(port);
|
||||||
|
}
|
||||||
|
if (Proxy.Type.valueOf(type) == Proxy.Type.SOCKS) {
|
||||||
|
proxy = ProxyConfig.socks(host, portValue, username, password);
|
||||||
|
} else {
|
||||||
|
proxy = ProxyConfig.http(host, portValue, username, password);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
UserPreferences.setProxyConfig(proxy);
|
||||||
|
}
|
||||||
|
|
||||||
private final TextWatcher requireTestOnChange = new TextWatcher() {
|
private final TextWatcher requireTestOnChange = new TextWatcher() {
|
||||||
@Override
|
@Override
|
||||||
public void beforeTextChanged(CharSequence s, int start, int count, int after) {}
|
public void beforeTextChanged(CharSequence s, int start, int count, int after) {}
|
||||||
|
@ -610,6 +610,11 @@ public class UserPreferences {
|
|||||||
public static void setProxyConfig(ProxyConfig config) {
|
public static void setProxyConfig(ProxyConfig config) {
|
||||||
SharedPreferences.Editor editor = prefs.edit();
|
SharedPreferences.Editor editor = prefs.edit();
|
||||||
editor.putString(PREF_PROXY_TYPE, config.type.name());
|
editor.putString(PREF_PROXY_TYPE, config.type.name());
|
||||||
|
Proxy.Type type = Proxy.Type.valueOf(config.type.name());
|
||||||
|
if (type == Proxy.Type.DIRECT) {
|
||||||
|
editor.apply();
|
||||||
|
return;
|
||||||
|
}
|
||||||
if(TextUtils.isEmpty(config.host)) {
|
if(TextUtils.isEmpty(config.host)) {
|
||||||
editor.remove(PREF_PROXY_HOST);
|
editor.remove(PREF_PROXY_HOST);
|
||||||
} else {
|
} else {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user