From d90a011561623dcf4f4ccb283a1e62338bc47125 Mon Sep 17 00:00:00 2001 From: Conny Duck Date: Mon, 30 Apr 2018 08:32:43 +0200 Subject: [PATCH] fix proxy settings --- .../tusky/fragment/PreferencesFragment.java | 17 ++++++++++++----- .../keylesspalace/tusky/util/OkHttpUtils.java | 9 +++++++-- 2 files changed, 19 insertions(+), 7 deletions(-) diff --git a/app/src/main/java/com/keylesspalace/tusky/fragment/PreferencesFragment.java b/app/src/main/java/com/keylesspalace/tusky/fragment/PreferencesFragment.java index 0d1530a7..e36d7cb6 100644 --- a/app/src/main/java/com/keylesspalace/tusky/fragment/PreferencesFragment.java +++ b/app/src/main/java/com/keylesspalace/tusky/fragment/PreferencesFragment.java @@ -284,13 +284,20 @@ public class PreferencesFragment extends PreferenceFragment implements SharedPre Boolean httpProxyEnabled = sharedPreferences.getBoolean("httpProxyEnabled", false); String httpServer = sharedPreferences.getString("httpProxyServer", ""); - int httpPort = Integer.parseInt(sharedPreferences.getString("httpProxyPort", "-1")); - if (httpProxyEnabled && !httpServer.isEmpty() && (httpPort > 0 && httpPort < 65535)) { - httpProxyPref.setSummary(httpServer + ":" + httpPort); - } else { - httpProxyPref.setSummary(""); + try { + int httpPort = Integer.parseInt(sharedPreferences.getString("httpProxyPort", "-1")); + + if (httpProxyEnabled && !httpServer.isEmpty() && (httpPort > 0 && httpPort < 65535)) { + httpProxyPref.setSummary(httpServer + ":" + httpPort); + return; + } + } catch (NumberFormatException e) { + // user has entered wrong port, fall back to empty summary } + + httpProxyPref.setSummary(""); + } } } diff --git a/app/src/main/java/com/keylesspalace/tusky/util/OkHttpUtils.java b/app/src/main/java/com/keylesspalace/tusky/util/OkHttpUtils.java index f714ec09..7ca05879 100644 --- a/app/src/main/java/com/keylesspalace/tusky/util/OkHttpUtils.java +++ b/app/src/main/java/com/keylesspalace/tusky/util/OkHttpUtils.java @@ -71,10 +71,15 @@ public class OkHttpUtils { SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(context); - boolean httpProxyEnabled = preferences.getBoolean("httpProxyEnabled", false); String httpServer = preferences.getString("httpProxyServer", ""); - int httpPort = Integer.parseInt(preferences.getString("httpProxyPort", "-1")); + int httpPort; + try { + httpPort = Integer.parseInt(preferences.getString("httpProxyPort", "-1")); + } catch (NumberFormatException e) { + // user has entered wrong port, fall back to no proxy + httpPort = -1; + } ConnectionSpec fallback = new ConnectionSpec.Builder(ConnectionSpec.MODERN_TLS) .allEnabledCipherSuites()