Browse Source

Revert "Fixed bug in dark mode where search suggestions wouldn't show up. Sped up app startup by using singleton in BookmarkManager."

This reverts commit 4822996da1.
master
Anthony Restaino 10 years ago
parent
commit
cc6d7c7aa9
  1. 10
      src/acr/browser/lightning/AdBlock.java
  2. 2
      src/acr/browser/lightning/BookmarkActivity.java
  3. 10
      src/acr/browser/lightning/BookmarkManager.java
  4. 30
      src/acr/browser/lightning/BrowserActivity.java
  5. 2
      src/acr/browser/lightning/HistoryPage.java
  6. 2
      src/acr/browser/lightning/LightningView.java
  7. 360
      src/acr/browser/lightning/Preferences.java
  8. 16
      src/acr/browser/lightning/SearchAdapter.java

10
src/acr/browser/lightning/AdBlock.java

@ -22,16 +22,8 @@ public class AdBlock { @@ -22,16 +22,8 @@ public class AdBlock {
private SharedPreferences mPreferences;
private boolean mBlockAds;
private static final Locale mLocale = Locale.getDefault();
private static AdBlock mInstance;
public static AdBlock getInstance(Context context) {
if (mInstance == null) {
mInstance = new AdBlock(context);
}
return mInstance;
}
private AdBlock(Context context) {
public AdBlock(Context context) {
if (mBlockedDomainsList.isEmpty()) {
loadBlockedDomainsList(context);
}

2
src/acr/browser/lightning/BookmarkActivity.java

@ -45,7 +45,7 @@ public class BookmarkActivity extends ThemableSettingsActivity implements OnClic @@ -45,7 +45,7 @@ public class BookmarkActivity extends ThemableSettingsActivity implements OnClic
TextView importBookmarks = (TextView) findViewById(R.id.isImportBrowserAvailable);
mBookmarkManager = BookmarkManager.getInstance(getApplicationContext());
mBookmarkManager = new BookmarkManager(this);
mPreferences = getSharedPreferences(PreferenceConstants.PREFERENCES, 0);

10
src/acr/browser/lightning/BookmarkManager.java

@ -34,16 +34,8 @@ public class BookmarkManager { @@ -34,16 +34,8 @@ public class BookmarkManager {
private static final String FILE_BOOKMARKS = "bookmarks.dat";
private static SortedMap<String, Integer> mBookmarkMap = new TreeMap<String, Integer>(
String.CASE_INSENSITIVE_ORDER);
private static BookmarkManager mInstance;
public static BookmarkManager getInstance(Context context) {
if (mInstance == null) {
mInstance = new BookmarkManager(context);
}
return mInstance;
}
private BookmarkManager(Context context) {
public BookmarkManager(Context context) {
mContext = context;
mBookmarkMap = getBookmarkUrls();
}

30
src/acr/browser/lightning/BrowserActivity.java

@ -18,6 +18,7 @@ import android.database.sqlite.SQLiteException; @@ -18,6 +18,7 @@ import android.database.sqlite.SQLiteException;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.ColorMatrix;
import android.graphics.ColorMatrixColorFilter;
import android.graphics.Paint;
@ -138,7 +139,13 @@ public class BrowserActivity extends ThemableActivity implements BrowserControll @@ -138,7 +139,13 @@ public class BrowserActivity extends ThemableActivity implements BrowserControll
} else {
mWebViews = new ArrayList<LightningView>();
}
mBookmarkManager = new BookmarkManager(this);
if (!mPreferences.getBoolean(PreferenceConstants.OLD_BOOKMARKS_IMPORTED, false)) {
List<HistoryItem> old = Utils.getOldBookmarks(this);
mBookmarkManager.addBookmarkList(old);
mPreferences.edit().putBoolean(PreferenceConstants.OLD_BOOKMARKS_IMPORTED, true)
.apply();
}
mActivity = this;
mClickHandler = new ClickHandler(this);
mBrowserFrame = (FrameLayout) findViewById(R.id.content_frame);
@ -186,10 +193,13 @@ public class BrowserActivity extends ThemableActivity implements BrowserControll @@ -186,10 +193,13 @@ public class BrowserActivity extends ThemableActivity implements BrowserControll
mDrawerListLeft.setOnItemClickListener(new DrawerItemClickListener());
mDrawerListLeft.setOnItemLongClickListener(new DrawerItemLongClickListener());
mBookmarkList = mBookmarkManager.getBookmarks(true);
mBookmarkAdapter = new BookmarkViewAdapter(this, R.layout.bookmark_list_item, mBookmarkList);
mDrawerListRight.setAdapter(mBookmarkAdapter);
mDrawerListRight.setOnItemClickListener(new BookmarkItemClickListener());
mDrawerListRight.setOnItemLongClickListener(new BookmarkItemLongClickListener());
mHistoryDatabase = HistoryDatabase.getInstance(getApplicationContext());
mHistoryDatabase = HistoryDatabase.getInstance(this);
// set display options of the ActionBar
mActionBar.setDisplayShowTitleEnabled(false);
@ -252,11 +262,6 @@ public class BrowserActivity extends ThemableActivity implements BrowserControll @@ -252,11 +262,6 @@ public class BrowserActivity extends ThemableActivity implements BrowserControll
@Override
public void run() {
mBookmarkManager = BookmarkManager.getInstance(mActivity.getApplicationContext());
mBookmarkList = mBookmarkManager.getBookmarks(true);
mBookmarkAdapter = new BookmarkViewAdapter(mActivity, R.layout.bookmark_list_item,
mBookmarkList);
mDrawerListRight.setAdapter(mBookmarkAdapter);
initializeSearchSuggestions(mSearch);
}
@ -606,9 +611,6 @@ public class BrowserActivity extends ThemableActivity implements BrowserControll @@ -606,9 +611,6 @@ public class BrowserActivity extends ThemableActivity implements BrowserControll
int count = 0;
for (int n = 0; n < array.length; n++) {
if (array[n].length() > 0) {
if (url != null && url.compareTo(array[n]) == 0) {
url = null;
}
newTab(array[n], true);
count++;
}
@ -1363,7 +1365,7 @@ public class BrowserActivity extends ThemableActivity implements BrowserControll @@ -1363,7 +1365,7 @@ public class BrowserActivity extends ThemableActivity implements BrowserControll
mCurrentView.resumeTimers();
mCurrentView.onResume();
mHistoryDatabase = HistoryDatabase.getInstance(getApplicationContext());
mHistoryDatabase = HistoryDatabase.getInstance(this);
mBookmarkList = mBookmarkManager.getBookmarks(true);
notifyBookmarkDataSetChanged();
}
@ -1590,9 +1592,11 @@ public class BrowserActivity extends ThemableActivity implements BrowserControll @@ -1590,9 +1592,11 @@ public class BrowserActivity extends ThemableActivity implements BrowserControll
public class BookmarkViewAdapter extends ArrayAdapter<HistoryItem> {
Context context;
List<HistoryItem> data = null;
int layoutResourceId;
List<HistoryItem> data = null;
public BookmarkViewAdapter(Context context, int layoutResourceId, List<HistoryItem> data) {
super(context, layoutResourceId, data);
this.layoutResourceId = layoutResourceId;
@ -1885,7 +1889,7 @@ public class BrowserActivity extends ThemableActivity implements BrowserControll @@ -1885,7 +1889,7 @@ public class BrowserActivity extends ThemableActivity implements BrowserControll
});
getUrl.setSelectAllOnFocus(true);
mSearchAdapter = new SearchAdapter(mContext, mDarkTheme, isIncognito());
mSearchAdapter = new SearchAdapter(mContext, isIncognito() || mDarkTheme);
getUrl.setAdapter(mSearchAdapter);
}

2
src/acr/browser/lightning/HistoryPage.java

@ -53,7 +53,7 @@ public class HistoryPage { @@ -53,7 +53,7 @@ public class HistoryPage {
}
private static List<HistoryItem> getWebHistory(Context context) {
HistoryDatabase databaseHandler = HistoryDatabase.getInstance(context.getApplicationContext());
HistoryDatabase databaseHandler = HistoryDatabase.getInstance(context);
return databaseHandler.getLastHundredItems();
}
}

2
src/acr/browser/lightning/LightningView.java

@ -86,7 +86,7 @@ public class LightningView { @@ -86,7 +86,7 @@ public class LightningView {
mActivity = activity;
mWebView = new WebView(activity);
mTitle = new Title(activity, darkTheme);
mAdBlock = AdBlock.getInstance(activity.getApplicationContext());
mAdBlock = new AdBlock(activity);
if (darkTheme) {
mWebpageBitmap = BitmapFactory.decodeResource(activity.getResources(),

360
src/acr/browser/lightning/Preferences.java

@ -1,360 +0,0 @@ @@ -1,360 +0,0 @@
package acr.browser.lightning;
import android.content.SharedPreferences;
import android.os.Environment;
public class Preferences {
private static Preferences mInstance;
private static SharedPreferences mPrefs;
private static final String PREFERENCES = "settings";
private Preferences(){
mPrefs = BrowserApp.getAppContext().getSharedPreferences(PREFERENCES, 0);
}
public static Preferences getInstance(){
if(mInstance == null){
mInstance = new Preferences();
}
return mInstance;
}
public int getFlashSupport(){
return mPrefs.getInt(Name.ADOBE_FLASH_SUPPORT, 0);
}
public void setFlashSupport(int n){
mPrefs.edit().putInt(Name.ADOBE_FLASH_SUPPORT, n).apply();
}
public boolean getAdBlockEnabled(){
return mPrefs.getBoolean(Name.BLOCK_ADS, false);
}
public void setAdBlockEnabled(boolean enable){
mPrefs.edit().putBoolean(Name.BLOCK_ADS, enable).apply();
}
public boolean getBlockImagesEnabled(){
return mPrefs.getBoolean(Name.BLOCK_IMAGES, false);
}
public void setBlockImagesEnabled(boolean enable){
mPrefs.edit().putBoolean(Name.BLOCK_IMAGES, enable).apply();
}
public boolean getClearCacheExit(){
return mPrefs.getBoolean(Name.CLEAR_CACHE_EXIT, false);
}
public void setClearCacheExit(boolean enable){
mPrefs.edit().putBoolean(Name.CLEAR_CACHE_EXIT, enable).apply();
}
public boolean getCookiesEnabled(){
return mPrefs.getBoolean(Name.COOKIES, true);
}
public void setCookiesEnabled(boolean enable){
mPrefs.edit().putBoolean(Name.COOKIES, enable).apply();
}
public String getDownloadDirectory(){
return mPrefs.getString(Name.DOWNLOAD_DIRECTORY, Environment.DIRECTORY_DOWNLOADS);
}
public void setDownloadDirectory(String directory){
mPrefs.edit().putString(Name.DOWNLOAD_DIRECTORY, directory).apply();
}
public boolean getFullScreenEnabled(){
return mPrefs.getBoolean(Name.FULL_SCREEN, false);
}
public void setFullScreenEnabled(boolean enable){
mPrefs.edit().putBoolean(Name.FULL_SCREEN, enable).apply();
}
public boolean getHideStatusBarEnabled(){
return mPrefs.getBoolean(Name.HIDE_STATUS_BAR, false);
}
public void setHideStatusBarEnabled(boolean enable){
mPrefs.edit().putBoolean(Name.HIDE_STATUS_BAR, enable).apply();
}
public String getHomepage(){
return mPrefs.getString(Name.HOMEPAGE, Constants.HOMEPAGE);
}
public void setHomepage(String homepage){
mPrefs.edit().putString(Name.HOMEPAGE, homepage).apply();
}
public boolean getIncognitoCookiesEnabled(){
return mPrefs.getBoolean(Name.INCOGNITO_COOKIES, false);
}
public void setIncognitoCookiesEnabled(boolean enable){
mPrefs.edit().putBoolean(Name.INCOGNITO_COOKIES, enable).apply();
}
public boolean getJavaScriptEnabled(){
return mPrefs.getBoolean(PreferenceConstants.JAVASCRIPT, true);
}
public void setJavaScriptEnabled(boolean enable){
mPrefs.edit().putBoolean(Name.JAVASCRIPT, enable).apply();
}
public boolean getLocationEnabled(){
return mPrefs.getBoolean(Name.LOCATION, false);
}
public void setLocationEnabled(boolean enable){
mPrefs.edit().putBoolean(Name.LOCATION, enable).apply();
}
public boolean getOverviewModeEnabled(){
return mPrefs.getBoolean(Name.OVERVIEW_MODE, true);
}
public void setOverviewModeEnabled(boolean enable){
mPrefs.edit().putBoolean(Name.OVERVIEW_MODE, enable).apply();
}
public boolean getPopupsEnabled(){
return mPrefs.getBoolean(Name.POPUPS, true);
}
public void setPopupsEnabled(boolean enable){
mPrefs.edit().putBoolean(Name.POPUPS, enable).apply();
}
public boolean getRestoreLostTabsEnabled(){
return mPrefs.getBoolean(Name.RESTORE_LOST_TABS, true);
}
public void setRestoreLostTabsEnabled(boolean enable){
mPrefs.edit().putBoolean(Name.RESTORE_LOST_TABS, enable).apply();
}
public boolean getSavePasswordsEnabled(){
return mPrefs.getBoolean(Name.SAVE_PASSWORDS, true);
}
public void setSavePasswordsEnabled(boolean enable){
mPrefs.edit().putBoolean(Name.SAVE_PASSWORDS, enable).apply();
}
public int getSearchChoice(){
return mPrefs.getInt(Name.SEARCH, 1);
}
public void setSearchChoice(int choice){
mPrefs.edit().putInt(Name.SEARCH, choice).apply();
}
public String getSearchUrl(){
return mPrefs.getString(Name.SEARCH_URL, Constants.GOOGLE_SEARCH);
}
public void setSearchUrl(String url){
mPrefs.edit().putString(Name.SEARCH_URL, url).apply();
}
public boolean getSystemBrowserPresent(){
return mPrefs.getBoolean(Name.SYSTEM_BROWSER_PRESENT, false);
}
public void setSystemBrowserPresent(boolean available){
mPrefs.edit().putBoolean(Name.SYSTEM_BROWSER_PRESENT, available).apply();
}
public boolean getTextReflowEnabled(){
return mPrefs.getBoolean(Name.TEXT_REFLOW, false);
}
public void setTextReflowEnabled(boolean enable){
mPrefs.edit().putBoolean(Name.TEXT_REFLOW, enable).apply();
}
public int getTextSize(){
return mPrefs.getInt(Name.TEXT_SIZE, 3);
}
public void setTextSize(int size){
mPrefs.edit().putInt(Name.TEXT_SIZE, size).apply();
}
public String getMemoryUrl(){
return mPrefs.getString(Name.URL_MEMORY, "");
}
public void setMemoryUrl(String url){
mPrefs.edit().putString(Name.URL_MEMORY, url).apply();
}
public boolean getUseWideViewportEnabled(){
return mPrefs.getBoolean(Name.USE_WIDE_VIEWPORT, true);
}
public void setUseWideViewportEnabled(boolean enable){
mPrefs.edit().putBoolean(Name.USE_WIDE_VIEWPORT, enable).apply();
}
public int getUserAgentChoice(){
return mPrefs.getInt(Name.USER_AGENT, 1);
}
public void setUserAgentChoice(int choice){
mPrefs.edit().putInt(Name.USER_AGENT, choice).apply();
}
public String getUserAgentString(String def){
return mPrefs.getString(Name.USER_AGENT_STRING, def);
}
public void setUserAgentString(String agent){
mPrefs.edit().putString(Name.USER_AGENT_STRING, agent).apply();
}
public boolean getGoogleSearchSuggestionsEnabled(){
return mPrefs.getBoolean(Name.GOOGLE_SEARCH_SUGGESTIONS, true);
}
public void setGoogleSearchSuggestionsEnabled(boolean enabled){
mPrefs.edit().putBoolean(Name.GOOGLE_SEARCH_SUGGESTIONS, enabled).apply();
}
public boolean getClearHistoryExitEnabled(){
return mPrefs.getBoolean(Name.CLEAR_HISTORY_EXIT, false);
}
public void setClearHistoryExitEnabled(boolean enable){
mPrefs.edit().putBoolean(Name.CLEAR_HISTORY_EXIT, enable).apply();
}
public boolean getClearCookiesExitEnabled(){
return mPrefs.getBoolean(Name.CLEAR_COOKIES_EXIT, false);
}
public void setClearCookiesExitEnabled(boolean enable){
mPrefs.edit().putBoolean(Name.CLEAR_COOKIES_EXIT, enable).apply();
}
public String getSavedUrl(){
return mPrefs.getString(Name.SAVE_URL, null);
}
public void setSavedUrl(String url){
mPrefs.edit().putString(Name.SAVE_URL, url).apply();
}
public int getRenderingMode(){
return mPrefs.getInt(Name.RENDERING_MODE, 0);
}
public void setRenderingMode(int mode){
mPrefs.edit().putInt(Name.RENDERING_MODE, mode).apply();
}
public boolean getSyncHistoryEnabled(){
return mPrefs.getBoolean(Name.SYNC_HISTORY, true);
}
public void setSyncHistoryEnabled(boolean enable){
mPrefs.edit().putBoolean(Name.SYNC_HISTORY, enable).apply();
}
public boolean getBlockThirdPartyCookiesEnabled(){
return mPrefs.getBoolean(Name.BLOCK_THIRD_PARTY, false);
}
public void setBlockThirdPartyCookiesEnabled(boolean enable){
mPrefs.edit().putBoolean(Name.BLOCK_THIRD_PARTY, enable).apply();
}
public boolean getColorModeEnabled(){
return mPrefs.getBoolean(Name.ENABLE_COLOR_MODE, true);
}
public void setColorModeEnabled(boolean enable){
mPrefs.edit().putBoolean(Name.ENABLE_COLOR_MODE, enable).apply();
}
public int getUrlBoxContentChoice(){
return mPrefs.getInt(Name.URL_BOX_CONTENTS, 0);
}
public void setUrlBoxContentChoice(int choice){
mPrefs.edit().putInt(Name.URL_BOX_CONTENTS, choice).apply();
}
public boolean getUseProxy(){
return mPrefs.getBoolean(Name.USE_PROXY, false);
}
public void setUseProxy(boolean enable){
mPrefs.edit().putBoolean(Name.USE_PROXY, enable).apply();
}
public String getProxyHost(){
return mPrefs.getString(Name.USE_PROXY_HOST, "localhost");
}
public int getProxyPort(){
return mPrefs.getInt(Name.USE_PROXY_PORT, 8118);
}
public boolean getCheckedForTor(){
return mPrefs.getBoolean(Name.INITIAL_CHECK_FOR_TOR, false);
}
public void setCheckedForTor(boolean check){
mPrefs.edit().putBoolean(Name.INITIAL_CHECK_FOR_TOR, check).apply();
}
private class Name {
public static final String ADOBE_FLASH_SUPPORT = "enableflash";
public static final String BLOCK_ADS = "AdBlock";
public static final String BLOCK_IMAGES = "blockimages";
public static final String CLEAR_CACHE_EXIT = "cache";
public static final String COOKIES = "cookies";
public static final String DOWNLOAD_DIRECTORY = "download";
public static final String FULL_SCREEN = "fullscreen";
public static final String HIDE_STATUS_BAR = "hidestatus";
public static final String HOMEPAGE = "home";
public static final String INCOGNITO_COOKIES = "incognitocookies";
public static final String JAVASCRIPT = "java";
public static final String LOCATION = "location";
public static final String OVERVIEW_MODE = "overviewmode";
public static final String POPUPS = "newwindows";
public static final String RESTORE_LOST_TABS = "restoreclosed";
public static final String SAVE_PASSWORDS = "passwords";
public static final String SEARCH = "search";
public static final String SEARCH_URL = "searchurl";
public static final String SYSTEM_BROWSER_PRESENT = "SystemBrowser";
public static final String TEXT_REFLOW = "textreflow";
public static final String TEXT_SIZE = "textsize";
public static final String URL_MEMORY = "memory";
public static final String USE_WIDE_VIEWPORT = "wideviewport";
public static final String USER_AGENT = "agentchoose";
public static final String USER_AGENT_STRING = "userAgentString";
public static final String GOOGLE_SEARCH_SUGGESTIONS = "GoogleSearchSuggestions";
public static final String CLEAR_HISTORY_EXIT = "clearHistoryExit";
public static final String CLEAR_COOKIES_EXIT = "clearCookiesExit";
public static final String SAVE_URL = "saveUrl";
public static final String RENDERING_MODE = "renderMode";
public static final String SYNC_HISTORY = "syncHistory";
public static final String BLOCK_THIRD_PARTY = "thirdParty";
public static final String ENABLE_COLOR_MODE = "colorMode";
public static final String URL_BOX_CONTENTS = "urlContent";
public static final String USE_PROXY = "useProxy";
public static final String USE_PROXY_HOST = "useProxyHost";
public static final String USE_PROXY_PORT = "useProxyPort";
public static final String INITIAL_CHECK_FOR_TOR = "checkForTor";
}
}

16
src/acr/browser/lightning/SearchAdapter.java

@ -50,7 +50,6 @@ public class SearchAdapter extends BaseAdapter implements Filterable { @@ -50,7 +50,6 @@ public class SearchAdapter extends BaseAdapter implements Filterable {
private boolean mUseGoogle = true;
private boolean mIsExecuting = false;
private boolean mDarkTheme;
private boolean mIncognito;
private BookmarkManager mBookmarkManager;
private static final String ENCODING = "ISO-8859-1";
private static final long INTERVAL_DAY = 86400000;
@ -59,21 +58,20 @@ public class SearchAdapter extends BaseAdapter implements Filterable { @@ -59,21 +58,20 @@ public class SearchAdapter extends BaseAdapter implements Filterable {
private Theme mTheme;
private SearchFilter mFilter;
public SearchAdapter(Context context, boolean dark, boolean incognito) {
mDatabaseHandler = HistoryDatabase.getInstance(context.getApplicationContext());
public SearchAdapter(Context context, boolean dark) {
mDatabaseHandler = HistoryDatabase.getInstance(context);
mTheme = context.getTheme();
mFilteredList = new ArrayList<HistoryItem>();
mHistory = new ArrayList<HistoryItem>();
mBookmarks = new ArrayList<HistoryItem>();
mSuggestions = new ArrayList<HistoryItem>();
mBookmarkManager = BookmarkManager.getInstance(context.getApplicationContext());
mBookmarkManager = new BookmarkManager(context);
mAllBookmarks = mBookmarkManager.getBookmarks(true);
mPreferences = context.getSharedPreferences(PreferenceConstants.PREFERENCES, 0);
mUseGoogle = mPreferences.getBoolean(PreferenceConstants.GOOGLE_SEARCH_SUGGESTIONS, true);
mContext = context;
mSearchSubtitle = mContext.getString(R.string.suggestion);
mDarkTheme = dark || incognito;
mIncognito = incognito;
mDarkTheme = dark;
Thread delete = new Thread(new Runnable() {
@Override
@ -229,7 +227,7 @@ public class SearchAdapter extends BaseAdapter implements Filterable { @@ -229,7 +227,7 @@ public class SearchAdapter extends BaseAdapter implements Filterable {
return results;
}
String query = constraint.toString().toLowerCase(Locale.getDefault());
if (mUseGoogle && !mIncognito && !mIsExecuting) {
if (mUseGoogle && !mDarkTheme && !mIsExecuting) {
new RetrieveSearchSuggestions().execute(query);
}
@ -250,7 +248,7 @@ public class SearchAdapter extends BaseAdapter implements Filterable { @@ -250,7 +248,7 @@ public class SearchAdapter extends BaseAdapter implements Filterable {
}
if (mDatabaseHandler == null) {
mDatabaseHandler = HistoryDatabase.getInstance(mContext.getApplicationContext());
mDatabaseHandler = HistoryDatabase.getInstance(mContext);
}
mHistory = mDatabaseHandler.findItemsContaining(constraint.toString());
@ -407,7 +405,7 @@ public class SearchAdapter extends BaseAdapter implements Filterable { @@ -407,7 +405,7 @@ public class SearchAdapter extends BaseAdapter implements Filterable {
int maxBookmarks = (suggestionsSize + historySize < 3) ? (5 - suggestionsSize - historySize)
: 2;
if (!mUseGoogle || mIncognito) {
if (!mUseGoogle || mDarkTheme) {
maxHistory++;
maxBookmarks++;
}

Loading…
Cancel
Save