From a912022c5529f43705d922509f3a890eacee1fc4 Mon Sep 17 00:00:00 2001 From: KOSBUM Date: Thu, 2 Jul 2015 02:18:22 +0300 Subject: [PATCH 1/3] proxy server settings were added to 'Advanced settings' screen --- .../src/main/java/org/floens/chan/Chan.java | 4 +- .../org/floens/chan/core/cache/FileCache.java | 12 +++ .../chan/core/net/ProxiedHurlStack.java | 29 ++++++++ .../chan/core/settings/ChanSettings.java | 8 ++ .../chan/core/settings/IntegerSetting.java | 39 ++++++++++ .../AdvancedSettingsController.java | 8 ++ .../chan/ui/settings/IntegerSettingView.java | 74 +++++++++++++++++++ .../chan/ui/settings/SettingsController.java | 11 ++- Clover/app/src/main/res/values/strings.xml | 5 ++ 9 files changed, 187 insertions(+), 3 deletions(-) create mode 100644 Clover/app/src/main/java/org/floens/chan/core/net/ProxiedHurlStack.java create mode 100644 Clover/app/src/main/java/org/floens/chan/core/settings/IntegerSetting.java create mode 100644 Clover/app/src/main/java/org/floens/chan/ui/settings/IntegerSettingView.java diff --git a/Clover/app/src/main/java/org/floens/chan/Chan.java b/Clover/app/src/main/java/org/floens/chan/Chan.java index 40a43f4b..979e0c6b 100644 --- a/Clover/app/src/main/java/org/floens/chan/Chan.java +++ b/Clover/app/src/main/java/org/floens/chan/Chan.java @@ -34,6 +34,7 @@ import org.floens.chan.core.manager.BoardManager; import org.floens.chan.core.manager.WatchManager; import org.floens.chan.core.net.BitmapLruImageCache; import org.floens.chan.core.http.ReplyManager; +import org.floens.chan.core.net.ProxiedHurlStack; import org.floens.chan.core.settings.ChanSettings; import org.floens.chan.database.DatabaseManager; import org.floens.chan.utils.AndroidUtils; @@ -151,7 +152,8 @@ public class Chan extends Application { replyManager = new ReplyManager(this); - volleyRequestQueue = Volley.newRequestQueue(this, getUserAgent(), null, new File(cacheDir, Volley.DEFAULT_CACHE_DIR), VOLLEY_CACHE_SIZE); + String userAgent = getUserAgent(); + volleyRequestQueue = Volley.newRequestQueue(this, userAgent, new ProxiedHurlStack(userAgent), new File(cacheDir, Volley.DEFAULT_CACHE_DIR), VOLLEY_CACHE_SIZE); imageLoader = new ImageLoader(volleyRequestQueue, new BitmapLruImageCache(VOLLEY_LRU_CACHE_SIZE)); fileCache = new FileCache(new File(cacheDir, FILE_CACHE_NAME), FILE_CACHE_DISK_SIZE, getUserAgent()); diff --git a/Clover/app/src/main/java/org/floens/chan/core/cache/FileCache.java b/Clover/app/src/main/java/org/floens/chan/core/cache/FileCache.java index 2b0af178..6a298ea7 100644 --- a/Clover/app/src/main/java/org/floens/chan/core/cache/FileCache.java +++ b/Clover/app/src/main/java/org/floens/chan/core/cache/FileCache.java @@ -25,6 +25,7 @@ import com.squareup.okhttp.Response; import com.squareup.okhttp.ResponseBody; import com.squareup.okhttp.internal.Util; +import org.floens.chan.core.settings.ChanSettings; import org.floens.chan.utils.AndroidUtils; import org.floens.chan.utils.Logger; import org.floens.chan.utils.Time; @@ -35,6 +36,8 @@ import java.io.File; import java.io.FileOutputStream; import java.io.InterruptedIOException; import java.io.OutputStream; +import java.net.InetSocketAddress; +import java.net.Proxy; import java.util.ArrayList; import java.util.Collections; import java.util.List; @@ -419,6 +422,15 @@ public class FileCache { .header("User-Agent", userAgent) .build(); + Proxy proxy = null; + if (ChanSettings.proxyEnabled.get()) + { + proxy = new Proxy(Proxy.Type.HTTP, InetSocketAddress.createUnresolved( + ChanSettings.proxyAddress.get(), + ChanSettings.proxyPort.get())); + } + fileCache.httpClient.setProxy(proxy); + call = fileCache.httpClient.newCall(request); Response response = call.execute(); if (!response.isSuccessful()) { diff --git a/Clover/app/src/main/java/org/floens/chan/core/net/ProxiedHurlStack.java b/Clover/app/src/main/java/org/floens/chan/core/net/ProxiedHurlStack.java new file mode 100644 index 00000000..877012ca --- /dev/null +++ b/Clover/app/src/main/java/org/floens/chan/core/net/ProxiedHurlStack.java @@ -0,0 +1,29 @@ +package org.floens.chan.core.net; + +import java.io.IOException; +import java.net.HttpURLConnection; +import java.net.InetSocketAddress; +import java.net.Proxy; +import java.net.URL; +import com.android.volley.toolbox.HurlStack; +import org.floens.chan.core.settings.ChanSettings; + +public class ProxiedHurlStack extends HurlStack { + + public ProxiedHurlStack(String userAgent) { + super(userAgent, null); + } + + @Override + protected HttpURLConnection createConnection(URL url) throws IOException { + // Start the connection by specifying a proxy server + Proxy proxy = null; + if (ChanSettings.proxyEnabled.get()) + { + proxy = new Proxy(Proxy.Type.HTTP, InetSocketAddress.createUnresolved( + ChanSettings.proxyAddress.get(), + ChanSettings.proxyPort.get())); + } + return (HttpURLConnection) url.openConnection(proxy); + } +} \ No newline at end of file diff --git a/Clover/app/src/main/java/org/floens/chan/core/settings/ChanSettings.java b/Clover/app/src/main/java/org/floens/chan/core/settings/ChanSettings.java index 4f6ae8b4..0fe4b500 100644 --- a/Clover/app/src/main/java/org/floens/chan/core/settings/ChanSettings.java +++ b/Clover/app/src/main/java/org/floens/chan/core/settings/ChanSettings.java @@ -94,6 +94,10 @@ public class ChanSettings { public static final StringSetting passPin; public static final StringSetting passId; + public static final BooleanSetting proxyEnabled; + public static final StringSetting proxyAddress; + public static final IntegerSetting proxyPort; + static { SharedPreferences p = AndroidUtils.getPreferences(); @@ -155,6 +159,10 @@ public class ChanSettings { passPin = new StringSetting(p, "preference_pass_pin", ""); passId = new StringSetting(p, "preference_pass_id", ""); + proxyEnabled = new BooleanSetting(p, "preference_proxy_enabled", false); + proxyAddress = new StringSetting(p, "preference_proxy_address", ""); + proxyPort = new IntegerSetting(p, "preference_proxy_port", 80); + // Old (but possibly still in some users phone) // preference_board_view_mode default "list" // preference_board_editor_filler default false diff --git a/Clover/app/src/main/java/org/floens/chan/core/settings/IntegerSetting.java b/Clover/app/src/main/java/org/floens/chan/core/settings/IntegerSetting.java new file mode 100644 index 00000000..19839fd7 --- /dev/null +++ b/Clover/app/src/main/java/org/floens/chan/core/settings/IntegerSetting.java @@ -0,0 +1,39 @@ +package org.floens.chan.core.settings; + +import android.content.SharedPreferences; + +/** + * Created by Zetsubou on 02.07.2015. + */ +public class IntegerSetting extends Setting { + private boolean hasCached = false; + private Integer cached; + + public IntegerSetting(SharedPreferences sharedPreferences, String key, Integer def) { + super(sharedPreferences, key, def); + } + + public IntegerSetting(SharedPreferences sharedPreferences, String key, Integer def, SettingCallback callback) { + super(sharedPreferences, key, def, callback); + } + + @Override + public Integer get() { + if (hasCached) { + return cached; + } else { + cached = sharedPreferences.getInt(key, def); + hasCached = true; + return cached; + } + } + + @Override + public void set(Integer value) { + if (!value.equals(get())) { + sharedPreferences.edit().putInt(key, value).apply(); + cached = value; + onValueChanged(); + } + } +} diff --git a/Clover/app/src/main/java/org/floens/chan/ui/controller/AdvancedSettingsController.java b/Clover/app/src/main/java/org/floens/chan/ui/controller/AdvancedSettingsController.java index a9af23bf..c36063b9 100644 --- a/Clover/app/src/main/java/org/floens/chan/ui/controller/AdvancedSettingsController.java +++ b/Clover/app/src/main/java/org/floens/chan/ui/controller/AdvancedSettingsController.java @@ -27,9 +27,11 @@ import org.floens.chan.R; import org.floens.chan.core.settings.ChanSettings; import org.floens.chan.ui.fragment.FolderPickFragment; import org.floens.chan.ui.settings.BooleanSettingView; +import org.floens.chan.ui.settings.IntegerSettingView; import org.floens.chan.ui.settings.LinkSettingView; import org.floens.chan.ui.settings.SettingsController; import org.floens.chan.ui.settings.SettingsGroup; +import org.floens.chan.ui.settings.StringSettingView; import java.io.File; @@ -91,6 +93,12 @@ public class AdvancedSettingsController extends SettingsController { settings.add(new BooleanSettingView(this, ChanSettings.confirmExit, string(R.string.setting_confirm_exit), null)); groups.add(settings); + + SettingsGroup proxy = new SettingsGroup(string(R.string.settings_group_proxy)); + proxy.add(new BooleanSettingView(this, ChanSettings.proxyEnabled, string(R.string.setting_proxy_enabled), null)); + proxy.add(new StringSettingView(this, ChanSettings.proxyAddress, string(R.string.setting_proxy_address), string(R.string.setting_proxy_address))); + proxy.add(new IntegerSettingView(this, ChanSettings.proxyPort, string(R.string.setting_proxy_port), string(R.string.setting_proxy_port))); + groups.add(proxy); } private void setSaveLocationDescription() { diff --git a/Clover/app/src/main/java/org/floens/chan/ui/settings/IntegerSettingView.java b/Clover/app/src/main/java/org/floens/chan/ui/settings/IntegerSettingView.java new file mode 100644 index 00000000..007c83c9 --- /dev/null +++ b/Clover/app/src/main/java/org/floens/chan/ui/settings/IntegerSettingView.java @@ -0,0 +1,74 @@ +package org.floens.chan.ui.settings; + +import android.app.AlertDialog; +import android.content.DialogInterface; +import android.text.InputType; +import android.view.View; +import android.view.WindowManager; +import android.view.inputmethod.EditorInfo; +import android.widget.EditText; +import android.widget.LinearLayout; + +import org.floens.chan.R; +import org.floens.chan.core.settings.Setting; + +import static org.floens.chan.utils.AndroidUtils.dp; + +/** + * Created by Zetsubou on 02.07.2015. + */ +public class IntegerSettingView extends SettingView implements View.OnClickListener { + private final Setting setting; + private final String dialogTitle; + + public IntegerSettingView(SettingsController settingsController, Setting setting, String name, String dialogTitle) { + super(settingsController, name); + this.setting = setting; + this.dialogTitle = dialogTitle; + } + + @Override + public void setView(View view) { + super.setView(view); + view.setOnClickListener(this); + } + + @Override + public String getBottomDescription() { + return setting.get() != null ? setting.get().toString() : null; + } + + @Override + public void onClick(View v) { + LinearLayout container = new LinearLayout(v.getContext()); + container.setPadding(dp(24), dp(8), dp(24), 0); + + final EditText editText = new EditText(v.getContext()); + editText.setImeOptions(EditorInfo.IME_FLAG_NO_FULLSCREEN); + editText.setText(setting.get().toString()); + editText.setInputType(InputType.TYPE_CLASS_NUMBER); + editText.setSingleLine(true); + + container.addView(editText, LinearLayout.LayoutParams.MATCH_PARENT, LinearLayout.LayoutParams.WRAP_CONTENT); + + AlertDialog dialog = new AlertDialog.Builder(v.getContext()) + .setPositiveButton(R.string.ok, new DialogInterface.OnClickListener() { + @Override + public void onClick(DialogInterface d, int which) { + try { + setting.set(Integer.parseInt(editText.getText().toString())); + } catch (Exception e) { + setting.set(setting.getDefault()); + } + + settingsController.onPreferenceChange(IntegerSettingView.this); + } + }) + .setNegativeButton(R.string.cancel, null) + .setTitle(dialogTitle) + .setView(container) + .create(); + dialog.getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_VISIBLE); + dialog.show(); + } +} \ No newline at end of file diff --git a/Clover/app/src/main/java/org/floens/chan/ui/settings/SettingsController.java b/Clover/app/src/main/java/org/floens/chan/ui/settings/SettingsController.java index 3b525b2f..1b2ce8d8 100644 --- a/Clover/app/src/main/java/org/floens/chan/ui/settings/SettingsController.java +++ b/Clover/app/src/main/java/org/floens/chan/ui/settings/SettingsController.java @@ -65,7 +65,10 @@ public class SettingsController extends Controller implements AndroidUtils.OnMea } public void onPreferenceChange(SettingView item) { - if ((item instanceof ListSettingView) || (item instanceof StringSettingView) || (item instanceof LinkSettingView)) { + if ((item instanceof ListSettingView) + || (item instanceof StringSettingView) + || (item instanceof IntegerSettingView) + || (item instanceof LinkSettingView)) { setDescriptionText(item.view, item.getTopDescription(), item.getBottomDescription()); } } @@ -130,7 +133,11 @@ public class SettingsController extends Controller implements AndroidUtils.OnMea String topValue = settingView.getTopDescription(); String bottomValue = settingView.getBottomDescription(); - if ((settingView instanceof ListSettingView) || (settingView instanceof LinkSettingView) || (settingView instanceof StringSettingView)) { + if ((settingView instanceof ListSettingView) + || (settingView instanceof LinkSettingView) + || (settingView instanceof StringSettingView) + || (settingView instanceof IntegerSettingView) ) + { preferenceView = (ViewGroup) inf.inflate(R.layout.setting_link, groupLayout, false); } else if (settingView instanceof BooleanSettingView) { preferenceView = (ViewGroup) inf.inflate(R.layout.setting_boolean, groupLayout, false); diff --git a/Clover/app/src/main/res/values/strings.xml b/Clover/app/src/main/res/values/strings.xml index 6d8fcc99..517910ea 100644 --- a/Clover/app/src/main/res/values/strings.xml +++ b/Clover/app/src/main/res/values/strings.xml @@ -243,6 +243,11 @@ along with this program. If not, see . Confirm before exit Confirm exit + HTTP Proxy + Enable proxy + Proxy server address + Proxy server port + Watcher settings Watcher settings To watch pins for new posts, turn the thread watcher on. From eea2302b03f0835eb1cad8e4ed22239537d929c6 Mon Sep 17 00:00:00 2001 From: KOSBUM Date: Sun, 12 Jul 2015 16:14:03 +0300 Subject: [PATCH 2/3] url.openConnection exception fix --- .../java/org/floens/chan/core/net/ProxiedHurlStack.java | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/Clover/app/src/main/java/org/floens/chan/core/net/ProxiedHurlStack.java b/Clover/app/src/main/java/org/floens/chan/core/net/ProxiedHurlStack.java index 877012ca..ec63a07f 100644 --- a/Clover/app/src/main/java/org/floens/chan/core/net/ProxiedHurlStack.java +++ b/Clover/app/src/main/java/org/floens/chan/core/net/ProxiedHurlStack.java @@ -17,13 +17,16 @@ public class ProxiedHurlStack extends HurlStack { @Override protected HttpURLConnection createConnection(URL url) throws IOException { // Start the connection by specifying a proxy server - Proxy proxy = null; if (ChanSettings.proxyEnabled.get()) { - proxy = new Proxy(Proxy.Type.HTTP, InetSocketAddress.createUnresolved( + Proxy proxy = new Proxy(Proxy.Type.HTTP, InetSocketAddress.createUnresolved( ChanSettings.proxyAddress.get(), ChanSettings.proxyPort.get())); + return (HttpURLConnection) url.openConnection(proxy); + } + else + { + return (HttpURLConnection) url.openConnection(); } - return (HttpURLConnection) url.openConnection(proxy); } } \ No newline at end of file From ce3202671a1f035aedd5ca60ac1dcb7911749c09 Mon Sep 17 00:00:00 2001 From: Floens Date: Sun, 26 Jul 2015 14:01:22 +0200 Subject: [PATCH 3/3] Cache Proxy object creation, formatting and license headers on all files --- .../src/main/java/org/floens/chan/Chan.java | 2 +- .../java/org/floens/chan/chan/ChanHelper.java | 17 ++++++++ .../org/floens/chan/core/cache/FileCache.java | 11 +---- .../floens/chan/core/http/PassHttpCall.java | 17 ++++++++ .../chan/core/net/ProxiedHurlStack.java | 38 ++++++++++------ .../chan/core/presenter/ReplyPresenter.java | 2 +- .../chan/core/settings/ChanSettings.java | 43 +++++++++++++++++-- .../chan/core/settings/IntegerSetting.java | 19 +++++++- .../floens/chan/core/watch/PinWatcher.java | 2 +- .../org/floens/chan/test/TestActivity.java | 4 +- .../ui/controller/MainSettingsController.java | 2 +- .../ui/controller/ViewThreadController.java | 2 +- .../chan/ui/helper/RefreshUIMessage.java | 17 ++++++++ .../floens/chan/ui/layout/ReplyLayout.java | 2 +- .../chan/ui/settings/IntegerSettingView.java | 19 +++++++- .../chan/ui/settings/SettingsController.java | 3 +- .../org/floens/chan/ui/state/ChanState.java | 17 ++++++++ .../org/floens/chan/ui/theme/DarkTheme.java | 17 ++++++++ 18 files changed, 196 insertions(+), 38 deletions(-) diff --git a/Clover/app/src/main/java/org/floens/chan/Chan.java b/Clover/app/src/main/java/org/floens/chan/Chan.java index 2a9aee84..fd2314d7 100644 --- a/Clover/app/src/main/java/org/floens/chan/Chan.java +++ b/Clover/app/src/main/java/org/floens/chan/Chan.java @@ -151,7 +151,7 @@ public class Chan extends Application { replyManager = new ReplyManager(this); - String userAgent = getUserAgent(); + String userAgent = getUserAgent(); volleyRequestQueue = Volley.newRequestQueue(this, userAgent, new ProxiedHurlStack(userAgent), new File(cacheDir, Volley.DEFAULT_CACHE_DIR), VOLLEY_CACHE_SIZE); final int runtimeMemory = (int) (Runtime.getRuntime().maxMemory() / 1024); diff --git a/Clover/app/src/main/java/org/floens/chan/chan/ChanHelper.java b/Clover/app/src/main/java/org/floens/chan/chan/ChanHelper.java index 42087118..e39f7393 100644 --- a/Clover/app/src/main/java/org/floens/chan/chan/ChanHelper.java +++ b/Clover/app/src/main/java/org/floens/chan/chan/ChanHelper.java @@ -1,3 +1,20 @@ +/* + * Clover - 4chan browser https://github.com/Floens/Clover/ + * Copyright (C) 2014 Floens + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ package org.floens.chan.chan; import android.net.Uri; diff --git a/Clover/app/src/main/java/org/floens/chan/core/cache/FileCache.java b/Clover/app/src/main/java/org/floens/chan/core/cache/FileCache.java index 6a298ea7..be2ae6e4 100644 --- a/Clover/app/src/main/java/org/floens/chan/core/cache/FileCache.java +++ b/Clover/app/src/main/java/org/floens/chan/core/cache/FileCache.java @@ -36,8 +36,6 @@ import java.io.File; import java.io.FileOutputStream; import java.io.InterruptedIOException; import java.io.OutputStream; -import java.net.InetSocketAddress; -import java.net.Proxy; import java.util.ArrayList; import java.util.Collections; import java.util.List; @@ -422,14 +420,7 @@ public class FileCache { .header("User-Agent", userAgent) .build(); - Proxy proxy = null; - if (ChanSettings.proxyEnabled.get()) - { - proxy = new Proxy(Proxy.Type.HTTP, InetSocketAddress.createUnresolved( - ChanSettings.proxyAddress.get(), - ChanSettings.proxyPort.get())); - } - fileCache.httpClient.setProxy(proxy); + fileCache.httpClient.setProxy(ChanSettings.getProxy()); call = fileCache.httpClient.newCall(request); Response response = call.execute(); diff --git a/Clover/app/src/main/java/org/floens/chan/core/http/PassHttpCall.java b/Clover/app/src/main/java/org/floens/chan/core/http/PassHttpCall.java index ad6457f7..cbf3fa1c 100644 --- a/Clover/app/src/main/java/org/floens/chan/core/http/PassHttpCall.java +++ b/Clover/app/src/main/java/org/floens/chan/core/http/PassHttpCall.java @@ -1,3 +1,20 @@ +/* + * Clover - 4chan browser https://github.com/Floens/Clover/ + * Copyright (C) 2014 Floens + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ package org.floens.chan.core.http; import com.squareup.okhttp.FormEncodingBuilder; diff --git a/Clover/app/src/main/java/org/floens/chan/core/net/ProxiedHurlStack.java b/Clover/app/src/main/java/org/floens/chan/core/net/ProxiedHurlStack.java index ec63a07f..7d57c2e3 100644 --- a/Clover/app/src/main/java/org/floens/chan/core/net/ProxiedHurlStack.java +++ b/Clover/app/src/main/java/org/floens/chan/core/net/ProxiedHurlStack.java @@ -1,15 +1,32 @@ +/* + * Clover - 4chan browser https://github.com/Floens/Clover/ + * Copyright (C) 2014 Floens + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ package org.floens.chan.core.net; +import com.android.volley.toolbox.HurlStack; + +import org.floens.chan.core.settings.ChanSettings; + import java.io.IOException; import java.net.HttpURLConnection; -import java.net.InetSocketAddress; import java.net.Proxy; import java.net.URL; -import com.android.volley.toolbox.HurlStack; -import org.floens.chan.core.settings.ChanSettings; public class ProxiedHurlStack extends HurlStack { - public ProxiedHurlStack(String userAgent) { super(userAgent, null); } @@ -17,16 +34,11 @@ public class ProxiedHurlStack extends HurlStack { @Override protected HttpURLConnection createConnection(URL url) throws IOException { // Start the connection by specifying a proxy server - if (ChanSettings.proxyEnabled.get()) - { - Proxy proxy = new Proxy(Proxy.Type.HTTP, InetSocketAddress.createUnresolved( - ChanSettings.proxyAddress.get(), - ChanSettings.proxyPort.get())); + Proxy proxy = ChanSettings.getProxy(); + if (proxy != null) { return (HttpURLConnection) url.openConnection(proxy); - } - else - { + } else { return (HttpURLConnection) url.openConnection(); } } -} \ No newline at end of file +} diff --git a/Clover/app/src/main/java/org/floens/chan/core/presenter/ReplyPresenter.java b/Clover/app/src/main/java/org/floens/chan/core/presenter/ReplyPresenter.java index 8b564a4f..12e25063 100644 --- a/Clover/app/src/main/java/org/floens/chan/core/presenter/ReplyPresenter.java +++ b/Clover/app/src/main/java/org/floens/chan/core/presenter/ReplyPresenter.java @@ -22,6 +22,7 @@ import android.text.TextUtils; import org.floens.chan.Chan; import org.floens.chan.R; import org.floens.chan.chan.ChanUrls; +import org.floens.chan.core.database.DatabaseManager; import org.floens.chan.core.http.ReplyHttpCall; import org.floens.chan.core.http.ReplyManager; import org.floens.chan.core.manager.BoardManager; @@ -32,7 +33,6 @@ import org.floens.chan.core.model.Post; import org.floens.chan.core.model.Reply; import org.floens.chan.core.model.SavedReply; import org.floens.chan.core.settings.ChanSettings; -import org.floens.chan.core.database.DatabaseManager; import org.floens.chan.ui.helper.ImagePickDelegate; import org.floens.chan.ui.layout.CaptchaLayout; diff --git a/Clover/app/src/main/java/org/floens/chan/core/settings/ChanSettings.java b/Clover/app/src/main/java/org/floens/chan/core/settings/ChanSettings.java index 91f38ca6..adce6c88 100644 --- a/Clover/app/src/main/java/org/floens/chan/core/settings/ChanSettings.java +++ b/Clover/app/src/main/java/org/floens/chan/core/settings/ChanSettings.java @@ -28,6 +28,8 @@ import org.floens.chan.ui.cell.PostCellInterface; import org.floens.chan.utils.AndroidUtils; import java.io.File; +import java.net.InetSocketAddress; +import java.net.Proxy; public class ChanSettings { public enum ImageAutoLoadMode { @@ -54,6 +56,8 @@ public class ChanSettings { } } + private static Proxy proxy; + private static final StringSetting theme; public static final StringSetting fontSize; public static final BooleanSetting openLinkConfirmation; @@ -165,9 +169,25 @@ public class ChanSettings { historyEnabled = new BooleanSetting(p, "preference_history_enabled", true); - proxyEnabled = new BooleanSetting(p, "preference_proxy_enabled", false); - proxyAddress = new StringSetting(p, "preference_proxy_address", ""); - proxyPort = new IntegerSetting(p, "preference_proxy_port", 80); + proxyEnabled = new BooleanSetting(p, "preference_proxy_enabled", false, new Setting.SettingCallback() { + @Override + public void onValueChange(Setting setting, Boolean value) { + loadProxy(); + } + }); + proxyAddress = new StringSetting(p, "preference_proxy_address", "", new Setting.SettingCallback() { + @Override + public void onValueChange(Setting setting, String value) { + loadProxy(); + } + }); + proxyPort = new IntegerSetting(p, "preference_proxy_port", 80, new Setting.SettingCallback() { + @Override + public void onValueChange(Setting setting, Integer value) { + loadProxy(); + } + }); + loadProxy(); // Old (but possibly still in some users phone) // preference_board_view_mode default "list" @@ -202,6 +222,23 @@ public class ChanSettings { } } + /** + * Returns a {@link Proxy} if a proxy is enabled, null otherwise. + * + * @return a proxy or null + */ + public static Proxy getProxy() { + return proxy; + } + + private static void loadProxy() { + if (proxyEnabled.get()) { + proxy = new Proxy(Proxy.Type.HTTP, InetSocketAddress.createUnresolved(proxyAddress.get(), proxyPort.get())); + } else { + proxy = null; + } + } + public static class ThemeColor { public String theme; public String color; diff --git a/Clover/app/src/main/java/org/floens/chan/core/settings/IntegerSetting.java b/Clover/app/src/main/java/org/floens/chan/core/settings/IntegerSetting.java index 19839fd7..72dcb102 100644 --- a/Clover/app/src/main/java/org/floens/chan/core/settings/IntegerSetting.java +++ b/Clover/app/src/main/java/org/floens/chan/core/settings/IntegerSetting.java @@ -1,9 +1,26 @@ +/* + * Clover - 4chan browser https://github.com/Floens/Clover/ + * Copyright (C) 2014 Floens + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ package org.floens.chan.core.settings; import android.content.SharedPreferences; /** - * Created by Zetsubou on 02.07.2015. + * Created by Zetsubou on 02.07.2015 */ public class IntegerSetting extends Setting { private boolean hasCached = false; diff --git a/Clover/app/src/main/java/org/floens/chan/core/watch/PinWatcher.java b/Clover/app/src/main/java/org/floens/chan/core/watch/PinWatcher.java index 6df7e77c..41e71f33 100644 --- a/Clover/app/src/main/java/org/floens/chan/core/watch/PinWatcher.java +++ b/Clover/app/src/main/java/org/floens/chan/core/watch/PinWatcher.java @@ -21,10 +21,10 @@ import com.android.volley.VolleyError; import org.floens.chan.Chan; import org.floens.chan.chan.ChanLoader; -import org.floens.chan.core.net.LoaderPool; import org.floens.chan.core.model.ChanThread; import org.floens.chan.core.model.Pin; import org.floens.chan.core.model.Post; +import org.floens.chan.core.net.LoaderPool; import org.floens.chan.utils.AndroidUtils; import org.floens.chan.utils.Logger; diff --git a/Clover/app/src/main/java/org/floens/chan/test/TestActivity.java b/Clover/app/src/main/java/org/floens/chan/test/TestActivity.java index 632a8f5b..ecd84569 100644 --- a/Clover/app/src/main/java/org/floens/chan/test/TestActivity.java +++ b/Clover/app/src/main/java/org/floens/chan/test/TestActivity.java @@ -28,13 +28,13 @@ import android.widget.LinearLayout; import com.android.volley.VolleyError; import org.floens.chan.Chan; -import org.floens.chan.core.cache.FileCache; import org.floens.chan.chan.ChanLoader; +import org.floens.chan.core.cache.FileCache; import org.floens.chan.core.model.ChanThread; import org.floens.chan.core.model.Loadable; import org.floens.chan.core.model.Post; -import org.floens.chan.utils.Logger; import org.floens.chan.ui.theme.ThemeHelper; +import org.floens.chan.utils.Logger; import java.io.File; diff --git a/Clover/app/src/main/java/org/floens/chan/ui/controller/MainSettingsController.java b/Clover/app/src/main/java/org/floens/chan/ui/controller/MainSettingsController.java index c39e3d08..4d01828a 100644 --- a/Clover/app/src/main/java/org/floens/chan/ui/controller/MainSettingsController.java +++ b/Clover/app/src/main/java/org/floens/chan/ui/controller/MainSettingsController.java @@ -172,7 +172,7 @@ public class MainSettingsController extends SettingsController implements Toolba List imageAutoLoadTypes = new ArrayList<>(); for (ChanSettings.ImageAutoLoadMode mode : ChanSettings.ImageAutoLoadMode.values()) { String name = ""; - switch(mode) { + switch (mode) { case ALL: name = string(R.string.setting_image_auto_load_all); break; diff --git a/Clover/app/src/main/java/org/floens/chan/ui/controller/ViewThreadController.java b/Clover/app/src/main/java/org/floens/chan/ui/controller/ViewThreadController.java index e6e08f7a..6c8ea6e0 100644 --- a/Clover/app/src/main/java/org/floens/chan/ui/controller/ViewThreadController.java +++ b/Clover/app/src/main/java/org/floens/chan/ui/controller/ViewThreadController.java @@ -177,7 +177,7 @@ public class ViewThreadController extends ThreadController implements ThreadLayo break; case UP_ID: case DOWN_ID: - boolean up = ((Integer)item.getId()) == UP_ID; + boolean up = ((Integer) item.getId()) == UP_ID; threadLayout.getPresenter().scrollTo(up ? 0 : -1, false); break; } diff --git a/Clover/app/src/main/java/org/floens/chan/ui/helper/RefreshUIMessage.java b/Clover/app/src/main/java/org/floens/chan/ui/helper/RefreshUIMessage.java index 3c3a6653..809e827c 100644 --- a/Clover/app/src/main/java/org/floens/chan/ui/helper/RefreshUIMessage.java +++ b/Clover/app/src/main/java/org/floens/chan/ui/helper/RefreshUIMessage.java @@ -1,3 +1,20 @@ +/* + * Clover - 4chan browser https://github.com/Floens/Clover/ + * Copyright (C) 2014 Floens + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ package org.floens.chan.ui.helper; public class RefreshUIMessage { diff --git a/Clover/app/src/main/java/org/floens/chan/ui/layout/ReplyLayout.java b/Clover/app/src/main/java/org/floens/chan/ui/layout/ReplyLayout.java index 211e5f14..c188efb5 100644 --- a/Clover/app/src/main/java/org/floens/chan/ui/layout/ReplyLayout.java +++ b/Clover/app/src/main/java/org/floens/chan/ui/layout/ReplyLayout.java @@ -38,9 +38,9 @@ import org.floens.chan.core.model.Loadable; import org.floens.chan.core.model.Reply; import org.floens.chan.core.presenter.ReplyPresenter; import org.floens.chan.core.settings.ChanSettings; -import org.floens.chan.ui.helper.ImagePickDelegate; import org.floens.chan.ui.activity.StartActivity; import org.floens.chan.ui.drawable.DropdownArrowDrawable; +import org.floens.chan.ui.helper.ImagePickDelegate; import org.floens.chan.ui.theme.ThemeHelper; import org.floens.chan.ui.view.LoadView; import org.floens.chan.ui.view.SelectionListeningEditText; diff --git a/Clover/app/src/main/java/org/floens/chan/ui/settings/IntegerSettingView.java b/Clover/app/src/main/java/org/floens/chan/ui/settings/IntegerSettingView.java index 007c83c9..c4b53ecb 100644 --- a/Clover/app/src/main/java/org/floens/chan/ui/settings/IntegerSettingView.java +++ b/Clover/app/src/main/java/org/floens/chan/ui/settings/IntegerSettingView.java @@ -1,3 +1,20 @@ +/* + * Clover - 4chan browser https://github.com/Floens/Clover/ + * Copyright (C) 2014 Floens + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ package org.floens.chan.ui.settings; import android.app.AlertDialog; @@ -15,7 +32,7 @@ import org.floens.chan.core.settings.Setting; import static org.floens.chan.utils.AndroidUtils.dp; /** - * Created by Zetsubou on 02.07.2015. + * Created by Zetsubou on 02.07.2015 */ public class IntegerSettingView extends SettingView implements View.OnClickListener { private final Setting setting; diff --git a/Clover/app/src/main/java/org/floens/chan/ui/settings/SettingsController.java b/Clover/app/src/main/java/org/floens/chan/ui/settings/SettingsController.java index 2d23dc86..1e8f31d3 100644 --- a/Clover/app/src/main/java/org/floens/chan/ui/settings/SettingsController.java +++ b/Clover/app/src/main/java/org/floens/chan/ui/settings/SettingsController.java @@ -136,8 +136,7 @@ public class SettingsController extends Controller implements AndroidUtils.OnMea if ((settingView instanceof ListSettingView) || (settingView instanceof LinkSettingView) || (settingView instanceof StringSettingView) - || (settingView instanceof IntegerSettingView) ) - { + || (settingView instanceof IntegerSettingView)) { preferenceView = (ViewGroup) inf.inflate(R.layout.setting_link, groupLayout, false); } else if (settingView instanceof BooleanSettingView) { preferenceView = (ViewGroup) inf.inflate(R.layout.setting_boolean, groupLayout, false); diff --git a/Clover/app/src/main/java/org/floens/chan/ui/state/ChanState.java b/Clover/app/src/main/java/org/floens/chan/ui/state/ChanState.java index ee2f412a..bb8b90e4 100644 --- a/Clover/app/src/main/java/org/floens/chan/ui/state/ChanState.java +++ b/Clover/app/src/main/java/org/floens/chan/ui/state/ChanState.java @@ -1,3 +1,20 @@ +/* + * Clover - 4chan browser https://github.com/Floens/Clover/ + * Copyright (C) 2014 Floens + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ package org.floens.chan.ui.state; import android.os.Parcel; diff --git a/Clover/app/src/main/java/org/floens/chan/ui/theme/DarkTheme.java b/Clover/app/src/main/java/org/floens/chan/ui/theme/DarkTheme.java index 9ece2259..8591fb69 100644 --- a/Clover/app/src/main/java/org/floens/chan/ui/theme/DarkTheme.java +++ b/Clover/app/src/main/java/org/floens/chan/ui/theme/DarkTheme.java @@ -1,3 +1,20 @@ +/* + * Clover - 4chan browser https://github.com/Floens/Clover/ + * Copyright (C) 2014 Floens + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ package org.floens.chan.ui.theme; import org.floens.chan.R;