dont show search history in suggestion when disabled
This commit is contained in:
parent
cf703d5213
commit
65a6488e44
3 changed files with 21 additions and 2 deletions
|
@ -113,6 +113,7 @@ public class SearchFragment extends BaseListFragment<SearchResult, ListExtractor
|
||||||
private int currentNextPage = 0;
|
private int currentNextPage = 0;
|
||||||
private String searchLanguage;
|
private String searchLanguage;
|
||||||
private boolean isSuggestionsEnabled = true;
|
private boolean isSuggestionsEnabled = true;
|
||||||
|
private boolean isSearchHistoryEnabled = true;
|
||||||
|
|
||||||
private PublishSubject<String> suggestionPublisher = PublishSubject.create();
|
private PublishSubject<String> suggestionPublisher = PublishSubject.create();
|
||||||
private Disposable searchDisposable;
|
private Disposable searchDisposable;
|
||||||
|
@ -160,7 +161,12 @@ public class SearchFragment extends BaseListFragment<SearchResult, ListExtractor
|
||||||
@Override
|
@Override
|
||||||
public void onAttach(Context context) {
|
public void onAttach(Context context) {
|
||||||
super.onAttach(context);
|
super.onAttach(context);
|
||||||
|
|
||||||
suggestionListAdapter = new SuggestionListAdapter(activity);
|
suggestionListAdapter = new SuggestionListAdapter(activity);
|
||||||
|
SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(activity);
|
||||||
|
isSearchHistoryEnabled = preferences.getBoolean(getString(R.string.enable_search_history_key), true);
|
||||||
|
suggestionListAdapter.setShowSugestinHistory(isSearchHistoryEnabled);
|
||||||
|
|
||||||
searchHistoryDAO = NewPipeDatabase.getInstance().searchHistoryDAO();
|
searchHistoryDAO = NewPipeDatabase.getInstance().searchHistoryDAO();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -19,6 +19,7 @@ public class SuggestionListAdapter extends RecyclerView.Adapter<SuggestionListAd
|
||||||
private final ArrayList<SuggestionItem> items = new ArrayList<>();
|
private final ArrayList<SuggestionItem> items = new ArrayList<>();
|
||||||
private final Context context;
|
private final Context context;
|
||||||
private OnSuggestionItemSelected listener;
|
private OnSuggestionItemSelected listener;
|
||||||
|
private boolean showSugestinHistory = true;
|
||||||
|
|
||||||
public interface OnSuggestionItemSelected {
|
public interface OnSuggestionItemSelected {
|
||||||
void onSuggestionItemSelected(SuggestionItem item);
|
void onSuggestionItemSelected(SuggestionItem item);
|
||||||
|
@ -31,7 +32,16 @@ public class SuggestionListAdapter extends RecyclerView.Adapter<SuggestionListAd
|
||||||
|
|
||||||
public void setItems(List<SuggestionItem> items) {
|
public void setItems(List<SuggestionItem> items) {
|
||||||
this.items.clear();
|
this.items.clear();
|
||||||
|
if (showSugestinHistory) {
|
||||||
this.items.addAll(items);
|
this.items.addAll(items);
|
||||||
|
} else {
|
||||||
|
// remove history items if history is disabled
|
||||||
|
for (SuggestionItem item : items) {
|
||||||
|
if (!item.fromHistory) {
|
||||||
|
this.items.add(item);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
notifyDataSetChanged();
|
notifyDataSetChanged();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -39,6 +49,10 @@ public class SuggestionListAdapter extends RecyclerView.Adapter<SuggestionListAd
|
||||||
this.listener = listener;
|
this.listener = listener;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void setShowSugestinHistory(boolean v) {
|
||||||
|
showSugestinHistory = v;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public SuggestionItemHolder onCreateViewHolder(ViewGroup parent, int viewType) {
|
public SuggestionItemHolder onCreateViewHolder(ViewGroup parent, int viewType) {
|
||||||
return new SuggestionItemHolder(LayoutInflater.from(context).inflate(R.layout.item_search_suggestion, parent, false));
|
return new SuggestionItemHolder(LayoutInflater.from(context).inflate(R.layout.item_search_suggestion, parent, false));
|
||||||
|
|
|
@ -13,7 +13,6 @@
|
||||||
android:id="@+id/appbar"
|
android:id="@+id/appbar"
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:paddingTop="@dimen/appbar_padding_top"
|
|
||||||
android:theme="@style/ThemeOverlay.AppCompat.ActionBar"
|
android:theme="@style/ThemeOverlay.AppCompat.ActionBar"
|
||||||
app:popupTheme="@style/ThemeOverlay.AppCompat.ActionBar">
|
app:popupTheme="@style/ThemeOverlay.AppCompat.ActionBar">
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue