Merge pull request #5703 from ByteHamster/proxy-hostname-null

Make sure that proxy host name does not get null
This commit is contained in:
ByteHamster 2022-02-08 21:13:57 +01:00 committed by GitHub
commit b26df9036c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 22 additions and 47 deletions

View File

@ -148,32 +148,24 @@ public class ProxyDialog {
}
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);
}
final String type = (String) spType.getSelectedItem();
final Proxy.Type typeEnum = Proxy.Type.valueOf(type);
final String host = etHost.getText().toString();
final String port = etPort.getText().toString();
String username = etUsername.getText().toString();
if (TextUtils.isEmpty(username)) {
username = null;
}
UserPreferences.setProxyConfig(proxy);
String password = etPassword.getText().toString();
if (TextUtils.isEmpty(password)) {
password = null;
}
int portValue = 0;
if (!TextUtils.isEmpty(port)) {
portValue = Integer.parseInt(port);
}
UserPreferences.setProxyConfig(new ProxyConfig(typeEnum, host, portValue, username, password));
}
private final TextWatcher requireTestOnChange = new TextWatcher() {

View File

@ -611,27 +611,22 @@ public class UserPreferences {
public static void setProxyConfig(ProxyConfig config) {
SharedPreferences.Editor editor = prefs.edit();
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);
} else {
editor.putString(PREF_PROXY_HOST, config.host);
}
if(config.port <= 0 || config.port > 65535) {
if (config.port <= 0 || config.port > 65535) {
editor.remove(PREF_PROXY_PORT);
} else {
editor.putInt(PREF_PROXY_PORT, config.port);
}
if(TextUtils.isEmpty(config.username)) {
if (TextUtils.isEmpty(config.username)) {
editor.remove(PREF_PROXY_USER);
} else {
editor.putString(PREF_PROXY_USER, config.username);
}
if(TextUtils.isEmpty(config.password)) {
if (TextUtils.isEmpty(config.password)) {
editor.remove(PREF_PROXY_PASSWORD);
} else {
editor.putString(PREF_PROXY_PASSWORD, config.password);

View File

@ -118,7 +118,7 @@ public class AntennapodHttpClient {
builder.followSslRedirects(true);
ProxyConfig config = UserPreferences.getProxyConfig();
if (config.type != Proxy.Type.DIRECT) {
if (config.type != Proxy.Type.DIRECT && !TextUtils.isEmpty(config.host)) {
int port = config.port > 0 ? config.port : ProxyConfig.DEFAULT_PORT;
SocketAddress address = InetSocketAddress.createUnresolved(config.host, port);
builder.proxy(new Proxy(config.type, address));

View File

@ -14,18 +14,6 @@ public class ProxyConfig {
public static final int DEFAULT_PORT = 8080;
public static ProxyConfig direct() {
return new ProxyConfig(Proxy.Type.DIRECT, null, 0, null, null);
}
public static ProxyConfig http(String host, int port, String username, String password) {
return new ProxyConfig(Proxy.Type.HTTP, host, port, username, password);
}
public static ProxyConfig socks(String host, int port, String username, String password) {
return new ProxyConfig(Proxy.Type.SOCKS, host, port, username, password);
}
public ProxyConfig(Proxy.Type type, String host, int port, String username, String password) {
this.type = type;
this.host = host;