Dbrant has uploaded a new change for review.

  https://gerrit.wikimedia.org/r/150014

Change subject: [WIP] Implement full-text search.
......................................................................

[WIP] Implement full-text search.

Change-Id: I9627539762e286f630ef1cea6ae193a042a0977d
---
M icon-svgs/32/search.svg
M wikipedia/res/drawable-hdpi/search.png
M wikipedia/res/drawable-ldpi/search.png
M wikipedia/res/drawable-mdpi/search.png
M wikipedia/res/drawable-xhdpi/search.png
M wikipedia/res/drawable-xxhdpi/search.png
R wikipedia/res/drawable/button_selector_complete.xml
R wikipedia/res/drawable/button_selector_progressive.xml
A wikipedia/res/layout/dialog_search_results.xml
M wikipedia/res/layout/fragment_search.xml
A wikipedia/res/layout/item_full_search_result.xml
M wikipedia/res/values-qq/strings.xml
M wikipedia/res/values/strings.xml
M wikipedia/src/main/java/org/wikipedia/editing/EditSectionActivity.java
A wikipedia/src/main/java/org/wikipedia/search/FullSearchArticlesTask.java
A wikipedia/src/main/java/org/wikipedia/search/FullSearchDialog.java
A wikipedia/src/main/java/org/wikipedia/search/FullSearchResult.java
A 
wikipedia/src/main/java/org/wikipedia/search/FullSearchSuggestionException.java
M wikipedia/src/main/java/org/wikipedia/search/SearchArticlesFragment.java
19 files changed, 472 insertions(+), 56 deletions(-)


  git pull ssh://gerrit.wikimedia.org:29418/apps/android/wikipedia 
refs/changes/14/150014/1

diff --git a/icon-svgs/32/search.svg b/icon-svgs/32/search.svg
index 9047910..ff158a6 100644
--- a/icon-svgs/32/search.svg
+++ b/icon-svgs/32/search.svg
@@ -1,12 +1,51 @@
-<?xml version="1.0" encoding="utf-8"?>
-<!-- Generator: Adobe Illustrator 16.0.4, SVG Export Plug-In . SVG Version: 
6.00 Build 0)  -->
-<!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN" 
"http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd";>
-<svg version="1.1" id="Layer_1" xmlns="http://www.w3.org/2000/svg"; 
xmlns:xlink="http://www.w3.org/1999/xlink"; x="0px" y="0px"
-        width="32px" height="32px" viewBox="0 0 32 32" enable-background="new 
0 0 32 32" xml:space="preserve">
-<path fill="#AAAAAA" 
d="M27.661,24.211l-0.146-0.145l0,0l-5.78-5.779c0.803-1.387,1.271-2.988,1.279-4.706
-       
c0.034-5.247-4.192-9.528-9.442-9.561c-0.021,0-0.041,0-0.062,0c-5.218,0-9.467,4.215-9.5,9.44
-       
c-0.034,5.248,4.192,9.529,9.441,9.564c0.021,0,0.041,0,0.062,0c1.745,0,3.378-0.471,4.786-1.295l5.776,5.777l0,0l0.146,0.143
-       
c0.437,0.439,1.144,0.439,1.58,0l1.859-1.857C28.098,25.357,28.098,24.65,27.661,24.211z
 M13.468,20.602
