summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorByteHamster <ByteHamster@users.noreply.github.com>2022-02-08 21:13:57 +0100
committerGitHub <noreply@github.com>2022-02-08 21:13:57 +0100
commitb26df9036cf6b13f41f8961d185f9eb0cfb8a27f (patch)
tree927479b8579e3ed199cf48babe416a46b3fcd493
parent4a135a5f051fcabc9ae94caf9c0561737e27865f (diff)
parent8967fd944abecedcfa323e682cf08c084f0277b5 (diff)
downloadantennapod-b26df9036cf6b13f41f8961d185f9eb0cfb8a27f.zip
Merge pull request #5703 from ByteHamster/proxy-hostname-null
Make sure that proxy host name does not get null
-rw-r--r--app/src/main/java/de/danoeh/antennapod/dialog/ProxyDialog.java42
-rw-r--r--core/src/main/java/de/danoeh/antennapod/core/preferences/UserPreferences.java13
-rw-r--r--core/src/main/java/de/danoeh/antennapod/core/service/download/AntennapodHttpClient.java2
-rw-r--r--core/src/main/java/de/danoeh/antennapod/core/service/download/ProxyConfig.java12
4 files changed, 22 insertions, 47 deletions
diff --git a/app/src/main/java/de/danoeh/antennapod/dialog/ProxyDialog.java b/app/src/main/java/de/danoeh/antennapod/dialog/ProxyDialog.java
index ad2ed3499..2c3c44b1d 100644
--- a/app/src/main/java/de/danoeh/antennapod/dialog/ProxyDialog.java
+++ b/app/src/main/java/de/danoeh/antennapod/dialog/ProxyDialog.java
@@ -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;
+ }
+ String password = etPassword.getText().toString();
+ if (TextUtils.isEmpty(password)) {
+ password = null;
+ }
+ int portValue = 0;
+ if (!TextUtils.isEmpty(port)) {
+ portValue = Integer.parseInt(port);
}
- UserPreferences.setProxyConfig(proxy);
+ UserPreferences.setProxyConfig(new ProxyConfig(typeEnum, host, portValue, username, password));
}
private final TextWatcher requireTestOnChange = new TextWatcher() {
diff --git a/core/src/main/java/de/danoeh/antennapod/core/preferences/UserPreferences.java b/core/src/main/java/de/danoeh/antennapod/core/preferences/UserPreferences.java
index 08daf01e2..74f89a039 100644
--- a/core/src/main/java/de/danoeh/antennapod/core/preferences/UserPreferences.java
+++ b/core/src/main/java/de/danoeh/antennapod/core/preferences/UserPreferences.java
@@ -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);
diff --git a/core/src/main/java/de/danoeh/antennapod/core/service/download/AntennapodHttpClient.java b/core/src/main/java/de/danoeh/antennapod/core/service/download/AntennapodHttpClient.java
index bca3792b0..b26c57963 100644
--- a/core/src/main/java/de/danoeh/antennapod/core/service/download/AntennapodHttpClient.java
+++ b/core/src/main/java/de/danoeh/antennapod/core/service/download/AntennapodHttpClient.java
@@ -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));
diff --git a/core/src/main/java/de/danoeh/antennapod/core/service/download/ProxyConfig.java b/core/src/main/java/de/danoeh/antennapod/core/service/download/ProxyConfig.java
index 0d59a1b7e..797001e3a 100644
--- a/core/src/main/java/de/danoeh/antennapod/core/service/download/ProxyConfig.java
+++ b/core/src/main/java/de/danoeh/antennapod/core/service/download/ProxyConfig.java
@@ -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;