leanback: Add example of section header and divider

Add example of SectionRow and Divider Row.

Also remove the need of adding hidden class PageRowPresenter to
Adapter,  it is automatically added by BrowseFragment.

Bug 28270725

Change-Id: I8f9a7ca40fab10d64f536b67d44fbe7aa9e99e17
diff --git a/samples/SupportLeanbackDemos/src/com/example/android/leanback/BrowseFragment.java b/samples/SupportLeanbackDemos/src/com/example/android/leanback/BrowseFragment.java
index afd4038..cb21c95 100644
--- a/samples/SupportLeanbackDemos/src/com/example/android/leanback/BrowseFragment.java
+++ b/samples/SupportLeanbackDemos/src/com/example/android/leanback/BrowseFragment.java
@@ -23,12 +23,13 @@
 import android.support.v17.leanback.widget.ArrayObjectAdapter;
 import android.support.v17.leanback.widget.HeaderItem;
 import android.support.v17.leanback.widget.ImageCardView;
+import android.support.v17.leanback.widget.DividerRow;
+import android.support.v17.leanback.widget.SectionRow;
 import android.support.v17.leanback.widget.ListRow;
 import android.support.v17.leanback.widget.ListRowPresenter;
 import android.support.v17.leanback.widget.OnItemViewClickedListener;
 import android.support.v17.leanback.widget.OnItemViewSelectedListener;
 import android.support.v17.leanback.widget.PageRow;
-import android.support.v17.leanback.widget.PageRowPresenter;
 import android.support.v17.leanback.widget.Presenter;
 import android.support.v17.leanback.widget.PresenterSelector;
 import android.support.v17.leanback.widget.Row;
@@ -114,23 +115,23 @@
     }
 
     private void setupRows() {
-        mRowsAdapter = new ArrayObjectAdapter(new MyPresenterSelector());
+        mRowsAdapter = new ArrayObjectAdapter(new ListRowPresenter());
         setAdapter(mRowsAdapter);
     }
 
     private void loadData() {
         int i = 0;
 
-        HeaderItem header = new HeaderItem(HEADER_ID1, "Page Row " + 0);
-        mRowsAdapter.add(new PageRow(header));
+        mRowsAdapter.add(new PageRow(new HeaderItem(HEADER_ID1, "Page Row 0")));
+        mRowsAdapter.add(new DividerRow());
 
+        mRowsAdapter.add(new SectionRow(new HeaderItem("section 0")));
         for (; i < NUM_ROWS; ++i) {
-            header = new HeaderItem(i, "Row " + i);
-            mRowsAdapter.add(new ListRow(header, createListRowAdapter(i)));
+            mRowsAdapter.add(new ListRow(new HeaderItem(i, "Row " + i), createListRowAdapter(i)));
         }
 
-        header = new HeaderItem(HEADER_ID2, "Page Row " + 1);
-        mRowsAdapter.add(new PageRow(header));
+        mRowsAdapter.add(new DividerRow());
+        mRowsAdapter.add(new PageRow(new HeaderItem(HEADER_ID2, "Page Row 1")));
     }
 
     private ArrayObjectAdapter createListRowAdapter(int i) {
@@ -346,24 +347,5 @@
         }
     }
 
-    private static class MyPresenterSelector extends PresenterSelector {
-        private Presenter[] presenters = {
-                new ListRowPresenter(),
-                new PageRowPresenter()
-        };
-
-        @Override
-        public Presenter getPresenter(Object item) {
-            if (item instanceof PageRow) {
-                return presenters[1];
-            }
-            return presenters[0];
-        }
-
-        @Override
-        public Presenter[] getPresenters() {
-            return presenters;
-        }
-    }
 }
 
diff --git a/samples/SupportLeanbackDemos/src/com/example/android/leanback/BrowseSupportFragment.java b/samples/SupportLeanbackDemos/src/com/example/android/leanback/BrowseSupportFragment.java
index 02da218..423c129 100644
--- a/samples/SupportLeanbackDemos/src/com/example/android/leanback/BrowseSupportFragment.java
+++ b/samples/SupportLeanbackDemos/src/com/example/android/leanback/BrowseSupportFragment.java
@@ -25,12 +25,13 @@
 import android.support.v17.leanback.widget.ArrayObjectAdapter;
 import android.support.v17.leanback.widget.HeaderItem;
 import android.support.v17.leanback.widget.ImageCardView;
+import android.support.v17.leanback.widget.DividerRow;
+import android.support.v17.leanback.widget.SectionRow;
 import android.support.v17.leanback.widget.ListRow;
 import android.support.v17.leanback.widget.ListRowPresenter;
 import android.support.v17.leanback.widget.OnItemViewClickedListener;
 import android.support.v17.leanback.widget.OnItemViewSelectedListener;
 import android.support.v17.leanback.widget.PageRow;
-import android.support.v17.leanback.widget.PageRowPresenter;
 import android.support.v17.leanback.widget.Presenter;
 import android.support.v17.leanback.widget.PresenterSelector;
 import android.support.v17.leanback.widget.Row;
@@ -116,23 +117,23 @@
     }
 
     private void setupRows() {
-        mRowsAdapter = new ArrayObjectAdapter(new MyPresenterSelector());
+        mRowsAdapter = new ArrayObjectAdapter(new ListRowPresenter());
         setAdapter(mRowsAdapter);
     }
 
     private void loadData() {
         int i = 0;
 
-        HeaderItem header = new HeaderItem(HEADER_ID1, "Page Row " + 0);
-        mRowsAdapter.add(new PageRow(header));
+        mRowsAdapter.add(new PageRow(new HeaderItem(HEADER_ID1, "Page Row 0")));
+        mRowsAdapter.add(new DividerRow());
 
+        mRowsAdapter.add(new SectionRow(new HeaderItem("section 0")));
         for (; i < NUM_ROWS; ++i) {
-            header = new HeaderItem(i, "Row " + i);
-            mRowsAdapter.add(new ListRow(header, createListRowAdapter(i)));
+            mRowsAdapter.add(new ListRow(new HeaderItem(i, "Row " + i), createListRowAdapter(i)));
         }
 
-        header = new HeaderItem(HEADER_ID2, "Page Row " + 1);
-        mRowsAdapter.add(new PageRow(header));
+        mRowsAdapter.add(new DividerRow());
+        mRowsAdapter.add(new PageRow(new HeaderItem(HEADER_ID2, "Page Row 1")));
     }
 
     private ArrayObjectAdapter createListRowAdapter(int i) {
@@ -329,6 +330,12 @@
         }
 
         @Override
+        public void onStart() {
+            super.onStart();
+            mMainFragmentAdapter.getFragmentHost().notifyViewCreated(mMainFragmentAdapter);
+        }
+
+        @Override
         public void onViewCreated(View view, Bundle savedInstanceState) {
             setEntranceTransitionState(mEntranceTransitionState);
         }
@@ -342,24 +349,5 @@
         }
     }
 
-    private static class MyPresenterSelector extends PresenterSelector {
-        private Presenter[] presenters = {
-                new ListRowPresenter(),
-                new PageRowPresenter()
-        };
-
-        @Override
-        public Presenter getPresenter(Object item) {
-            if (item instanceof PageRow) {
-                return presenters[1];
-            }
-            return presenters[0];
-        }
-
-        @Override
-        public Presenter[] getPresenters() {
-            return presenters;
-        }
-    }
 }