-       
c-3.903-0.025-7.061-3.223-7.035-7.125C6.459,9.6,9.635,6.443,13.513,6.443h0.046c1.891,0.012,3.664,0.76,4.993,2.104
-       
c1.328,1.347,2.052,3.128,2.04,5.021c-0.01,1.882-0.755,3.651-2.089,4.977c-1.335,1.326-3.107,2.057-4.989,2.057H13.468z"/>
-</svg>
+<?xml version="1.0" encoding="UTF-8" standalone="no"?>
+<!-- Generator: Adobe Illustrator 16.0.4, SVG Export Plug-In . SVG Version: 
6.00 Build 0)  -->
+
+<svg
+   xmlns:dc="http://purl.org/dc/elements/1.1/";
+   xmlns:cc="http://creativecommons.org/ns#";
+   xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#";
+   xmlns:svg="http://www.w3.org/2000/svg";
+   xmlns="http://www.w3.org/2000/svg";
+   xmlns:sodipodi="http://sodipodi.sourceforge.net/DTD/sodipodi-0.dtd";
+   xmlns:inkscape="http://www.inkscape.org/namespaces/inkscape";
+   version="1.1"
+   id="Layer_1"
+   x="0px"
+   y="0px"
+   width="32px"
+   height="32px"
+   viewBox="0 0 32 32"
+   enable-background="new 0 0 32 32"
+   xml:space="preserve"
+   inkscape:version="0.48.1 "
+   sodipodi:docname="search.svg"><metadata
+   id="metadata9"><rdf:RDF><cc:Work
+       rdf:about=""><dc:format>image/svg+xml</dc:format><dc:type
+         rdf:resource="http://purl.org/dc/dcmitype/StillImage"; 
/></cc:Work></rdf:RDF></metadata><defs
+   id="defs7" /><sodipodi:namedview
+   pagecolor="#ffffff"
+   bordercolor="#666666"
+   borderopacity="1"
+   objecttolerance="10"
+   gridtolerance="10"
+   guidetolerance="10"
+   inkscape:pageopacity="0"
+   inkscape:pageshadow="2"
+   inkscape:window-width="708"
+   inkscape:window-height="480"
+   id="namedview5"
+   showgrid="false"
+   inkscape:zoom="9.09375"
+   inkscape:cx="16"
+   inkscape:cy="16"
+   inkscape:window-x="0"
+   inkscape:window-y="0"
+   inkscape:window-maximized="0"
+   inkscape:current-layer="Layer_1" />
+<path
+   fill="#AAAAAA"
+   
d="M27.661,24.211l-0.146-0.145l0,0l-5.78-5.779c0.803-1.387,1.271-2.988,1.279-4.706
  
c0.034-5.247-4.192-9.528-9.442-9.561c-0.021,0-0.041,0-0.062,0c-5.218,0-9.467,4.215-9.5,9.44
  
c-0.034,5.248,4.192,9.529,9.441,9.564c0.021,0,0.041,0,0.062,0c1.745,0,3.378-0.471,4.786-1.295l5.776,5.777l0,0l0.146,0.143
  
c0.437,0.439,1.144,0.439,1.58,0l1.859-1.857C28.098,25.357,28.098,24.65,27.661,24.211z
 M13.468,20.602  
c-3.903-0.025-7.061-3.223-7.035-7.125C6.459,9.6,9.635,6.443,13.513,6.443h0.046c1.891,0.012,3.664,0.76,4.993,2.104
  
