Bug 1291751 - Enable searching from ASDetailActivity draft
authorAndrzej Hunt <ahunt@mozilla.com>
Wed, 03 Aug 2016 09:34:45 -0700
changeset 398859 e8ddf6cc2e217050e031fa0e60111cf7c1a47b25
parent 398858 32550b97b94ae15b71f93d86381287115adfc8a3
child 398860 a70612489ec13f7dec804fafaf057dcd49a0f0ba
push id25659
push userahunt@mozilla.com
push dateTue, 09 Aug 2016 21:55:04 +0000
bugs1291751
milestone51.0a1
Bug 1291751 - Enable searching from ASDetailActivity MozReview-Commit-ID: FJSCWQXkVrf
mobile/android/base/java/org/mozilla/gecko/home/activitystream/ASDetailActivity.java
mobile/android/base/java/org/mozilla/gecko/home/activitystream/ASOpenURLDelegate.java
--- a/mobile/android/base/java/org/mozilla/gecko/home/activitystream/ASDetailActivity.java
+++ b/mobile/android/base/java/org/mozilla/gecko/home/activitystream/ASDetailActivity.java
@@ -1,39 +1,43 @@
 /* -*- Mode: Java; c-basic-offset: 4; tab-width: 20; indent-tabs-mode: nil; -*-
  * This Source Code Form is subject to the terms of the Mozilla Public
  * License, v. 2.0. If a copy of the MPL was not distributed with this
  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 package org.mozilla.gecko.home.activitystream;
 
+import android.content.Intent;
 import android.os.Bundle;
 import android.support.annotation.Nullable;
 import android.support.design.widget.TabLayout;
 import android.support.v4.app.Fragment;
 import android.support.v4.app.FragmentPagerAdapter;
 import android.support.v4.view.ViewPager;
 import android.support.v7.app.AppCompatActivity;
 import android.view.View;
-import android.widget.Button;
 import android.widget.ImageView;
 
+import org.mozilla.gecko.BrowserApp;
 import org.mozilla.gecko.R;
 import org.mozilla.gecko.home.CombinedHistoryPanel;
 import org.mozilla.gecko.home.HomeFragment;
 import org.mozilla.gecko.home.HomePager;
+import org.mozilla.gecko.home.activitystream.search.ASSearchActivity;
 
 import java.util.EnumSet;
 
 /**
  * Detail view for history/bookmarks/synced-tabs etc.
  */
 public class ASDetailActivity
         extends AppCompatActivity
         implements HomePager.OnUrlOpenListener, HomePager.OnUrlOpenInBackgroundListener {
-    
+
+    public static final int ACTIVITY_REQUEST_SEARCH = 100;
+
     @Override
     protected void onCreate(@Nullable Bundle savedInstanceState) {
         super.onCreate(savedInstanceState);
 
         setContentView(R.layout.as_detail_activity);
 
         ViewPager pager = (ViewPager) findViewById(R.id.as_pager);
 
@@ -82,21 +86,37 @@ public class ASDetailActivity
 
         final ImageView exitButton = (ImageView) findViewById(R.id.as_close_button);
         exitButton.setOnClickListener(new View.OnClickListener() {
             @Override
             public void onClick(View v) {
                 finish();
             }
         });
+
+        final ImageView searchButton = (ImageView) findViewById(R.id.as_search_button);
+        searchButton.setOnClickListener(new View.OnClickListener() {
+            @Override
+            public void onClick(View v) {
+                Intent i = new Intent(ASDetailActivity.this, ASSearchActivity.class);
+                startActivityForResult(i, ACTIVITY_REQUEST_SEARCH);
+            }
+        });
     }
 
     @Override
     public void onUrlOpen(String url, EnumSet<HomePager.OnUrlOpenListener.Flags> flags) {
         ASOpenURLDelegate.openURL(this, url, flags);
     }
 
     @Override
     public void onUrlOpenInBackground(String url,
                                       EnumSet<HomePager.OnUrlOpenInBackgroundListener.Flags> flags) {
         ASOpenURLDelegate.openInBackground(this, url, flags);
     }
+
+    @Override
+    protected void onActivityResult(int requestCode, int resultCode, Intent data) {
+        if (requestCode == ACTIVITY_REQUEST_SEARCH) {
+            ASOpenURLDelegate.onActivityResult(this, requestCode, resultCode, data);
+        }
+    }
 }
--- a/mobile/android/base/java/org/mozilla/gecko/home/activitystream/ASOpenURLDelegate.java
+++ b/mobile/android/base/java/org/mozilla/gecko/home/activitystream/ASOpenURLDelegate.java
@@ -63,16 +63,25 @@ public class ASOpenURLDelegate extends B
         Bundle flagsBundle = new Bundle();
         flagsBundle.putSerializable(KEY_FLAGS, flags);
         data.putExtra(KEY_FLAGS, flagsBundle);
 
         activity.setResult(BrowserApp.ACTIVITY_RESULT_AS_DETAIL_OPEN, data);
         activity.finish();
     }
 
+    public static void onActivityResult(Activity activity, int requestCode, int resultCode, Intent data) {
+        if (resultCode == BrowserApp.ACTIVITY_RESULT_AS_DETAIL_OPEN) {
+            // Pass results through again - we could have multiple levels of activities e.g.
+            // when search is opened from the detail activity
+            activity.setResult(BrowserApp.ACTIVITY_RESULT_AS_DETAIL_OPEN, data);
+            activity.finish();
+        }
+    }
+
     @SuppressWarnings("unchecked")
     static EnumSet<HomePager.OnUrlOpenListener.Flags> castEnumSetToHomePagerFlags(EnumSet<?> in) {
         // Bundle's only return a Serializable, whereas we're trying to obtain the actual
         // Enumset. Casting to a generic type results in unchecked warnings, which we need to suppress
         // here (there is unfortunately no way around this). We use a separate method to minimise
         // the volume of code with suppressed warnings (warning supressions can't be applied to single
         // lines of code, or even to blocks, but they can be applied to methods). This also gives
         // us the opportunity to verify that we have the correct type parameter. Not checking the type