jenkins-bot has submitted this change and it was merged.

Change subject: Integrate search into Feed (with voice).
......................................................................


Integrate search into Feed (with voice).

Change-Id: Iff74f9054f1f6913dc1e15d433cc78e6283d1e9e
---
M app/src/main/java/org/wikipedia/MainActivity.java
M app/src/main/java/org/wikipedia/MainActivityToolbarCoordinator.java
M app/src/main/java/org/wikipedia/feed/FeedFragment.java
M app/src/main/java/org/wikipedia/feed/FeedViewCallback.java
M app/src/main/java/org/wikipedia/feed/searchbar/SearchCardView.java
M app/src/main/java/org/wikipedia/feed/view/FeedRecyclerAdapter.java
M app/src/main/java/org/wikipedia/search/SearchArticlesFragment.java
M app/src/main/res/values-qq/strings.xml
M app/src/main/res/values/strings.xml
9 files changed, 98 insertions(+), 18 deletions(-)

Approvals:
  BearND: Looks good to me, approved
  Mholloway: Looks good to me, but someone else must approve
  jenkins-bot: Verified



diff --git a/app/src/main/java/org/wikipedia/MainActivity.java 
b/app/src/main/java/org/wikipedia/MainActivity.java
index 54ec68a..791b307 100644
--- a/app/src/main/java/org/wikipedia/MainActivity.java
+++ b/app/src/main/java/org/wikipedia/MainActivity.java
@@ -3,6 +3,7 @@
 import android.annotation.TargetApi;
 import android.app.SearchManager;
 import android.appwidget.AppWidgetManager;
+import android.content.ActivityNotFoundException;
 import android.content.ComponentName;
 import android.content.DialogInterface;
 import android.content.Intent;
@@ -13,6 +14,7 @@
 import android.os.Bundle;
 import android.os.Handler;
 import android.os.Looper;
+import android.speech.RecognizerIntent;
 import android.support.annotation.NonNull;
 import android.support.annotation.Nullable;
 import android.support.design.widget.BottomSheetDialog;
@@ -102,6 +104,7 @@
     public static final int ACTIVITY_REQUEST_LANGLINKS = 0;
     public static final int ACTIVITY_REQUEST_EDIT_SECTION = 1;
     public static final int ACTIVITY_REQUEST_GALLERY = 2;
+    public static final int ACTIVITY_REQUEST_VOICE_SEARCH = 3;
 
     public static final int PROGRESS_BAR_MAX_VALUE = 10000;
 
@@ -411,6 +414,15 @@
         return true;
     }
 
+    public void setSearchMode(boolean enabled) {
+        // invalidate our ActionBar, so that all action items are removed, and
+        // we can fill up the whole width of the ActionBar with our SearchView.
+        supportInvalidateOptionsMenu();
+        toolbarCoordinator.setSearchMode(enabled);
+        getSearchBarHideHandler().setForceNoFade(enabled);
+        getDrawerToggle().setDrawerIndicatorEnabled(!enabled);
+    }
+
     public void showToolbar() {
         ViewAnimations.ensureTranslationY(toolbarContainer, 0);
     }
@@ -456,7 +468,7 @@
             handleProcessTextIntent(intent);
         } else if (intent.hasExtra(EXTRA_SEARCH_FROM_WIDGET)) {
             new IntentFunnel(app).logSearchWidgetTap();
-            openSearch();
+            openSearchFromIntent();
         } else if (intent.hasExtra(EXTRA_FEATURED_ARTICLE_FROM_WIDGET)) {
             new IntentFunnel(app).logFeaturedArticleWidgetTap();
             loadMainPageInForegroundTab();
@@ -469,7 +481,7 @@
 
     private void handleShareIntent(Intent intent) {
         String text = intent.getStringExtra(Intent.EXTRA_TEXT);
-        openSearch(text == null ? null : text.trim());
+        openSearchFromIntent(text == null ? null : text.trim(), true);
     }
 
     @TargetApi(Build.VERSION_CODES.M)
@@ -478,18 +490,18 @@
             return;
         }
         String text = intent.getStringExtra(Intent.EXTRA_PROCESS_TEXT);
