1816bfc28b79d802b4366684775df74cf40109e6eJerome Poichetpackage com.example.android.leanback;
2816bfc28b79d802b4366684775df74cf40109e6eJerome Poichet
308a38559a3751252fc8a1f36db0a431508a8f7d5jingjiangliimport static com.example.android.leanback.CardPresenter.CONTENT;
408a38559a3751252fc8a1f36db0a431508a8f7d5jingjiangliimport static com.example.android.leanback.CardPresenter.IMAGE;
508a38559a3751252fc8a1f36db0a431508a8f7d5jingjiangliimport static com.example.android.leanback.CardPresenter.TITLE;
608a38559a3751252fc8a1f36db0a431508a8f7d5jingjiangli
7b7087e036a48f5a3db28d02ff7f9b97fbbc46c4fDake Guimport android.content.Context;
8816bfc28b79d802b4366684775df74cf40109e6eJerome Poichetimport android.content.Intent;
9816bfc28b79d802b4366684775df74cf40109e6eJerome Poichetimport android.os.Bundle;
10816bfc28b79d802b4366684775df74cf40109e6eJerome Poichetimport android.os.Handler;
11def582a5836579a3fadabfdbe4413cb1652bf098Aurimas Liutikasimport android.text.TextUtils;
12def582a5836579a3fadabfdbe4413cb1652bf098Aurimas Liutikasimport android.util.Log;
13def582a5836579a3fadabfdbe4413cb1652bf098Aurimas Liutikas
14ac5fe7c617c66850fff75a9fce9979c6e5674b0fAurimas Liutikasimport androidx.annotation.Nullable;
15def582a5836579a3fadabfdbe4413cb1652bf098Aurimas Liutikasimport androidx.core.app.ActivityOptionsCompat;
16def582a5836579a3fadabfdbe4413cb1652bf098Aurimas Liutikasimport androidx.core.content.res.ResourcesCompat;
17ac5fe7c617c66850fff75a9fce9979c6e5674b0fAurimas Liutikasimport androidx.leanback.widget.ArrayObjectAdapter;
18ac5fe7c617c66850fff75a9fce9979c6e5674b0fAurimas Liutikasimport androidx.leanback.widget.DiffCallback;
19ac5fe7c617c66850fff75a9fce9979c6e5674b0fAurimas Liutikasimport androidx.leanback.widget.HeaderItem;
20ac5fe7c617c66850fff75a9fce9979c6e5674b0fAurimas Liutikasimport androidx.leanback.widget.ImageCardView;
21ac5fe7c617c66850fff75a9fce9979c6e5674b0fAurimas Liutikasimport androidx.leanback.widget.ListRow;
22ac5fe7c617c66850fff75a9fce9979c6e5674b0fAurimas Liutikasimport androidx.leanback.widget.ListRowPresenter;
23ac5fe7c617c66850fff75a9fce9979c6e5674b0fAurimas Liutikasimport androidx.leanback.widget.ObjectAdapter;
24ac5fe7c617c66850fff75a9fce9979c6e5674b0fAurimas Liutikasimport androidx.leanback.widget.OnItemViewClickedListener;
25ac5fe7c617c66850fff75a9fce9979c6e5674b0fAurimas Liutikasimport androidx.leanback.widget.Presenter;
26ac5fe7c617c66850fff75a9fce9979c6e5674b0fAurimas Liutikasimport androidx.leanback.widget.Row;
27ac5fe7c617c66850fff75a9fce9979c6e5674b0fAurimas Liutikasimport androidx.leanback.widget.RowPresenter;
28816bfc28b79d802b4366684775df74cf40109e6eJerome Poichet
2957ac90cf3fc528ac56b6b83718541624173b1368jingjiangliimport java.util.ArrayList;
3057ac90cf3fc528ac56b6b83718541624173b1368jingjiangli
31ac5fe7c617c66850fff75a9fce9979c6e5674b0fAurimas Liutikaspublic class SearchFragment extends androidx.leanback.app.SearchFragment
32ac5fe7c617c66850fff75a9fce9979c6e5674b0fAurimas Liutikas        implements androidx.leanback.app.SearchFragment.SearchResultProvider {
33816bfc28b79d802b4366684775df74cf40109e6eJerome Poichet    private static final String TAG = "leanback.SearchFragment";
34816bfc28b79d802b4366684775df74cf40109e6eJerome Poichet    private static final int NUM_ROWS = 3;
3527cab4ef89f8f6081fe66e9302236befd6842a8fCraig Stout    private static final int SEARCH_DELAY_MS = 1000;
36816bfc28b79d802b4366684775df74cf40109e6eJerome Poichet
37816bfc28b79d802b4366684775df74cf40109e6eJerome Poichet    private ArrayObjectAdapter mRowsAdapter;
38816bfc28b79d802b4366684775df74cf40109e6eJerome Poichet    private Handler mHandler = new Handler();
3927cab4ef89f8f6081fe66e9302236befd6842a8fCraig Stout    private String mQuery;
40816bfc28b79d802b4366684775df74cf40109e6eJerome Poichet
4157ac90cf3fc528ac56b6b83718541624173b1368jingjiangli    // Flag to represent if data set one is presented in the fragment
4257ac90cf3fc528ac56b6b83718541624173b1368jingjiangli    private boolean mIsDataSetOnePresented;
4357ac90cf3fc528ac56b6b83718541624173b1368jingjiangli
4457ac90cf3fc528ac56b6b83718541624173b1368jingjiangli    // Adapter for first row
4557ac90cf3fc528ac56b6b83718541624173b1368jingjiangli    private ArrayObjectAdapter mFirstRowAdapter;
4657ac90cf3fc528ac56b6b83718541624173b1368jingjiangli
4757ac90cf3fc528ac56b6b83718541624173b1368jingjiangli    // The diff callback which defines the standard to judge if two items are the same or if
4857ac90cf3fc528ac56b6b83718541624173b1368jingjiangli    // two items have the same content.
4957ac90cf3fc528ac56b6b83718541624173b1368jingjiangli    private DiffCallback<PhotoItem> mDiffCallback = new DiffCallback<PhotoItem>() {
5057ac90cf3fc528ac56b6b83718541624173b1368jingjiangli
5157ac90cf3fc528ac56b6b83718541624173b1368jingjiangli        // when two photo items have the same id, they are the same from adapter's
5257ac90cf3fc528ac56b6b83718541624173b1368jingjiangli        // perspective
5357ac90cf3fc528ac56b6b83718541624173b1368jingjiangli        @Override
5457ac90cf3fc528ac56b6b83718541624173b1368jingjiangli        public boolean areItemsTheSame(PhotoItem oldItem, PhotoItem newItem) {
5557ac90cf3fc528ac56b6b83718541624173b1368jingjiangli            return oldItem.getId() == newItem.getId();
5657ac90cf3fc528ac56b6b83718541624173b1368jingjiangli        }
5757ac90cf3fc528ac56b6b83718541624173b1368jingjiangli
5857ac90cf3fc528ac56b6b83718541624173b1368jingjiangli        // when two photo items is equal to each other (based on the equal method defined in
5957ac90cf3fc528ac56b6b83718541624173b1368jingjiangli        // PhotoItem), they have the same content.
6057ac90cf3fc528ac56b6b83718541624173b1368jingjiangli        @Override
6157ac90cf3fc528ac56b6b83718541624173b1368jingjiangli        public boolean areContentsTheSame(PhotoItem oldItem, PhotoItem newItem) {
6257ac90cf3fc528ac56b6b83718541624173b1368jingjiangli            return oldItem.equals(newItem);
6357ac90cf3fc528ac56b6b83718541624173b1368jingjiangli        }
6408a38559a3751252fc8a1f36db0a431508a8f7d5jingjiangli
6508a38559a3751252fc8a1f36db0a431508a8f7d5jingjiangli        @Nullable
6608a38559a3751252fc8a1f36db0a431508a8f7d5jingjiangli        @Override
6708a38559a3751252fc8a1f36db0a431508a8f7d5jingjiangli        public Object getChangePayload(PhotoItem oldItem, PhotoItem newItem) {
6808a38559a3751252fc8a1f36db0a431508a8f7d5jingjiangli            Bundle diff = new Bundle();
6908a38559a3751252fc8a1f36db0a431508a8f7d5jingjiangli            if (oldItem.getImageResourceId()
7008a38559a3751252fc8a1f36db0a431508a8f7d5jingjiangli                    != newItem.getImageResourceId()) {
7108a38559a3751252fc8a1f36db0a431508a8f7d5jingjiangli                diff.putLong(IMAGE, newItem.getImageResourceId());
7208a38559a3751252fc8a1f36db0a431508a8f7d5jingjiangli            }
7308a38559a3751252fc8a1f36db0a431508a8f7d5jingjiangli
7408a38559a3751252fc8a1f36db0a431508a8f7d5jingjiangli            if (oldItem.getTitle() != null && newItem.getTitle() != null
7508a38559a3751252fc8a1f36db0a431508a8f7d5jingjiangli                    && !oldItem.getTitle().equals(newItem.getTitle())) {
7608a38559a3751252fc8a1f36db0a431508a8f7d5jingjiangli                diff.putString(TITLE, newItem.getTitle());
7708a38559a3751252fc8a1f36db0a431508a8f7d5jingjiangli            }
7808a38559a3751252fc8a1f36db0a431508a8f7d5jingjiangli
7908a38559a3751252fc8a1f36db0a431508a8f7d5jingjiangli            if (oldItem.getContent() != null && newItem.getContent() != null
8008a38559a3751252fc8a1f36db0a431508a8f7d5jingjiangli                    && !oldItem.getContent().equals(newItem.getContent())) {
8108a38559a3751252fc8a1f36db0a431508a8f7d5jingjiangli                diff.putString(CONTENT, newItem.getContent());
8208a38559a3751252fc8a1f36db0a431508a8f7d5jingjiangli            }
8308a38559a3751252fc8a1f36db0a431508a8f7d5jingjiangli            return diff;
8408a38559a3751252fc8a1f36db0a431508a8f7d5jingjiangli        }
8557ac90cf3fc528ac56b6b83718541624173b1368jingjiangli    };
8657ac90cf3fc528ac56b6b83718541624173b1368jingjiangli
87816bfc28b79d802b4366684775df74cf40109e6eJerome Poichet    @Override
88816bfc28b79d802b4366684775df74cf40109e6eJerome Poichet    public void onCreate(Bundle savedInstanceState) {
89816bfc28b79d802b4366684775df74cf40109e6eJerome Poichet        super.onCreate(savedInstanceState);
90816bfc28b79d802b4366684775df74cf40109e6eJerome Poichet
91816bfc28b79d802b4366684775df74cf40109e6eJerome Poichet        mRowsAdapter = new ArrayObjectAdapter(new ListRowPresenter());
9205a2ef073edfc6226e014d93c70e0774887de700Jerome Poichet
93b7087e036a48f5a3db28d02ff7f9b97fbbc46c4fDake Gu        final Context context = getActivity();
94b7087e036a48f5a3db28d02ff7f9b97fbbc46c4fDake Gu        setBadgeDrawable(ResourcesCompat.getDrawable(context.getResources(),
95b7087e036a48f5a3db28d02ff7f9b97fbbc46c4fDake Gu                R.drawable.ic_title, context.getTheme()));
9605a2ef073edfc6226e014d93c70e0774887de700Jerome Poichet        setTitle("Leanback Sample App");
97816bfc28b79d802b4366684775df74cf40109e6eJerome Poichet        setSearchResultProvider(this);
9812945ebf764b6ee1e92de2099c128c32f6d80e7aDake Gu        setOnItemViewClickedListener(new ItemViewClickedListener());
99816bfc28b79d802b4366684775df74cf40109e6eJerome Poichet    }
100816bfc28b79d802b4366684775df74cf40109e6eJerome Poichet
101816bfc28b79d802b4366684775df74cf40109e6eJerome Poichet    @Override
102816bfc28b79d802b4366684775df74cf40109e6eJerome Poichet    public ObjectAdapter getResultsAdapter() {
103816bfc28b79d802b4366684775df74cf40109e6eJerome Poichet        return mRowsAdapter;
104816bfc28b79d802b4366684775df74cf40109e6eJerome Poichet    }
105816bfc28b79d802b4366684775df74cf40109e6eJerome Poichet
106816bfc28b79d802b4366684775df74cf40109e6eJerome Poichet    @Override
107816bfc28b79d802b4366684775df74cf40109e6eJerome Poichet    public boolean onQueryTextChange(String newQuery) {
108816bfc28b79d802b4366684775df74cf40109e6eJerome Poichet        Log.i(TAG, String.format("Search Query Text Change %s", newQuery));
109816bfc28b79d802b4366684775df74cf40109e6eJerome Poichet        mRowsAdapter.clear();
11027cab4ef89f8f6081fe66e9302236befd6842a8fCraig Stout        loadQuery(newQuery);
111816bfc28b79d802b4366684775df74cf40109e6eJerome Poichet        return true;
112816bfc28b79d802b4366684775df74cf40109e6eJerome Poichet    }
113816bfc28b79d802b4366684775df74cf40109e6eJerome Poichet
114816bfc28b79d802b4366684775df74cf40109e6eJerome Poichet    @Override
115816bfc28b79d802b4366684775df74cf40109e6eJerome Poichet    public boolean onQueryTextSubmit(String query) {
116816bfc28b79d802b4366684775df74cf40109e6eJerome Poichet        Log.i(TAG, String.format("Search Query Text Submit %s", query));
117816bfc28b79d802b4366684775df74cf40109e6eJerome Poichet        mRowsAdapter.clear();
11827cab4ef89f8f6081fe66e9302236befd6842a8fCraig Stout        loadQuery(query);
11927cab4ef89f8f6081fe66e9302236befd6842a8fCraig Stout        return true;
12027cab4ef89f8f6081fe66e9302236befd6842a8fCraig Stout    }
12127cab4ef89f8f6081fe66e9302236befd6842a8fCraig Stout
12227cab4ef89f8f6081fe66e9302236befd6842a8fCraig Stout    private void loadQuery(String query) {
12327cab4ef89f8f6081fe66e9302236befd6842a8fCraig Stout        mQuery = query;
12427cab4ef89f8f6081fe66e9302236befd6842a8fCraig Stout        mHandler.removeCallbacks(mDelayedLoad);
12527cab4ef89f8f6081fe66e9302236befd6842a8fCraig Stout        if (!TextUtils.isEmpty(query) && !query.equals("nil")) {
126816bfc28b79d802b4366684775df74cf40109e6eJerome Poichet            mHandler.postDelayed(mDelayedLoad, SEARCH_DELAY_MS);
127816bfc28b79d802b4366684775df74cf40109e6eJerome Poichet        }
128816bfc28b79d802b4366684775df74cf40109e6eJerome Poichet    }
129816bfc28b79d802b4366684775df74cf40109e6eJerome Poichet
130816bfc28b79d802b4366684775df74cf40109e6eJerome Poichet    private void loadRows() {
13157ac90cf3fc528ac56b6b83718541624173b1368jingjiangli        HeaderItem header = new HeaderItem(0, mQuery + " results row " + 0);
13257ac90cf3fc528ac56b6b83718541624173b1368jingjiangli
13357ac90cf3fc528ac56b6b83718541624173b1368jingjiangli        // Every time when the query event is fired, we will update the fake search result in the
13457ac90cf3fc528ac56b6b83718541624173b1368jingjiangli        // first row based on the flag mIsDataSetOnePresented flag.
13557ac90cf3fc528ac56b6b83718541624173b1368jingjiangli        // Also the first row adapter will only be created once so the animation will be triggered
13657ac90cf3fc528ac56b6b83718541624173b1368jingjiangli        // when the items in the adapter changed.
13757ac90cf3fc528ac56b6b83718541624173b1368jingjiangli        if (!mIsDataSetOnePresented) {
13857ac90cf3fc528ac56b6b83718541624173b1368jingjiangli            if (mFirstRowAdapter == null) {
13957ac90cf3fc528ac56b6b83718541624173b1368jingjiangli                mFirstRowAdapter = createFirstListRowAdapter();
14057ac90cf3fc528ac56b6b83718541624173b1368jingjiangli            } else {
14108a38559a3751252fc8a1f36db0a431508a8f7d5jingjiangli                mFirstRowAdapter.setItems(createDataSetOneDebug(), mDiffCallback);
14257ac90cf3fc528ac56b6b83718541624173b1368jingjiangli            }
14357ac90cf3fc528ac56b6b83718541624173b1368jingjiangli            mIsDataSetOnePresented = true;
14457ac90cf3fc528ac56b6b83718541624173b1368jingjiangli        } else {
14508a38559a3751252fc8a1f36db0a431508a8f7d5jingjiangli            mFirstRowAdapter.setItems(createDataSetTwoDebug(), mDiffCallback);
14657ac90cf3fc528ac56b6b83718541624173b1368jingjiangli            mIsDataSetOnePresented = false;
14757ac90cf3fc528ac56b6b83718541624173b1368jingjiangli        }
14857ac90cf3fc528ac56b6b83718541624173b1368jingjiangli        mRowsAdapter.add(new ListRow(header, mFirstRowAdapter));
14957ac90cf3fc528ac56b6b83718541624173b1368jingjiangli        for (int i = 1; i < NUM_ROWS + 1; ++i) {
15012945ebf764b6ee1e92de2099c128c32f6d80e7aDake Gu            ArrayObjectAdapter listRowAdapter = new ArrayObjectAdapter(new CardPresenter());
15112945ebf764b6ee1e92de2099c128c32f6d80e7aDake Gu            listRowAdapter.add(new PhotoItem("Hello world", R.drawable.gallery_photo_1));
15212945ebf764b6ee1e92de2099c128c32f6d80e7aDake Gu            listRowAdapter.add(new PhotoItem("This is a test", R.drawable.gallery_photo_2));
15357ac90cf3fc528ac56b6b83718541624173b1368jingjiangli            header = new HeaderItem(i, mQuery + " results row " + i);
154816bfc28b79d802b4366684775df74cf40109e6eJerome Poichet            mRowsAdapter.add(new ListRow(header, listRowAdapter));
155816bfc28b79d802b4366684775df74cf40109e6eJerome Poichet        }
156816bfc28b79d802b4366684775df74cf40109e6eJerome Poichet    }
157816bfc28b79d802b4366684775df74cf40109e6eJerome Poichet
158816bfc28b79d802b4366684775df74cf40109e6eJerome Poichet    private Runnable mDelayedLoad = new Runnable() {
159816bfc28b79d802b4366684775df74cf40109e6eJerome Poichet        @Override
160816bfc28b79d802b4366684775df74cf40109e6eJerome Poichet        public void run() {
161816bfc28b79d802b4366684775df74cf40109e6eJerome Poichet            loadRows();
162816bfc28b79d802b4366684775df74cf40109e6eJerome Poichet        }
163816bfc28b79d802b4366684775df74cf40109e6eJerome Poichet    };
16412945ebf764b6ee1e92de2099c128c32f6d80e7aDake Gu
16512945ebf764b6ee1e92de2099c128c32f6d80e7aDake Gu    private final class ItemViewClickedListener implements OnItemViewClickedListener {
16612945ebf764b6ee1e92de2099c128c32f6d80e7aDake Gu        @Override
16712945ebf764b6ee1e92de2099c128c32f6d80e7aDake Gu        public void onItemClicked(Presenter.ViewHolder itemViewHolder, Object item,
16812945ebf764b6ee1e92de2099c128c32f6d80e7aDake Gu                RowPresenter.ViewHolder rowViewHolder, Row row) {
169816bfc28b79d802b4366684775df74cf40109e6eJerome Poichet            Intent intent = new Intent(getActivity(), DetailsActivity.class);
17012945ebf764b6ee1e92de2099c128c32f6d80e7aDake Gu            intent.putExtra(DetailsActivity.EXTRA_ITEM, (PhotoItem) item);
17112945ebf764b6ee1e92de2099c128c32f6d80e7aDake Gu
17212945ebf764b6ee1e92de2099c128c32f6d80e7aDake Gu            Bundle bundle = ActivityOptionsCompat.makeSceneTransitionAnimation(
17312945ebf764b6ee1e92de2099c128c32f6d80e7aDake Gu                    getActivity(),
17457ac90cf3fc528ac56b6b83718541624173b1368jingjiangli                    ((ImageCardView) itemViewHolder.view).getMainImageView(),
17512945ebf764b6ee1e92de2099c128c32f6d80e7aDake Gu                    DetailsActivity.SHARED_ELEMENT_NAME).toBundle();
17612945ebf764b6ee1e92de2099c128c32f6d80e7aDake Gu            getActivity().startActivity(intent, bundle);
177816bfc28b79d802b4366684775df74cf40109e6eJerome Poichet        }
178816bfc28b79d802b4366684775df74cf40109e6eJerome Poichet    }
17957ac90cf3fc528ac56b6b83718541624173b1368jingjiangli
18057ac90cf3fc528ac56b6b83718541624173b1368jingjiangli
18157ac90cf3fc528ac56b6b83718541624173b1368jingjiangli    private ArrayObjectAdapter createFirstListRowAdapter() {
18257ac90cf3fc528ac56b6b83718541624173b1368jingjiangli        ArrayObjectAdapter listRowAdapter = new ArrayObjectAdapter(new CardPresenter());
18308a38559a3751252fc8a1f36db0a431508a8f7d5jingjiangli        listRowAdapter.setItems(createDataSetOneDebug(), mDiffCallback);
18457ac90cf3fc528ac56b6b83718541624173b1368jingjiangli        mIsDataSetOnePresented = true;
18557ac90cf3fc528ac56b6b83718541624173b1368jingjiangli        return listRowAdapter;
18657ac90cf3fc528ac56b6b83718541624173b1368jingjiangli    }
18757ac90cf3fc528ac56b6b83718541624173b1368jingjiangli
18857ac90cf3fc528ac56b6b83718541624173b1368jingjiangli    /**
18957ac90cf3fc528ac56b6b83718541624173b1368jingjiangli     * Create a data set (data set one) for the last row of this browse fragment. It will be
19057ac90cf3fc528ac56b6b83718541624173b1368jingjiangli     * changed by another set of data when user click one of the photo items in the list.
19157ac90cf3fc528ac56b6b83718541624173b1368jingjiangli     * Different with other rows in the browsing fragment, the photo item in last row all have been
19257ac90cf3fc528ac56b6b83718541624173b1368jingjiangli     * allocated with a unique id. And the id will be used to jduge if two photo items are the same
19357ac90cf3fc528ac56b6b83718541624173b1368jingjiangli     * or not.
19457ac90cf3fc528ac56b6b83718541624173b1368jingjiangli     *
19557ac90cf3fc528ac56b6b83718541624173b1368jingjiangli     * @return List of photoItem
19657ac90cf3fc528ac56b6b83718541624173b1368jingjiangli     */
19757ac90cf3fc528ac56b6b83718541624173b1368jingjiangli    private ArrayList<PhotoItem> createDataSetOne() {
19857ac90cf3fc528ac56b6b83718541624173b1368jingjiangli        ArrayList<PhotoItem> photoItems = new ArrayList<>();
19957ac90cf3fc528ac56b6b83718541624173b1368jingjiangli        photoItems.add(new PhotoItem(
20057ac90cf3fc528ac56b6b83718541624173b1368jingjiangli                "Hello world",
20157ac90cf3fc528ac56b6b83718541624173b1368jingjiangli                R.drawable.gallery_photo_1,
20257ac90cf3fc528ac56b6b83718541624173b1368jingjiangli                1));
20357ac90cf3fc528ac56b6b83718541624173b1368jingjiangli        photoItems.add(new PhotoItem(
20457ac90cf3fc528ac56b6b83718541624173b1368jingjiangli                "This is a test",
20557ac90cf3fc528ac56b6b83718541624173b1368jingjiangli                "Only a test",
20657ac90cf3fc528ac56b6b83718541624173b1368jingjiangli                R.drawable.gallery_photo_2,
20757ac90cf3fc528ac56b6b83718541624173b1368jingjiangli                2));
20857ac90cf3fc528ac56b6b83718541624173b1368jingjiangli        photoItems.add(new PhotoItem(
20957ac90cf3fc528ac56b6b83718541624173b1368jingjiangli                "Android TV",
21057ac90cf3fc528ac56b6b83718541624173b1368jingjiangli                "by Google",
21157ac90cf3fc528ac56b6b83718541624173b1368jingjiangli                R.drawable.gallery_photo_3,
21257ac90cf3fc528ac56b6b83718541624173b1368jingjiangli                3));
21357ac90cf3fc528ac56b6b83718541624173b1368jingjiangli        photoItems.add(new PhotoItem(
21457ac90cf3fc528ac56b6b83718541624173b1368jingjiangli                "Leanback",
21557ac90cf3fc528ac56b6b83718541624173b1368jingjiangli                R.drawable.gallery_photo_4,
21657ac90cf3fc528ac56b6b83718541624173b1368jingjiangli                4));
21757ac90cf3fc528ac56b6b83718541624173b1368jingjiangli        photoItems.add(new PhotoItem(
21857ac90cf3fc528ac56b6b83718541624173b1368jingjiangli                "GuidedStep (Slide left/right)",
21957ac90cf3fc528ac56b6b83718541624173b1368jingjiangli                R.drawable.gallery_photo_5,
22057ac90cf3fc528ac56b6b83718541624173b1368jingjiangli                5));
22157ac90cf3fc528ac56b6b83718541624173b1368jingjiangli        photoItems.add(new PhotoItem(
22257ac90cf3fc528ac56b6b83718541624173b1368jingjiangli                "GuidedStep (Slide bottom up)",
22357ac90cf3fc528ac56b6b83718541624173b1368jingjiangli                "Open GuidedStepFragment",
22457ac90cf3fc528ac56b6b83718541624173b1368jingjiangli                R.drawable.gallery_photo_6,
22557ac90cf3fc528ac56b6b83718541624173b1368jingjiangli                6));
22657ac90cf3fc528ac56b6b83718541624173b1368jingjiangli        photoItems.add(new PhotoItem(
22757ac90cf3fc528ac56b6b83718541624173b1368jingjiangli                "Android TV",
22857ac90cf3fc528ac56b6b83718541624173b1368jingjiangli                "open RowsActivity",
22957ac90cf3fc528ac56b6b83718541624173b1368jingjiangli                R.drawable.gallery_photo_7,
23057ac90cf3fc528ac56b6b83718541624173b1368jingjiangli                7));
23157ac90cf3fc528ac56b6b83718541624173b1368jingjiangli        photoItems.add(new PhotoItem(
23257ac90cf3fc528ac56b6b83718541624173b1368jingjiangli                "Leanback",
23357ac90cf3fc528ac56b6b83718541624173b1368jingjiangli                "open BrowseActivity",
23457ac90cf3fc528ac56b6b83718541624173b1368jingjiangli                R.drawable.gallery_photo_8,
23557ac90cf3fc528ac56b6b83718541624173b1368jingjiangli                8));
23657ac90cf3fc528ac56b6b83718541624173b1368jingjiangli        photoItems.add(new PhotoItem(
23757ac90cf3fc528ac56b6b83718541624173b1368jingjiangli                "Hello world",
23857ac90cf3fc528ac56b6b83718541624173b1368jingjiangli                R.drawable.gallery_photo_1,
23957ac90cf3fc528ac56b6b83718541624173b1368jingjiangli                1));
24057ac90cf3fc528ac56b6b83718541624173b1368jingjiangli        photoItems.add(new PhotoItem(
24157ac90cf3fc528ac56b6b83718541624173b1368jingjiangli                "This is a test",
24257ac90cf3fc528ac56b6b83718541624173b1368jingjiangli                "Only a test",
24357ac90cf3fc528ac56b6b83718541624173b1368jingjiangli                R.drawable.gallery_photo_2,
24457ac90cf3fc528ac56b6b83718541624173b1368jingjiangli                2));
24557ac90cf3fc528ac56b6b83718541624173b1368jingjiangli        photoItems.add(new PhotoItem(
24657ac90cf3fc528ac56b6b83718541624173b1368jingjiangli                "Android TV",
24757ac90cf3fc528ac56b6b83718541624173b1368jingjiangli                "by Google",
24857ac90cf3fc528ac56b6b83718541624173b1368jingjiangli                R.drawable.gallery_photo_3,
24957ac90cf3fc528ac56b6b83718541624173b1368jingjiangli                3));
25057ac90cf3fc528ac56b6b83718541624173b1368jingjiangli        photoItems.add(new PhotoItem(
25157ac90cf3fc528ac56b6b83718541624173b1368jingjiangli                "Leanback",
25257ac90cf3fc528ac56b6b83718541624173b1368jingjiangli                R.drawable.gallery_photo_4,
25357ac90cf3fc528ac56b6b83718541624173b1368jingjiangli                4));
25457ac90cf3fc528ac56b6b83718541624173b1368jingjiangli        return photoItems;
25557ac90cf3fc528ac56b6b83718541624173b1368jingjiangli    }
25657ac90cf3fc528ac56b6b83718541624173b1368jingjiangli
25757ac90cf3fc528ac56b6b83718541624173b1368jingjiangli    /**
25857ac90cf3fc528ac56b6b83718541624173b1368jingjiangli     * Create a new data set (data set one) for the last row of this browse fragment. It will be
25957ac90cf3fc528ac56b6b83718541624173b1368jingjiangli     * changed by another set of data when user click one of the photo items in the list.
26057ac90cf3fc528ac56b6b83718541624173b1368jingjiangli     * Different with other rows in the browsing fragment, the photo item in last row all have been
26157ac90cf3fc528ac56b6b83718541624173b1368jingjiangli     * allocated with a unique id. And the id will be used to jduge if two photo items are the same
26257ac90cf3fc528ac56b6b83718541624173b1368jingjiangli     * or not.
26357ac90cf3fc528ac56b6b83718541624173b1368jingjiangli     *
26457ac90cf3fc528ac56b6b83718541624173b1368jingjiangli     * @return List of photoItem
26557ac90cf3fc528ac56b6b83718541624173b1368jingjiangli     */
26657ac90cf3fc528ac56b6b83718541624173b1368jingjiangli    private ArrayList<PhotoItem> createDataSetTwo() {
26757ac90cf3fc528ac56b6b83718541624173b1368jingjiangli        ArrayList<PhotoItem> photoItems = new ArrayList<>();
26857ac90cf3fc528ac56b6b83718541624173b1368jingjiangli        photoItems.add(new PhotoItem(
26957ac90cf3fc528ac56b6b83718541624173b1368jingjiangli                "This is a test",
27057ac90cf3fc528ac56b6b83718541624173b1368jingjiangli                "Only a test",
27157ac90cf3fc528ac56b6b83718541624173b1368jingjiangli                R.drawable.gallery_photo_2,
27257ac90cf3fc528ac56b6b83718541624173b1368jingjiangli                2));
27357ac90cf3fc528ac56b6b83718541624173b1368jingjiangli        photoItems.add(new PhotoItem(
27457ac90cf3fc528ac56b6b83718541624173b1368jingjiangli                "Hello world",
27557ac90cf3fc528ac56b6b83718541624173b1368jingjiangli                R.drawable.gallery_photo_1,
27657ac90cf3fc528ac56b6b83718541624173b1368jingjiangli                1));
27757ac90cf3fc528ac56b6b83718541624173b1368jingjiangli        photoItems.add(new PhotoItem(
27857ac90cf3fc528ac56b6b83718541624173b1368jingjiangli                "Leanback",
27957ac90cf3fc528ac56b6b83718541624173b1368jingjiangli                R.drawable.gallery_photo_4,
28057ac90cf3fc528ac56b6b83718541624173b1368jingjiangli                4));
28157ac90cf3fc528ac56b6b83718541624173b1368jingjiangli        photoItems.add(new PhotoItem(
28257ac90cf3fc528ac56b6b83718541624173b1368jingjiangli                "Android TV",
28357ac90cf3fc528ac56b6b83718541624173b1368jingjiangli                "by Google",
28457ac90cf3fc528ac56b6b83718541624173b1368jingjiangli                R.drawable.gallery_photo_3,
28557ac90cf3fc528ac56b6b83718541624173b1368jingjiangli                3));
28657ac90cf3fc528ac56b6b83718541624173b1368jingjiangli        photoItems.add(new PhotoItem(
28757ac90cf3fc528ac56b6b83718541624173b1368jingjiangli                "change title",
28857ac90cf3fc528ac56b6b83718541624173b1368jingjiangli                R.drawable.gallery_photo_5,
28957ac90cf3fc528ac56b6b83718541624173b1368jingjiangli                5));
29057ac90cf3fc528ac56b6b83718541624173b1368jingjiangli        photoItems.add(new PhotoItem(
29157ac90cf3fc528ac56b6b83718541624173b1368jingjiangli                "GuidedStep (Slide bottom up)",
29257ac90cf3fc528ac56b6b83718541624173b1368jingjiangli                "change comment",
29357ac90cf3fc528ac56b6b83718541624173b1368jingjiangli                R.drawable.gallery_photo_6,
29457ac90cf3fc528ac56b6b83718541624173b1368jingjiangli                6));
29557ac90cf3fc528ac56b6b83718541624173b1368jingjiangli        photoItems.add(new PhotoItem(
29657ac90cf3fc528ac56b6b83718541624173b1368jingjiangli                "Android TV",
29757ac90cf3fc528ac56b6b83718541624173b1368jingjiangli                R.drawable.gallery_photo_7,
29857ac90cf3fc528ac56b6b83718541624173b1368jingjiangli                7));
29957ac90cf3fc528ac56b6b83718541624173b1368jingjiangli        photoItems.add(new PhotoItem(
30057ac90cf3fc528ac56b6b83718541624173b1368jingjiangli                "Leanback",
30157ac90cf3fc528ac56b6b83718541624173b1368jingjiangli                "open BrowseActivity",
30257ac90cf3fc528ac56b6b83718541624173b1368jingjiangli                R.drawable.gallery_photo_7,
30357ac90cf3fc528ac56b6b83718541624173b1368jingjiangli                8));
30457ac90cf3fc528ac56b6b83718541624173b1368jingjiangli        photoItems.add(new PhotoItem(
30557ac90cf3fc528ac56b6b83718541624173b1368jingjiangli                "Hello world",
30657ac90cf3fc528ac56b6b83718541624173b1368jingjiangli                R.drawable.gallery_photo_1,
30757ac90cf3fc528ac56b6b83718541624173b1368jingjiangli                10));
30857ac90cf3fc528ac56b6b83718541624173b1368jingjiangli        photoItems.add(new PhotoItem(
30957ac90cf3fc528ac56b6b83718541624173b1368jingjiangli                "This is a test",
31057ac90cf3fc528ac56b6b83718541624173b1368jingjiangli                "Only a test",
31157ac90cf3fc528ac56b6b83718541624173b1368jingjiangli                R.drawable.gallery_photo_2,
31257ac90cf3fc528ac56b6b83718541624173b1368jingjiangli                20));
31357ac90cf3fc528ac56b6b83718541624173b1368jingjiangli        photoItems.add(new PhotoItem(
31457ac90cf3fc528ac56b6b83718541624173b1368jingjiangli                "Android TV",
31557ac90cf3fc528ac56b6b83718541624173b1368jingjiangli                "by Google",
31657ac90cf3fc528ac56b6b83718541624173b1368jingjiangli                R.drawable.gallery_photo_3,
31757ac90cf3fc528ac56b6b83718541624173b1368jingjiangli                30));
31857ac90cf3fc528ac56b6b83718541624173b1368jingjiangli        photoItems.add(new PhotoItem(
31957ac90cf3fc528ac56b6b83718541624173b1368jingjiangli                "Leanback",
32057ac90cf3fc528ac56b6b83718541624173b1368jingjiangli                R.drawable.gallery_photo_4,
32157ac90cf3fc528ac56b6b83718541624173b1368jingjiangli                40));
32257ac90cf3fc528ac56b6b83718541624173b1368jingjiangli        return photoItems;
32357ac90cf3fc528ac56b6b83718541624173b1368jingjiangli    }
32457ac90cf3fc528ac56b6b83718541624173b1368jingjiangli
32508a38559a3751252fc8a1f36db0a431508a8f7d5jingjiangli
32608a38559a3751252fc8a1f36db0a431508a8f7d5jingjiangli    private ArrayList<PhotoItem> createDataSetOneDebug() {
32708a38559a3751252fc8a1f36db0a431508a8f7d5jingjiangli        ArrayList<PhotoItem> photoItems = new ArrayList<>();
32808a38559a3751252fc8a1f36db0a431508a8f7d5jingjiangli        photoItems.add(new PhotoItem(
32908a38559a3751252fc8a1f36db0a431508a8f7d5jingjiangli                "Hello world",
33008a38559a3751252fc8a1f36db0a431508a8f7d5jingjiangli                R.drawable.gallery_photo_1,
33108a38559a3751252fc8a1f36db0a431508a8f7d5jingjiangli                1));
33208a38559a3751252fc8a1f36db0a431508a8f7d5jingjiangli        return photoItems;
33308a38559a3751252fc8a1f36db0a431508a8f7d5jingjiangli    }
33408a38559a3751252fc8a1f36db0a431508a8f7d5jingjiangli
33508a38559a3751252fc8a1f36db0a431508a8f7d5jingjiangli    /**
33608a38559a3751252fc8a1f36db0a431508a8f7d5jingjiangli     * Create a new data set (data set one) for the last row of this browse fragment. It will be
33708a38559a3751252fc8a1f36db0a431508a8f7d5jingjiangli     * changed by another set of data when user click one of the photo items in the list.
33808a38559a3751252fc8a1f36db0a431508a8f7d5jingjiangli     * Different with other rows in the browsing fragment, the photo item in last row all have been
33908a38559a3751252fc8a1f36db0a431508a8f7d5jingjiangli     * allocated with a unique id. And the id will be used to jduge if two photo items are the same
34008a38559a3751252fc8a1f36db0a431508a8f7d5jingjiangli     * or not.
34108a38559a3751252fc8a1f36db0a431508a8f7d5jingjiangli     *
34208a38559a3751252fc8a1f36db0a431508a8f7d5jingjiangli     * @return List of photoItem
34308a38559a3751252fc8a1f36db0a431508a8f7d5jingjiangli     */
34408a38559a3751252fc8a1f36db0a431508a8f7d5jingjiangli    private ArrayList<PhotoItem> createDataSetTwoDebug() {
34508a38559a3751252fc8a1f36db0a431508a8f7d5jingjiangli        ArrayList<PhotoItem> photoItems = new ArrayList<>();
34608a38559a3751252fc8a1f36db0a431508a8f7d5jingjiangli        photoItems.add(new PhotoItem(
34708a38559a3751252fc8a1f36db0a431508a8f7d5jingjiangli                "Hello world Hello world",
34808a38559a3751252fc8a1f36db0a431508a8f7d5jingjiangli                R.drawable.gallery_photo_1,
34908a38559a3751252fc8a1f36db0a431508a8f7d5jingjiangli                1));
35008a38559a3751252fc8a1f36db0a431508a8f7d5jingjiangli        return photoItems;
35108a38559a3751252fc8a1f36db0a431508a8f7d5jingjiangli    }
352816bfc28b79d802b4366684775df74cf40109e6eJerome Poichet}
353