Bug 1013419 - Close the share dialog after sharing. r=bnicholson, a=lsblakk
authorWes Johnston <wjohnston@mozilla.com>
Tue, 27 May 2014 14:06:39 -0700
changeset 193432 d24783ed4ab50d4684f5167366183be2c94778b3
parent 193431 35ec38e5d96ea024a11ad200b0958c4a4475da9c
child 193433 aef210a74b6914c1e09b0e0eb35b4ad6efdc4986
push id474
push userasasaki@mozilla.com
push dateMon, 02 Jun 2014 21:01:02 +0000
treeherdermozilla-release@967f4cf1b31c [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersbnicholson, lsblakk
bugs1013419
milestone30.0
Bug 1013419 - Close the share dialog after sharing. r=bnicholson, a=lsblakk
mobile/android/base/menu/MenuItemActionView.java
mobile/android/base/prompts/PromptListAdapter.java
mobile/android/base/widget/GeckoActionProvider.java
--- a/mobile/android/base/menu/MenuItemActionView.java
+++ b/mobile/android/base/menu/MenuItemActionView.java
@@ -17,23 +17,24 @@ import android.graphics.drawable.Drawabl
 import android.util.AttributeSet;
 import android.view.LayoutInflater;
 import android.view.View;
 import android.widget.ImageButton;
 import android.widget.LinearLayout;
 import android.os.Build;
 
 public class MenuItemActionView extends LinearLayout
-                                implements GeckoMenuItem.Layout {
+                                implements GeckoMenuItem.Layout,
+                                           View.OnClickListener {
     private static final String LOGTAG = "GeckoMenuItemActionView";
 
     private MenuItemDefault mMenuItem;
     private MenuItemActionBar mMenuButton;
     private List<ImageButton> mActionButtons;
-    private View.OnClickListener mActionButtonListener;
+    private List<View.OnClickListener> mActionButtonListeners = new ArrayList<View.OnClickListener>();
 
     public MenuItemActionView(Context context) {
         this(context, null);
     }
 
     public MenuItemActionView(Context context, AttributeSet attrs) {
         this(context, attrs, R.attr.menuItemActionViewStyle);
     }
@@ -96,22 +97,18 @@ public class MenuItemActionView extends 
         }
     }
 
     public void setMenuItemClickListener(View.OnClickListener listener) {
         mMenuItem.setOnClickListener(listener);
         mMenuButton.setOnClickListener(listener);
     }
 
-    public void setActionButtonClickListener(View.OnClickListener listener) {
-        mActionButtonListener = listener;
-
-        for (ImageButton button : mActionButtons) {
-            button.setOnClickListener(listener);
-        }
+    public void addActionButtonClickListener(View.OnClickListener listener) {
+        mActionButtonListeners.add(listener);
     }
 
     @Override
     public void setShowIcon(boolean show) {
         mMenuItem.setShowIcon(show);
     }
 
     public void setIcon(Drawable icon) {
@@ -138,22 +135,29 @@ public class MenuItemActionView extends 
         // If not, make the menu item an icon.
         final int count = mActionButtons.size();
         mMenuItem.setVisibility(View.GONE);
         mMenuButton.setVisibility(View.VISIBLE);
 
         if (drawable != null) {
             ImageButton button = new ImageButton(getContext(), null, R.attr.menuItemShareActionButtonStyle);
             button.setImageDrawable(drawable);
-            button.setOnClickListener(mActionButtonListener);
+            button.setOnClickListener(this);
             button.setTag(count);
 
             final int height = (int) (getResources().getDimension(R.dimen.menu_item_row_height));
             LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(0, height);
             params.weight = 1.0f;
             button.setLayoutParams(params);
 
             // Fill in the action-buttons to the left of the actual menu button.
             mActionButtons.add(button);
             addView(button, count);
         }
     }
+
+    @Override
+    public void onClick(View view) {
+        for (View.OnClickListener listener : mActionButtonListeners) {
+            listener.onClick(view);
+        }
+    }
 }
--- a/mobile/android/base/prompts/PromptListAdapter.java
+++ b/mobile/android/base/prompts/PromptListAdapter.java
@@ -168,26 +168,41 @@ public class PromptListAdapter extends A
         for (int i = 0; i< length; i++) {
             if (isSelected(i)) {
                 return i;
             }
         }
         return -1;
     }
 
-    private View getActionView(PromptListItem item) {
-        GeckoActionProvider provider = GeckoActionProvider.getForType(item.getIntent().getType(), getContext());
+    private View getActionView(PromptListItem item, final ListView list, final int position) {
+        final GeckoActionProvider provider = GeckoActionProvider.getForType(item.getIntent().getType(), getContext());
         provider.setIntent(item.getIntent());
-        return provider.onCreateActionView();
+
+        final MenuItemActionView view = (MenuItemActionView) provider.onCreateActionView();
+        // If a quickshare button is clicked, we need to close the dialog.
+        view.addActionButtonClickListener(new View.OnClickListener() {
+            @Override
+            public void onClick(View v) {
+                ListView.OnItemClickListener listener = list.getOnItemClickListener();
+                if (listener != null) {
+                    listener.onItemClick(list, view, position, position);
+                }
+            }
+        });
+
+        return view;
     }
 
     private void updateActionView(final PromptListItem item, final MenuItemActionView view, final ListView list, final int position) {
         view.setTitle(item.label);
         view.setIcon(item.getIcon());
         view.setSubMenuIndicator(item.isParent);
+
+        // If the share button is clicked, we need to close the dialog and then show an intent chooser
         view.setMenuItemClickListener(new View.OnClickListener() {
             @Override
             public void onClick(View v) {
                 ListView.OnItemClickListener listener = list.getOnItemClickListener();
                 if (listener != null) {
                     listener.onItemClick(list, view, position, position);
                 }
 
@@ -211,17 +226,17 @@ public class PromptListAdapter extends A
     @Override
     public View getView(int position, View convertView, ViewGroup parent) {
         PromptListItem item = getItem(position);
         int type = getItemViewType(position);
         ViewHolder viewHolder = null;
 
         if (convertView == null) {
             if (type == VIEW_TYPE_ACTIONS) {
-                convertView = getActionView(item);
+                convertView = getActionView(item, (ListView) parent, position);
             } else {
                 int resourceId = mResourceId;
                 if (item.isGroup) {
                     resourceId = R.layout.list_item_header;
                 }
 
                 LayoutInflater mInflater = LayoutInflater.from(getContext());
                 convertView = mInflater.inflate(resourceId, null);
--- a/mobile/android/base/widget/GeckoActionProvider.java
+++ b/mobile/android/base/widget/GeckoActionProvider.java
@@ -81,17 +81,17 @@ public class GeckoActionProvider {
     public GeckoActionProvider(Context context) {
         mContext = context;
     }
 
     public View onCreateActionView() {
         // Create the view and set its data model.
         ActivityChooserModel dataModel = ActivityChooserModel.get(mContext, mHistoryFileName);
         MenuItemActionView view = new MenuItemActionView(mContext, null);
-        view.setActionButtonClickListener(mCallbacks);
+        view.addActionButtonClickListener(mCallbacks);
 
         final PackageManager packageManager = mContext.getPackageManager();
         int historySize = dataModel.getDistinctActivityCountInHistory();
         if (historySize > MAX_HISTORY_SIZE) {
             historySize = MAX_HISTORY_SIZE;
         }
 
         // Historical data is dependent on past selection of activities.