Some cleanup

multisite
Floens 10 years ago
parent 66e9bebce7
commit e93fa1d79f
  1. 16
      Clover/app/build.gradle
  2. 73
      Clover/app/src/main/java/org/floens/chan/Chan.java
  3. 2
      Clover/app/src/main/java/org/floens/chan/core/cache/FileCache.java
  4. 7
      Clover/app/src/main/java/org/floens/chan/core/http/ReplyManager.java
  5. 2
      Clover/app/src/main/java/org/floens/chan/utils/AndroidUtils.java
  6. 2
      Clover/app/src/main/java/org/floens/chan/utils/Time.java

@ -79,12 +79,12 @@ android {
}
dependencies {
compile 'com.android.support:support-v13:23.1.0'
compile 'com.android.support:appcompat-v7:23.1.0'
compile 'com.android.support:recyclerview-v7:23.1.0'
compile 'com.android.support:cardview-v7:23.1.0'
compile 'com.android.support:support-annotations:23.1.0'
compile 'com.android.support:design:23.1.0'
compile 'com.android.support:support-v13:23.1.1'
compile 'com.android.support:appcompat-v7:23.1.1'
compile 'com.android.support:recyclerview-v7:23.1.1'
compile 'com.android.support:cardview-v7:23.1.1'
compile 'com.android.support:support-annotations:23.1.1'
compile 'com.android.support:design:23.1.1'
compile 'org.jsoup:jsoup:1.8.3'
compile 'com.j256.ormlite:ormlite-core:4.48'
@ -93,8 +93,4 @@ dependencies {
compile 'com.davemorrissey.labs:subsampling-scale-image-view:3.4.1'
compile 'com.squareup.okhttp:okhttp:2.5.0'
compile 'de.greenrobot:eventbus:2.4.0'
debugCompile 'com.squareup.leakcanary:leakcanary-android:1.3.1'
betaCompile 'com.squareup.leakcanary:leakcanary-android-no-op:1.3.1'
releaseCompile 'com.squareup.leakcanary:leakcanary-android-no-op:1.3.1'
}

@ -21,12 +21,10 @@ import android.app.Application;
import android.content.Context;
import android.content.pm.PackageManager;
import android.os.StrictMode;
import android.view.ViewConfiguration;
import com.android.volley.RequestQueue;
import com.android.volley.toolbox.ImageLoader;
import com.android.volley.toolbox.Volley;
import com.squareup.leakcanary.RefWatcher;
import org.floens.chan.chan.ChanUrls;
import org.floens.chan.core.cache.FileCache;
@ -39,9 +37,9 @@ import org.floens.chan.core.net.ProxiedHurlStack;
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;
import java.io.File;
import java.lang.reflect.Field;
import java.util.Locale;
import de.greenrobot.event.EventBus;
@ -57,13 +55,12 @@ public class Chan extends Application {
private static Chan instance;
private static RequestQueue volleyRequestQueue;
private static com.android.volley.toolbox.ImageLoader imageLoader;
private static ImageLoader imageLoader;
private static BoardManager boardManager;
private static WatchManager watchManager;
private static ReplyManager replyManager;
private static DatabaseManager databaseManager;
private static FileCache fileCache;
private static RefWatcher refWatcher;
private String userAgent;
private int activityForegroundCounter = 0;
@ -105,51 +102,22 @@ public class Chan extends Application {
return fileCache;
}
public static RefWatcher getRefWatcher() {
return refWatcher;
}
@Override
public void onCreate() {
super.onCreate();
// Force the overflow button to show, even on devices that have a
// physical button.
try {
ViewConfiguration config = ViewConfiguration.get(this);
Field menuKeyField = ViewConfiguration.class.getDeclaredField("sHasPermanentMenuKey");
if (menuKeyField != null) {
menuKeyField.setAccessible(true);
menuKeyField.setBoolean(config, false);
}
} catch (Exception e) {
}
if (ChanBuild.DEVELOPER_MODE) {
// refWatcher = LeakCanary.install(this);
StrictMode.setThreadPolicy(new StrictMode.ThreadPolicy.Builder().detectCustomSlowCalls().detectNetwork().penaltyLog().build());
StrictMode.setVmPolicy(new StrictMode.VmPolicy.Builder().detectAll().penaltyLog().build());
}
final long startTime = Time.startTiming();
AndroidUtils.init();
ChanUrls.loadScheme(ChanSettings.networkHttps.get());
// User agent is <appname>/<version>
String version = "";
try {
version = getPackageManager().getPackageInfo(getPackageName(), 0).versionName;
} catch (PackageManager.NameNotFoundException e) {
e.printStackTrace();
}
version = version.toLowerCase(Locale.ENGLISH).replace(" ", "_");
userAgent = getString(R.string.app_name) + "/" + version;
userAgent = createUserAgent();
File cacheDir = getExternalCacheDir() != null ? getExternalCacheDir() : getCacheDir();
replyManager = new ReplyManager(this);
replyManager = new ReplyManager(this, userAgent);
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);
@ -162,6 +130,25 @@ public class Chan extends Application {
databaseManager = new DatabaseManager(this);
boardManager = new BoardManager();
watchManager = new WatchManager(this);
Time.endTiming("Initializing application", startTime);
// Start watching for slow disk reads and writes after the heavy initializing is done
if (ChanBuild.DEVELOPER_MODE) {
StrictMode.setThreadPolicy(
new StrictMode.ThreadPolicy.Builder()
.detectCustomSlowCalls()
.detectNetwork()
.detectDiskReads()
.detectDiskWrites()
.penaltyLog()
.build());
StrictMode.setVmPolicy(
new StrictMode.VmPolicy.Builder()
.detectAll()
.penaltyLog()
.build());
}
}
public String getUserAgent() {
@ -202,4 +189,16 @@ public class Chan extends Application {
this.inForeground = inForeground;
}
}
private String createUserAgent() {
// User agent is <appname>/<version>
String version = "Unknown";
try {
version = getPackageManager().getPackageInfo(getPackageName(), 0).versionName;
} catch (PackageManager.NameNotFoundException e) {
Logger.e(TAG, "Error getting app version", e);
}
version = version.toLowerCase(Locale.ENGLISH).replace(" ", "_");
return getString(R.string.app_name) + "/" + version;
}
}

@ -73,7 +73,7 @@ public class FileCache {
httpClient.setReadTimeout(TIMEOUT, TimeUnit.MILLISECONDS);
httpClient.setWriteTimeout(TIMEOUT, TimeUnit.MILLISECONDS);
// Disable SPDY, causes reproducable timeouts, only one download at the same time and other fun stuff
// Disable SPDY, causes reproducible timeouts, only one download at the same time and other fun stuff
httpClient.setProtocols(Collections.singletonList(Protocol.HTTP_1_1));
makeDir();

@ -22,7 +22,6 @@ import android.content.Context;
import com.squareup.okhttp.OkHttpClient;
import com.squareup.okhttp.Request;
import org.floens.chan.Chan;
import org.floens.chan.core.model.Loadable;
import org.floens.chan.core.model.Reply;
@ -38,12 +37,14 @@ public class ReplyManager {
private static final int TIMEOUT = 30000;
private final Context context;
private String userAgent;
private OkHttpClient client;
private Map<Loadable, Reply> drafts = new HashMap<>();
public ReplyManager(Context context) {
public ReplyManager(Context context, String userAgent) {
this.context = context;
this.userAgent = userAgent;
client = new OkHttpClient();
client.setConnectTimeout(TIMEOUT, TimeUnit.MILLISECONDS);
@ -85,7 +86,7 @@ public class ReplyManager {
httpCall.setup(requestBuilder);
requestBuilder.header("User-Agent", Chan.getInstance().getUserAgent());
requestBuilder.header("User-Agent", userAgent);
Request request = requestBuilder.build();
client.newCall(request).enqueue(httpCall);

@ -325,7 +325,7 @@ public class AndroidUtils {
}
public static boolean removeFromParentView(View view) {
if (view.getParent() instanceof ViewGroup) {
if (view.getParent() instanceof ViewGroup && ((ViewGroup) view.getParent()).indexOfChild(view) >= 0) {
((ViewGroup) view.getParent()).removeView(view);
return true;
} else {

@ -27,6 +27,6 @@ public class Time {
}
public static void endTiming(String tag, long start) {
Logger.test(tag + " took " + ((System.nanoTime() - start) / 1_000_000.0) + "ms");
Logger.v("Timer", tag + " took " + ((System.nanoTime() - start) / 1_000_000.0) + "ms");
}
}

Loading…
Cancel
Save