-        openSearch(text == null ? null : text.trim());
+        openSearchFromIntent(text == null ? null : text.trim(), true);
     }
 
-    private void openSearch() {
-        openSearch(null);
+    private void openSearchFromIntent() {
+        openSearchFromIntent(null, true);
     }
 
-    private void openSearch(@Nullable final CharSequence query) {
+    private void openSearchFromIntent(@Nullable final CharSequence query, 
final boolean fromWidget) {
         fragmentContainerView.post(new Runnable() {
             @Override
             public void run() {
-                searchFragment.setLaunchedFromWidget(true);
+                searchFragment.setLaunchedFromWidget(fromWidget);
                 searchFragment.openSearch();
                 if (query != null) {
                     searchFragment.setSearchText(query);
@@ -814,6 +826,16 @@
     }
 
     @Override
+    public void onFeedVoiceSearchRequested() {
+        Intent intent = new Intent(RecognizerIntent.ACTION_RECOGNIZE_SPEECH);
+        try {
+            startActivityForResult(intent, ACTIVITY_REQUEST_VOICE_SEARCH);
+        } catch (ActivityNotFoundException a) {
+            FeedbackUtil.showMessage(this, 
R.string.error_voice_search_not_available);
+        }
+    }
+
+    @Override
     public void onFeedSelectPage(PageTitle title) {
         loadPage(title, new HistoryEntry(title, HistoryEntry.SOURCE_FEED));
     }
@@ -959,6 +981,8 @@
             handleLoginActivityResult(resultCode);
         } else if (newArticleLanguageSelected(requestCode, resultCode) || 
galleryFilePageSelected(requestCode, resultCode)) {
             handleLangLinkOrFilePageResult(data);
+        } else if (voiceSearchRequested(requestCode)) {
+            handleVoiceSearchResult(resultCode, data);
         } else {
             super.onActivityResult(requestCode, resultCode, data);
         }
@@ -1076,6 +1100,18 @@
         return resultCode == SettingsActivity.ACTIVITY_RESULT_LANGUAGE_CHANGED;
     }
 
+    private boolean voiceSearchRequested(int requestCode) {
+        return requestCode == ACTIVITY_REQUEST_VOICE_SEARCH;
+    }
+
+    private void handleVoiceSearchResult(int resultCode, Intent data) {
+        if (resultCode == RESULT_OK && data != null
+                && 
data.getStringArrayListExtra(RecognizerIntent.EXTRA_RESULTS) != null) {
+            String searchQuery = 
data.getStringArrayListExtra(RecognizerIntent.EXTRA_RESULTS).get(0);
+            openSearchFromIntent(searchQuery, false);
+        }
+    }
+
     /**
      * Reload the main page in the new language, after delaying for one second 
in order to:
      * (1) Make sure that onStart in MainActivity gets called, thus 
registering the activity for the bus.
@@ -1103,4 +1139,4 @@
         widgetIntent.putExtra(AppWidgetManager.EXTRA_APPWIDGET_IDS, ids);
         sendBroadcast(widgetIntent);
     }
-}
\ No newline at end of file
+}
diff --git 
a/app/src/main/java/org/wikipedia/MainActivityToolbarCoordinator.java 
b/app/src/main/java/org/wikipedia/MainActivityToolbarCoordinator.java
index e549967..13bc2e5 100644
--- a/app/src/main/java/org/wikipedia/MainActivityToolbarCoordinator.java
+++ b/app/src/main/java/org/wikipedia/MainActivityToolbarCoordinator.java
@@ -29,6 +29,12 @@
         setActivityToolbar(defaultToolbar);
     }
 
+    public void setSearchMode(boolean enabled) {
+        if (overrideToolbar != null) {
+            defaultToolbar.setVisibility(enabled ? View.VISIBLE : View.GONE);
+        }
+    }
+
     private void setActivityToolbar(Toolbar toolbar) {
         activity.setSupportActionBar(toolbar);
         activity.getSupportActionBar().setDisplayHomeAsUpEnabled(true);
diff --git a/app/src/main/java/org/wikipedia/feed/FeedFragment.java 
b/app/src/main/java/org/wikipedia/feed/FeedFragment.java
index b610639..df5c02d 100644
--- a/app/src/main/java/org/wikipedia/feed/FeedFragment.java
+++ b/app/src/main/java/org/wikipedia/feed/FeedFragment.java
@@ -43,6 +43,7 @@
 
     public interface Callback extends CallbackFragment.Callback {
         void onFeedSearchRequested();
+        void onFeedVoiceSearchRequested();
         void onFeedSelectPage(PageTitle title);
         void onFeedAddPageToList(PageTitle title);
     }
@@ -142,5 +143,19 @@
                 getCallback().onFeedAddPageToList(title);
             }
         }
+
+        @Override
+        public void onSearchRequested() {
+            if (getCallback() != null) {
+                getCallback().onFeedSearchRequested();
+            }
+        }
+
+        @Override
+        public void onVoiceSearchRequested() {
+            if (getCallback() != null) {
+                getCallback().onFeedVoiceSearchRequested();
+            }
+        }
     }
 }
diff --git a/app/src/main/java/org/wikipedia/feed/FeedViewCallback.java 
b/app/src/main/java/org/wikipedia/feed/FeedViewCallback.java
index 7954be9..1816d9a 100644
--- a/app/src/main/java/org/wikipedia/feed/FeedViewCallback.java
+++ b/app/src/main/java/org/wikipedia/feed/FeedViewCallback.java
@@ -7,4 +7,6 @@
 public interface FeedViewCallback {
     void onSelectPage(@NonNull PageTitle title);
     void onAddPageToList(@NonNull PageTitle title);
+    void onSearchRequested();
+    void onVoiceSearchRequested();
 }
diff --git a/app/src/main/java/org/wikipedia/feed/searchbar/SearchCardView.java 
b/app/src/main/java/org/wikipedia/feed/searchbar/SearchCardView.java
index 1b6d0f2..289776d 100644
--- a/app/src/main/java/org/wikipedia/feed/searchbar/SearchCardView.java
+++ b/app/src/main/java/org/wikipedia/feed/searchbar/SearchCardView.java
@@ -2,10 +2,12 @@
 
 import android.content.Context;
 import android.support.annotation.NonNull;
+import android.support.annotation.Nullable;
 import android.support.v7.widget.CardView;
 import android.view.View;
 
 import org.wikipedia.R;
+import org.wikipedia.feed.FeedViewCallback;
 import org.wikipedia.util.FeedbackUtil;
 
 import butterknife.BindView;
@@ -14,6 +16,7 @@
 public class SearchCardView extends CardView {
     @BindView(R.id.search_container) View searchContainer;
     @BindView(R.id.voice_search_button) View voiceSearchButton;
+    @Nullable private FeedViewCallback callback;
 
     public SearchCardView(Context context) {
         super(context);
@@ -21,6 +24,29 @@
         inflate(getContext(), R.layout.view_search_bar, this);
         ButterKnife.bind(this);
         FeedbackUtil.setToolbarButtonLongPressToast(voiceSearchButton);
+
+        searchContainer.setOnClickListener(new OnClickListener() {
+            @Override
+            public void onClick(View v) {
+                if (callback != null) {
+                    callback.onSearchRequested();
+                }
+            }
+        });
+
+        voiceSearchButton.setOnClickListener(new OnClickListener() {
+            @Override
+            public void onClick(View v) {
+                if (callback != null) {
+                    callback.onVoiceSearchRequested();
+                }
+            }
+        });
+    }
+
+    @NonNull public SearchCardView setCallback(@Nullable FeedViewCallback 
callback) {
+        this.callback = callback;
+        return this;
     }
 
     public void set(@NonNull SearchCard card) {
diff --git a/app/src/main/java/org/wikipedia/feed/view/FeedRecyclerAdapter.java 
b/app/src/main/java/org/wikipedia/feed/view/FeedRecyclerAdapter.java
index 5faf189..d477abd 100644
--- a/app/src/main/java/org/wikipedia/feed/view/FeedRecyclerAdapter.java
+++ b/app/src/main/java/org/wikipedia/feed/view/FeedRecyclerAdapter.java
@@ -86,7 +86,7 @@
             case VIEW_TYPE_BECAUSE_YOU_READ:
                 return new 
BecauseYouReadCardView(context).setCallback(callback);
             case VIEW_TYPE_SEARCH_BAR:
-                return new SearchCardView(context);
+                return new SearchCardView(context).setCallback(callback);
             case VIEW_TYPE_MOST_READ:
                 return new MostReadCardView(context);
             default:
diff --git a/app/src/main/java/org/wikipedia/search/SearchArticlesFragment.java 
b/app/src/main/java/org/wikipedia/search/SearchArticlesFragment.java
index 7edf43b..b30aead 100644
--- a/app/src/main/java/org/wikipedia/search/SearchArticlesFragment.java
+++ b/app/src/main/java/org/wikipedia/search/SearchArticlesFragment.java
@@ -248,12 +248,8 @@
         funnel = new SearchFunnel(WikipediaApp.getInstance());
         funnel.searchStart();
         isSearchActive = true;
-        // invalidate our activity's ActionBar, so that all action items are 
removed, and
-        // we can fill up the whole width of the ActionBar with our SearchView.
-        getActivity().supportInvalidateOptionsMenu();
-        
((MainActivity)getActivity()).getSearchBarHideHandler().setForceNoFade(true);
         setSearchViewEnabled(true);
-        ((MainActivity) 
getActivity()).getDrawerToggle().setDrawerIndicatorEnabled(false);
+        ((MainActivity) getActivity()).setSearchMode(true);
         // show ourselves
         searchContainerView.setVisibility(View.VISIBLE);
 
@@ -267,11 +263,8 @@
 
     public void closeSearch() {
         isSearchActive = false;
-        // invalidate our activity's ActionBar, so that the original action 
items are restored.
-        getActivity().supportInvalidateOptionsMenu();
-        
((MainActivity)getActivity()).getSearchBarHideHandler().setForceNoFade(false);
         setSearchViewEnabled(false);
-        ((MainActivity) 
getActivity()).getDrawerToggle().setDrawerIndicatorEnabled(true);
+        ((MainActivity) getActivity()).setSearchMode(false);
         // hide ourselves
         searchContainerView.setVisibility(View.GONE);
         hideSoftKeyboard(getActivity());
diff --git a/app/src/main/res/values-qq/strings.xml 
b/app/src/main/res/values-qq/strings.xml
index a3ce57c..aa8b8b8 100644
--- a/app/src/main/res/values-qq/strings.xml
+++ b/app/src/main/res/values-qq/strings.xml
@@ -403,4 +403,5 @@
 {{Identical|Preferences}}</string>
   <string name="view_continue_reading_card_title">Label for card in the feed 
that reminds the user to continue reading an article from their browsing 
history.</string>
   <string name="view_because_you_read_card_title">Label for card in the feed 
that gives the user reading suggestions based on an article from their browsing 
history.</string>
+  <string name="error_voice_search_not_available">Error displayed when the 
device does not support voice recognition.</string>
 </resources>
diff --git a/app/src/main/res/values/strings.xml 
b/app/src/main/res/values/strings.xml
index 52481b0..d1d051c 100644
--- a/app/src/main/res/values/strings.xml
+++ b/app/src/main/res/values/strings.xml
@@ -253,6 +253,7 @@
     <string name="preference_title_show_link_previews">Show link 
previews</string>
     <string name="preference_summary_show_link_previews">Show a quick preview 
of articles when tapping on links.</string>
     <string name="nav_item_donate">Support Wikipedia</string>
+    <string name="error_voice_search_not_available">Sorry, voice recognition 
is not available.</string>
 
     <!-- Crash reporter -->
     <string name="crash_report_dialog_title">Sorry, app crashed last 
time</string>

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

Gerrit-MessageType: merged
Gerrit-Change-Id: Iff74f9054f1f6913dc1e15d433cc78e6283d1e9e
Gerrit-PatchSet: 4
Gerrit-Project: apps/android/wikipedia
Gerrit-Branch: master
Gerrit-Owner: Dbrant <dbr...@wikimedia.org>
Gerrit-Reviewer: BearND <bsitzm...@wikimedia.org>
Gerrit-Reviewer: Brion VIBBER <br...@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