c1.328,1.347,2.052,3.128,2.04,5.021c-0.01,1.882-0.755,3.651-2.089,4.977c-1.335,1.326-3.107,2.057-4.989,2.057H13.468z"
+   id="path3"
+   style="fill:#ffffff;fill-opacity:1" />
+</svg>
\ No newline at end of file
diff --git a/wikipedia/res/drawable-hdpi/search.png 
b/wikipedia/res/drawable-hdpi/search.png
index fb6a399..3587132 100644
--- a/wikipedia/res/drawable-hdpi/search.png
+++ b/wikipedia/res/drawable-hdpi/search.png
Binary files differ
diff --git a/wikipedia/res/drawable-ldpi/search.png 
b/wikipedia/res/drawable-ldpi/search.png
index d504955..4f2bc4c 100644
--- a/wikipedia/res/drawable-ldpi/search.png
+++ b/wikipedia/res/drawable-ldpi/search.png
Binary files differ
diff --git a/wikipedia/res/drawable-mdpi/search.png 
b/wikipedia/res/drawable-mdpi/search.png
index ca8cbcb..59dbd25 100644
--- a/wikipedia/res/drawable-mdpi/search.png
+++ b/wikipedia/res/drawable-mdpi/search.png
Binary files differ
diff --git a/wikipedia/res/drawable-xhdpi/search.png 
b/wikipedia/res/drawable-xhdpi/search.png
index ee49761..0329152 100644
--- a/wikipedia/res/drawable-xhdpi/search.png
+++ b/wikipedia/res/drawable-xhdpi/search.png
Binary files differ
diff --git a/wikipedia/res/drawable-xxhdpi/search.png 
b/wikipedia/res/drawable-xxhdpi/search.png
index 433096e..96ef324 100644
--- a/wikipedia/res/drawable-xxhdpi/search.png
+++ b/wikipedia/res/drawable-xxhdpi/search.png
Binary files differ
diff --git a/wikipedia/res/drawable/editpage_button_background_complete.xml 
b/wikipedia/res/drawable/button_selector_complete.xml
similarity index 100%
rename from wikipedia/res/drawable/editpage_button_background_complete.xml
rename to wikipedia/res/drawable/button_selector_complete.xml
diff --git a/wikipedia/res/drawable/editpage_button_background_progressive.xml 
b/wikipedia/res/drawable/button_selector_progressive.xml
similarity index 100%
rename from wikipedia/res/drawable/editpage_button_background_progressive.xml
rename to wikipedia/res/drawable/button_selector_progressive.xml
diff --git a/wikipedia/res/layout/dialog_search_results.xml 
b/wikipedia/res/layout/dialog_search_results.xml
new file mode 100644
index 0000000..87891ab
--- /dev/null
+++ b/wikipedia/res/layout/dialog_search_results.xml
@@ -0,0 +1,62 @@
+<?xml version="1.0" encoding="utf-8"?>
+
+<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android";
+             android:layout_width="match_parent"
+             android:layout_height="match_parent">
+    <LinearLayout
+            android:id="@+id/search_results_container"
+            android:visibility="gone"
+            android:orientation="vertical"
+            android:layout_width="match_parent"
+            android:layout_height="match_parent">
+
+        <TextView
+                android:id="@+id/search_results_status"
+                android:layout_width="wrap_content"
+                android:layout_height="wrap_content"
+                android:visibility="gone"
+                android:textColor="@color/license_text_light"
+                android:layout_marginTop="8dp"
+                android:layout_marginBottom="8dp"
+                android:layout_marginLeft="16dp"
+                android:layout_marginRight="16dp"/>
+
+        <ListView
+                android:id="@+id/full_search_results_list"
+                android:layout_width="match_parent"
+                android:layout_height="match_parent"
+                android:layout_marginTop="8dp"
+                android:layout_marginLeft="8dp"
+                android:layout_marginRight="8dp"
+                android:dividerHeight="0dp"
+                />
+
+    </LinearLayout>
+    <ProgressBar
+            android:id="@+id/search_progress_bar"
+            android:layout_gravity="center"
+            android:layout_width="wrap_content"
+            android:layout_height="wrap_content"/>
+    <LinearLayout
+            android:id="@+id/search_failed_container"
+            android:orientation="vertical"
+            android:layout_gravity="center"
+            android:visibility="gone"
+            android:layout_width="wrap_content"
+            android:layout_height="wrap_content">
+        <TextView
+                android:id="@+id/search_failed_text"
+                android:layout_width="wrap_content"
+                android:layout_height="wrap_content"
+                android:gravity="center"
+                android:padding="12dp"
+                android:textAppearance="?android:attr/textAppearanceLarge"/>
+        <Button
+                android:id="@+id/search_retry_button"
+                android:layout_marginTop="8dp"
+                android:layout_width="wrap_content"
+                android:layout_height="wrap_content"
+                android:text="@string/search_error_retry"
+                android:textAppearance="?android:attr/textAppearanceMedium"/>
+    </LinearLayout>
+</FrameLayout>
\ No newline at end of file
diff --git a/wikipedia/res/layout/fragment_search.xml 
b/wikipedia/res/layout/fragment_search.xml
index 86c788b..6c59013 100644
--- a/wikipedia/res/layout/fragment_search.xml
+++ b/wikipedia/res/layout/fragment_search.xml
@@ -65,12 +65,25 @@
                     android:id="@+id/search_progress"
                     android:layout_width="wrap_content"
                     android:layout_height="wrap_content"
+                    android:layout_marginRight="4dp"
                     android:layout_gravity="right|center_vertical|end"
                     android:indeterminate="true"
                     android:visibility="invisible"
                     style="@android:style/Widget.ProgressBar.Small"
                     />
         </LinearLayout>
+        <ImageView
+                android:id="@+id/search_bar_full_search"
+                android:visibility="gone"
+                android:layout_width="48dp"
+                android:layout_height="48dp"
+                android:layout_gravity="center_vertical"
+                android:padding="10dp"
+                android:clickable="true"
+                android:src="@drawable/search"
+                android:background="@drawable/button_selector_progressive"
+                android:contentDescription="@string/menu_show_toc"
+                />
         <ImageView
                 android:id="@+id/search_bar_show_toc"
                 android:layout_width="48dp"
@@ -96,15 +109,6 @@
     <!-- Android has no easy way to give us a light border -->
     <View android:layout_width="match_parent" android:layout_height="1dp"
           android:background="@color/border" />
-    <TextView
-            android:id="@+id/search_results_empty"
-            android:layout_width="match_parent"
-            android:layout_height="48dp"
-            android:gravity="center"
-            android:text="@string/search_no_results_found"
-            style="?android:textAppearanceMedium"
-            android:visibility="gone"
-            />
     <Button
             android:id="@+id/search_network_error"
             android:layout_width="match_parent"
