Dbrant has uploaded a new change for review. ( https://gerrit.wikimedia.org/r/342012 )
Change subject: Update design of empty state when searching Wikipedia. ...................................................................... Update design of empty state when searching Wikipedia. ...and butter up SearchResultsFragment, while we're at it. Bug: T156086 Change-Id: Ic570db7bef4db6e06d9139c7109de299448bd110 --- M app/src/main/java/org/wikipedia/search/SearchResultsFragment.java M app/src/main/res/layout/fragment_search.xml M app/src/main/res/layout/fragment_search_recent.xml M app/src/main/res/layout/fragment_search_results.xml 4 files changed, 69 insertions(+), 71 deletions(-) git pull ssh://gerrit.wikimedia.org:29418/apps/android/wikipedia refs/changes/12/342012/1 diff --git a/app/src/main/java/org/wikipedia/search/SearchResultsFragment.java b/app/src/main/java/org/wikipedia/search/SearchResultsFragment.java index d75fc46..b175bf1 100644 --- a/app/src/main/java/org/wikipedia/search/SearchResultsFragment.java +++ b/app/src/main/java/org/wikipedia/search/SearchResultsFragment.java @@ -11,7 +11,6 @@ import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; -import android.widget.AdapterView; import android.widget.BaseAdapter; import android.widget.ListView; import android.widget.TextView; @@ -37,6 +36,12 @@ import java.util.ArrayList; import java.util.List; +import butterknife.BindView; +import butterknife.ButterKnife; +import butterknife.OnClick; +import butterknife.OnItemClick; +import butterknife.Unbinder; + import static org.apache.commons.lang3.StringUtils.isBlank; public class SearchResultsFragment extends Fragment { @@ -60,12 +65,13 @@ */ private static final int NANO_TO_MILLI = 1_000_000; - private View searchResultsDisplay; - private View searchResultsContainer; - private ListView searchResultsList; - private WikiErrorView searchErrorView; - private View searchNoResults; - private TextView searchSuggestion; + @BindView(R.id.search_results_display) View searchResultsDisplay; + @BindView(R.id.search_results_container) View searchResultsContainer; + @BindView(R.id.search_results_list) ListView searchResultsList; + @BindView(R.id.search_error_view) WikiErrorView searchErrorView; + @BindView(R.id.search_empty_view) View searchEmptyView; + @BindView(R.id.search_suggestion) TextView searchSuggestion; + private Unbinder unbinder; private WikipediaApp app; @NonNull private final LruCache<String, List<SearchResult>> searchResultsCache @@ -84,43 +90,12 @@ @Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { - View rootView = inflater.inflate(R.layout.fragment_search_results, container, false); - searchResultsDisplay = rootView.findViewById(R.id.search_results_display); - - searchResultsContainer = rootView.findViewById(R.id.search_results_container); - searchResultsList = (ListView) rootView.findViewById(R.id.search_results_list); - - searchResultsList.setOnItemClickListener(new AdapterView.OnItemClickListener() { - @Override - public void onItemClick(AdapterView<?> parent, View view, int position, long id) { - Callback callback = callback(); - if (callback != null) { - PageTitle item = ((SearchResult) getAdapter().getItem(position)).getPageTitle(); - callback.navigateToTitle(item, false, position); - } - } - }); + View view = inflater.inflate(R.layout.fragment_search_results, container, false); + unbinder = ButterKnife.bind(this, view); SearchResultAdapter adapter = new SearchResultAdapter(inflater); searchResultsList.setAdapter(adapter); - searchSuggestion = (TextView) rootView.findViewById(R.id.search_suggestion); - searchSuggestion.setOnClickListener(new View.OnClickListener() { - @Override - public void onClick(View view) { - Callback callback = callback(); - String suggestion = (String) searchSuggestion.getTag(); - if (callback != null && suggestion != null) { - callback.getFunnel().searchDidYouMean(); - callback.setSearchText(suggestion); - startSearch(suggestion, true); - } - } - }); - - searchNoResults = rootView.findViewById(R.id.search_results_empty); - - searchErrorView = (WikiErrorView) rootView.findViewById(R.id.search_error_view); searchErrorView.setRetryClickListener(new View.OnClickListener() { @Override public void onClick(View view) { @@ -131,7 +106,7 @@ searchHandler = new Handler(new SearchHandlerCallback()); - return rootView; + return view; } @Override @@ -139,6 +114,32 @@ super.onActivityCreated(savedInstanceState); new LongPressHandler(searchResultsList, HistoryEntry.SOURCE_SEARCH, new SearchResultsFragmentLongPressHandler()); + } + + @Override + public void onDestroyView() { + searchErrorView.setRetryClickListener(null); + unbinder.unbind(); + unbinder = null; + super.onDestroyView(); + } + + @OnItemClick(R.id.search_results_list) void onItemClick(ListView view, int position) { + Callback callback = callback(); + if (callback != null) { + PageTitle item = ((SearchResult) getAdapter().getItem(position)).getPageTitle(); + callback.navigateToTitle(item, false, position); + } + } + + @OnClick(R.id.search_suggestion) void onSuggestionClick(View view) { + Callback callback = callback(); + String suggestion = (String) searchSuggestion.getTag(); + if (callback != null && suggestion != null) { + callback.getFunnel().searchDidYouMean(); + callback.setSearchText(suggestion); + startSearch(suggestion, true); + } } public void show() { @@ -390,7 +391,7 @@ private void clearResults(boolean clearSuggestion) { searchResultsContainer.setVisibility(View.GONE); - searchNoResults.setVisibility(View.GONE); + searchEmptyView.setVisibility(View.GONE); searchErrorView.setVisibility(View.GONE); if (clearSuggestion) { searchSuggestion.setVisibility(View.GONE); @@ -426,13 +427,12 @@ } } - searchResultsContainer.setVisibility(View.VISIBLE); - if (totalResults.size() == 0) { - searchNoResults.setVisibility(View.VISIBLE); - searchResultsList.setVisibility(View.GONE); + if (totalResults.isEmpty()) { + searchEmptyView.setVisibility(View.VISIBLE); + searchResultsContainer.setVisibility(View.GONE); } else { - searchNoResults.setVisibility(View.GONE); - searchResultsList.setVisibility(View.VISIBLE); + searchEmptyView.setVisibility(View.GONE); + searchResultsContainer.setVisibility(View.VISIBLE); } getAdapter().notifyDataSetChanged(); diff --git a/app/src/main/res/layout/fragment_search.xml b/app/src/main/res/layout/fragment_search.xml index 13f6e80..c93c977 100644 --- a/app/src/main/res/layout/fragment_search.xml +++ b/app/src/main/res/layout/fragment_search.xml @@ -95,7 +95,7 @@ <FrameLayout android:layout_width="match_parent" android:layout_height="match_parent" - android:background="?attr/search_background_color"> + android:background="?attr/feed_window_background_color"> <fragment android:id="@+id/fragment_search_results" diff --git a/app/src/main/res/layout/fragment_search_recent.xml b/app/src/main/res/layout/fragment_search_recent.xml index 23a86cf..feab661 100644 --- a/app/src/main/res/layout/fragment_search_recent.xml +++ b/app/src/main/res/layout/fragment_search_recent.xml @@ -3,10 +3,11 @@ <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:app="http://schemas.android.com/apk/res-auto" - android:id="@+id/recent_searches_container" - android:orientation="vertical" - android:layout_width="match_parent" - android:layout_height="match_parent"> + android:id="@+id/recent_searches_container" + android:orientation="vertical" + android:layout_width="match_parent" + android:layout_height="match_parent" + android:background="?attr/window_background_color"> <FrameLayout android:layout_width="match_parent" android:layout_height="wrap_content"> diff --git a/app/src/main/res/layout/fragment_search_results.xml b/app/src/main/res/layout/fragment_search_results.xml index 6feaefb..12d217c 100644 --- a/app/src/main/res/layout/fragment_search_results.xml +++ b/app/src/main/res/layout/fragment_search_results.xml @@ -1,10 +1,11 @@ <?xml version="1.0" encoding="utf-8"?> -<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android" - xmlns:tools="http://schemas.android.com/tools" - android:id="@+id/search_results_display" - android:layout_width="match_parent" - android:layout_height="match_parent"> +<FrameLayout + xmlns:android="http://schemas.android.com/apk/res/android" + xmlns:tools="http://schemas.android.com/tools" + android:id="@+id/search_results_display" + android:layout_width="match_parent" + android:layout_height="match_parent"> <org.wikipedia.views.WikiErrorView android:id="@+id/search_error_view" @@ -20,7 +21,8 @@ tools:visibility="visible" android:orientation="vertical" android:layout_width="match_parent" - android:layout_height="match_parent"> + android:layout_height="match_parent" + android:background="?attr/window_background_color"> <TextView android:id="@+id/search_suggestion" @@ -38,19 +40,14 @@ android:id="@+id/search_results_list" android:layout_width="match_parent" android:layout_height="match_parent" /> - <TextView - android:id="@+id/search_results_empty" - android:layout_width="wrap_content" - android:layout_height="wrap_content" - android:layout_marginTop="8dp" - android:layout_gravity="center" - android:textColor="@color/foundation_gray" - android:text="@string/search_no_results_found" - style="?android:textAppearanceMedium" - android:visibility="gone" - tools:visibility="visible" - /> </LinearLayout> + <org.wikipedia.views.SearchEmptyView + android:id="@+id/search_empty_view" + android:layout_width="wrap_content" + android:layout_height="wrap_content" + android:layout_gravity="center" + android:visibility="gone"/> + </FrameLayout> -- To view, visit https://gerrit.wikimedia.org/r/342012 To unsubscribe, visit https://gerrit.wikimedia.org/r/settings Gerrit-MessageType: newchange Gerrit-Change-Id: Ic570db7bef4db6e06d9139c7109de299448bd110 Gerrit-PatchSet: 1 Gerrit-Project: apps/android/wikipedia Gerrit-Branch: master Gerrit-Owner: Dbrant <dbr...@wikimedia.org> _______________________________________________ MediaWiki-commits mailing list MediaWiki-commits@lists.wikimedia.org https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits