Backed out changeset f464c44bf882 (bug 1220928)
authorCarsten "Tomcat" Book <cbook@mozilla.com>
Wed, 30 Mar 2016 14:38:06 +0200
changeset 290891 d27578912ddd678b2a6f428da25924573508d7ba
parent 290890 6c3e6356f8a75eb3b6171d02c67e96b27b43bb14
child 290892 52247b54de2a3bfd7ce377ced22fd7e706878712
push id19656
push usergwagner@mozilla.com
push dateMon, 04 Apr 2016 13:43:23 +0000
treeherderb2g-inbound@e99061fde28a [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
bugs1220928
milestone48.0a1
backs outf464c44bf88255e4aafe3fa64900aa13c0905339
Backed out changeset f464c44bf882 (bug 1220928)
mobile/android/base/java/org/mozilla/gecko/home/CombinedHistoryAdapter.java
--- a/mobile/android/base/java/org/mozilla/gecko/home/CombinedHistoryAdapter.java
+++ b/mobile/android/base/java/org/mozilla/gecko/home/CombinedHistoryAdapter.java
@@ -3,41 +3,29 @@
  * 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;
 
 import android.support.v7.widget.RecyclerView;
 
 import android.content.Context;
 import android.database.Cursor;
-import android.util.Log;
 import android.view.LayoutInflater;
 import android.view.View;
 import android.view.ViewGroup;
 import org.mozilla.gecko.R;
 import org.mozilla.gecko.db.RemoteClient;
 
 import java.util.Collections;
 import java.util.List;
 
 public class CombinedHistoryAdapter extends RecyclerView.Adapter<CombinedHistoryItem> {
-    private static final String LOGTAG = "GeckoCombinedHistAdapt";
+    // These ordinal positions are used in CombinedHistoryAdapter as viewType.
     private enum ItemType {
-        CLIENT, HISTORY;
-
-        public static ItemType viewTypeToItemType(int viewType) {
-            if (viewType >= ItemType.values().length) {
-                Log.e(LOGTAG, "No corresponding ItemType!");
-            }
-            return ItemType.values()[viewType];
-        }
-
-        public static int itemTypeToViewType(ItemType itemType) {
-            return itemType.ordinal();
-        }
+        CLIENT, HISTORY
     }
 
     private List<RemoteClient> remoteClients = Collections.emptyList();
     private Cursor historyCursor;
     private final Context context;
 
     public CombinedHistoryAdapter(Context context) {
         super();
@@ -53,55 +41,50 @@ public class CombinedHistoryAdapter exte
         historyCursor = history;
         notifyDataSetChanged();
     }
 
     private int transformPosition(ItemType type, int position) {
         if (type == ItemType.CLIENT) {
             return position;
         } else {
-            return position - remoteClients.size();
+            return position - (remoteClients == null ? 0 : remoteClients.size());
         }
     }
 
     @Override
     public CombinedHistoryItem onCreateViewHolder(ViewGroup viewGroup, int viewType) {
         final LayoutInflater inflater = LayoutInflater.from(viewGroup.getContext());
         final View view;
 
-        final ItemType itemType = ItemType.viewTypeToItemType(viewType);
-
-        switch (itemType) {
-            case CLIENT:
-                view = inflater.inflate(R.layout.home_remote_tabs_group, viewGroup, false);
-                return new CombinedHistoryItem.ClientItem(view);
-            case HISTORY:
-                view = inflater.inflate(R.layout.home_item_row, viewGroup, false);
-                return new CombinedHistoryItem.HistoryItem(view);
-            default:
-                throw new IllegalArgumentException("Unexpected Home Panel item type");
+        if (viewType == ItemType.CLIENT.ordinal()) {
+            view = inflater.inflate(R.layout.home_remote_tabs_group, viewGroup, false);
+            return new CombinedHistoryItem.ClientItem(view);
+        } else {
+            view = inflater.inflate(R.layout.home_item_row, viewGroup, false);
+            return new CombinedHistoryItem.HistoryItem(view);
         }
     }
 
     @Override
     public int getItemViewType(int position) {
         final int numClients = remoteClients.size();
-        return (position < numClients) ? ItemType.itemTypeToViewType(ItemType.CLIENT) : ItemType.itemTypeToViewType(ItemType.HISTORY);
+        return (position < numClients) ? ItemType.CLIENT.ordinal() : ItemType.HISTORY.ordinal();
     }
 
     @Override
     public int getItemCount() {
         final int remoteSize = remoteClients.size();
         final int historySize = historyCursor == null ? 0 : historyCursor.getCount();
         return remoteSize + historySize;
     }
 
     @Override
     public void onBindViewHolder(CombinedHistoryItem viewHolder, int position) {
-        final ItemType itemType = ItemType.viewTypeToItemType(getItemViewType(position));
+        final ItemType itemType = ItemType.values()[getItemViewType(position)];
         final int localPosition = transformPosition(itemType, position);
 
         switch (itemType) {
             case CLIENT:
                 final CombinedHistoryItem.ClientItem clientItem = (CombinedHistoryItem.ClientItem) viewHolder;
                 final RemoteClient client = remoteClients.get(localPosition);
                 clientItem.bind(client, context);
                 break;