summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-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;