Browse Source

Lint fixes, save scroll position in bookmarks list

master
Anthony Restaino 9 years ago
parent
commit
38d1973a93
  1. 2
      app/src/main/java/acr/browser/lightning/activity/BrowserActivity.java
  2. 6
      app/src/main/java/acr/browser/lightning/async/AsyncExecutor.java
  3. 2
      app/src/main/java/acr/browser/lightning/database/BookmarkLocalSync.java
  4. 2
      app/src/main/java/acr/browser/lightning/download/DownloadHandler.java
  5. 2
      app/src/main/java/acr/browser/lightning/fragment/BookmarkSettingsFragment.java
  6. 25
      app/src/main/java/acr/browser/lightning/fragment/BookmarksFragment.java
  7. 56
      app/src/main/java/acr/browser/lightning/object/SearchAdapter.java
  8. 2
      app/src/main/java/acr/browser/lightning/reading/JResult.java

2
app/src/main/java/acr/browser/lightning/activity/BrowserActivity.java

@ -194,7 +194,7 @@ public abstract class BrowserActivity extends ThemableBrowserActivity implements @@ -194,7 +194,7 @@ public abstract class BrowserActivity extends ThemableBrowserActivity implements
// Storage
private HistoryDatabase mHistoryDatabase;
private PreferenceManager mPreferences = PreferenceManager.getInstance();
private final PreferenceManager mPreferences = PreferenceManager.getInstance();
// The singleton BookmarkManager
@Inject

6
app/src/main/java/acr/browser/lightning/async/AsyncExecutor.java