diff --git a/wikipedia/res/layout/item_full_search_result.xml 
b/wikipedia/res/layout/item_full_search_result.xml
new file mode 100644
index 0000000..604a572
--- /dev/null
+++ b/wikipedia/res/layout/item_full_search_result.xml
@@ -0,0 +1,23 @@
+<?xml version="1.0" encoding="utf-8"?>
+
+<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android";
+              android:orientation="vertical"
+              android:layout_width="match_parent"
+              android:layout_height="wrap_content"
+              android:background="@drawable/selectable_item_background"
+              android:padding="8dp">
+
+    <TextView android:id="@+id/result_title"
+              android:layout_width="match_parent"
+              android:layout_height="wrap_content"
+              android:layout_gravity="left"
+              style="?android:textAppearanceLarge"
+            />
+    <TextView android:id="@+id/result_snippet"
+              android:layout_width="match_parent"
+              android:layout_height="wrap_content"
+              android:layout_gravity="left"
+              android:layout_marginLeft="32dp"
+            />
+
+</LinearLayout>
\ No newline at end of file
diff --git a/wikipedia/res/values-qq/strings.xml 
b/wikipedia/res/values-qq/strings.xml
index c5646c9..cc32b2b 100644
--- a/wikipedia/res/values-qq/strings.xml
+++ b/wikipedia/res/values-qq/strings.xml
@@ -278,5 +278,9 @@
   <string name="color_theme_select">Label that describes color theme 
selection</string>
   <string name="color_theme_light">Button label for Light color theme</string>
   <string name="color_theme_dark">Button label for Dark color theme</string>
+  <string name="search_no_results">Label that tells the user that no results 
were found. The \"%s\" symbol is replaced with the phrase that was 
searched.</string>
+  <string name="search_showing_instead">Label that tells the user that no 
results were found, but other results were found for a similar search term. The 
first \"%s\" symbol is the original search term, and the second symbol is the 
new suggested search term.</string>
+  <string name="search_results_title">Title of the dialog box that contains 
search results.</string>
+  <string name="search_error_retry">Retry</string>
   <string name="app_store_description">Description of the app as put up on the 
Google Play Store</string>
 </resources>
diff --git a/wikipedia/res/values/strings.xml b/wikipedia/res/values/strings.xml
index 0268e93..53fdd37 100644
--- a/wikipedia/res/values/strings.xml
+++ b/wikipedia/res/values/strings.xml
@@ -209,6 +209,10 @@
     <string name="color_theme_select">Theme</string>
     <string name="color_theme_light">Light</string>
     <string name="color_theme_dark">Dark</string>
+    <string name="search_no_results">No results found for \"%s\".</string>
+    <string name="search_showing_instead">No results found for \"%1$s\". 
Showing results for \"%2$s\":</string>
+    <string name="search_results_title">Search results</string>
+    <string name="search_error_retry">Retry</string>
     <string name="app_store_description">Official Wikipedia App for Android. 
Wikipedia is the free encyclopedia containing more than 32 million articles in 
280 languages, and is the most comprehensive and widely used reference work 
humans have ever compiled. The app has been rewritten from scratch and is 
better than ever before.
 
 Features:
diff --git 
a/wikipedia/src/main/java/org/wikipedia/editing/EditSectionActivity.java 
b/wikipedia/src/main/java/org/wikipedia/editing/EditSectionActivity.java
index b0a455f..0a4e853 100644
--- a/wikipedia/src/main/java/org/wikipedia/editing/EditSectionActivity.java
+++ b/wikipedia/src/main/java/org/wikipedia/editing/EditSectionActivity.java
@@ -530,11 +530,11 @@
             });
 
             if (editSummaryFragment.isActive()) {
-                
v.setBackgroundResource(R.drawable.editpage_button_background_progressive);
+                
v.setBackgroundResource(R.drawable.button_selector_progressive);
             } else if (editPreviewFragment.isActive()) {
-                
v.setBackgroundResource(R.drawable.editpage_button_background_complete);
+                v.setBackgroundResource(R.drawable.button_selector_complete);
             } else {
-                
v.setBackgroundResource(R.drawable.editpage_button_background_progressive);
+                
v.setBackgroundResource(R.drawable.button_selector_progressive);
             }
         }
 
