Add missing PreferenceLayouts when querying item type

If a preference object's layout or widget layout changes after it's added
it won't appear in the list of PreferenceLayout objects, so we'll mistakenly
return -1 as the item type and then won't have a clue what to inflate in
onCreatViewHolder. Thus we need to ensure we fill in any missing PreferenceLayout
objects when checking the view type.

The majority of PreferenceLayout objects are still created during hierarchy
refresh, to keep things performant during scrolling etc.

b/24961118

Change-Id: I11be124594eb4ccbf006612238227c96d5b64af8
diff --git a/v7/preference/src/android/support/v7/preference/PreferenceGroupAdapter.java b/v7/preference/src/android/support/v7/preference/PreferenceGroupAdapter.java
index 9943087..c4ccc66 100644
--- a/v7/preference/src/android/support/v7/preference/PreferenceGroupAdapter.java
+++ b/v7/preference/src/android/support/v7/preference/PreferenceGroupAdapter.java
@@ -79,6 +79,14 @@
         private int widgetResId;
         private String name;
 
+        public PreferenceLayout() {}
+
+        public PreferenceLayout(PreferenceLayout other) {
+            resId = other.resId;
+            widgetResId = other.widgetResId;
+            name = other.name;
+        }
+
         @Override
         public boolean equals(Object o) {
             if (!(o instanceof PreferenceLayout)) {
@@ -249,7 +257,14 @@
 
         mTempPreferenceLayout = createPreferenceLayout(preference, mTempPreferenceLayout);
 
-        return mPreferenceLayouts.indexOf(mTempPreferenceLayout);
+        int viewType = mPreferenceLayouts.indexOf(mTempPreferenceLayout);
+        if (viewType != -1) {
+            return viewType;
+        } else {
+            viewType = mPreferenceLayouts.size();
+            mPreferenceLayouts.add(new PreferenceLayout(mTempPreferenceLayout));
+            return viewType;
+        }
     }
 
     @Override