Lint fixes, save scroll position in bookmarks list
This commit is contained in:
parent
6bbc0805de
commit
38d1973a93
@ -194,7 +194,7 @@ public abstract class BrowserActivity extends ThemableBrowserActivity implements
|
|||||||
|
|
||||||
// Storage
|
// Storage
|
||||||
private HistoryDatabase mHistoryDatabase;
|
private HistoryDatabase mHistoryDatabase;
|
||||||
private PreferenceManager mPreferences = PreferenceManager.getInstance();
|
private final PreferenceManager mPreferences = PreferenceManager.getInstance();
|
||||||
|
|
||||||
// The singleton BookmarkManager
|
// The singleton BookmarkManager
|
||||||
@Inject
|
@Inject
|
||||||
|
@ -16,9 +16,9 @@ import java.util.concurrent.RejectedExecutionException;
|
|||||||
public class AsyncExecutor implements Executor {
|
public class AsyncExecutor implements Executor {
|
||||||
|
|
||||||
private static final String TAG = AsyncExecutor.class.getSimpleName();
|
private static final String TAG = AsyncExecutor.class.getSimpleName();
|
||||||
private static AsyncExecutor INSTANCE = new AsyncExecutor();
|
private static final AsyncExecutor INSTANCE = new AsyncExecutor();
|
||||||
private Queue<Runnable> mQueue = new ArrayDeque<>(1);
|
private final Queue<Runnable> mQueue = new ArrayDeque<>(1);
|
||||||
private ExecutorService mExecutor = Executors.newFixedThreadPool(4);
|
private final ExecutorService mExecutor = Executors.newFixedThreadPool(4);
|
||||||
|
|
||||||
private AsyncExecutor() {}
|
private AsyncExecutor() {}
|
||||||
|
|
||||||
|
@ -24,7 +24,7 @@ public class BookmarkLocalSync {
|
|||||||
private static final String COLUMN_URL = "url";
|
private static final String COLUMN_URL = "url";
|
||||||
private static final String COLUMN_BOOKMARK = "bookmark";
|
private static final String COLUMN_BOOKMARK = "bookmark";
|
||||||
|
|
||||||
private Context mContext;
|
private final Context mContext;
|
||||||
|
|
||||||
public BookmarkLocalSync(Context context) {
|
public BookmarkLocalSync(Context context) {
|
||||||
mContext = context;
|
mContext = context;
|
||||||
|
@ -13,7 +13,6 @@ import android.content.pm.PackageManager;
|
|||||||
import android.content.pm.ResolveInfo;
|
import android.content.pm.ResolveInfo;
|
||||||
import android.net.Uri;
|
import android.net.Uri;
|
||||||
import android.os.Environment;
|
import android.os.Environment;
|
||||||
import android.support.annotation.NonNull;
|
|
||||||
import android.support.v7.app.AlertDialog;
|
import android.support.v7.app.AlertDialog;
|
||||||
import android.text.TextUtils;
|
import android.text.TextUtils;
|
||||||
import android.util.Log;
|
import android.util.Log;
|
||||||
@ -22,7 +21,6 @@ import android.webkit.URLUtil;
|
|||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.net.URI;
|
|
||||||
|
|
||||||
import acr.browser.lightning.R;
|
import acr.browser.lightning.R;
|
||||||
import acr.browser.lightning.constant.Constants;
|
import acr.browser.lightning.constant.Constants;
|
||||||
|
@ -75,8 +75,6 @@ public class BookmarkSettingsFragment extends PreferenceFragment implements Pref
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
;
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onCreate(Bundle savedInstanceState) {
|
public void onCreate(Bundle savedInstanceState) {
|
||||||
super.onCreate(savedInstanceState);
|
super.onCreate(savedInstanceState);
|
||||||
|
@ -1,5 +1,6 @@
|
|||||||
package acr.browser.lightning.fragment;
|
package acr.browser.lightning.fragment;
|
||||||
|
|
||||||
|
import android.app.Activity;
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.graphics.Bitmap;
|
import android.graphics.Bitmap;
|
||||||
import android.graphics.PorterDuff;
|
import android.graphics.PorterDuff;
|
||||||
@ -78,7 +79,7 @@ public class BookmarksFragment extends Fragment implements View.OnClickListener,
|
|||||||
private ImageView mBookmarkTitleImage, mBookmarkImage;
|
private ImageView mBookmarkTitleImage, mBookmarkImage;
|
||||||
|
|
||||||
// Colors
|
// Colors
|
||||||
private int mIconColor;
|
private int mIconColor, mScrollIndex;
|
||||||
|
|
||||||
// Init asynchronously the bookmark manager
|
// Init asynchronously the bookmark manager
|
||||||
private final Runnable mInitBookmarkManager = new Runnable() {
|
private final Runnable mInitBookmarkManager = new Runnable() {
|
||||||
@ -98,11 +99,12 @@ public class BookmarksFragment extends Fragment implements View.OnClickListener,
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Handle bookmark click
|
// Handle bookmark click
|
||||||
private final OnItemClickListener itemClickListener = new OnItemClickListener() {
|
private final OnItemClickListener mItemClickListener = new OnItemClickListener() {
|
||||||
@Override
|
@Override
|
||||||
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
|
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
|
||||||
final HistoryItem item = mBookmarks.get(position);
|
final HistoryItem item = mBookmarks.get(position);
|
||||||
if (item.isFolder()) {
|
if (item.isFolder()) {
|
||||||
|
mScrollIndex = mBookmarksListView.getFirstVisiblePosition();
|
||||||
setBookmarkDataSet(mBookmarkManager.getBookmarksFromFolder(item.getTitle(), true), true);
|
setBookmarkDataSet(mBookmarkManager.getBookmarksFromFolder(item.getTitle(), true), true);
|
||||||
} else {
|
} else {
|
||||||
mEventBus.post(new BookmarkEvents.Clicked(item));
|
mEventBus.post(new BookmarkEvents.Clicked(item));
|
||||||
@ -110,7 +112,7 @@ public class BookmarksFragment extends Fragment implements View.OnClickListener,
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
private final OnItemLongClickListener itemLongClickListener = new OnItemLongClickListener() {
|
private final OnItemLongClickListener mItemLongClickListener = new OnItemLongClickListener() {
|
||||||
@Override
|
@Override
|
||||||
public boolean onItemLongClick(AdapterView<?> parent, View view, int position, long id) {
|
public boolean onItemLongClick(AdapterView<?> parent, View view, int position, long id) {
|
||||||
final HistoryItem item = mBookmarks.get(position);
|
final HistoryItem item = mBookmarks.get(position);
|
||||||
@ -130,8 +132,8 @@ public class BookmarksFragment extends Fragment implements View.OnClickListener,
|
|||||||
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
|
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
|
||||||
final View view = inflater.inflate(R.layout.bookmark_drawer, container, false);
|
final View view = inflater.inflate(R.layout.bookmark_drawer, container, false);
|
||||||
mBookmarksListView = (ListView) view.findViewById(R.id.right_drawer_list);
|
mBookmarksListView = (ListView) view.findViewById(R.id.right_drawer_list);
|
||||||
mBookmarksListView.setOnItemClickListener(itemClickListener);
|
mBookmarksListView.setOnItemClickListener(mItemClickListener);
|
||||||
mBookmarksListView.setOnItemLongClickListener(itemLongClickListener);
|
mBookmarksListView.setOnItemLongClickListener(mItemLongClickListener);
|
||||||
mBookmarkTitleImage = (ImageView) view.findViewById(R.id.starIcon);
|
mBookmarkTitleImage = (ImageView) view.findViewById(R.id.starIcon);
|
||||||
mBookmarkImage = (ImageView) view.findViewById(R.id.icon_star);
|
mBookmarkImage = (ImageView) view.findViewById(R.id.icon_star);
|
||||||
final View backView = view.findViewById(R.id.bookmark_back_button);
|
final View backView = view.findViewById(R.id.bookmark_back_button);
|
||||||
@ -141,9 +143,11 @@ public class BookmarksFragment extends Fragment implements View.OnClickListener,
|
|||||||
if (mBookmarkManager == null) return;
|
if (mBookmarkManager == null) return;
|
||||||
if (!mBookmarkManager.isRootFolder()) {
|
if (!mBookmarkManager.isRootFolder()) {
|
||||||
setBookmarkDataSet(mBookmarkManager.getBookmarksFromFolder(null, true), true);
|
setBookmarkDataSet(mBookmarkManager.getBookmarksFromFolder(null, true), true);
|
||||||
|
mBookmarksListView.setSelection(mScrollIndex);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
setupNavigationButton(view, R.id.action_add_bookmark, R.id.icon_star);
|
||||||
|
|
||||||
// Must be called here, only here we have a reference to the ListView
|
// Must be called here, only here we have a reference to the ListView
|
||||||
new Thread(mInitBookmarkManager).run();
|
new Thread(mInitBookmarkManager).run();
|
||||||
@ -152,16 +156,15 @@ public class BookmarksFragment extends Fragment implements View.OnClickListener,
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onActivityCreated(@Nullable Bundle savedInstanceState) {
|
public void onActivityCreated(@Nullable Bundle savedInstanceState) {
|
||||||
// TODO this code depend way too much on BrowserActivity
|
// TODO remove dependency on BrowserActivity
|
||||||
super.onActivityCreated(savedInstanceState);
|
super.onActivityCreated(savedInstanceState);
|
||||||
final BrowserActivity activity = (BrowserActivity) getActivity();
|
final Activity activity = getActivity();
|
||||||
final PreferenceManager preferenceManager = PreferenceManager.getInstance();
|
final PreferenceManager preferenceManager = PreferenceManager.getInstance();
|
||||||
boolean darkTheme = preferenceManager.getUseTheme() != 0 || activity.isIncognito();
|
boolean darkTheme = preferenceManager.getUseTheme() != 0 || ((BrowserActivity) activity).isIncognito();
|
||||||
mWebpageBitmap = ThemeUtils.getThemedBitmap(activity, R.drawable.ic_webpage, darkTheme);
|
mWebpageBitmap = ThemeUtils.getThemedBitmap(activity, R.drawable.ic_webpage, darkTheme);
|
||||||
mFolderBitmap = ThemeUtils.getThemedBitmap(activity, R.drawable.ic_folder, darkTheme);
|
mFolderBitmap = ThemeUtils.getThemedBitmap(activity, R.drawable.ic_folder, darkTheme);
|
||||||
mIconColor = darkTheme ? ThemeUtils.getIconDarkThemeColor(activity) :
|
mIconColor = darkTheme ? ThemeUtils.getIconDarkThemeColor(activity) :
|
||||||
ThemeUtils.getIconLightThemeColor(activity);
|
ThemeUtils.getIconLightThemeColor(activity);
|
||||||
setupFrameLayoutButton(getView(), R.id.action_add_bookmark, R.id.icon_star);
|
|
||||||
mBookmarkTitleImage.setColorFilter(mIconColor, PorterDuff.Mode.SRC_IN);
|
mBookmarkTitleImage.setColorFilter(mIconColor, PorterDuff.Mode.SRC_IN);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -216,6 +219,7 @@ public class BookmarksFragment extends Fragment implements View.OnClickListener,
|
|||||||
mEventBus.post(new BookmarkEvents.CloseBookmarks());
|
mEventBus.post(new BookmarkEvents.CloseBookmarks());
|
||||||
} else {
|
} else {
|
||||||
setBookmarkDataSet(mBookmarkManager.getBookmarksFromFolder(null, true), true);
|
setBookmarkDataSet(mBookmarkManager.getBookmarksFromFolder(null, true), true);
|
||||||
|
mBookmarksListView.setSelection(mScrollIndex);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -279,8 +283,7 @@ public class BookmarksFragment extends Fragment implements View.OnClickListener,
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO this is basically a copy/paste from BrowserActivity, should be changed
|
private void setupNavigationButton(@NonNull View view, @IdRes int buttonId, @IdRes int imageId) {
|
||||||
private void setupFrameLayoutButton(@NonNull View view, @IdRes int buttonId, @IdRes int imageId) {
|
|
||||||
FrameLayout frameButton = (FrameLayout) view.findViewById(buttonId);
|
FrameLayout frameButton = (FrameLayout) view.findViewById(buttonId);
|
||||||
frameButton.setOnClickListener(this);
|
frameButton.setOnClickListener(this);
|
||||||
frameButton.setOnLongClickListener(this);
|
frameButton.setOnLongClickListener(this);
|
||||||
|
@ -34,6 +34,7 @@ import java.util.Comparator;
|
|||||||
import java.util.Iterator;
|
import java.util.Iterator;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Locale;
|
import java.util.Locale;
|
||||||
|
import java.util.regex.Pattern;
|
||||||
|
|
||||||
import javax.inject.Inject;
|
import javax.inject.Inject;
|
||||||
|
|
||||||
@ -48,6 +49,7 @@ import acr.browser.lightning.utils.Utils;
|
|||||||
|
|
||||||
public class SearchAdapter extends BaseAdapter implements Filterable {
|
public class SearchAdapter extends BaseAdapter implements Filterable {
|
||||||
|
|
||||||
|
private static final Pattern SPACE_PATTERN = Pattern.compile(" ", Pattern.LITERAL);
|
||||||
private final List<HistoryItem> mHistory = new ArrayList<>(5);
|
private final List<HistoryItem> mHistory = new ArrayList<>(5);
|
||||||
private final List<HistoryItem> mBookmarks = new ArrayList<>(5);
|
private final List<HistoryItem> mBookmarks = new ArrayList<>(5);
|
||||||
private final List<HistoryItem> mSuggestions = new ArrayList<>(5);
|
private final List<HistoryItem> mSuggestions = new ArrayList<>(5);
|
||||||
@ -60,7 +62,8 @@ public class SearchAdapter extends BaseAdapter implements Filterable {
|
|||||||
private boolean mIsExecuting = false;
|
private boolean mIsExecuting = false;
|
||||||
private final boolean mDarkTheme;
|
private final boolean mDarkTheme;
|
||||||
private final boolean mIncognito;
|
private final boolean mIncognito;
|
||||||
@Inject BookmarkManager mBookmarkManager;
|
@Inject
|
||||||
|
BookmarkManager mBookmarkManager;
|
||||||
private static final String CACHE_FILE_TYPE = ".sgg";
|
private static final String CACHE_FILE_TYPE = ".sgg";
|
||||||
private static final String ENCODING = "ISO-8859-1";
|
private static final String ENCODING = "ISO-8859-1";
|
||||||
private static final long INTERVAL_DAY = 86400000;
|
private static final long INTERVAL_DAY = 86400000;
|
||||||
@ -81,14 +84,7 @@ public class SearchAdapter extends BaseAdapter implements Filterable {
|
|||||||
mSearchSubtitle = mContext.getString(R.string.suggestion);
|
mSearchSubtitle = mContext.getString(R.string.suggestion);
|
||||||
mDarkTheme = dark || incognito;
|
mDarkTheme = dark || incognito;
|
||||||
mIncognito = incognito;
|
mIncognito = incognito;
|
||||||
Thread delete = new Thread(new Runnable() {
|
Thread delete = new Thread(new ClearCacheRunnable());
|
||||||
|
|
||||||
@Override
|
|
||||||
public void run() {
|
|
||||||
deleteOldCacheFiles();
|
|
||||||
}
|
|
||||||
|
|
||||||
});
|
|
||||||
mSearchDrawable = ThemeUtils.getThemedDrawable(context, R.drawable.ic_search, mDarkTheme);
|
mSearchDrawable = ThemeUtils.getThemedDrawable(context, R.drawable.ic_search, mDarkTheme);
|
||||||
mBookmarkDrawable = ThemeUtils.getThemedDrawable(context, R.drawable.ic_bookmark, mDarkTheme);
|
mBookmarkDrawable = ThemeUtils.getThemedDrawable(context, R.drawable.ic_bookmark, mDarkTheme);
|
||||||
mHistoryDrawable = ThemeUtils.getThemedDrawable(context, R.drawable.ic_history, mDarkTheme);
|
mHistoryDrawable = ThemeUtils.getThemedDrawable(context, R.drawable.ic_history, mDarkTheme);
|
||||||
@ -210,6 +206,15 @@ public class SearchAdapter extends BaseAdapter implements Filterable {
|
|||||||
return mFilter;
|
return mFilter;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private static class ClearCacheRunnable implements Runnable {
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void run() {
|
||||||
|
deleteOldCacheFiles();
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
private class SearchFilter extends Filter {
|
private class SearchFilter extends Filter {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -220,7 +225,7 @@ public class SearchAdapter extends BaseAdapter implements Filterable {
|
|||||||
}
|
}
|
||||||
String query = constraint.toString().toLowerCase(Locale.getDefault());
|
String query = constraint.toString().toLowerCase(Locale.getDefault());
|
||||||
if (mUseGoogle && !mIncognito && !mIsExecuting) {
|
if (mUseGoogle && !mIncognito && !mIsExecuting) {
|
||||||
new RetrieveSearchSuggestions().executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR, query);
|
new RetrieveSearchSuggestions().executeOnExecutor(AsyncTask.SERIAL_EXECUTOR, query);
|
||||||
}
|
}
|
||||||
|
|
||||||
int counter = 0;
|
int counter = 0;
|
||||||
@ -291,7 +296,7 @@ public class SearchAdapter extends BaseAdapter implements Filterable {
|
|||||||
List<HistoryItem> filter = new ArrayList<>();
|
List<HistoryItem> filter = new ArrayList<>();
|
||||||
String query = arg0[0];
|
String query = arg0[0];
|
||||||
try {
|
try {
|
||||||
query = query.replace(" ", "+");
|
query = SPACE_PATTERN.matcher(query).replaceAll("+");
|
||||||
URLEncoder.encode(query, ENCODING);
|
URLEncoder.encode(query, ENCODING);
|
||||||
} catch (UnsupportedEncodingException e) {
|
} catch (UnsupportedEncodingException e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
@ -335,6 +340,7 @@ public class SearchAdapter extends BaseAdapter implements Filterable {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void onPostExecute(List<HistoryItem> result) {
|
protected void onPostExecute(List<HistoryItem> result) {
|
||||||
|
mIsExecuting = false;
|
||||||
synchronized (mSuggestions) {
|
synchronized (mSuggestions) {
|
||||||
mSuggestions.clear();
|
mSuggestions.clear();
|
||||||
mSuggestions.addAll(result);
|
mSuggestions.addAll(result);
|
||||||
@ -346,7 +352,6 @@ public class SearchAdapter extends BaseAdapter implements Filterable {
|
|||||||
mFilteredList.addAll(filtered);
|
mFilteredList.addAll(filtered);
|
||||||
notifyDataSetChanged();
|
notifyDataSetChanged();
|
||||||
}
|
}
|
||||||
mIsExecuting = false;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
@ -354,6 +359,7 @@ public class SearchAdapter extends BaseAdapter implements Filterable {
|
|||||||
/**
|
/**
|
||||||
* This method downloads the search suggestions for the specific query.
|
* This method downloads the search suggestions for the specific query.
|
||||||
* NOTE: This is a blocking operation, do not run on the UI thread.
|
* NOTE: This is a blocking operation, do not run on the UI thread.
|
||||||
|
*
|
||||||
* @param query the query to get suggestions for
|
* @param query the query to get suggestions for
|
||||||
* @return the cache file containing the suggestions
|
* @return the cache file containing the suggestions
|
||||||
*/
|
*/
|
||||||
@ -407,32 +413,6 @@ public class SearchAdapter extends BaseAdapter implements Filterable {
|
|||||||
return connectivity.getActiveNetworkInfo();
|
return connectivity.getActiveNetworkInfo();
|
||||||
}
|
}
|
||||||
|
|
||||||
// The old suggestions algorithm, leaving here just for reference
|
|
||||||
// private List<HistoryItem> getSuggestions() {
|
|
||||||
// List<HistoryItem> filteredList = new ArrayList<>();
|
|
||||||
//
|
|
||||||
// int suggestionsSize = mSuggestions.size();
|
|
||||||
// int historySize = mHistory.size();
|
|
||||||
// int bookmarkSize = mBookmarks.size();
|
|
||||||
//
|
|
||||||
// int maxSuggestions = (bookmarkSize + historySize < 3) ? (5 - bookmarkSize - historySize) : (bookmarkSize < 2) ? (4 - bookmarkSize) : (historySize < 1) ? 3 : 2;
|
|
||||||
// int maxHistory = (suggestionsSize + bookmarkSize < 4) ? (5 - suggestionsSize - bookmarkSize) : 1;
|
|
||||||
// int maxBookmarks = (suggestionsSize + historySize < 3) ? (5 - suggestionsSize - historySize) : 2;
|
|
||||||
//
|
|
||||||
// for (int n = 0; n < bookmarkSize && n < maxBookmarks; n++) {
|
|
||||||
// filteredList.add(mBookmarks.get(n));
|
|
||||||
// }
|
|
||||||
//
|
|
||||||
// for (int n = 0; n < historySize && n < maxHistory; n++) {
|
|
||||||
// filteredList.add(mHistory.get(n));
|
|
||||||
// }
|
|
||||||
//
|
|
||||||
// for (int n = 0; n < suggestionsSize && n < maxSuggestions; n++) {
|
|
||||||
// filteredList.add(mSuggestions.get(n));
|
|
||||||
// }
|
|
||||||
// return filteredList;
|
|
||||||
// }
|
|
||||||
|
|
||||||
private List<HistoryItem> getFilteredList() {
|
private List<HistoryItem> getFilteredList() {
|
||||||
List<HistoryItem> list = new ArrayList<>(5);
|
List<HistoryItem> list = new ArrayList<>(5);
|
||||||
synchronized (mBookmarks) {
|
synchronized (mBookmarks) {
|
||||||
|
@ -47,7 +47,7 @@ public class JResult implements Serializable {
|
|||||||
private Date date;
|
private Date date;
|
||||||
private Collection<String> keywords;
|
private Collection<String> keywords;
|
||||||
private List<ImageResult> images = null;
|
private List<ImageResult> images = null;
|
||||||
private List<Map<String, String>> links = new ArrayList<>();
|
private final List<Map<String, String>> links = new ArrayList<>();
|
||||||
private String type;
|
private String type;
|
||||||
private String sitename;
|
private String sitename;
|
||||||
private String language;
|
private String language;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user