More suggestions cleanup
This commit is contained in:
parent
7a256707a7
commit
d75675e006
@ -44,7 +44,7 @@ public class SuggestionsAdapter extends BaseAdapter implements Filterable, Sugge
|
|||||||
private final List<HistoryItem> mSuggestions = new ArrayList<>(5);
|
private final List<HistoryItem> mSuggestions = new ArrayList<>(5);
|
||||||
private final List<HistoryItem> mFilteredList = new ArrayList<>(5);
|
private final List<HistoryItem> mFilteredList = new ArrayList<>(5);
|
||||||
private final List<HistoryItem> mAllBookmarks = new ArrayList<>(5);
|
private final List<HistoryItem> mAllBookmarks = new ArrayList<>(5);
|
||||||
@NonNull private final Context mContext;
|
|
||||||
private boolean mUseGoogle = true;
|
private boolean mUseGoogle = true;
|
||||||
private boolean mIsExecuting = false;
|
private boolean mIsExecuting = false;
|
||||||
private final boolean mDarkTheme;
|
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 String CACHE_FILE_TYPE = ".sgg";
|
||||||
private static final long INTERVAL_DAY = 86400000;
|
private static final long INTERVAL_DAY = 86400000;
|
||||||
private static final int MAX_SUGGESTIONS = 5;
|
private static final int MAX_SUGGESTIONS = 5;
|
||||||
private static final SuggestionsComparator mComparator = new SuggestionsComparator();
|
private static final SuggestionsComparator sComparator = new SuggestionsComparator();
|
||||||
private SearchFilter mFilter;
|
|
||||||
|
@NonNull private final Context mContext;
|
||||||
|
@Nullable private SearchFilter mFilter;
|
||||||
@NonNull private final Drawable mSearchDrawable;
|
@NonNull private final Drawable mSearchDrawable;
|
||||||
@NonNull private final Drawable mHistoryDrawable;
|
@NonNull private final Drawable mHistoryDrawable;
|
||||||
@NonNull private final Drawable mBookmarkDrawable;
|
@NonNull private final Drawable mBookmarkDrawable;
|
||||||
|
|
||||||
@Inject
|
@Inject HistoryDatabase mDatabaseHandler;
|
||||||
HistoryDatabase mDatabaseHandler;
|
@Inject BookmarkManager mBookmarkManager;
|
||||||
|
@Inject PreferenceManager mPreferenceManager;
|
||||||
@Inject
|
|
||||||
BookmarkManager mBookmarkManager;
|
|
||||||
|
|
||||||
@Inject
|
|
||||||
PreferenceManager mPreferenceManager;
|
|
||||||
|
|
||||||
public SuggestionsAdapter(@NonNull Context context, boolean dark, boolean incognito) {
|
public SuggestionsAdapter(@NonNull Context context, boolean dark, boolean incognito) {
|
||||||
BrowserApp.getAppComponent().inject(this);
|
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);
|
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() {
|
public void refreshPreferences() {
|
||||||
mUseGoogle = mPreferenceManager.getGoogleSearchSuggestionsEnabled();
|
mUseGoogle = mPreferenceManager.getGoogleSearchSuggestionsEnabled();
|
||||||
if (!mUseGoogle) {
|
if (!mUseGoogle) {
|
||||||
@ -120,6 +108,12 @@ public class SuggestionsAdapter extends BaseAdapter implements Filterable, Sugge
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private static class SuggestionHolder {
|
||||||
|
ImageView mImage;
|
||||||
|
TextView mTitle;
|
||||||
|
TextView mUrl;
|
||||||
|
}
|
||||||
|
|
||||||
@Nullable
|
@Nullable
|
||||||
@Override
|
@Override
|
||||||
public View getView(int position, @Nullable View convertView, ViewGroup parent) {
|
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 {
|
private class SearchFilter extends Filter {
|
||||||
@ -260,7 +263,7 @@ public class SuggestionsAdapter extends BaseAdapter implements Filterable, Sugge
|
|||||||
synchronized (mFilteredList) {
|
synchronized (mFilteredList) {
|
||||||
mFilteredList.clear();
|
mFilteredList.clear();
|
||||||
List<HistoryItem> filtered = getFilteredList();
|
List<HistoryItem> filtered = getFilteredList();
|
||||||
Collections.sort(filtered, mComparator);
|
Collections.sort(filtered, sComparator);
|
||||||
mFilteredList.addAll(filtered);
|
mFilteredList.addAll(filtered);
|
||||||
}
|
}
|
||||||
notifyDataSetChanged();
|
notifyDataSetChanged();
|
||||||
@ -268,12 +271,6 @@ public class SuggestionsAdapter extends BaseAdapter implements Filterable, Sugge
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private static class SuggestionHolder {
|
|
||||||
ImageView mImage;
|
|
||||||
TextView mTitle;
|
|
||||||
TextView mUrl;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void resultReceived(@NonNull List<HistoryItem> searchResults) {
|
public void resultReceived(@NonNull List<HistoryItem> searchResults) {
|
||||||
mIsExecuting = false;
|
mIsExecuting = false;
|
||||||
@ -284,7 +281,7 @@ public class SuggestionsAdapter extends BaseAdapter implements Filterable, Sugge
|
|||||||
synchronized (mFilteredList) {
|
synchronized (mFilteredList) {
|
||||||
mFilteredList.clear();
|
mFilteredList.clear();
|
||||||
List<HistoryItem> filtered = getFilteredList();
|
List<HistoryItem> filtered = getFilteredList();
|
||||||
Collections.sort(filtered, mComparator);
|
Collections.sort(filtered, sComparator);
|
||||||
mFilteredList.addAll(filtered);
|
mFilteredList.addAll(filtered);
|
||||||
notifyDataSetChanged();
|
notifyDataSetChanged();
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user