Cache Proxy object creation, formatting and license headers on all files

multisite
Floens 10 years ago
parent 448abe033c
commit ce3202671a
  1. 2
      Clover/app/src/main/java/org/floens/chan/Chan.java
  2. 17
      Clover/app/src/main/java/org/floens/chan/chan/ChanHelper.java
  3. 11
      Clover/app/src/main/java/org/floens/chan/core/cache/FileCache.java
  4. 17
      Clover/app/src/main/java/org/floens/chan/core/http/PassHttpCall.java
  5. 38
      Clover/app/src/main/java/org/floens/chan/core/net/ProxiedHurlStack.java
  6. 2
      Clover/app/src/main/java/org/floens/chan/core/presenter/ReplyPresenter.java
  7. 43
      Clover/app/src/main/java/org/floens/chan/core/settings/ChanSettings.java
  8. 19
      Clover/app/src/main/java/org/floens/chan/core/settings/IntegerSetting.java
  9. 2
      Clover/app/src/main/java/org/floens/chan/core/watch/PinWatcher.java
  10. 4
      Clover/app/src/main/java/org/floens/chan/test/TestActivity.java
  11. 2
      Clover/app/src/main/java/org/floens/chan/ui/controller/MainSettingsController.java
  12. 2
      Clover/app/src/main/java/org/floens/chan/ui/controller/ViewThreadController.java
  13. 17
      Clover/app/src/main/java/org/floens/chan/ui/helper/RefreshUIMessage.java
  14. 2
      Clover/app/src/main/java/org/floens/chan/ui/layout/ReplyLayout.java
  15. 19
      Clover/app/src/main/java/org/floens/chan/ui/settings/IntegerSettingView.java
  16. 3
      Clover/app/src/main/java/org/floens/chan/ui/settings/SettingsController.java
  17. 17
      Clover/app/src/main/java/org/floens/chan/ui/state/ChanState.java
  18. 17
      Clover/app/src/main/java/org/floens/chan/ui/theme/DarkTheme.java

@ -151,7 +151,7 @@ public class Chan extends Application {
replyManager = new ReplyManager(this); 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); 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); final int runtimeMemory = (int) (Runtime.getRuntime().maxMemory() / 1024);

@ -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 <http://www.gnu.org/licenses/>.
*/
package org.floens.chan.chan; package org.floens.chan.chan;
import android.net.Uri; import android.net.Uri;

@ -36,8 +36,6 @@ import java.io.File;
import java.io.FileOutputStream; import java.io.FileOutputStream;
import java.io.InterruptedIOException; import java.io.InterruptedIOException;
import java.io.OutputStream; import java.io.OutputStream;
import java.net.InetSocketAddress;
import java.net.Proxy;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Collections; import java.util.Collections;
import java.util.List; import java.util.List;
@ -422,14 +420,7 @@ public class FileCache {
.header("User-Agent", userAgent) .header("User-Agent", userAgent)
.build(); .build();
Proxy proxy = null; fileCache.httpClient.setProxy(ChanSettings.getProxy());
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); call = fileCache.httpClient.newCall(request);
Response response = call.execute(); Response response = call.execute();

@ -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 <http://www.gnu.org/licenses/>.
*/
package org.floens.chan.core.http; package org.floens.chan.core.http;
import com.squareup.okhttp.FormEncodingBuilder; import com.squareup.okhttp.FormEncodingBuilder;

