|
|
@ -43,11 +43,11 @@ import com.anthonycr.bonsai.Subscriber; |
|
|
|
|
|
|
|
|
|
|
|
import acr.browser.lightning.utils.ThemeUtils; |
|
|
|
import acr.browser.lightning.utils.ThemeUtils; |
|
|
|
|
|
|
|
|
|
|
|
public class Suggestions extends BaseAdapter implements Filterable { |
|
|
|
public class SuggestionsAdapter extends BaseAdapter implements Filterable { |
|
|
|
|
|
|
|
|
|
|
|
private static final Scheduler FILTER_SCHEDULER = Schedulers.newSingleThreadedScheduler(); |
|
|
|
private static final Scheduler FILTER_SCHEDULER = Schedulers.newSingleThreadedScheduler(); |
|
|
|
|
|
|
|
|
|
|
|
public static final String CACHE_FILE_TYPE = ".sgg"; |
|
|
|
static final String CACHE_FILE_TYPE = ".sgg"; |
|
|
|
|
|
|
|
|
|
|
|
private final List<HistoryItem> mFilteredList = new ArrayList<>(5); |
|
|
|
private final List<HistoryItem> mFilteredList = new ArrayList<>(5); |
|
|
|
|
|
|
|
|
|
|
@ -74,7 +74,7 @@ public class Suggestions extends BaseAdapter implements Filterable { |
|
|
|
@NonNull private final Context mContext; |
|
|
|
@NonNull private final Context mContext; |
|
|
|
private PreferenceManager.Suggestion mSuggestionChoice; |
|
|
|
private PreferenceManager.Suggestion mSuggestionChoice; |
|
|
|
|
|
|
|
|
|
|
|
public Suggestions(@NonNull Context context, boolean dark, boolean incognito) { |
|
|
|
public SuggestionsAdapter(@NonNull Context context, boolean dark, boolean incognito) { |
|
|
|
super(); |
|
|
|
super(); |
|
|
|
BrowserApp.getAppComponent().inject(this); |
|
|
|
BrowserApp.getAppComponent().inject(this); |
|
|
|
mContext = context; |
|
|
|
mContext = context; |
|
|
@ -123,7 +123,7 @@ public class Suggestions extends BaseAdapter implements Filterable { |
|
|
|
|
|
|
|
|
|
|
|
private static class SuggestionHolder { |
|
|
|
private static class SuggestionHolder { |
|
|
|
|
|
|
|
|
|
|
|
public SuggestionHolder(@NonNull View view) { |
|
|
|
SuggestionHolder(@NonNull View view) { |
|
|
|
mTitle = (TextView) view.findViewById(R.id.title); |
|
|
|
mTitle = (TextView) view.findViewById(R.id.title); |
|
|
|
mUrl = (TextView) view.findViewById(R.id.url); |
|
|
|
mUrl = (TextView) view.findViewById(R.id.url); |
|
|
|
mImage = (ImageView) view.findViewById(R.id.suggestionIcon); |
|
|
|
mImage = (ImageView) view.findViewById(R.id.suggestionIcon); |
|
|
@ -319,50 +319,50 @@ public class Suggestions extends BaseAdapter implements Filterable { |
|
|
|
|
|
|
|
|
|
|
|
private static class SearchFilter extends Filter { |
|
|
|
private static class SearchFilter extends Filter { |
|
|
|
|
|
|
|
|
|
|
|
@NonNull private final Suggestions mSuggestions; |
|
|
|
@NonNull private final SuggestionsAdapter mSuggestionsAdapter; |
|
|
|
|
|
|
|
|
|
|
|
public SearchFilter(@NonNull Suggestions suggestions) { |
|
|
|
SearchFilter(@NonNull SuggestionsAdapter suggestionsAdapter) { |
|
|
|
mSuggestions = suggestions; |
|
|
|
mSuggestionsAdapter = suggestionsAdapter; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
@Override |
|
|
|
protected FilterResults performFiltering(CharSequence constraint) { |
|
|
|
protected FilterResults performFiltering(CharSequence constraint) { |
|
|
|
FilterResults results = new FilterResults(); |
|
|
|
FilterResults results = new FilterResults(); |
|
|
|
if (constraint == null || constraint.length() == 0) { |
|
|
|
if (constraint == null || constraint.length() == 0) { |
|
|
|
mSuggestions.clearSuggestions(); |
|
|
|
mSuggestionsAdapter.clearSuggestions(); |
|
|
|
return results; |
|
|
|
return results; |
|
|
|
} |
|
|
|
} |
|
|
|
String query = constraint.toString().toLowerCase(Locale.getDefault()).trim(); |
|
|
|
String query = constraint.toString().toLowerCase(Locale.getDefault()).trim(); |
|
|
|
|
|
|
|
|
|
|
|
if (mSuggestions.shouldRequestNetwork() && !SuggestionsManager.isRequestInProgress()) { |
|
|
|
if (mSuggestionsAdapter.shouldRequestNetwork() && !SuggestionsManager.isRequestInProgress()) { |
|
|
|
mSuggestions.getSuggestionsForQuery(query) |
|
|
|
mSuggestionsAdapter.getSuggestionsForQuery(query) |
|
|
|
.subscribeOn(Schedulers.worker()) |
|
|
|
.subscribeOn(Schedulers.worker()) |
|
|
|
.observeOn(Schedulers.main()) |
|
|
|
.observeOn(Schedulers.main()) |
|
|
|
.subscribe(new OnSubscribe<List<HistoryItem>>() { |
|
|
|
.subscribe(new OnSubscribe<List<HistoryItem>>() { |
|
|
|
@Override |
|
|
|
@Override |
|
|
|
public void onNext(@Nullable List<HistoryItem> item) { |
|
|
|
public void onNext(@Nullable List<HistoryItem> item) { |
|
|
|
mSuggestions.combineResults(null, null, item); |
|
|
|
mSuggestionsAdapter.combineResults(null, null, item); |
|
|
|
} |
|
|
|
} |
|
|
|
}); |
|
|
|
}); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
mSuggestions.getBookmarksForQuery(query) |
|
|
|
mSuggestionsAdapter.getBookmarksForQuery(query) |
|
|
|
.subscribeOn(Schedulers.io()) |
|
|
|
.subscribeOn(Schedulers.io()) |
|
|
|
.observeOn(Schedulers.main()) |
|
|
|
.observeOn(Schedulers.main()) |
|
|
|
.subscribe(new OnSubscribe<List<HistoryItem>>() { |
|
|
|
.subscribe(new OnSubscribe<List<HistoryItem>>() { |
|
|
|
@Override |
|
|
|
@Override |
|
|
|
public void onNext(@Nullable List<HistoryItem> item) { |
|
|
|
public void onNext(@Nullable List<HistoryItem> item) { |
|
|
|
mSuggestions.combineResults(item, null, null); |
|
|
|
mSuggestionsAdapter.combineResults(item, null, null); |
|
|
|
} |
|
|
|
} |
|
|
|
}); |
|
|
|
}); |
|
|
|
|
|
|
|
|
|
|
|
mSuggestions.getHistoryForQuery(query) |
|
|
|
mSuggestionsAdapter.getHistoryForQuery(query) |
|
|
|
.subscribeOn(Schedulers.io()) |
|
|
|
.subscribeOn(Schedulers.io()) |
|
|
|
.observeOn(Schedulers.main()) |
|
|
|
.observeOn(Schedulers.main()) |
|
|
|
.subscribe(new OnSubscribe<List<HistoryItem>>() { |
|
|
|
.subscribe(new OnSubscribe<List<HistoryItem>>() { |
|
|
|
@Override |
|
|
|
@Override |
|
|
|
public void onNext(@Nullable List<HistoryItem> item) { |
|
|
|
public void onNext(@Nullable List<HistoryItem> item) { |
|
|
|
mSuggestions.combineResults(null, item, null); |
|
|
|
mSuggestionsAdapter.combineResults(null, item, null); |
|
|
|
} |
|
|
|
} |
|
|
|
}); |
|
|
|
}); |
|
|
|
results.count = 1; |
|
|
|
results.count = 1; |
|
|
@ -376,7 +376,7 @@ public class Suggestions extends BaseAdapter implements Filterable { |
|
|
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
@Override |
|
|
|
protected void publishResults(CharSequence constraint, FilterResults results) { |
|
|
|
protected void publishResults(CharSequence constraint, FilterResults results) { |
|
|
|
mSuggestions.combineResults(null, null, null); |
|
|
|
mSuggestionsAdapter.combineResults(null, null, null); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
@ -385,7 +385,7 @@ public class Suggestions extends BaseAdapter implements Filterable { |
|
|
|
@NonNull |
|
|
|
@NonNull |
|
|
|
private final Application app; |
|
|
|
private final Application app; |
|
|
|
|
|
|
|
|
|
|
|
public ClearCacheRunnable(@NonNull Application app) { |
|
|
|
ClearCacheRunnable(@NonNull Application app) { |
|
|
|
this.app = app; |
|
|
|
this.app = app; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|