@ -16,9 +16,9 @@ import java.util.concurrent.RejectedExecutionException; @@ -16,9 +16,9 @@ import java.util.concurrent.RejectedExecutionException;
public class AsyncExecutor implements Executor {
private static final String TAG = AsyncExecutor.class.getSimpleName();
private static AsyncExecutor INSTANCE = new AsyncExecutor();
private Queue<Runnable> mQueue = new ArrayDeque<>(1);
private ExecutorService mExecutor = Executors.newFixedThreadPool(4);
private static final AsyncExecutor INSTANCE = new AsyncExecutor();
private final Queue<Runnable> mQueue = new ArrayDeque<>(1);
private final ExecutorService mExecutor = Executors.newFixedThreadPool(4);
private AsyncExecutor() {}

2
app/src/main/java/acr/browser/lightning/database/BookmarkLocalSync.java

@ -24,7 +24,7 @@ public class BookmarkLocalSync { @@ -24,7 +24,7 @@ public class BookmarkLocalSync {
private static final String COLUMN_URL = "url";
private static final String COLUMN_BOOKMARK = "bookmark";
private Context mContext;
private final Context mContext;
public BookmarkLocalSync(Context context) {
mContext = context;

2
app/src/main/java/acr/browser/lightning/download/DownloadHandler.java

@ -13,7 +13,6 @@ import android.content.pm.PackageManager; @@ -13,7 +13,6 @@ import android.content.pm.PackageManager;
import android.content.pm.ResolveInfo;
import android.net.Uri;
import android.os.Environment;
import android.support.annotation.NonNull;
import android.support.v7.app.AlertDialog;
import android.text.TextUtils;
import android.util.Log;
@ -22,7 +21,6 @@ import android.webkit.URLUtil; @@ -22,7 +21,6 @@ import android.webkit.URLUtil;
import java.io.File;
import java.io.IOException;
import java.net.URI;
import acr.browser.lightning.R;
import acr.browser.lightning.constant.Constants;

2
app/src/main/java/acr/browser/lightning/fragment/BookmarkSettingsFragment.java

@ -75,8 +75,6 @@ public class BookmarkSettingsFragment extends PreferenceFragment implements Pref @@ -75,8 +75,6 @@ public class BookmarkSettingsFragment extends PreferenceFragment implements Pref
}
}
;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);

25
app/src/main/java/acr/browser/lightning/fragment/BookmarksFragment.java

@ -1,5 +1,6 @@ @@ -1,5 +1,6 @@
package acr.browser.lightning.fragment;
import android.app.Activity;
import android.content.Context;
import android.graphics.Bitmap;
import android.graphics.PorterDuff;
@ -78,7 +79,7 @@ public class BookmarksFragment extends Fragment implements View.OnClickListener, @@ -78,7 +79,7 @@ public class BookmarksFragment extends Fragment implements View.OnClickListener,
private ImageView mBookmarkTitleImage, mBookmarkImage;
// Colors
private int mIconColor;
private int mIconColor, mScrollIndex;
// Init asynchronously the bookmark manager
private final Runnable mInitBookmarkManager = new Runnable() {
@ -98,11 +99,12 @@ public class BookmarksFragment extends Fragment implements View.OnClickListener, @@ -98,11 +99,12 @@ public class BookmarksFragment extends Fragment implements View.OnClickListener,
}
// Handle bookmark click
private final OnItemClickListener itemClickListener = new OnItemClickListener() {
private final OnItemClickListener mItemClickListener = new OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
final HistoryItem item = mBookmarks.get(position);
if (item.isFolder()) {
mScrollIndex = mBookmarksListView.getFirstVisiblePosition();
setBookmarkDataSet(mBookmarkManager.getBookmarksFromFolder(item.getTitle(), true), true);
} else {
mEventBus.post(new BookmarkEvents.Clicked(item));
@ -110,7 +112,7 @@ public class BookmarksFragment extends Fragment implements View.OnClickListener, @@ -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
public boolean onItemLongClick(AdapterView<?> parent, View view, int position, long id) {
final HistoryItem item = mBookmarks.get(position);
@ -130,8 +132,8 @@ public class BookmarksFragment extends Fragment implements View.OnClickListener, @@ -130,8 +132,8 @@ public class BookmarksFragment extends Fragment implements View.OnClickListener,
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
final View view = inflater.inflate(R.layout.bookmark_drawer, container, false);
mBookmarksListView = (ListView) view.findViewById(R.id.right_drawer_list);
mBookmarksListView.setOnItemClickListener(itemClickListener);
mBookmarksListView.setOnItemLongClickListener(itemLongClickListener);
mBookmarksListView.setOnItemClickListener(mItemClickListener);
mBookmarksListView.setOnItemLongClickListener(mItemLongClickListener);
mBookmarkTitleImage = (ImageView) view.findViewById(R.id.starIcon);
mBookmarkImage = (ImageView) view.findViewById(R.id.icon_star);
final View backView = view.findViewById(R.id.bookmark_back_button);
@ -141,9 +143,11 @@ public class BookmarksFragment extends Fragment implements View.OnClickListener, @@ -141,9 +143,11 @@ public class BookmarksFragment extends Fragment implements View.OnClickListener,
if (mBookmarkManager == null) return;
if (!mBookmarkManager.isRootFolder()) {
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
new Thread(mInitBookmarkManager).run();
@ -152,16 +156,15 @@ public class BookmarksFragment extends Fragment implements View.OnClickListener, @@ -152,16 +156,15 @@ public class BookmarksFragment extends Fragment implements View.OnClickListener,
@Override
public void onActivityCreated(@Nullable Bundle savedInstanceState) {
// TODO this code depend way too much on BrowserActivity
// TODO remove dependency on BrowserActivity
super.onActivityCreated(savedInstanceState);
final BrowserActivity activity = (BrowserActivity) getActivity();
final Activity activity = getActivity();
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);
mFolderBitmap = ThemeUtils.getThemedBitmap(activity, R.drawable.ic_folder, darkTheme);
mIconColor = darkTheme ? ThemeUtils.getIconDarkThemeColor(activity) :
ThemeUtils.getIconLightThemeColor(activity);
setupFrameLayoutButton(getView(), R.id.action_add_bookmark, R.id.icon_star);
mBookmarkTitleImage.setColorFilter(mIconColor, PorterDuff.Mode.SRC_IN);
}
@ -216,6 +219,7 @@ public class BookmarksFragment extends Fragment implements View.OnClickListener, @@ -216,6 +219,7 @@ public class BookmarksFragment extends Fragment implements View.OnClickListener,
mEventBus.post(new BookmarkEvents.CloseBookmarks());
} else {
setBookmarkDataSet(mBookmarkManager.getBookmarksFromFolder(null, true), true);
mBookmarksListView.setSelection(mScrollIndex);
}
}
@ -279,8 +283,7 @@ public class BookmarksFragment extends Fragment implements View.OnClickListener, @@ -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 setupFrameLayoutButton(@NonNull View view, @IdRes int buttonId, @IdRes int imageId) {
private void setupNavigationButton(@NonNull View view, @IdRes int buttonId, @IdRes int imageId) {
FrameLayout frameButton = (FrameLayout) view.findViewById(buttonId);
frameButton.setOnClickListener(this);
frameButton.setOnLongClickListener(this);

56
app/src/main/java/acr/browser/lightning/object/SearchAdapter.java

@ -34,6 +34,7 @@ import java.util.Comparator; @@ -34,6 +34,7 @@ import java.util.Comparator;
import java.util.Iterator;
import java.util.List;
import java.util.Locale;
import java.util.regex.Pattern;
import javax.inject.Inject;
@ -48,6 +49,7 @@ import acr.browser.lightning.utils.Utils; @@ -48,6 +49,7 @@ import acr.browser.lightning.utils.Utils;
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> mBookmarks = new ArrayList<>(5);
private final List<HistoryItem> mSuggestions = new ArrayList<>(5);
@ -60,7 +62,8 @@ public class SearchAdapter extends BaseAdapter implements Filterable { @@ -60,7 +62,8 @@ public class SearchAdapter extends BaseAdapter implements Filterable {
private boolean mIsExecuting = false;
private final boolean mDarkTheme;
private final boolean mIncognito;
@Inject BookmarkManager mBookmarkManager;
@Inject
BookmarkManager mBookmarkManager;
private static final String CACHE_FILE_TYPE = ".sgg";
private static final String ENCODING = "ISO-8859-1";
private static final long INTERVAL_DAY = 86400000;
@ -81,14 +84,7 @@ public class SearchAdapter extends BaseAdapter implements Filterable { @@ -81,14 +84,7 @@ public class SearchAdapter extends BaseAdapter implements Filterable {
mSearchSubtitle = mContext.getString(R.string.suggestion);
mDarkTheme = dark || incognito;
mIncognito = incognito;
Thread delete = new Thread(new Runnable() {
@Override
public void run() {
deleteOldCacheFiles();
}
});
Thread delete = new Thread(new ClearCacheRunnable());
mSearchDrawable = ThemeUtils.getThemedDrawable(context, R.drawable.ic_search, mDarkTheme);
mBookmarkDrawable = ThemeUtils.getThemedDrawable(context, R.drawable.ic_bookmark, mDarkTheme);
mHistoryDrawable = ThemeUtils.getThemedDrawable(context, R.drawable.ic_history, mDarkTheme);
@ -210,6 +206,15 @@ public class SearchAdapter extends BaseAdapter implements Filterable { @@ -210,6 +206,15 @@ public class SearchAdapter extends BaseAdapter implements Filterable {
return mFilter;
}
private static class ClearCacheRunnable implements Runnable {
@Override
public void run() {
deleteOldCacheFiles();
}
}
private class SearchFilter extends Filter {
@Override
@ -220,7 +225,7 @@ public class SearchAdapter extends BaseAdapter implements Filterable { @@ -220,7 +225,7 @@ public class SearchAdapter extends BaseAdapter implements Filterable {
}
String query = constraint.toString().toLowerCase(Locale.getDefault());
if (mUseGoogle && !mIncognito && !mIsExecuting) {
new RetrieveSearchSuggestions().executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR, query);
new RetrieveSearchSuggestions().executeOnExecutor(AsyncTask.SERIAL_EXECUTOR, query);
}
int counter = 0;
@ -291,7 +296,7 @@ public class SearchAdapter extends BaseAdapter implements Filterable { @@ -291,7 +296,7 @@ public class SearchAdapter extends BaseAdapter implements Filterable {
List<HistoryItem> filter = new ArrayList<>();
String query = arg0[0];
try {
query = query.replace(" ", "+");
query = SPACE_PATTERN.matcher(query).replaceAll("+");
URLEncoder.encode(query, ENCODING);
} catch (UnsupportedEncodingException e) {
e.printStackTrace();
@ -335,6 +340,7 @@ public class SearchAdapter extends BaseAdapter implements Filterable { @@ -335,6 +340,7 @@ public class SearchAdapter extends BaseAdapter implements Filterable {
@Override
protected void onPostExecute(List<HistoryItem> result) {
mIsExecuting = false;
synchronized (mSuggestions) {
mSuggestions.clear();
mSuggestions.addAll(result);
@ -346,7 +352,6 @@ public class SearchAdapter extends BaseAdapter implements Filterable { @@ -346,7 +352,6 @@ public class SearchAdapter extends BaseAdapter implements Filterable {
mFilteredList.addAll(filtered);
notifyDataSetChanged();
}
mIsExecuting = false;
}
}
@ -354,6 +359,7 @@ public class SearchAdapter extends BaseAdapter implements Filterable { @@ -354,6 +359,7 @@ public class SearchAdapter extends BaseAdapter implements Filterable {
/**
* This method downloads the search suggestions for the specific query.
* NOTE: This is a blocking operation, do not run on the UI thread.
*
* @param query the query to get suggestions for
* @return the cache file containing the suggestions
*/
@ -407,32 +413,6 @@ public class SearchAdapter extends BaseAdapter implements Filterable { @@ -407,32 +413,6 @@ public class SearchAdapter extends BaseAdapter implements Filterable {
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() {
List<HistoryItem> list = new ArrayList<>(5);
synchronized (mBookmarks) {

2
app/src/main/java/acr/browser/lightning/reading/JResult.java

@ -47,7 +47,7 @@ public class JResult implements Serializable { @@ -47,7 +47,7 @@ public class JResult implements Serializable {
private Date date;
private Collection<String> keywords;
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 sitename;
private String language;

Loading…
Cancel
Save