diff --git 
a/wikipedia/src/main/java/org/wikipedia/search/FullSearchArticlesTask.java 
b/wikipedia/src/main/java/org/wikipedia/search/FullSearchArticlesTask.java
new file mode 100644
index 0000000..bfa81cd
--- /dev/null
+++ b/wikipedia/src/main/java/org/wikipedia/search/FullSearchArticlesTask.java
@@ -0,0 +1,58 @@
+package org.wikipedia.search;
+
+import android.content.Context;
+import org.json.JSONArray;
+import org.json.JSONObject;
+import org.mediawiki.api.json.Api;
+import org.mediawiki.api.json.ApiResult;
+import org.mediawiki.api.json.RequestBuilder;
+import org.wikipedia.ApiTask;
+import org.wikipedia.Site;
+import org.wikipedia.Utils;
+import org.wikipedia.WikipediaApp;
+
+import java.util.ArrayList;
+import java.util.List;
+
+public class FullSearchArticlesTask extends ApiTask<List<FullSearchResult>> {
+    private final String searchTerm;
+    private final Site site;
+    private final WikipediaApp app;
+
+    public FullSearchArticlesTask(Context context, Api api, Site site, String 
searchTerm) {
+        super(LOW_CONCURRENCY, api);
+        this.searchTerm = searchTerm;
+        this.site = site;
+        this.app = (WikipediaApp)context.getApplicationContext();
+    }
+
+    @Override
+    public RequestBuilder buildRequest(Api api) {
+        return api.action("query").param("list", "search").param("srsearch", 
searchTerm).param("srlimit", "25");
+    }
+
+    @Override
+    public List<FullSearchResult> processResult(final ApiResult result) throws 
Throwable {
+        JSONObject queryResult = result.asObject().optJSONObject("query");
+        JSONArray searchResults = queryResult.optJSONArray("search");
+
+        if (searchResults.length() == 0) {
+            String suggestion = 
queryResult.optJSONObject("searchinfo").optString("suggestion");
+            if (suggestion != null && suggestion.length() > 0) {
+                throw new FullSearchSuggestionException(suggestion);
+            }
+        }
+
+        ArrayList<FullSearchResult> results = new 
ArrayList<FullSearchResult>();
+        for (int i = 0; i < searchResults.length(); i++) {
+            results.add(new 
FullSearchResult(searchResults.optJSONObject(i).optString("title"),
+                    searchResults.optJSONObject(i).optString("snippet")));
+        }
+
+        if (WikipediaApp.isWikipediaZeroDevmodeOn()) {
+            Utils.processHeadersForZero(app, result);
+        }
+
+        return results;
+    }
+}
diff --git a/wikipedia/src/main/java/org/wikipedia/search/FullSearchDialog.java 
b/wikipedia/src/main/java/org/wikipedia/search/FullSearchDialog.java
new file mode 100644
index 0000000..30d5400
--- /dev/null
+++ b/wikipedia/src/main/java/org/wikipedia/search/FullSearchDialog.java
@@ -0,0 +1,185 @@
+package org.wikipedia.search;
+
+import android.app.Dialog;
+import android.content.Context;
+import android.text.Html;
+import android.view.LayoutInflater;
+import android.view.View;
+import android.view.ViewGroup;
+import android.view.WindowManager;
+import android.widget.AdapterView;
+import android.widget.BaseAdapter;
+import android.widget.ListView;
+import android.widget.TextView;
+import org.wikipedia.PageTitle;
+import org.wikipedia.R;
+import org.wikipedia.WikipediaApp;
+
+import java.util.List;
+
+public class FullSearchDialog extends Dialog {
+
+    private WikipediaApp app;
+
+    private SearchArticlesFragment parentFragment;
+    private View searchResultsContainer;
+    private ListView searchResultsList;
+    private SearchResultAdapter adapter;
+    private TextView resultsStatusText;
+    private String searchTerm;
+
+    private View searchFailedContainer;
+    private TextView searchFailedText;
+    private View searchRetryButton;
+    private View searchProgressBar;
+
+    public FullSearchDialog(SearchArticlesFragment parent, String searchTerm) {
+        super(parent.getActivity());
+        this.parentFragment = parent;
+        this.searchTerm = searchTerm;
+        app = WikipediaApp.getInstance();
+
+        LayoutInflater inflater = (LayoutInflater) 
parent.getActivity().getSystemService(Context.LAYOUT_INFLATER_SERVICE);
+        View dlgLayout = inflater.inflate(R.layout.dialog_search_results, 
null);
+        setContentView(dlgLayout);
+
+        WindowManager.LayoutParams lp = new WindowManager.LayoutParams();
+        lp.copyFrom(getWindow().getAttributes());
+        lp.width = WindowManager.LayoutParams.MATCH_PARENT;
+        lp.height = WindowManager.LayoutParams.MATCH_PARENT;
+        getWindow().setAttributes(lp);
+
+        setTitle(app.getString(R.string.search_results_title));
+
+        searchResultsContainer = 
dlgLayout.findViewById(R.id.search_results_container);
+        searchResultsList = (ListView) 
dlgLayout.findViewById(R.id.full_search_results_list);
+
+        searchResultsList.setOnItemClickListener(new 
AdapterView.OnItemClickListener() {
+            @Override
+            public void onItemClick(AdapterView<?> parent, View view, int 
position, long id) {
+                PageTitle title = new PageTitle(((FullSearchResult) 
searchResultsList.getAdapter().getItem(position)).getTitle(),
+                        app.getPrimarySite());
+                parentFragment.navigateToTitle(title);
+                dismiss();
+            }
+        });
+
+        adapter = new SearchResultAdapter(inflater);
+        searchResultsList.setAdapter(adapter);
+
+        resultsStatusText = (TextView) 
dlgLayout.findViewById(R.id.search_results_status);
+        searchFailedText = (TextView) 
dlgLayout.findViewById(R.id.search_failed_text);
+        searchFailedContainer = 
dlgLayout.findViewById(R.id.search_failed_container);
+
+        searchRetryButton = dlgLayout.findViewById(R.id.search_retry_button);
+        searchRetryButton.setOnClickListener(new View.OnClickListener() {
+            @Override
+            public void onClick(View view) {
+                doSearch(FullSearchDialog.this.searchTerm, false);
+            }
+        });
+
+        searchProgressBar = dlgLayout.findViewById(R.id.search_progress_bar);
+
+        doSearch(searchTerm, false);
+    }
+
+    private void doSearch(final String searchTerm, final boolean 
fromSuggestion) {
+        (new FullSearchArticlesTask(app, 
app.getAPIForSite(app.getPrimarySite()), app.getPrimarySite(), searchTerm) {
+            @Override
+            public void onFinish(List<FullSearchResult> result) {
+                adapter.setResults(result);
+                
((BaseAdapter)searchResultsList.getAdapter()).notifyDataSetInvalidated();
+
+                searchProgressBar.setVisibility(View.GONE);
+                if (result.size() == 0) {
+                    searchResultsContainer.setVisibility(View.GONE);
+                    searchFailedContainer.setVisibility(View.VISIBLE);
+                    
searchFailedText.setText(app.getString(R.string.search_no_results, 
FullSearchDialog.this.searchTerm));
+                    searchRetryButton.setVisibility(View.GONE);
+                } else {
+                    searchResultsContainer.setVisibility(View.VISIBLE);
+                    searchFailedContainer.setVisibility(View.GONE);
+
+                    if (fromSuggestion) {
+                        resultsStatusText.setVisibility(View.VISIBLE);
+                        
resultsStatusText.setText(app.getString(R.string.search_showing_instead, 
FullSearchDialog.this.searchTerm, searchTerm));
+                    } else {
+                        resultsStatusText.setVisibility(View.GONE);
+                    }
+                }
+            }
+
+            @Override
+            public void onCatch(Throwable caught) {
+                if (caught instanceof FullSearchSuggestionException) {
+                    if (!fromSuggestion) {
+                        String suggestion = ((FullSearchSuggestionException) 
caught).getSuggestion();
+                        doSearch(suggestion, true);
+                    }
+                } else {
+                    searchProgressBar.setVisibility(View.GONE);
+                    searchResultsContainer.setVisibility(View.GONE);
+                    searchFailedContainer.setVisibility(View.VISIBLE);
+                    
searchFailedText.setText(app.getString(R.string.error_network_error));
+                    searchRetryButton.setVisibility(View.VISIBLE);
+                }
+            }
+
+            @Override
+            public void onBeforeExecute() {
+                searchProgressBar.setVisibility(View.VISIBLE);
+                searchResultsContainer.setVisibility(View.GONE);
+                searchFailedContainer.setVisibility(View.GONE);
+            }
+        }).execute();
+    }
+
+
+    private final class SearchResultAdapter extends BaseAdapter {
+        private List<FullSearchResult> results;
+        private final LayoutInflater inflater;
+
+        private SearchResultAdapter(LayoutInflater inflater) {
+            this.inflater = inflater;
+        }
+
+        private List<FullSearchResult> getResults() {
+            return results;
+        }
+
+        private void setResults(List<FullSearchResult> results) {
+            this.results = results;
+        }
+
+        @Override
+        public int getCount() {
+            return results == null ? 0 : results.size();
+        }
+
+        @Override
+        public Object getItem(int position) {
+            return results.get(position);
+        }
+
+        @Override
+        public long getItemId(int position) {
+            return position;
+        }
+
+        @Override
+        public View getView(int position, View convertView, ViewGroup parent) {
+            if (convertView == null) {
+                convertView = 
inflater.inflate(R.layout.item_full_search_result, parent, false);
+            }
+            TextView pageTitleText = (TextView) 
convertView.findViewById(R.id.result_title);
+            TextView pageSnippetText = (TextView) 
convertView.findViewById(R.id.result_snippet);
+            FullSearchResult result = (FullSearchResult) getItem(position);
+            pageTitleText.setText(result.getTitle());
+            pageSnippetText.setText(Html.fromHtml(result.getSnippet()));
+            return convertView;
+        }
+    }
+
+}
+
diff --git a/wikipedia/src/main/java/org/wikipedia/search/FullSearchResult.java 
b/wikipedia/src/main/java/org/wikipedia/search/FullSearchResult.java
new file mode 100644
index 0000000..6d5ba81
--- /dev/null
+++ b/wikipedia/src/main/java/org/wikipedia/search/FullSearchResult.java
@@ -0,0 +1,19 @@
+package org.wikipedia.search;
+
+public class FullSearchResult {
+    private String title;
+    private String snippet;
+
+    public String getTitle() {
+        return title;
+    }
+
+    public String getSnippet() {
+        return snippet;
+    }
+
+    public FullSearchResult(String title, String snippet) {
+        this.title = title;
+        this.snippet = snippet.replace("<span class='searchmatch'>", "<font 
color='#00b000'><strong>").replace("</span>", "</strong></font>");
+    }
+}
diff --git 
a/wikipedia/src/main/java/org/wikipedia/search/FullSearchSuggestionException.java
 
b/wikipedia/src/main/java/org/wikipedia/search/FullSearchSuggestionException.java
new file mode 100644
index 0000000..7ca665c
--- /dev/null
+++ 
b/wikipedia/src/main/java/org/wikipedia/search/FullSearchSuggestionException.java
@@ -0,0 +1,14 @@
+package org.wikipedia.search;
+
+public class FullSearchSuggestionException extends Exception {
+    private final String suggestion;
+
+    public FullSearchSuggestionException(String suggestion) {
+        this.suggestion = suggestion;
+    }
+
+    public String getSuggestion() {
+        return suggestion;
+    }
+
+}
diff --git 
a/wikipedia/src/main/java/org/wikipedia/search/SearchArticlesFragment.java 
b/wikipedia/src/main/java/org/wikipedia/search/SearchArticlesFragment.java
index 5f2ea27..8926929 100644
--- a/wikipedia/src/main/java/org/wikipedia/search/SearchArticlesFragment.java
+++ b/wikipedia/src/main/java/org/wikipedia/search/SearchArticlesFragment.java
@@ -58,7 +58,7 @@
     private ListView searchResultsList;
     private ProgressBar searchProgress;
     private View searchNetworkError;
-    private View searchNoResults;
+    private ImageView fullSearchButton;
     private ImageView searchBarMenuButton;
     private ImageView searchBarTocButton;
     private ImageView drawerIndicator;
@@ -93,7 +93,7 @@
             curSearchTask = null;
         }
         searchProgress.setVisibility(View.INVISIBLE);
