Bug 1000616 - Fix clicks on items when empty views and panel views are swapped. r=lucasr
authorMargaret Leibovic <margaret.leibovic@gmail.com>
Fri, 25 Apr 2014 08:29:24 -0700
changeset 180670 548827cce8d7209cb5604ced64d3c4b77ef49b95
parent 180669 0bfe1f94e8748674542edc4333bd6810b71f802d
child 180671 528ed2029bc27fb1111f1de9697b4011b80a951a
push id272
push userpvanderbeken@mozilla.com
push dateMon, 05 May 2014 16:31:18 +0000
reviewerslucasr
bugs1000616
milestone31.0a1
Bug 1000616 - Fix clicks on items when empty views and panel views are swapped. r=lucasr * * * 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 viewConfig;
     private final PanelViewAdapter adapter;
     private PanelViewItemHandler itemHandler;
+    private OnItemOpenListener itemOpenListener;
 
     public PanelGridView(Context context, ViewConfig viewConfig) {
         super(context, null, R.attr.panelGridViewStyle);
 
         this.viewConfig = viewConfig;
         itemHandler = new PanelViewItemHandler(viewConfig);
 
         adapter = new PanelViewAdapter(context, viewConfig);
         setAdapter(adapter);
 
         setOnItemClickListener(new PanelGridItemClickListener());
     }
 
     @Override
+    public void onAttachedToWindow() {
+        super.onAttachedToWindow();
+        itemHandler.setOnItemOpenListener(itemOpenListener);
+    }
+
+    @Override
     public void onDetachedFromWindow() {
         super.onDetachedFromWindow();
         itemHandler.setOnItemOpenListener(null);
     }
 
     @Override
     public void setDataset(Cursor cursor) {
+        Log.d(LOGTAG, "Setting dataset: " + viewConfig.getDatasetId());
         adapter.swapCursor(cursor);
     }
 
     @Override
     public void setOnItemOpenListener(OnItemOpenListener listener) {
         itemHandler.setOnItemOpenListener(listener);
+        itemOpenListener = listener;
     }
 
     @Override
     public void setFilterManager(FilterManager filterManager) {
         adapter.setFilterManager(filterManager);
         itemHandler.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);
         }
     }
 }