Bug 961773 - (Part 2) Check to make sure a panel is in the adapter before setting it as the current item in HomePager. r=lucasr
authorMargaret Leibovic <margaret.leibovic@gmail.com>
Wed, 12 Feb 2014 14:42:35 -0800
changeset 168880 bf91ce1c9102c4fa406a8a8e95ac5346aa5bcd27
parent 168879 90a3bd215dff141e0045740815ce9dd27b6d0df1
child 168881 3d831d84bd76145ac5b5b8a248252ab55276e0ef
push id270
push userpvanderbeken@mozilla.com
push dateThu, 06 Mar 2014 09:24:21 +0000
reviewerslucasr
bugs961773
milestone30.0a1
Bug 961773 - (Part 2) Check to make sure a panel is in the adapter before setting it as the current item in HomePager. r=lucasr
mobile/android/base/home/HomePager.java
--- a/mobile/android/base/home/HomePager.java
+++ b/mobile/android/base/home/HomePager.java
@@ -313,20 +313,21 @@ public class HomePager extends ViewPager
         // Hide the tab strip if the new configuration contains no panels.
         final int count = enabledPanels.size();
         mTabStrip.setVisibility(count > 0 ? View.VISIBLE : View.INVISIBLE);
         // Re-install the adapter with the final state
         // in the pager.
         setAdapter(adapter);
 
         // Use the default panel as defined in the HomePager's configuration
-        // if the initial panel wasn't explicitly set by the show() caller.
-        if (mInitialPanelId != null) {
-            // XXX: Handle the case where the desired panel isn't currently in the adapter (bug 949178)
-            setCurrentItem(adapter.getItemPosition(mInitialPanelId), false);
+        // if the initial panel wasn't explicitly set by the show() caller,
+        // or if the initial panel is not found in the adapter.
+        final int itemPosition = (mInitialPanelId == null) ? -1 : adapter.getItemPosition(mInitialPanelId);
+        if (itemPosition > -1) {
+            setCurrentItem(itemPosition, false);
             mInitialPanelId = null;
         } else {
             for (int i = 0; i < count; i++) {
                 final PanelConfig panelConfig = enabledPanels.get(i);
                 if (panelConfig.isDefault()) {
                     setCurrentItem(i, false);
                     break;
                 }