From d75675e006d75d4ee8cb1b3253148606fc464859 Mon Sep 17 00:00:00 2001 From: Anthony Restaino Date: Sun, 17 Apr 2016 00:17:46 -0400 Subject: [PATCH] More suggestions cleanup --- .../lightning/search/SuggestionsAdapter.java | 53 +++++++++---------- 1 file changed, 25 insertions(+), 28 deletions(-) diff --git a/app/src/main/java/acr/browser/lightning/search/SuggestionsAdapter.java b/app/src/main/java/acr/browser/lightning/search/SuggestionsAdapter.java index accb0c0..4dd8378 100644 --- a/app/src/main/java/acr/browser/lightning/search/SuggestionsAdapter.java +++ b/app/src/main/java/acr/browser/lightning/search/SuggestionsAdapter.java @@ -44,7 +44,7 @@ public class SuggestionsAdapter extends BaseAdapter implements Filterable, Sugge private final List mSuggestions = new ArrayList<>(5); private final List mFilteredList = new ArrayList<>(5); private final List mAllBookmarks = new ArrayList<>(5); - @NonNull private final Context mContext; + private boolean mUseGoogle = true; private boolean mIsExecuting = false; private final boolean mDarkTheme; @@ -52,20 +52,17 @@ public class SuggestionsAdapter extends BaseAdapter implements Filterable, Sugge private static final String CACHE_FILE_TYPE = ".sgg"; private static final long INTERVAL_DAY = 86400000; private static final int MAX_SUGGESTIONS = 5; - private static final SuggestionsComparator mComparator = new SuggestionsComparator(); - private SearchFilter mFilter; + private static final SuggestionsComparator sComparator = new SuggestionsComparator(); + + @NonNull private final Context mContext; + @Nullable private SearchFilter mFilter; @NonNull private final Drawable mSearchDrawable; @NonNull private final Drawable mHistoryDrawable; @NonNull private final Drawable mBookmarkDrawable; - @Inject - HistoryDatabase mDatabaseHandler; - - @Inject - BookmarkManager mBookmarkManager; - - @Inject - PreferenceManager mPreferenceManager; + @Inject HistoryDatabase mDatabaseHandler; + @Inject BookmarkManager mBookmarkManager; + @Inject PreferenceManager mPreferenceManager; public SuggestionsAdapter(@NonNull Context context, boolean dark, boolean incognito) { BrowserApp.getAppComponent().inject(this); @@ -80,15 +77,6 @@ public class SuggestionsAdapter extends BaseAdapter implements Filterable, Sugge mHistoryDrawable = ThemeUtils.getThemedDrawable(context, R.drawable.ic_history, mDarkTheme); } - private static class NameFilter implements FilenameFilter { - - @Override - public boolean accept(File dir, @NonNull String filename) { - return filename.endsWith(CACHE_FILE_TYPE); - } - - } - public void refreshPreferences() { mUseGoogle = mPreferenceManager.getGoogleSearchSuggestionsEnabled(); if (!mUseGoogle) { @@ -120,6 +108,12 @@ public class SuggestionsAdapter extends BaseAdapter implements Filterable, Sugge return 0; } + private static class SuggestionHolder { + ImageView mImage; + TextView mTitle; + TextView mUrl; + } + @Nullable @Override public View getView(int position, @Nullable View convertView, ViewGroup parent) { @@ -204,6 +198,15 @@ public class SuggestionsAdapter extends BaseAdapter implements Filterable, Sugge } } + private static class NameFilter implements FilenameFilter { + + @Override + public boolean accept(File dir, @NonNull String filename) { + return filename.endsWith(CACHE_FILE_TYPE); + } + + } + } private class SearchFilter extends Filter { @@ -260,7 +263,7 @@ public class SuggestionsAdapter extends BaseAdapter implements Filterable, Sugge synchronized (mFilteredList) { mFilteredList.clear(); List filtered = getFilteredList(); - Collections.sort(filtered, mComparator); + Collections.sort(filtered, sComparator); mFilteredList.addAll(filtered); } notifyDataSetChanged(); @@ -268,12 +271,6 @@ public class SuggestionsAdapter extends BaseAdapter implements Filterable, Sugge } - private static class SuggestionHolder { - ImageView mImage; - TextView mTitle; - TextView mUrl; - } - @Override public void resultReceived(@NonNull List searchResults) { mIsExecuting = false; @@ -284,7 +281,7 @@ public class SuggestionsAdapter extends BaseAdapter implements Filterable, Sugge synchronized (mFilteredList) { mFilteredList.clear(); List filtered = getFilteredList(); - Collections.sort(filtered, mComparator); + Collections.sort(filtered, sComparator); mFilteredList.addAll(filtered); notifyDataSetChanged(); }