-Added search suggestion insert per #840.
|
@ -165,7 +165,7 @@ public class SearchFragment extends BaseListFragment<SearchResult, ListExtractor
|
||||||
suggestionListAdapter = new SuggestionListAdapter(activity);
|
suggestionListAdapter = new SuggestionListAdapter(activity);
|
||||||
SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(activity);
|
SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(activity);
|
||||||
isSearchHistoryEnabled = preferences.getBoolean(getString(R.string.enable_search_history_key), true);
|
isSearchHistoryEnabled = preferences.getBoolean(getString(R.string.enable_search_history_key), true);
|
||||||
suggestionListAdapter.setShowSugestinHistory(isSearchHistoryEnabled);
|
suggestionListAdapter.setShowSuggestionHistory(isSearchHistoryEnabled);
|
||||||
|
|
||||||
searchHistoryDAO = NewPipeDatabase.getInstance().searchHistoryDAO();
|
searchHistoryDAO = NewPipeDatabase.getInstance().searchHistoryDAO();
|
||||||
}
|
}
|
||||||
|
@ -446,6 +446,11 @@ public class SearchFragment extends BaseListFragment<SearchResult, ListExtractor
|
||||||
searchEditText.setText(item.query);
|
searchEditText.setText(item.query);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onSuggestionItemInserted(SuggestionItem item) {
|
||||||
|
searchEditText.setText(item.query);
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onSuggestionItemLongClick(SuggestionItem item) {
|
public void onSuggestionItemLongClick(SuggestionItem item) {
|
||||||
if (item.fromHistory) showDeleteSuggestionDialog(item);
|
if (item.fromHistory) showDeleteSuggestionDialog(item);
|
||||||
|
|
|
@ -19,10 +19,11 @@ 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;
|
private boolean showSuggestionHistory = true;
|
||||||
|
|
||||||
public interface OnSuggestionItemSelected {
|
public interface OnSuggestionItemSelected {
|
||||||
void onSuggestionItemSelected(SuggestionItem item);
|
void onSuggestionItemSelected(SuggestionItem item);
|
||||||
|
void onSuggestionItemInserted(SuggestionItem item);
|
||||||
void onSuggestionItemLongClick(SuggestionItem item);
|
void onSuggestionItemLongClick(SuggestionItem item);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -32,7 +33,7 @@ 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) {
|
if (showSuggestionHistory) {
|
||||||
this.items.addAll(items);
|
this.items.addAll(items);
|
||||||
} else {
|
} else {
|
||||||
// remove history items if history is disabled
|
// remove history items if history is disabled
|
||||||
|
@ -49,8 +50,8 @@ public class SuggestionListAdapter extends RecyclerView.Adapter<SuggestionListAd
|
||||||
this.listener = listener;
|
this.listener = listener;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setShowSugestinHistory(boolean v) {
|
public void setShowSuggestionHistory(boolean v) {
|
||||||
showSugestinHistory = v;
|
showSuggestionHistory = v;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -62,19 +63,25 @@ public class SuggestionListAdapter extends RecyclerView.Adapter<SuggestionListAd
|
||||||
public void onBindViewHolder(SuggestionItemHolder holder, int position) {
|
public void onBindViewHolder(SuggestionItemHolder holder, int position) {
|
||||||
final SuggestionItem currentItem = getItem(position);
|
final SuggestionItem currentItem = getItem(position);
|
||||||
holder.updateFrom(currentItem);
|
holder.updateFrom(currentItem);
|
||||||
holder.itemView.setOnClickListener(new View.OnClickListener() {
|
holder.queryView.setOnClickListener(new View.OnClickListener() {
|
||||||
@Override
|
@Override
|
||||||
public void onClick(View v) {
|
public void onClick(View v) {
|
||||||
if (listener != null) listener.onSuggestionItemSelected(currentItem);
|
if (listener != null) listener.onSuggestionItemSelected(currentItem);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
holder.itemView.setOnLongClickListener(new View.OnLongClickListener() {
|
holder.queryView.setOnLongClickListener(new View.OnLongClickListener() {
|
||||||
@Override
|
@Override
|
||||||
public boolean onLongClick(View v) {
|
public boolean onLongClick(View v) {
|
||||||
if (listener != null) listener.onSuggestionItemLongClick(currentItem);
|
if (listener != null) listener.onSuggestionItemLongClick(currentItem);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
holder.insertView.setOnClickListener(new View.OnClickListener() {
|
||||||
|
@Override
|
||||||
|
public void onClick(View v) {
|
||||||
|
if (listener != null) listener.onSuggestionItemInserted(currentItem);
|
||||||
|
}
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
private SuggestionItem getItem(int position) {
|
private SuggestionItem getItem(int position) {
|
||||||
|
@ -93,6 +100,8 @@ public class SuggestionListAdapter extends RecyclerView.Adapter<SuggestionListAd
|
||||||
public static class SuggestionItemHolder extends RecyclerView.ViewHolder {
|
public static class SuggestionItemHolder extends RecyclerView.ViewHolder {
|
||||||
private final TextView itemSuggestionQuery;
|
private final TextView itemSuggestionQuery;
|
||||||
private final ImageView suggestionIcon;
|
private final ImageView suggestionIcon;
|
||||||
|
private final View queryView;
|
||||||
|
private final View insertView;
|
||||||
|
|
||||||
// Cache some ids, as they can potentially be constantly updated/recycled
|
// Cache some ids, as they can potentially be constantly updated/recycled
|
||||||
private final int historyResId;
|
private final int historyResId;
|
||||||
|
@ -103,6 +112,9 @@ public class SuggestionListAdapter extends RecyclerView.Adapter<SuggestionListAd
|
||||||
suggestionIcon = rootView.findViewById(R.id.item_suggestion_icon);
|
suggestionIcon = rootView.findViewById(R.id.item_suggestion_icon);
|
||||||
itemSuggestionQuery = rootView.findViewById(R.id.item_suggestion_query);
|
itemSuggestionQuery = rootView.findViewById(R.id.item_suggestion_query);
|
||||||
|
|
||||||
|
queryView = rootView.findViewById(R.id.suggestion_search);
|
||||||
|
insertView = rootView.findViewById(R.id.suggestion_insert);
|
||||||
|
|
||||||
historyResId = resolveResourceIdFromAttr(rootView.getContext(), R.attr.history);
|
historyResId = resolveResourceIdFromAttr(rootView.getContext(), R.attr.history);
|
||||||
searchResId = resolveResourceIdFromAttr(rootView.getContext(), R.attr.search);
|
searchResId = resolveResourceIdFromAttr(rootView.getContext(), R.attr.search);
|
||||||
}
|
}
|
||||||
|
|
After Width: | Height: | Size: 554 B |
After Width: | Height: | Size: 546 B |
After Width: | Height: | Size: 418 B |
After Width: | Height: | Size: 427 B |
After Width: | Height: | Size: 492 B |
After Width: | Height: | Size: 500 B |
After Width: | Height: | Size: 570 B |
After Width: | Height: | Size: 573 B |
After Width: | Height: | Size: 675 B |
After Width: | Height: | Size: 730 B |
|
@ -1,11 +1,22 @@
|
||||||
<?xml version="1.0" encoding="utf-8"?>
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
<LinearLayout
|
<RelativeLayout
|
||||||
xmlns:android="http://schemas.android.com/apk/res/android"
|
xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
xmlns:tools="http://schemas.android.com/tools"
|
xmlns:tools="http://schemas.android.com/tools"
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="wrap_content">
|
||||||
|
|
||||||
|
<LinearLayout
|
||||||
|
android:id="@+id/suggestion_search"
|
||||||
|
android:layout_width="match_parent"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:background="?attr/selectableItemBackground"
|
android:background="?attr/selectableItemBackground"
|
||||||
android:clickable="true"
|
android:clickable="true"
|
||||||
|
android:focusable="true"
|
||||||
|
android:layout_alignParentLeft="true"
|
||||||
|
android:layout_alignParentStart="true"
|
||||||
|
android:layout_toLeftOf="@id/suggestion_insert"
|
||||||
|
android:layout_toStartOf="@id/suggestion_insert"
|
||||||
|
android:layout_centerVertical="true"
|
||||||
android:orientation="horizontal"
|
android:orientation="horizontal"
|
||||||
android:paddingBottom="8dp"
|
android:paddingBottom="8dp"
|
||||||
android:paddingTop="8dp">
|
android:paddingTop="8dp">
|
||||||
|
@ -25,8 +36,6 @@
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:layout_gravity="center_vertical"
|
android:layout_gravity="center_vertical"
|
||||||
android:layout_marginLeft="8dp"
|
|
||||||
android:layout_marginRight="16dp"
|
|
||||||
android:ellipsize="end"
|
android:ellipsize="end"
|
||||||
android:maxLines="2"
|
android:maxLines="2"
|
||||||
android:textAppearance="@style/TextAppearance.AppCompat.Body1"
|
android:textAppearance="@style/TextAppearance.AppCompat.Body1"
|
||||||
|
@ -34,3 +43,18 @@
|
||||||
tools:ignore="RtlHardcoded"
|
tools:ignore="RtlHardcoded"
|
||||||
tools:text="Search query"/>
|
tools:text="Search query"/>
|
||||||
</LinearLayout>
|
</LinearLayout>
|
||||||
|
|
||||||
|
<ImageView
|
||||||
|
android:id="@+id/suggestion_insert"
|
||||||
|
android:layout_width="24dp"
|
||||||
|
android:layout_height="24dp"
|
||||||
|
android:layout_centerVertical="true"
|
||||||
|
android:layout_alignParentRight="true"
|
||||||
|
android:clickable="true"
|
||||||
|
android:focusable="true"
|
||||||
|
android:layout_marginLeft="16dp"
|
||||||
|
android:layout_marginRight="16dp"
|
||||||
|
android:src="?attr/search_add"
|
||||||
|
android:background="?attr/selectableItemBackgroundBorderless"
|
||||||
|
tools:ignore="ContentDescription,RtlHardcoded"/>
|
||||||
|
</RelativeLayout>
|
||||||
|
|
|
@ -20,6 +20,7 @@
|
||||||
<attr name="history" format="reference"/>
|
<attr name="history" format="reference"/>
|
||||||
<attr name="drag_handle" format="reference"/>
|
<attr name="drag_handle" format="reference"/>
|
||||||
<attr name="selected" format="reference"/>
|
<attr name="selected" format="reference"/>
|
||||||
|
<attr name="search_add" format="reference"/>
|
||||||
|
|
||||||
<!-- Can't refer to colors directly into drawable's xml-->
|
<!-- Can't refer to colors directly into drawable's xml-->
|
||||||
<attr name="toolbar_shadow_drawable" format="reference"/>
|
<attr name="toolbar_shadow_drawable" format="reference"/>
|
||||||
|
|
|
@ -27,6 +27,7 @@
|
||||||
<item name="history">@drawable/ic_history_black_24dp</item>
|
<item name="history">@drawable/ic_history_black_24dp</item>
|
||||||
<item name="drag_handle">@drawable/ic_drag_handle_black_24dp</item>
|
<item name="drag_handle">@drawable/ic_drag_handle_black_24dp</item>
|
||||||
<item name="selected">@drawable/ic_fiber_manual_record_black_24dp</item>
|
<item name="selected">@drawable/ic_fiber_manual_record_black_24dp</item>
|
||||||
|
<item name="search_add">@drawable/ic_arrow_top_left_black_24dp</item>
|
||||||
|
|
||||||
<item name="separator_color">@color/light_separator_color</item>
|
<item name="separator_color">@color/light_separator_color</item>
|
||||||
<item name="contrast_background_color">@color/light_contrast_background_color</item>
|
<item name="contrast_background_color">@color/light_contrast_background_color</item>
|
||||||
|
@ -65,6 +66,7 @@
|
||||||
<item name="history">@drawable/ic_history_white_24dp</item>
|
<item name="history">@drawable/ic_history_white_24dp</item>
|
||||||
<item name="drag_handle">@drawable/ic_drag_handle_white_24dp</item>
|
<item name="drag_handle">@drawable/ic_drag_handle_white_24dp</item>
|
||||||
<item name="selected">@drawable/ic_fiber_manual_record_white_24dp</item>
|
<item name="selected">@drawable/ic_fiber_manual_record_white_24dp</item>
|
||||||
|
<item name="search_add">@drawable/ic_arrow_top_left_white_24dp</item>
|
||||||
|
|
||||||
<item name="separator_color">@color/dark_separator_color</item>
|
<item name="separator_color">@color/dark_separator_color</item>
|
||||||
<item name="contrast_background_color">@color/dark_contrast_background_color</item>
|
<item name="contrast_background_color">@color/dark_contrast_background_color</item>
|
||||||
|
|