jenkins-bot has submitted this change and it was merged. ( 
https://gerrit.wikimedia.org/r/364588 )

Change subject: Compilations: integrate with Search.
......................................................................


Compilations: integrate with Search.

This enables the Search bar to fetch results (transparently) from a
compilation when offline.

Change-Id: Ieb0aa92cb85f08c32cf032096fcfb95de60ebd04
---
M app/src/main/java/org/wikipedia/search/SearchResultsFragment.java
1 file changed, 28 insertions(+), 2 deletions(-)

Approvals:
  jenkins-bot: Verified
  Mholloway: Looks good to me, approved



diff --git a/app/src/main/java/org/wikipedia/search/SearchResultsFragment.java 
b/app/src/main/java/org/wikipedia/search/SearchResultsFragment.java
index 27fdca5..53f3ae6 100644
--- a/app/src/main/java/org/wikipedia/search/SearchResultsFragment.java
+++ b/app/src/main/java/org/wikipedia/search/SearchResultsFragment.java
@@ -25,9 +25,12 @@
 import org.wikipedia.analytics.SearchFunnel;
 import org.wikipedia.dataclient.mwapi.MwQueryResponse;
 import org.wikipedia.history.HistoryEntry;
+import org.wikipedia.offline.OfflineManager;
 import org.wikipedia.page.PageTitle;
 import org.wikipedia.readinglist.AddToReadingListDialog;
+import org.wikipedia.util.DeviceUtil;
 import org.wikipedia.util.StringUtil;
+import org.wikipedia.util.log.L;
 import org.wikipedia.views.GoneIfEmptyTextView;
 import org.wikipedia.views.ViewUtil;
 import org.wikipedia.views.WikiErrorView;
@@ -202,9 +205,32 @@
                 return true;
             }
             final String mySearchTerm = (String) msg.obj;
-            doTitlePrefixSearch(mySearchTerm);
+            if (!DeviceUtil.isOnline() && OfflineManager.hasCompilation()) {
+                doOfflineSearch(mySearchTerm);
+            } else {
+                doTitlePrefixSearch(mySearchTerm);
+            }
             return true;
         }
+    }
+
+    private void doOfflineSearch(final String searchTerm) {
+        searchSuggestion.setVisibility(View.GONE);
+        searchErrorView.setVisibility(View.GONE);
+        updateProgressBar(false);
+
+        List<SearchResult> resultList = new ArrayList<>();
+        try {
+            List<String> results = 
OfflineManager.instance().searchByPrefix(searchTerm, BATCH_SIZE);
+            for (String title : results) {
+                resultList.add(new SearchResult(new PageTitle(title, 
app.getWikiSite())));
+            }
+        } catch (IOException e) {
+            L.d(e);
+        }
+
+        clearResults();
+        displayResults(resultList);
     }
 
     private void doTitlePrefixSearch(final String searchTerm) {
@@ -494,7 +520,7 @@
 
             // ...and lastly, if we've scrolled to the last item in the list, 
then
             // continue searching!
-            if (position == (totalResults.size() - 1)) {
+            if (position == (totalResults.size() - 1) && 
DeviceUtil.isOnline()) {
                 if (lastFullTextResults == null) {
                     // the first full text search
                     doFullTextSearch(currentSearchTerm, null, false);

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

Gerrit-MessageType: merged
Gerrit-Change-Id: Ieb0aa92cb85f08c32cf032096fcfb95de60ebd04
Gerrit-PatchSet: 4
Gerrit-Project: apps/android/wikipedia
Gerrit-Branch: master
Gerrit-Owner: Dbrant <dbr...@wikimedia.org>
Gerrit-Reviewer: Brion VIBBER <br...@wikimedia.org>
Gerrit-Reviewer: Dbrant <dbr...@wikimedia.org>
Gerrit-Reviewer: Mholloway <mhollo...@wikimedia.org>
Gerrit-Reviewer: Niedzielski <sniedziel...@wikimedia.org>
Gerrit-Reviewer: jenkins-bot <>

_______________________________________________
MediaWiki-commits mailing list
MediaWiki-commits@lists.wikimedia.org
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to