Bug 1000616 - Fix clicks on items when empty views and panel views are swapped. r=lucasr a=lsblakk
authorMargaret Leibovic <margaret.leibovic@gmail.com>
Fri, 25 Apr 2014 08:29:24 -0700
changeset 192135 e67471d96cb659b73c5f4e2ca6ff721ffa45f36d
parent 192134 41b3780cc1d36bb31aa163fb8a2deec7965b9beb
child 192136 c763c8695fe47f682d62aa72d9d1ac639ff7ff48
push id3503
push userraliiev@mozilla.com
push dateMon, 28 Apr 2014 18:51:11 +0000
treeherdermozilla-beta@c95ac01e332e [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerslucasr, lsblakk
bugs1000616
milestone30.0a2
Bug 1000616 - Fix clicks on items when empty views and panel views are swapped. r=lucasr a=lsblakk * * * Bug 1000616 - (Part 1) Make PanelListView and PanelGridView variable naming and implementation consistent * * * Bug 1000616 - (Part 2) Reset OnItemOpenListener when PanelViews are reattached
mobile/android/base/home/PanelGridView.java
mobile/android/base/home/PanelListView.java
--- a/mobile/android/base/home/PanelGridView.java
+++ b/mobile/android/base/home/PanelGridView.java
@@ -14,54 +14,64 @@ import org.mozilla.gecko.home.HomeConfig
 import org.mozilla.gecko.home.HomePager.OnUrlOpenListener;
 import org.mozilla.gecko.home.PanelLayout.DatasetBacked;
 import org.mozilla.gecko.home.PanelLayout.FilterManager;
 import org.mozilla.gecko.home.PanelLayout.OnItemOpenListener;
 import org.mozilla.gecko.home.PanelLayout.PanelView;
 
 import android.content.Context;
 import android.database.Cursor;
+import android.util.Log;
 import android.view.View;
 import android.widget.AdapterView;
 import android.widget.GridView;
 
 public class PanelGridView extends GridView
                            implements DatasetBacked, PanelView {
     private static final String LOGTAG = "GeckoPanelGridView";
 
     private final ViewConfig mViewConfig;
     private final PanelViewAdapter mAdapter;
     private PanelViewItemHandler mItemHandler;
+    private OnItemOpenListener mItemOpenListener;
 
     public PanelGridView(Context context, ViewConfig viewConfig) {
         super(context, null, R.attr.panelGridViewStyle);
 
         mViewConfig = viewConfig;
         mItemHandler = new PanelViewItemHandler(viewConfig);
 
         mAdapter = new PanelViewAdapter(context, viewConfig);
         setAdapter(mAdapter);
 
         setOnItemClickListener(new PanelGridItemClickListener());
     }
 
     @Override
+    public void onAttachedToWindow() {
+        super.onAttachedToWindow();
+        mItemHandler.setOnItemOpenListener(mItemOpenListener);
+    }
+
+    @Override
     public void onDetachedFromWindow() {
         super.onDetachedFromWindow();
         mItemHandler.setOnItemOpenListener(null);
     }
 
     @Override
     public void setDataset(Cursor cursor) {
+        Log.d(LOGTAG, "Setting dataset: " + mViewConfig.getDatasetId());
         mAdapter.swapCursor(cursor);
     }
 
     @Override
     public void setOnItemOpenListener(OnItemOpenListener listener) {
         mItemHandler.setOnItemOpenListener(listener);
+        mItemOpenListener = listener;
     }
 
     @Override
     public void setFilterManager(FilterManager filterManager) {
         mAdapter.setFilterManager(filterManager);
         mItemHandler.setFilterManager(filterManager);
     }
 
--- a/mobile/android/base/home/PanelListView.java
+++ b/mobile/android/base/home/PanelListView.java
@@ -22,54 +22,62 @@ import android.util.Log;
 import android.view.View;
 import android.widget.AdapterView;
 
 public class PanelListView extends HomeListView
                            implements DatasetBacked, PanelView {
 
     private static final String LOGTAG = "GeckoPanelListView";
 
-    private final PanelViewAdapter mAdapter;
-    private final ViewConfig mViewConfig;
-    private final PanelViewItemHandler mItemHandler;
+    private final ViewConfig viewConfig;
+    private final PanelViewAdapter adapter;
+    private final PanelViewItemHandler itemHandler;
+    private OnItemOpenListener itemOpenListener;
 
     public PanelListView(Context context, ViewConfig viewConfig) {
         super(context);
 
-        mViewConfig = viewConfig;
-        mItemHandler = new PanelViewItemHandler(viewConfig);
+        this.viewConfig = viewConfig;
+        itemHandler = new PanelViewItemHandler(viewConfig);
 
-        mAdapter = new PanelViewAdapter(context, viewConfig);
-        setAdapter(mAdapter);
+        adapter = new PanelViewAdapter(context, viewConfig);
+        setAdapter(adapter);
 
         setOnItemClickListener(new PanelListItemClickListener());
     }
 
+     @Override
+    public void onAttachedToWindow() {
+        super.onAttachedToWindow();
+        itemHandler.setOnItemOpenListener(itemOpenListener);
+    }
+
     @Override
     public void onDetachedFromWindow() {
         super.onDetachedFromWindow();
-        mItemHandler.setOnItemOpenListener(null);
+        itemHandler.setOnItemOpenListener(null);
     }
 
     @Override
     public void setDataset(Cursor cursor) {
-        Log.d(LOGTAG, "Setting dataset: " + mViewConfig.getDatasetId());
-        mAdapter.swapCursor(cursor);
+        Log.d(LOGTAG, "Setting dataset: " + viewConfig.getDatasetId());
+        adapter.swapCursor(cursor);
     }
 
     @Override
     public void setOnItemOpenListener(OnItemOpenListener listener) {
-        mItemHandler.setOnItemOpenListener(listener);
+        itemHandler.setOnItemOpenListener(listener);
+        itemOpenListener = listener;
     }
 
     @Override
     public void setFilterManager(FilterManager filterManager) {
-        mAdapter.setFilterManager(filterManager);
-        mItemHandler.setFilterManager(filterManager);
+        adapter.setFilterManager(filterManager);
+        itemHandler.setFilterManager(filterManager);
     }
 
     private class PanelListItemClickListener implements AdapterView.OnItemClickListener {
         @Override
         public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
-            mItemHandler.openItemAtPosition(mAdapter.getCursor(), position);
+            itemHandler.openItemAtPosition(adapter.getCursor(), position);
         }
     }
 }