@ -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 <http://www.gnu.org/licenses/>.
*/
package org.floens.chan.core.net; 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.io.IOException;
import java.net.HttpURLConnection; import java.net.HttpURLConnection;
import java.net.InetSocketAddress;
import java.net.Proxy; import java.net.Proxy;
import java.net.URL; import java.net.URL;
import com.android.volley.toolbox.HurlStack;
import org.floens.chan.core.settings.ChanSettings;
public class ProxiedHurlStack extends HurlStack { public class ProxiedHurlStack extends HurlStack {
public ProxiedHurlStack(String userAgent) { public ProxiedHurlStack(String userAgent) {
super(userAgent, null); super(userAgent, null);
} }
@ -17,16 +34,11 @@ public class ProxiedHurlStack extends HurlStack {
@Override @Override
protected HttpURLConnection createConnection(URL url) throws IOException { protected HttpURLConnection createConnection(URL url) throws IOException {
// Start the connection by specifying a proxy server // Start the connection by specifying a proxy server
if (ChanSettings.proxyEnabled.get()) Proxy proxy = ChanSettings.getProxy();
{ if (proxy != null) {
Proxy proxy = new Proxy(Proxy.Type.HTTP, InetSocketAddress.createUnresolved(
ChanSettings.proxyAddress.get(),
ChanSettings.proxyPort.get()));
return (HttpURLConnection) url.openConnection(proxy); return (HttpURLConnection) url.openConnection(proxy);
} } else {
else
{
return (HttpURLConnection) url.openConnection(); return (HttpURLConnection) url.openConnection();
} }
} }
} }

@ -22,6 +22,7 @@ import android.text.TextUtils;
import org.floens.chan.Chan; import org.floens.chan.Chan;
import org.floens.chan.R; import org.floens.chan.R;
import org.floens.chan.chan.ChanUrls; 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.ReplyHttpCall;
import org.floens.chan.core.http.ReplyManager; import org.floens.chan.core.http.ReplyManager;
import org.floens.chan.core.manager.BoardManager; 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.Reply;
import org.floens.chan.core.model.SavedReply; import org.floens.chan.core.model.SavedReply;
import org.floens.chan.core.settings.ChanSettings; 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.helper.ImagePickDelegate;
import org.floens.chan.ui.layout.CaptchaLayout; import org.floens.chan.ui.layout.CaptchaLayout;

@ -28,6 +28,8 @@ import org.floens.chan.ui.cell.PostCellInterface;
import org.floens.chan.utils.AndroidUtils; import org.floens.chan.utils.AndroidUtils;
import java.io.File; import java.io.File;
import java.net.InetSocketAddress;
import java.net.Proxy;
public class ChanSettings { public class ChanSettings {
public enum ImageAutoLoadMode { public enum ImageAutoLoadMode {
@ -54,6 +56,8 @@ public class ChanSettings {
} }
} }
private static Proxy proxy;
private static final StringSetting theme; private static final StringSetting theme;
public static final StringSetting fontSize; public static final StringSetting fontSize;
public static final BooleanSetting openLinkConfirmation; public static final BooleanSetting openLinkConfirmation;
@ -165,9 +169,25 @@ public class ChanSettings {
historyEnabled = new BooleanSetting(p, "preference_history_enabled", true); historyEnabled = new BooleanSetting(p, "preference_history_enabled", true);
proxyEnabled = new BooleanSetting(p, "preference_proxy_enabled", false); proxyEnabled = new BooleanSetting(p, "preference_proxy_enabled", false, new Setting.SettingCallback<Boolean>() {
proxyAddress = new StringSetting(p, "preference_proxy_address", ""); @Override
proxyPort = new IntegerSetting(p, "preference_proxy_port", 80); public void onValueChange(Setting setting, Boolean value) {
loadProxy();
}
});
proxyAddress = new StringSetting(p, "preference_proxy_address", "", new Setting.SettingCallback<String>() {
@Override
public void onValueChange(Setting setting, String value) {
loadProxy();
}
});
proxyPort = new IntegerSetting(p, "preference_proxy_port", 80, new Setting.SettingCallback<Integer>() {
@Override
public void onValueChange(Setting setting, Integer value) {
loadProxy();
}
});
loadProxy();
// Old (but possibly still in some users phone) // Old (but possibly still in some users phone)
// preference_board_view_mode default "list" // preference_board_view_mode default "list"
@ -202,6 +222,23 @@ public class ChanSettings {
} }
} }
/**
* Returns a {@link Proxy} if a proxy is enabled, <tt>null</tt> 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 static class ThemeColor {
public String theme; public String theme;
public String color; public String color;

@ -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 <http://www.gnu.org/licenses/>.
*/
package org.floens.chan.core.settings; package org.floens.chan.core.settings;
import android.content.SharedPreferences; import android.content.SharedPreferences;
/** /**
* Created by Zetsubou on 02.07.2015. * Created by Zetsubou on 02.07.2015
*/ */
public class IntegerSetting extends Setting<Integer> { public class IntegerSetting extends Setting<Integer> {
private boolean hasCached = false; private boolean hasCached = false;

@ -21,10 +21,10 @@ import com.android.volley.VolleyError;
import org.floens.chan.Chan; import org.floens.chan.Chan;
import org.floens.chan.chan.ChanLoader; 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.ChanThread;
import org.floens.chan.core.model.Pin; import org.floens.chan.core.model.Pin;
import org.floens.chan.core.model.Post; 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.AndroidUtils;
import org.floens.chan.utils.Logger; import org.floens.chan.utils.Logger;

@ -28,13 +28,13 @@ import android.widget.LinearLayout;
import com.android.volley.VolleyError; import com.android.volley.VolleyError;
import org.floens.chan.Chan; import org.floens.chan.Chan;
import org.floens.chan.core.cache.FileCache;
import org.floens.chan.chan.ChanLoader; 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.ChanThread;
import org.floens.chan.core.model.Loadable; import org.floens.chan.core.model.Loadable;
import org.floens.chan.core.model.Post; import org.floens.chan.core.model.Post;
import org.floens.chan.utils.Logger;
import org.floens.chan.ui.theme.ThemeHelper; import org.floens.chan.ui.theme.ThemeHelper;
import org.floens.chan.utils.Logger;
import java.io.File; import java.io.File;

@ -172,7 +172,7 @@ public class MainSettingsController extends SettingsController implements Toolba
List<ListSettingView.Item> imageAutoLoadTypes = new ArrayList<>(); List<ListSettingView.Item> imageAutoLoadTypes = new ArrayList<>();
for (ChanSettings.ImageAutoLoadMode mode : ChanSettings.ImageAutoLoadMode.values()) { for (ChanSettings.ImageAutoLoadMode mode : ChanSettings.ImageAutoLoadMode.values()) {
String name = ""; String name = "";
switch(mode) { switch (mode) {
case ALL: case ALL:
name = string(R.string.setting_image_auto_load_all); name = string(R.string.setting_image_auto_load_all);
break; break;

@ -177,7 +177,7 @@ public class ViewThreadController extends ThreadController implements ThreadLayo
break; break;
case UP_ID: case UP_ID:
case DOWN_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); threadLayout.getPresenter().scrollTo(up ? 0 : -1, false);
break; break;
} }

@ -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 <http://www.gnu.org/licenses/>.
*/
package org.floens.chan.ui.helper; package org.floens.chan.ui.helper;
public class RefreshUIMessage { public class RefreshUIMessage {

@ -38,9 +38,9 @@ import org.floens.chan.core.model.Loadable;
import org.floens.chan.core.model.Reply; import org.floens.chan.core.model.Reply;
import org.floens.chan.core.presenter.ReplyPresenter; import org.floens.chan.core.presenter.ReplyPresenter;
import org.floens.chan.core.settings.ChanSettings; 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.activity.StartActivity;
import org.floens.chan.ui.drawable.DropdownArrowDrawable; 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.theme.ThemeHelper;
import org.floens.chan.ui.view.LoadView; import org.floens.chan.ui.view.LoadView;
import org.floens.chan.ui.view.SelectionListeningEditText; import org.floens.chan.ui.view.SelectionListeningEditText;

@ -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 <http://www.gnu.org/licenses/>.
*/
package org.floens.chan.ui.settings; package org.floens.chan.ui.settings;
import android.app.AlertDialog; import android.app.AlertDialog;
@ -15,7 +32,7 @@ import org.floens.chan.core.settings.Setting;
import static org.floens.chan.utils.AndroidUtils.dp; 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 { public class IntegerSettingView extends SettingView implements View.OnClickListener {
private final Setting<Integer> setting; private final Setting<Integer> setting;

@ -136,8 +136,7 @@ public class SettingsController extends Controller implements AndroidUtils.OnMea
if ((settingView instanceof ListSettingView) if ((settingView instanceof ListSettingView)
|| (settingView instanceof LinkSettingView) || (settingView instanceof LinkSettingView)
|| (settingView instanceof StringSettingView) || (settingView instanceof StringSettingView)
|| (settingView instanceof IntegerSettingView) ) || (settingView instanceof IntegerSettingView)) {
{
preferenceView = (ViewGroup) inf.inflate(R.layout.setting_link, groupLayout, false); preferenceView = (ViewGroup) inf.inflate(R.layout.setting_link, groupLayout, false);
} else if (settingView instanceof BooleanSettingView) { } else if (settingView instanceof BooleanSettingView) {
preferenceView = (ViewGroup) inf.inflate(R.layout.setting_boolean, groupLayout, false); preferenceView = (ViewGroup) inf.inflate(R.layout.setting_boolean, groupLayout, false);

@ -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 <http://www.gnu.org/licenses/>.
*/
package org.floens.chan.ui.state; package org.floens.chan.ui.state;
import android.os.Parcel; import android.os.Parcel;

@ -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 <http://www.gnu.org/licenses/>.
*/
package org.floens.chan.ui.theme; package org.floens.chan.ui.theme;
import org.floens.chan.R; import org.floens.chan.R;

Loading…
Cancel
Save