mirror of
				https://github.com/TeamNewPipe/NewPipe
				synced 2025-10-30 23:03:00 +00:00 
			
		
		
		
	Display search suggestion: did you mean & showing result for
This commit is contained in:
		| @@ -143,6 +143,9 @@ public class SearchFragment extends BaseListFragment<SearchInfo, ListExtractor.I | |||||||
|     private EditText searchEditText; |     private EditText searchEditText; | ||||||
|     private View searchClear; |     private View searchClear; | ||||||
|  |  | ||||||
|  |     private View correctSuggestionPanel; | ||||||
|  |     private TextView correctSuggestionText; | ||||||
|  |  | ||||||
|     private View suggestionsPanel; |     private View suggestionsPanel; | ||||||
|     private RecyclerView suggestionsRecyclerView; |     private RecyclerView suggestionsRecyclerView; | ||||||
|  |  | ||||||
| @@ -345,6 +348,9 @@ public class SearchFragment extends BaseListFragment<SearchInfo, ListExtractor.I | |||||||
|         searchToolbarContainer = activity.findViewById(R.id.toolbar_search_container); |         searchToolbarContainer = activity.findViewById(R.id.toolbar_search_container); | ||||||
|         searchEditText = searchToolbarContainer.findViewById(R.id.toolbar_search_edit_text); |         searchEditText = searchToolbarContainer.findViewById(R.id.toolbar_search_edit_text); | ||||||
|         searchClear = searchToolbarContainer.findViewById(R.id.toolbar_search_clear); |         searchClear = searchToolbarContainer.findViewById(R.id.toolbar_search_clear); | ||||||
|  |  | ||||||
|  |         correctSuggestionPanel = rootView.findViewById(R.id.correct_suggestion_panel); | ||||||
|  |         correctSuggestionText = rootView.findViewById(R.id.correct_suggestion_text); | ||||||
|     } |     } | ||||||
|  |  | ||||||
|     /*////////////////////////////////////////////////////////////////////////// |     /*////////////////////////////////////////////////////////////////////////// | ||||||
| @@ -497,6 +503,8 @@ public class SearchFragment extends BaseListFragment<SearchInfo, ListExtractor.I | |||||||
|                 return; |                 return; | ||||||
|             } |             } | ||||||
|  |  | ||||||
|  |             correctSuggestionPanel.setVisibility(View.GONE); | ||||||
|  |  | ||||||
|             searchEditText.setText(""); |             searchEditText.setText(""); | ||||||
|             suggestionListAdapter.setItems(new ArrayList<>()); |             suggestionListAdapter.setItems(new ArrayList<>()); | ||||||
|             showKeyboardSearch(); |             showKeyboardSearch(); | ||||||
| @@ -554,11 +562,13 @@ public class SearchFragment extends BaseListFragment<SearchInfo, ListExtractor.I | |||||||
|         textWatcher = new TextWatcher() { |         textWatcher = new TextWatcher() { | ||||||
|             @Override |             @Override | ||||||
|             public void beforeTextChanged(final CharSequence s, final int start, |             public void beforeTextChanged(final CharSequence s, final int start, | ||||||
|                                           final int count, final int after) { } |                                           final int count, final int after) { | ||||||
|  |             } | ||||||
|  |  | ||||||
|             @Override |             @Override | ||||||
|             public void onTextChanged(final CharSequence s, final int start, |             public void onTextChanged(final CharSequence s, final int start, | ||||||
|                                       final int before, final int count) { } |                                       final int before, final int count) { | ||||||
|  |             } | ||||||
|  |  | ||||||
|             @Override |             @Override | ||||||
|             public void afterTextChanged(final Editable s) { |             public void afterTextChanged(final Editable s) { | ||||||
| @@ -961,6 +971,8 @@ public class SearchFragment extends BaseListFragment<SearchInfo, ListExtractor.I | |||||||
|                     NewPipe.getNameOfService(serviceId), searchString, 0); |                     NewPipe.getNameOfService(serviceId), searchString, 0); | ||||||
|         } |         } | ||||||
|  |  | ||||||
|  |         handleSearchSuggestion(result); | ||||||
|  |  | ||||||
|         lastSearchedString = searchString; |         lastSearchedString = searchString; | ||||||
|         nextPageUrl = result.getNextPageUrl(); |         nextPageUrl = result.getNextPageUrl(); | ||||||
|         currentPageUrl = result.getUrl(); |         currentPageUrl = result.getUrl(); | ||||||
| @@ -978,6 +990,26 @@ public class SearchFragment extends BaseListFragment<SearchInfo, ListExtractor.I | |||||||
|         super.handleResult(result); |         super.handleResult(result); | ||||||
|     } |     } | ||||||
|  |  | ||||||
|  |     private void handleSearchSuggestion(@NonNull final SearchInfo result) { | ||||||
|  |         if (!TextUtils.isEmpty(result.getSearchSuggestion())) { | ||||||
|  |             String helperText = getString(result.isCorrectedSearch() | ||||||
|  |                     ? R.string.search_showing_result_for | ||||||
|  |                     : R.string.did_you_mean); | ||||||
|  |  | ||||||
|  |             correctSuggestionText.setText(String.format(helperText, result.getSearchSuggestion())); | ||||||
|  |  | ||||||
|  |             correctSuggestionPanel.setOnClickListener(v -> { | ||||||
|  |                 correctSuggestionPanel.setVisibility(View.GONE); | ||||||
|  |                 search(result.getSearchSuggestion(), contentFilter, sortFilter); | ||||||
|  |                 searchEditText.setText(result.getSearchSuggestion()); | ||||||
|  |             }); | ||||||
|  |  | ||||||
|  |             correctSuggestionPanel.setVisibility(View.VISIBLE); | ||||||
|  |         } else { | ||||||
|  |             correctSuggestionPanel.setVisibility(View.GONE); | ||||||
|  |         } | ||||||
|  |     } | ||||||
|  |  | ||||||
|     @Override |     @Override | ||||||
|     public void handleNextItems(final ListExtractor.InfoItemsPage result) { |     public void handleNextItems(final ListExtractor.InfoItemsPage result) { | ||||||
|         showListFooter(false); |         showListFooter(false); | ||||||
|   | |||||||
| @@ -6,13 +6,34 @@ | |||||||
|     android:layout_width="match_parent" |     android:layout_width="match_parent" | ||||||
|     android:layout_height="match_parent"> |     android:layout_height="match_parent"> | ||||||
|  |  | ||||||
|  |     <LinearLayout | ||||||
|  |         android:id="@+id/correct_suggestion_panel" | ||||||
|  |         android:layout_width="match_parent" | ||||||
|  |         android:layout_height="wrap_content" | ||||||
|  |         android:layout_alignTop="@id/error_panel" | ||||||
|  |         android:layout_marginTop="0dp" | ||||||
|  |         android:orientation="horizontal"> | ||||||
|  |  | ||||||
|  |         <TextView | ||||||
|  |             android:id="@+id/correct_suggestion_text" | ||||||
|  |             android:layout_width="0dp" | ||||||
|  |             android:layout_height="wrap_content" | ||||||
|  |             android:layout_marginStart="10dp" | ||||||
|  |             android:layout_marginTop="10dp" | ||||||
|  |             android:layout_marginBottom="10dp" | ||||||
|  |             android:layout_weight="1" | ||||||
|  |             android:textColor="@color/background_title_color" | ||||||
|  |             android:textSize="@dimen/search_suggestion_text_size" /> | ||||||
|  |     </LinearLayout> | ||||||
|  |  | ||||||
|     <androidx.recyclerview.widget.RecyclerView |     <androidx.recyclerview.widget.RecyclerView | ||||||
|         android:id="@+id/items_list" |         android:id="@+id/items_list" | ||||||
|         android:layout_width="match_parent" |         android:layout_width="match_parent" | ||||||
|         android:layout_height="match_parent" |         android:layout_height="match_parent" | ||||||
|  |         android:layout_below="@+id/correct_suggestion_panel" | ||||||
|         android:scrollbars="vertical" |         android:scrollbars="vertical" | ||||||
|         app:layoutManager="LinearLayoutManager" |         app:layoutManager="LinearLayoutManager" | ||||||
|         tools:listitem="@layout/list_stream_item"/> |         tools:listitem="@layout/list_stream_item" /> | ||||||
|  |  | ||||||
|     <ProgressBar |     <ProgressBar | ||||||
|         android:id="@+id/loading_progress_bar" |         android:id="@+id/loading_progress_bar" | ||||||
| @@ -58,6 +79,7 @@ | |||||||
|         android:background="?android:attr/windowBackground" |         android:background="?android:attr/windowBackground" | ||||||
|         android:focusable="true" |         android:focusable="true" | ||||||
|         android:focusableInTouchMode="true" |         android:focusableInTouchMode="true" | ||||||
|  |         android:orientation="vertical" | ||||||
|         android:visibility="gone" |         android:visibility="gone" | ||||||
|         tools:background="@android:color/transparent" |         tools:background="@android:color/transparent" | ||||||
|         tools:visibility="visible"> |         tools:visibility="visible"> | ||||||
| @@ -68,7 +90,7 @@ | |||||||
|             android:layout_height="match_parent" |             android:layout_height="match_parent" | ||||||
|             android:scrollbars="vertical" |             android:scrollbars="vertical" | ||||||
|             app:layoutManager="LinearLayoutManager" |             app:layoutManager="LinearLayoutManager" | ||||||
|             tools:listitem="@layout/item_search_suggestion"/> |             tools:listitem="@layout/item_search_suggestion" /> | ||||||
|     </LinearLayout> |     </LinearLayout> | ||||||
|  |  | ||||||
|     <!--ERROR PANEL--> |     <!--ERROR PANEL--> | ||||||
|   | |||||||
| @@ -51,4 +51,6 @@ | |||||||
|  |  | ||||||
|     <!-- File picker dimensions --> |     <!-- File picker dimensions --> | ||||||
|     <dimen name="file_picker_items_text_size">16sp</dimen> |     <dimen name="file_picker_items_text_size">16sp</dimen> | ||||||
|  |  | ||||||
|  |     <dimen name="search_suggestion_text_size">14sp</dimen> | ||||||
| </resources> | </resources> | ||||||
|   | |||||||
| @@ -21,4 +21,5 @@ | |||||||
|     <!-- Paddings & Margins --> |     <!-- Paddings & Margins --> | ||||||
|     <dimen name="video_item_detail_like_margin">10dp</dimen> |     <dimen name="video_item_detail_like_margin">10dp</dimen> | ||||||
|  |  | ||||||
|  |     <dimen name="search_suggestion_text_size">14sp</dimen> | ||||||
| </resources> | </resources> | ||||||
|   | |||||||
| @@ -115,4 +115,5 @@ | |||||||
|     <dimen name="feed_group_carousel_top_bottom_margin">2dp</dimen> |     <dimen name="feed_group_carousel_top_bottom_margin">2dp</dimen> | ||||||
|     <dimen name="feed_group_carousel_between_items_margin">4dp</dimen> |     <dimen name="feed_group_carousel_between_items_margin">4dp</dimen> | ||||||
|  |  | ||||||
|  |     <dimen name="search_suggestion_text_size">16sp</dimen> | ||||||
| </resources> | </resources> | ||||||
|   | |||||||
| @@ -16,6 +16,7 @@ | |||||||
|     <string name="search">Search</string> |     <string name="search">Search</string> | ||||||
|     <string name="settings">Settings</string> |     <string name="settings">Settings</string> | ||||||
|     <string name="did_you_mean">Did you mean: %1$s?</string> |     <string name="did_you_mean">Did you mean: %1$s?</string> | ||||||
|  |     <string name="search_showing_result_for">Showing results for: %s</string> | ||||||
|     <string name="share_dialog_title">Share with</string> |     <string name="share_dialog_title">Share with</string> | ||||||
|     <string name="choose_browser">Choose browser</string> |     <string name="choose_browser">Choose browser</string> | ||||||
|     <string name="screen_rotation">rotation</string> |     <string name="screen_rotation">rotation</string> | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user
	 Roy Yosef
					Roy Yosef