-        searchNoResults.setVisibility(View.GONE);
+        fullSearchButton.setVisibility(View.GONE);
     }
 
     /**
@@ -104,34 +104,31 @@
     private void displayResults(List<PageTitle> results) {
         adapter.setResults(results);
         
((BaseAdapter)searchResultsList.getAdapter()).notifyDataSetInvalidated();
-        if (results.size() == 0) {
-            searchNoResults.setVisibility(View.VISIBLE);
-        } else {
-            searchResultsList.setVisibility(View.VISIBLE);
-            PageImagesTask imagesTask = new PageImagesTask(
-                    app.getAPIForSite(app.getPrimarySite()),
-                    app.getPrimarySite(),
-                    results,
-                    (int)(THUMB_SIZE_DP * WikipediaApp.SCREEN_DENSITY)) {
-                @Override
-                public void onFinish(Map<PageTitle, String> result) {
-                    for (Map.Entry<PageTitle, String> entry : 
result.entrySet()) {
-                        if (entry.getValue() == null) {
-                            continue;
-                        }
-                        pageImagesCache.put(entry.getKey().getPrefixedText(), 
entry.getValue());
+        fullSearchButton.setVisibility(View.VISIBLE);
+        searchResultsList.setVisibility(View.VISIBLE);
+        PageImagesTask imagesTask = new PageImagesTask(
+                app.getAPIForSite(app.getPrimarySite()),
+                app.getPrimarySite(),
+                results,
+                (int)(THUMB_SIZE_DP * WikipediaApp.SCREEN_DENSITY)) {
+            @Override
+            public void onFinish(Map<PageTitle, String> result) {
+                for (Map.Entry<PageTitle, String> entry : result.entrySet()) {
+                    if (entry.getValue() == null) {
+                        continue;
                     }
-                    
((BaseAdapter)searchResultsList.getAdapter()).notifyDataSetInvalidated();
+                    pageImagesCache.put(entry.getKey().getPrefixedText(), 
entry.getValue());
                 }
+                
((BaseAdapter)searchResultsList.getAdapter()).notifyDataSetInvalidated();
+            }
 
-                @Override
-                public void onCatch(Throwable caught) {
-                    // Don't actually do anything.
-                    // Thumbnails are expendable
-                }
-            };
-            imagesTask.execute();
-        }
+            @Override
+            public void onCatch(Throwable caught) {
+                // Don't actually do anything.
+                // Thumbnails are expendable
+            }
+        };
+        imagesTask.execute();
     }
 
     @Override
@@ -156,7 +153,14 @@
         searchBarTocButton = 
(ImageView)parentLayout.findViewById(R.id.search_bar_show_toc);
         drawerIndicator = 
(ImageView)parentLayout.findViewById(R.id.search_drawer_indicator);
         ImageView wikipediaIcon = (ImageView) 
parentLayout.findViewById(R.id.wikipedia_icon);
-        searchNoResults = parentLayout.findViewById(R.id.search_results_empty);
+
+        fullSearchButton = 
(ImageView)parentLayout.findViewById(R.id.search_bar_full_search);
+        fullSearchButton.setOnClickListener(new View.OnClickListener() {
+            @Override
+            public void onClick(View view) {
+                (new FullSearchDialog(SearchArticlesFragment.this, 
searchTermText.getText().toString())).show();
+            }
+        });
 
         app.adjustDrawableToTheme(wikipediaIcon.getDrawable());
         app.adjustDrawableToTheme(searchBarTocButton.getDrawable());
@@ -196,7 +200,6 @@
 
             @Override
             public void afterTextChanged(final Editable s) {
-                searchNoResults.setVisibility(View.GONE);
                 startSearch(s.toString());
             }
         });
@@ -217,8 +220,7 @@
                 if (action == EditorInfo.IME_ACTION_GO) {
                     String searchTerm = searchTermText.getText().toString();
                     if (searchTerm.length() > 0) {
-                        PageTitle title = new 
PageTitle(searchTermText.getText().toString(), app.getPrimarySite());
-                        navigateToTitle(title);
+                        (new FullSearchDialog(SearchArticlesFragment.this, 
searchTermText.getText().toString())).show();
                     } else {
                         hideSearchResults();
                     }
@@ -268,7 +270,7 @@
         return parentLayout;
     }
 
-    private void navigateToTitle(PageTitle title) {
+    public void navigateToTitle(PageTitle title) {
         HistoryEntry historyEntry = new HistoryEntry(title, 
HistoryEntry.SOURCE_SEARCH);
         InputMethodManager keyboard = 
(InputMethodManager)app.getSystemService(Context.INPUT_METHOD_SERVICE);
         keyboard.hideSoftInputFromWindow(searchTermText.getWindowToken(), 0);
@@ -284,8 +286,10 @@
         }
         if (term.equals("")) {
             hideSearchResults();
+            fullSearchButton.setVisibility(View.GONE);
             return;
         }
+        fullSearchButton.setVisibility(View.VISIBLE);
 
         List<PageTitle> cacheResult = 
searchResultsCache.get(app.getPrimaryLanguage() + "-" + term);
         if (cacheResult != null) {

-- 
To view, visit https://gerrit.wikimedia.org/r/150014
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings

Gerrit-MessageType: newchange
Gerrit-Change-Id: I9627539762e286f630ef1cea6ae193a042a0977d
Gerrit-PatchSet: 1
Gerrit-Project: apps/android/wikipedia
Gerrit-Branch: master
Gerrit-Owner: Dbrant <[email protected]>

_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to