Start using a single thread executor for any database access to eliminate unnecessary thread creation
This commit is contained in:
parent
cb19ce2d0a
commit
f00bb77851
@ -173,7 +173,9 @@ public abstract class BrowserActivity extends ThemableBrowserActivity implements
|
||||
private boolean mShowTabsInDrawer;
|
||||
private int mOriginalOrientation, mBackgroundColor, mIdGenerator, mIconColor,
|
||||
mCurrentUiColor = Color.BLACK;
|
||||
private String mSearchText, mUntitledTitle, mHomepage, mCameraPhotoPath;
|
||||
private String mSearchText;
|
||||
private String mUntitledTitle;
|
||||
private String mCameraPhotoPath;
|
||||
|
||||
// The singleton BookmarkManager
|
||||
@Inject
|
||||
@ -258,8 +260,6 @@ public abstract class BrowserActivity extends ThemableBrowserActivity implements
|
||||
|
||||
mWebpageBitmap = ThemeUtils.getThemedBitmap(this, R.drawable.ic_webpage, mDarkTheme);
|
||||
|
||||
mHomepage = mPreferences.getHomepage();
|
||||
|
||||
final TabsFragment tabsFragment = new TabsFragment();
|
||||
final int containerId = mShowTabsInDrawer ? R.id.left_drawer : R.id.tabs_toolbar_container;
|
||||
final Bundle tabsFragmentArguments = new Bundle();
|
||||
@ -1339,7 +1339,10 @@ public abstract class BrowserActivity extends ThemableBrowserActivity implements
|
||||
}
|
||||
|
||||
void addItemToHistory(@Nullable final String title, @NonNull final String url) {
|
||||
Runnable update = new Runnable() {
|
||||
if (UrlUtils.isSpecialUrl(url)) {
|
||||
return;
|
||||
}
|
||||
BrowserApp.getAppComponent().getHistoryDatabase().getIOThread().execute(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
try {
|
||||
@ -1352,10 +1355,7 @@ public abstract class BrowserActivity extends ThemableBrowserActivity implements
|
||||
Log.e(Constants.TAG, "SQLiteException in updateHistory", e);
|
||||
}
|
||||
}
|
||||
};
|
||||
if (!UrlUtils.isSpecialUrl(url)) {
|
||||
new Thread(update).start();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
@ -1406,7 +1406,7 @@ public abstract class BrowserActivity extends ThemableBrowserActivity implements
|
||||
*/
|
||||
private void openHistory() {
|
||||
// use a thread so that history retrieval doesn't block the UI
|
||||
Thread history = new Thread(new Runnable() {
|
||||
BrowserApp.getAppComponent().getHistoryDatabase().getIOThread().execute(new Runnable() {
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
@ -1415,7 +1415,6 @@ public abstract class BrowserActivity extends ThemableBrowserActivity implements
|
||||
}
|
||||
|
||||
});
|
||||
history.run();
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -13,6 +13,8 @@ import android.support.annotation.Nullable;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.concurrent.Executor;
|
||||
import java.util.concurrent.Executors;
|
||||
|
||||
import javax.inject.Inject;
|
||||
import javax.inject.Singleton;
|
||||
@ -40,6 +42,8 @@ public class HistoryDatabase extends SQLiteOpenHelper {
|
||||
|
||||
private SQLiteDatabase mDatabase;
|
||||
|
||||
private Executor mIOThread = Executors.newSingleThreadExecutor();
|
||||
|
||||
@Inject
|
||||
public HistoryDatabase(Context context) {
|
||||
super(context.getApplicationContext(), DATABASE_NAME, null, DATABASE_VERSION);
|
||||
@ -74,6 +78,10 @@ public class HistoryDatabase extends SQLiteOpenHelper {
|
||||
return mDatabase == null || !mDatabase.isOpen();
|
||||
}
|
||||
|
||||
public Executor getIOThread() {
|
||||
return mIOThread;
|
||||
}
|
||||
|
||||
@Override
|
||||
public synchronized void close() {
|
||||
if (mDatabase != null) {
|
||||
|
@ -15,6 +15,7 @@ import android.support.v7.app.AlertDialog;
|
||||
import android.webkit.WebView;
|
||||
|
||||
import acr.browser.lightning.R;
|
||||
import acr.browser.lightning.app.BrowserApp;
|
||||
import acr.browser.lightning.utils.Utils;
|
||||
import acr.browser.lightning.utils.WebUtils;
|
||||
import acr.browser.lightning.view.LightningView;
|
||||
@ -148,13 +149,15 @@ public class PrivacySettingsFragment extends LightningPreferenceFragment impleme
|
||||
new DialogInterface.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(DialogInterface arg0, int arg1) {
|
||||
Thread clear = new Thread(new Runnable() {
|
||||
BrowserApp.getAppComponent()
|
||||
.getHistoryDatabase()
|
||||
.getIOThread()
|
||||
.execute(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
clearHistory();
|
||||
}
|
||||
});
|
||||
clear.start();
|
||||
}
|
||||
})
|
||||
.setNegativeButton(getResources().getString(R.string.action_no), null).show();
|
||||
|
@ -12,7 +12,6 @@ import android.graphics.Color;
|
||||
import android.graphics.ColorMatrix;
|
||||
import android.graphics.ColorMatrixColorFilter;
|
||||
import android.graphics.Paint;
|
||||
import android.net.Uri;
|
||||
import android.os.Build;
|
||||
import android.os.Handler;
|
||||
import android.os.Message;
|
||||
@ -546,20 +545,6 @@ public class LightningView {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Naive caching of the favicon according to the domain name of the URL
|
||||
*
|
||||
* @param icon the icon to cache
|
||||
*/
|
||||
private void cacheFavicon(final Bitmap icon) {
|
||||
if (icon == null) return;
|
||||
final Uri uri = Uri.parse(getUrl());
|
||||
if (uri.getHost() == null) {
|
||||
return;
|
||||
}
|
||||
new Thread(new IconCacheTask(uri, icon)).start();
|
||||
}
|
||||
|
||||
@SuppressLint("NewApi")
|
||||
public synchronized void find(String text) {
|
||||
if (mWebView != null) {
|
||||
|
Loading…
Reference in New Issue
Block a user