17ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout/*
27ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout * Copyright (C) 2014 The Android Open Source Project
37ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout *
47ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except
57ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout * in compliance with the License. You may obtain a copy of the License at
67ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout *
77ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout * http://www.apache.org/licenses/LICENSE-2.0
87ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout *
97ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout * Unless required by applicable law or agreed to in writing, software distributed under the License
107ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
117ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout * or implied. See the License for the specific language governing permissions and limitations under
127ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout * the License.
137ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout */
147ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stoutpackage android.support.v17.leanback.widget;
157ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout
167ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stoutimport android.support.v17.leanback.R;
17cf992de2d34abb8228dc6cb39fffe97346823a37Craig Stoutimport android.support.v17.leanback.widget.ControlBarPresenter.OnControlClickedListener;
18cf992de2d34abb8228dc6cb39fffe97346823a37Craig Stoutimport android.support.v17.leanback.widget.ControlBarPresenter.OnControlSelectedListener;
197ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stoutimport android.content.Context;
207ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stoutimport android.graphics.Color;
217ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stoutimport android.util.TypedValue;
227ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stoutimport android.view.LayoutInflater;
237ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stoutimport android.view.View;
247ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stoutimport android.view.ViewGroup;
257ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stoutimport android.view.ViewGroup.LayoutParams;
267ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stoutimport android.view.ViewGroup.MarginLayoutParams;
277ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stoutimport android.widget.ImageView;
287ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout
297ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout/**
307ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout * A PlaybackControlsRowPresenter renders a {@link PlaybackControlsRow} to display a
317ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout * series of playback control buttons. Typically this row will be the first row in a fragment
327ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout * such as the {@link android.support.v17.leanback.app.PlaybackOverlayFragment
337ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout * PlaybackControlsFragment}.
347ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout */
357ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stoutpublic class PlaybackControlsRowPresenter extends RowPresenter {
367ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout
37cf992de2d34abb8228dc6cb39fffe97346823a37Craig Stout    static class BoundData extends PlaybackControlsPresenter.BoundData {
38cf992de2d34abb8228dc6cb39fffe97346823a37Craig Stout        ViewHolder mRowViewHolder;
39cf992de2d34abb8228dc6cb39fffe97346823a37Craig Stout    }
40cf992de2d34abb8228dc6cb39fffe97346823a37Craig Stout
417ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout    /**
427ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout     * A ViewHolder for the PlaybackControlsRow.
437ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout     */
446dca725412977bb56b933bdec120e31909233cdbCraig Stout    public class ViewHolder extends RowPresenter.ViewHolder {
456b2e5b5117f1b8dfafbd81b995bb423ab0297564Craig Stout        public final Presenter.ViewHolder mDescriptionViewHolder;
467ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout        final ViewGroup mCard;
477ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout        final ImageView mImageView;
487ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout        final ViewGroup mDescriptionDock;
497ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout        final ViewGroup mControlsDock;
507ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout        final ViewGroup mSecondaryControlsDock;
517ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout        final View mSpacer;
52d20507e0f5ac7ad021f42ca87c294787246f0591Craig Stout        final View mBottomSpacer;
53adf55abedd17eb9484d03da4b521209f15724f1fCraig Stout        View mBgView;
547ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout        int mCardHeight;
557ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout        int mControlsDockMarginStart;
567ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout        int mControlsDockMarginEnd;
576dca725412977bb56b933bdec120e31909233cdbCraig Stout        PlaybackControlsPresenter.ViewHolder mControlsVh;
587ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout        Presenter.ViewHolder mSecondaryControlsVh;
59cf992de2d34abb8228dc6cb39fffe97346823a37Craig Stout        BoundData mControlsBoundData = new BoundData();
60cf992de2d34abb8228dc6cb39fffe97346823a37Craig Stout        BoundData mSecondaryBoundData = new BoundData();
61cf992de2d34abb8228dc6cb39fffe97346823a37Craig Stout        Presenter.ViewHolder mSelectedViewHolder;
62cf992de2d34abb8228dc6cb39fffe97346823a37Craig Stout        Object mSelectedItem;
634cc255c1c9ce5f3a718970b6e0be2c3ae6abf9edCraig Stout        final PlaybackControlsRow.OnPlaybackStateChangedListener mListener =
646dca725412977bb56b933bdec120e31909233cdbCraig Stout                new PlaybackControlsRow.OnPlaybackStateChangedListener() {
654cc255c1c9ce5f3a718970b6e0be2c3ae6abf9edCraig Stout            @Override
664cc255c1c9ce5f3a718970b6e0be2c3ae6abf9edCraig Stout            public void onCurrentTimeChanged(int ms) {
674cc255c1c9ce5f3a718970b6e0be2c3ae6abf9edCraig Stout                mPlaybackControlsPresenter.setCurrentTime(mControlsVh, ms);
684cc255c1c9ce5f3a718970b6e0be2c3ae6abf9edCraig Stout            }
694cc255c1c9ce5f3a718970b6e0be2c3ae6abf9edCraig Stout            @Override
704cc255c1c9ce5f3a718970b6e0be2c3ae6abf9edCraig Stout            public void onBufferedProgressChanged(int ms) {
714cc255c1c9ce5f3a718970b6e0be2c3ae6abf9edCraig Stout                mPlaybackControlsPresenter.setSecondaryProgress(mControlsVh, ms);
724cc255c1c9ce5f3a718970b6e0be2c3ae6abf9edCraig Stout            }
734cc255c1c9ce5f3a718970b6e0be2c3ae6abf9edCraig Stout        };
747ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout
756b2e5b5117f1b8dfafbd81b995bb423ab0297564Craig Stout        ViewHolder(View rootView, Presenter descriptionPresenter) {
767ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout            super(rootView);
777ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout            mCard = (ViewGroup) rootView.findViewById(R.id.controls_card);
787ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout            mImageView = (ImageView) rootView.findViewById(R.id.image);
797ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout            mDescriptionDock = (ViewGroup) rootView.findViewById(R.id.description_dock);
807ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout            mControlsDock = (ViewGroup) rootView.findViewById(R.id.controls_dock);
817ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout            mSecondaryControlsDock =
827ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout                    (ViewGroup) rootView.findViewById(R.id.secondary_controls_dock);
837ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout            mSpacer = rootView.findViewById(R.id.spacer);
84d20507e0f5ac7ad021f42ca87c294787246f0591Craig Stout            mBottomSpacer = rootView.findViewById(R.id.bottom_spacer);
856b2e5b5117f1b8dfafbd81b995bb423ab0297564Craig Stout            mDescriptionViewHolder = descriptionPresenter == null ? null :
866b2e5b5117f1b8dfafbd81b995bb423ab0297564Craig Stout                    descriptionPresenter.onCreateViewHolder(mDescriptionDock);
876b2e5b5117f1b8dfafbd81b995bb423ab0297564Craig Stout            if (mDescriptionViewHolder != null) {
886b2e5b5117f1b8dfafbd81b995bb423ab0297564Craig Stout                mDescriptionDock.addView(mDescriptionViewHolder.view);
896b2e5b5117f1b8dfafbd81b995bb423ab0297564Craig Stout            }
907ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout        }
917ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout
92cf992de2d34abb8228dc6cb39fffe97346823a37Craig Stout        void dispatchItemSelection() {
93cf992de2d34abb8228dc6cb39fffe97346823a37Craig Stout            if (!isSelected()) {
94cf992de2d34abb8228dc6cb39fffe97346823a37Craig Stout                return;
95cf992de2d34abb8228dc6cb39fffe97346823a37Craig Stout            }
96cf992de2d34abb8228dc6cb39fffe97346823a37Craig Stout            if (mSelectedViewHolder == null) {
97cf992de2d34abb8228dc6cb39fffe97346823a37Craig Stout                if (getOnItemSelectedListener() != null) {
98cf992de2d34abb8228dc6cb39fffe97346823a37Craig Stout                    getOnItemSelectedListener().onItemSelected(null, getRow());
99cf992de2d34abb8228dc6cb39fffe97346823a37Craig Stout                }
100cf992de2d34abb8228dc6cb39fffe97346823a37Craig Stout                if (getOnItemViewSelectedListener() != null) {
101cf992de2d34abb8228dc6cb39fffe97346823a37Craig Stout                    getOnItemViewSelectedListener().onItemSelected(null, null,
102cf992de2d34abb8228dc6cb39fffe97346823a37Craig Stout                            ViewHolder.this, getRow());
103cf992de2d34abb8228dc6cb39fffe97346823a37Craig Stout                }
104cf992de2d34abb8228dc6cb39fffe97346823a37Craig Stout            } else {
105cf992de2d34abb8228dc6cb39fffe97346823a37Craig Stout                if (getOnItemSelectedListener() != null) {
106cf992de2d34abb8228dc6cb39fffe97346823a37Craig Stout                    getOnItemSelectedListener().onItemSelected(mSelectedItem, getRow());
107cf992de2d34abb8228dc6cb39fffe97346823a37Craig Stout                }
108cf992de2d34abb8228dc6cb39fffe97346823a37Craig Stout                if (getOnItemViewSelectedListener() != null) {
109cf992de2d34abb8228dc6cb39fffe97346823a37Craig Stout                    getOnItemViewSelectedListener().onItemSelected(mSelectedViewHolder, mSelectedItem,
110cf992de2d34abb8228dc6cb39fffe97346823a37Craig Stout                            ViewHolder.this, getRow());
111cf992de2d34abb8228dc6cb39fffe97346823a37Craig Stout                }
112cf992de2d34abb8228dc6cb39fffe97346823a37Craig Stout            }
113cf992de2d34abb8228dc6cb39fffe97346823a37Craig Stout        };
114cf992de2d34abb8228dc6cb39fffe97346823a37Craig Stout
115cf992de2d34abb8228dc6cb39fffe97346823a37Craig Stout        Presenter getPresenter(boolean primary) {
1167ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout            ObjectAdapter adapter = primary ?
1177ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout                    ((PlaybackControlsRow) getRow()).getPrimaryActionsAdapter() :
1187ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout                            ((PlaybackControlsRow) getRow()).getSecondaryActionsAdapter();
1195dac2c723e1d50da356170a6f372dcbab1a7d83cCraig Stout            if (adapter == null) {
1205dac2c723e1d50da356170a6f372dcbab1a7d83cCraig Stout                return null;
1215dac2c723e1d50da356170a6f372dcbab1a7d83cCraig Stout            }
1227ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout            if (adapter.getPresenterSelector() instanceof ControlButtonPresenterSelector) {
1237ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout                ControlButtonPresenterSelector selector =
1247ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout                        (ControlButtonPresenterSelector) adapter.getPresenterSelector();
1257ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout                return primary ? selector.getPrimaryPresenter() :
1267ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout                    selector.getSecondaryPresenter();
1277ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout            }
128cf992de2d34abb8228dc6cb39fffe97346823a37Craig Stout            return adapter.getPresenter(adapter.size() > 0 ? adapter.get(0) : null);
1297ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout        }
130adf55abedd17eb9484d03da4b521209f15724f1fCraig Stout
131adf55abedd17eb9484d03da4b521209f15724f1fCraig Stout        void setBackground(View view) {
132adf55abedd17eb9484d03da4b521209f15724f1fCraig Stout            if (mBgView != null) {
1334f34a05cdf73b68c3b2eb8678f740ab15225126aCraig Stout                RoundedRectHelper.getInstance().clearBackground(mBgView);
134c62efa44831b1c60dcbdfd968735e27ac8294439Craig Stout                ShadowHelper.getInstance().setZ(mBgView, 0);
135adf55abedd17eb9484d03da4b521209f15724f1fCraig Stout            }
136adf55abedd17eb9484d03da4b521209f15724f1fCraig Stout            mBgView = view;
1374f34a05cdf73b68c3b2eb8678f740ab15225126aCraig Stout            RoundedRectHelper.getInstance().setRoundedRectBackground(view, mBackgroundColorSet ?
138adf55abedd17eb9484d03da4b521209f15724f1fCraig Stout                    mBackgroundColor : getDefaultBackgroundColor(view.getContext()));
139c62efa44831b1c60dcbdfd968735e27ac8294439Craig Stout
140c62efa44831b1c60dcbdfd968735e27ac8294439Craig Stout            if (sShadowZ == 0) {
141c62efa44831b1c60dcbdfd968735e27ac8294439Craig Stout                sShadowZ = view.getResources().getDimensionPixelSize(
142c62efa44831b1c60dcbdfd968735e27ac8294439Craig Stout                        R.dimen.lb_playback_controls_z);
143c62efa44831b1c60dcbdfd968735e27ac8294439Craig Stout            }
144c62efa44831b1c60dcbdfd968735e27ac8294439Craig Stout            ShadowHelper.getInstance().setZ(view, sShadowZ);
145adf55abedd17eb9484d03da4b521209f15724f1fCraig Stout        }
1467ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout    }
1477ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout
1487ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout    private int mBackgroundColor = Color.TRANSPARENT;
1497ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout    private boolean mBackgroundColorSet;
1506dca725412977bb56b933bdec120e31909233cdbCraig Stout    private int mProgressColor = Color.TRANSPARENT;
1516dca725412977bb56b933bdec120e31909233cdbCraig Stout    private boolean mProgressColorSet;
1527ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout    private boolean mSecondaryActionsHidden;
1537ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout    private Presenter mDescriptionPresenter;
1547ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout    private PlaybackControlsPresenter mPlaybackControlsPresenter;
1557ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout    private ControlBarPresenter mSecondaryControlsPresenter;
156cf992de2d34abb8228dc6cb39fffe97346823a37Craig Stout    private OnActionClickedListener mOnActionClickedListener;
157c62efa44831b1c60dcbdfd968735e27ac8294439Craig Stout    private static float sShadowZ;
158cf992de2d34abb8228dc6cb39fffe97346823a37Craig Stout
159cf992de2d34abb8228dc6cb39fffe97346823a37Craig Stout    private final OnControlSelectedListener mOnControlSelectedListener =
160cf992de2d34abb8228dc6cb39fffe97346823a37Craig Stout            new OnControlSelectedListener() {
161cf992de2d34abb8228dc6cb39fffe97346823a37Craig Stout        @Override
162cf992de2d34abb8228dc6cb39fffe97346823a37Craig Stout        public void onControlSelected(Presenter.ViewHolder itemViewHolder, Object item,
163cf992de2d34abb8228dc6cb39fffe97346823a37Craig Stout                ControlBarPresenter.BoundData data) {
164cf992de2d34abb8228dc6cb39fffe97346823a37Craig Stout            ViewHolder vh = ((BoundData) data).mRowViewHolder;
165cf992de2d34abb8228dc6cb39fffe97346823a37Craig Stout            if (vh.mSelectedViewHolder != itemViewHolder || vh.mSelectedItem != item) {
166cf992de2d34abb8228dc6cb39fffe97346823a37Craig Stout                vh.mSelectedViewHolder = itemViewHolder;
167cf992de2d34abb8228dc6cb39fffe97346823a37Craig Stout                vh.mSelectedItem = item;
168cf992de2d34abb8228dc6cb39fffe97346823a37Craig Stout                vh.dispatchItemSelection();
169cf992de2d34abb8228dc6cb39fffe97346823a37Craig Stout            }
170cf992de2d34abb8228dc6cb39fffe97346823a37Craig Stout        }
171cf992de2d34abb8228dc6cb39fffe97346823a37Craig Stout    };
172cf992de2d34abb8228dc6cb39fffe97346823a37Craig Stout
173cf992de2d34abb8228dc6cb39fffe97346823a37Craig Stout    private final OnControlClickedListener mOnControlClickedListener =
174cf992de2d34abb8228dc6cb39fffe97346823a37Craig Stout            new OnControlClickedListener() {
175cf992de2d34abb8228dc6cb39fffe97346823a37Craig Stout        @Override
176cf992de2d34abb8228dc6cb39fffe97346823a37Craig Stout        public void onControlClicked(Presenter.ViewHolder itemViewHolder, Object item,
177cf992de2d34abb8228dc6cb39fffe97346823a37Craig Stout                ControlBarPresenter.BoundData data) {
178cf992de2d34abb8228dc6cb39fffe97346823a37Craig Stout            ViewHolder vh = ((BoundData) data).mRowViewHolder;
179cf992de2d34abb8228dc6cb39fffe97346823a37Craig Stout            if (getOnItemClickedListener() != null) {
180cf992de2d34abb8228dc6cb39fffe97346823a37Craig Stout                getOnItemClickedListener().onItemClicked(item, vh.getRow());
181cf992de2d34abb8228dc6cb39fffe97346823a37Craig Stout            }
182cf992de2d34abb8228dc6cb39fffe97346823a37Craig Stout            if (getOnItemViewClickedListener() != null) {
183cf992de2d34abb8228dc6cb39fffe97346823a37Craig Stout                getOnItemViewClickedListener().onItemClicked(itemViewHolder, item,
184cf992de2d34abb8228dc6cb39fffe97346823a37Craig Stout                        vh, vh.getRow());
185cf992de2d34abb8228dc6cb39fffe97346823a37Craig Stout            }
186cf992de2d34abb8228dc6cb39fffe97346823a37Craig Stout            if (mOnActionClickedListener != null && item instanceof Action) {
187cf992de2d34abb8228dc6cb39fffe97346823a37Craig Stout                mOnActionClickedListener.onActionClicked((Action) item);
188cf992de2d34abb8228dc6cb39fffe97346823a37Craig Stout            }
189cf992de2d34abb8228dc6cb39fffe97346823a37Craig Stout        }
190cf992de2d34abb8228dc6cb39fffe97346823a37Craig Stout    };
1917ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout
1927ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout    /**
1937ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout     * Constructor for a PlaybackControlsRowPresenter.
1947ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout     *
1957ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout     * @param descriptionPresenter Presenter for displaying item details.
1967ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout     */
1977ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout    public PlaybackControlsRowPresenter(Presenter descriptionPresenter) {
1987ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout        setHeaderPresenter(null);
1997ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout        setSelectEffectEnabled(false);
2007ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout
2017ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout        mDescriptionPresenter = descriptionPresenter;
2027ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout        mPlaybackControlsPresenter = new PlaybackControlsPresenter(R.layout.lb_playback_controls);
2037ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout        mSecondaryControlsPresenter = new ControlBarPresenter(R.layout.lb_control_bar);
204cf992de2d34abb8228dc6cb39fffe97346823a37Craig Stout
205cf992de2d34abb8228dc6cb39fffe97346823a37Craig Stout        mPlaybackControlsPresenter.setOnControlSelectedListener(mOnControlSelectedListener);
206cf992de2d34abb8228dc6cb39fffe97346823a37Craig Stout        mSecondaryControlsPresenter.setOnControlSelectedListener(mOnControlSelectedListener);
207cf992de2d34abb8228dc6cb39fffe97346823a37Craig Stout        mPlaybackControlsPresenter.setOnControlClickedListener(mOnControlClickedListener);
208cf992de2d34abb8228dc6cb39fffe97346823a37Craig Stout        mSecondaryControlsPresenter.setOnControlClickedListener(mOnControlClickedListener);
2097ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout    }
2107ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout
2117ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout    /**
2127ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout     * Constructor for a PlaybackControlsRowPresenter.
2137ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout     */
2147ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout    public PlaybackControlsRowPresenter() {
2157ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout        this(null);
2167ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout    }
2177ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout
2187ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout    /**
2197ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout     * Sets the listener for {@link Action} click events.
2207ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout     */
2217ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout    public void setOnActionClickedListener(OnActionClickedListener listener) {
222cf992de2d34abb8228dc6cb39fffe97346823a37Craig Stout        mOnActionClickedListener = listener;
2237ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout    }
2247ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout
2257ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout    /**
2267ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout     * Gets the listener for {@link Action} click events.
2277ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout     */
2287ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout    public OnActionClickedListener getOnActionClickedListener() {
229cf992de2d34abb8228dc6cb39fffe97346823a37Craig Stout        return mOnActionClickedListener;
2307ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout    }
2317ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout
2327ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout    /**
2337ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout     * Sets the background color.  If not set, a default from the theme will be used.
2347ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout     */
2357ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout    public void setBackgroundColor(int color) {
2367ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout        mBackgroundColor = color;
2377ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout        mBackgroundColorSet = true;
2387ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout    }
2397ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout
2407ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout    /**
2417ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout     * Returns the background color.  If no background color was set, transparent
2427ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout     * is returned.
2437ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout     */
2447ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout    public int getBackgroundColor() {
2457ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout        return mBackgroundColor;
2467ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout    }
2477ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout
2487ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout    /**
2496dca725412977bb56b933bdec120e31909233cdbCraig Stout     * Sets the primary color for the progress bar.  If not set, a default from
2506dca725412977bb56b933bdec120e31909233cdbCraig Stout     * the theme will be used.
2516dca725412977bb56b933bdec120e31909233cdbCraig Stout     */
2526dca725412977bb56b933bdec120e31909233cdbCraig Stout    public void setProgressColor(int color) {
2536dca725412977bb56b933bdec120e31909233cdbCraig Stout        mProgressColor = color;
2546dca725412977bb56b933bdec120e31909233cdbCraig Stout        mProgressColorSet = true;
2556dca725412977bb56b933bdec120e31909233cdbCraig Stout    }
2566dca725412977bb56b933bdec120e31909233cdbCraig Stout
2576dca725412977bb56b933bdec120e31909233cdbCraig Stout    /**
2586dca725412977bb56b933bdec120e31909233cdbCraig Stout     * Returns the primary color for the progress bar.  If no color was set, transparent
2596dca725412977bb56b933bdec120e31909233cdbCraig Stout     * is returned.
2606dca725412977bb56b933bdec120e31909233cdbCraig Stout     */
2616dca725412977bb56b933bdec120e31909233cdbCraig Stout    public int getProgressColor() {
2626dca725412977bb56b933bdec120e31909233cdbCraig Stout        return mProgressColor;
2636dca725412977bb56b933bdec120e31909233cdbCraig Stout    }
2646dca725412977bb56b933bdec120e31909233cdbCraig Stout
2656dca725412977bb56b933bdec120e31909233cdbCraig Stout    /**
2667ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout     * Sets the secondary actions to be hidden behind a "more actions" button.
2677ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout     * When "more actions" is selected, the primary actions are replaced with
2687ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout     * the secondary actions.
2697ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout     */
2707ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout    public void setSecondaryActionsHidden(boolean hidden) {
2717ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout        mSecondaryActionsHidden = hidden;
2727ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout    }
2737ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout
2747ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout    /**
2757ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout     * Returns true if secondary actions are hidden.
2767ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout     */
2777ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout    public boolean areSecondaryActionsHidden() {
2787ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout        return mSecondaryActionsHidden;
2797ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout    }
2807ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout
281d20507e0f5ac7ad021f42ca87c294787246f0591Craig Stout    /**
282d20507e0f5ac7ad021f42ca87c294787246f0591Craig Stout     * Shows or hides space at the bottom of the playback controls row.
283d20507e0f5ac7ad021f42ca87c294787246f0591Craig Stout     * This allows the row to hug the bottom of the display when no
284d20507e0f5ac7ad021f42ca87c294787246f0591Craig Stout     * other rows are present.
285d20507e0f5ac7ad021f42ca87c294787246f0591Craig Stout     */
286d20507e0f5ac7ad021f42ca87c294787246f0591Craig Stout    public void showBottomSpace(ViewHolder vh, boolean show) {
287d20507e0f5ac7ad021f42ca87c294787246f0591Craig Stout        vh.mBottomSpacer.setVisibility(show ? View.VISIBLE : View.GONE);
288d20507e0f5ac7ad021f42ca87c294787246f0591Craig Stout    }
289d20507e0f5ac7ad021f42ca87c294787246f0591Craig Stout
290aa67105babce5fb14e1f39b57d4c84ce634afa62Craig Stout    /**
291aa67105babce5fb14e1f39b57d4c84ce634afa62Craig Stout     * Display the primary actions.
292aa67105babce5fb14e1f39b57d4c84ce634afa62Craig Stout     */
293aa67105babce5fb14e1f39b57d4c84ce634afa62Craig Stout    public void showPrimaryActions(ViewHolder vh) {
294aa67105babce5fb14e1f39b57d4c84ce634afa62Craig Stout        mPlaybackControlsPresenter.showPrimaryActions(vh.mControlsVh);
295aa67105babce5fb14e1f39b57d4c84ce634afa62Craig Stout    }
296aa67105babce5fb14e1f39b57d4c84ce634afa62Craig Stout
2977ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout    private int getDefaultBackgroundColor(Context context) {
2987ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout        TypedValue outValue = new TypedValue();
2997ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout        context.getTheme().resolveAttribute(R.attr.defaultBrandColor, outValue, true);
3007ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout        return context.getResources().getColor(outValue.resourceId);
3017ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout    }
3027ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout
3036dca725412977bb56b933bdec120e31909233cdbCraig Stout    private int getDefaultProgressColor(Context context) {
3046dca725412977bb56b933bdec120e31909233cdbCraig Stout        TypedValue outValue = new TypedValue();
3056dca725412977bb56b933bdec120e31909233cdbCraig Stout        context.getTheme().resolveAttribute(R.attr.playbackProgressPrimaryColor, outValue, true);
3066dca725412977bb56b933bdec120e31909233cdbCraig Stout        return context.getResources().getColor(outValue.resourceId);
3076dca725412977bb56b933bdec120e31909233cdbCraig Stout    }
3086dca725412977bb56b933bdec120e31909233cdbCraig Stout
3097ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout    @Override
3107ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout    protected RowPresenter.ViewHolder createRowViewHolder(ViewGroup parent) {
3117ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout        View v = LayoutInflater.from(parent.getContext())
3127ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout            .inflate(R.layout.lb_playback_controls_row, parent, false);
3136b2e5b5117f1b8dfafbd81b995bb423ab0297564Craig Stout        ViewHolder vh = new ViewHolder(v, mDescriptionPresenter);
3147ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout        initRow(vh);
3157ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout        return vh;
3167ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout    }
3177ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout
3187ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout    private void initRow(ViewHolder vh) {
3197ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout        vh.mCardHeight = vh.mCard.getLayoutParams().height;
3207ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout
3217ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout        MarginLayoutParams lp = (MarginLayoutParams) vh.mControlsDock.getLayoutParams();
3227ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout        vh.mControlsDockMarginStart = lp.getMarginStart();
3237ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout        vh.mControlsDockMarginEnd = lp.getMarginEnd();
3247ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout
3256dca725412977bb56b933bdec120e31909233cdbCraig Stout        vh.mControlsVh = (PlaybackControlsPresenter.ViewHolder)
3266dca725412977bb56b933bdec120e31909233cdbCraig Stout                mPlaybackControlsPresenter.onCreateViewHolder(vh.mControlsDock);
3276dca725412977bb56b933bdec120e31909233cdbCraig Stout        mPlaybackControlsPresenter.setProgressColor(vh.mControlsVh,
3286dca725412977bb56b933bdec120e31909233cdbCraig Stout                mProgressColorSet ? mProgressColor :
3296dca725412977bb56b933bdec120e31909233cdbCraig Stout                        getDefaultProgressColor(vh.mControlsDock.getContext()));
3307ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout        vh.mControlsDock.addView(vh.mControlsVh.view);
3317ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout
3327ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout        vh.mSecondaryControlsVh =
3337ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout                mSecondaryControlsPresenter.onCreateViewHolder(vh.mSecondaryControlsDock);
3347ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout        if (!mSecondaryActionsHidden) {
3357ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout            vh.mSecondaryControlsDock.addView(vh.mSecondaryControlsVh.view);
3367ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout        }
3377ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout    }
3387ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout
3397ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout    @Override
3407ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout    protected void onBindRowViewHolder(RowPresenter.ViewHolder holder, Object item) {
3417ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout        super.onBindRowViewHolder(holder, item);
3427ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout
3437ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout        ViewHolder vh = (ViewHolder) holder;
3447ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout        PlaybackControlsRow row = (PlaybackControlsRow) vh.getRow();
3457ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout
3467ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout        mPlaybackControlsPresenter.enableSecondaryActions(mSecondaryActionsHidden);
3477ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout
3487ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout        if (row.getItem() == null) {
3497ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout            LayoutParams lp = vh.mCard.getLayoutParams();
3507ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout            lp.height = LayoutParams.WRAP_CONTENT;
3517ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout            vh.mCard.setLayoutParams(lp);
3527ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout            vh.mDescriptionDock.setVisibility(View.GONE);
3537ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout            vh.mSpacer.setVisibility(View.GONE);
3547ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout        } else {
3557ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout            LayoutParams lp = vh.mCard.getLayoutParams();
3567ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout            lp.height = vh.mCardHeight;
3577ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout            vh.mCard.setLayoutParams(lp);
3587ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout            vh.mDescriptionDock.setVisibility(View.VISIBLE);
3596b2e5b5117f1b8dfafbd81b995bb423ab0297564Craig Stout            if (vh.mDescriptionViewHolder != null) {
3606b2e5b5117f1b8dfafbd81b995bb423ab0297564Craig Stout                mDescriptionPresenter.onBindViewHolder(vh.mDescriptionViewHolder, row.getItem());
3617ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout            }
3627ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout            vh.mSpacer.setVisibility(View.VISIBLE);
3637ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout        }
3647ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout
3657ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout        MarginLayoutParams lp = (MarginLayoutParams) vh.mControlsDock.getLayoutParams();
3667ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout        if (row.getImageDrawable() == null || row.getItem() == null) {
3675dac2c723e1d50da356170a6f372dcbab1a7d83cCraig Stout            vh.mImageView.setImageDrawable(null);
368adf55abedd17eb9484d03da4b521209f15724f1fCraig Stout            vh.setBackground(vh.mControlsDock);
3697ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout            lp.setMarginStart(0);
3707ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout            lp.setMarginEnd(0);
371e5b67be786d519377ae275ef76f3ad72187183d5Craig Stout            mPlaybackControlsPresenter.enableTimeMargins(vh.mControlsVh, true);
3727ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout        } else {
3737ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout            vh.mImageView.setImageDrawable(row.getImageDrawable());
374adf55abedd17eb9484d03da4b521209f15724f1fCraig Stout            vh.setBackground(vh.mCard);
3757ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout            lp.setMarginStart(vh.mControlsDockMarginStart);
3767ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout            lp.setMarginEnd(vh.mControlsDockMarginEnd);
377e5b67be786d519377ae275ef76f3ad72187183d5Craig Stout            mPlaybackControlsPresenter.enableTimeMargins(vh.mControlsVh, false);
3787ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout        }
3797ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout        vh.mControlsDock.setLayoutParams(lp);
3807ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout
3817ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout        vh.mControlsBoundData.adapter = row.getPrimaryActionsAdapter();
3827ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout        vh.mControlsBoundData.secondaryActionsAdapter = row.getSecondaryActionsAdapter();
383cf992de2d34abb8228dc6cb39fffe97346823a37Craig Stout        vh.mControlsBoundData.presenter = vh.getPresenter(true);
384cf992de2d34abb8228dc6cb39fffe97346823a37Craig Stout        vh.mControlsBoundData.mRowViewHolder = vh;
3857ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout        mPlaybackControlsPresenter.onBindViewHolder(vh.mControlsVh, vh.mControlsBoundData);
3867ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout
3877ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout        vh.mSecondaryBoundData.adapter = row.getSecondaryActionsAdapter();
388cf992de2d34abb8228dc6cb39fffe97346823a37Craig Stout        vh.mSecondaryBoundData.presenter = vh.getPresenter(false);
389cf992de2d34abb8228dc6cb39fffe97346823a37Craig Stout        vh.mSecondaryBoundData.mRowViewHolder = vh;
3907ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout        mSecondaryControlsPresenter.onBindViewHolder(vh.mSecondaryControlsVh,
3917ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout                vh.mSecondaryBoundData);
3926dca725412977bb56b933bdec120e31909233cdbCraig Stout
3936dca725412977bb56b933bdec120e31909233cdbCraig Stout        mPlaybackControlsPresenter.setTotalTime(vh.mControlsVh, row.getTotalTime());
3946dca725412977bb56b933bdec120e31909233cdbCraig Stout        mPlaybackControlsPresenter.setCurrentTime(vh.mControlsVh, row.getCurrentTime());
3956dca725412977bb56b933bdec120e31909233cdbCraig Stout        mPlaybackControlsPresenter.setSecondaryProgress(vh.mControlsVh, row.getBufferedProgress());
3966dca725412977bb56b933bdec120e31909233cdbCraig Stout        row.setOnPlaybackStateChangedListener(vh.mListener);
3977ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout    }
3987ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout
3997ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout    @Override
4007ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout    protected void onUnbindRowViewHolder(RowPresenter.ViewHolder holder) {
4017ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout        ViewHolder vh = (ViewHolder) holder;
4026dca725412977bb56b933bdec120e31909233cdbCraig Stout        PlaybackControlsRow row = (PlaybackControlsRow) vh.getRow();
4036dca725412977bb56b933bdec120e31909233cdbCraig Stout
4046b2e5b5117f1b8dfafbd81b995bb423ab0297564Craig Stout        if (vh.mDescriptionViewHolder != null) {
4056b2e5b5117f1b8dfafbd81b995bb423ab0297564Craig Stout            mDescriptionPresenter.onUnbindViewHolder(vh.mDescriptionViewHolder);
4067ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout        }
4077ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout        mPlaybackControlsPresenter.onUnbindViewHolder(vh.mControlsVh);
4087ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout        mSecondaryControlsPresenter.onUnbindViewHolder(vh.mSecondaryControlsVh);
4096dca725412977bb56b933bdec120e31909233cdbCraig Stout        row.setOnPlaybackStateChangedListener(null);
4106dca725412977bb56b933bdec120e31909233cdbCraig Stout
4116dca725412977bb56b933bdec120e31909233cdbCraig Stout        super.onUnbindRowViewHolder(holder);
4127ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout    }
413cf992de2d34abb8228dc6cb39fffe97346823a37Craig Stout
414cf992de2d34abb8228dc6cb39fffe97346823a37Craig Stout    protected void onRowViewSelected(RowPresenter.ViewHolder vh, boolean selected) {
415cf992de2d34abb8228dc6cb39fffe97346823a37Craig Stout        super.onRowViewSelected(vh, selected);
416cf992de2d34abb8228dc6cb39fffe97346823a37Craig Stout        if (selected) {
417cf992de2d34abb8228dc6cb39fffe97346823a37Craig Stout            ((ViewHolder) vh).dispatchItemSelection();
418cf992de2d34abb8228dc6cb39fffe97346823a37Craig Stout        }
419cf992de2d34abb8228dc6cb39fffe97346823a37Craig Stout    }
42026d11212c4a66b075807888caacac5ee7fc10dc1Craig Stout
42126d11212c4a66b075807888caacac5ee7fc10dc1Craig Stout    @Override
42226d11212c4a66b075807888caacac5ee7fc10dc1Craig Stout    protected void onRowViewAttachedToWindow(RowPresenter.ViewHolder vh) {
42326d11212c4a66b075807888caacac5ee7fc10dc1Craig Stout        super.onRowViewAttachedToWindow(vh);
42426d11212c4a66b075807888caacac5ee7fc10dc1Craig Stout        if (mDescriptionPresenter != null) {
42526d11212c4a66b075807888caacac5ee7fc10dc1Craig Stout            mDescriptionPresenter.onViewAttachedToWindow(
42626d11212c4a66b075807888caacac5ee7fc10dc1Craig Stout                    ((ViewHolder) vh).mDescriptionViewHolder);
42726d11212c4a66b075807888caacac5ee7fc10dc1Craig Stout        }
42826d11212c4a66b075807888caacac5ee7fc10dc1Craig Stout    }
42926d11212c4a66b075807888caacac5ee7fc10dc1Craig Stout
43026d11212c4a66b075807888caacac5ee7fc10dc1Craig Stout    @Override
43126d11212c4a66b075807888caacac5ee7fc10dc1Craig Stout    protected void onRowViewDetachedFromWindow(RowPresenter.ViewHolder vh) {
43226d11212c4a66b075807888caacac5ee7fc10dc1Craig Stout        super.onRowViewDetachedFromWindow(vh);
43326d11212c4a66b075807888caacac5ee7fc10dc1Craig Stout        if (mDescriptionPresenter != null) {
43426d11212c4a66b075807888caacac5ee7fc10dc1Craig Stout            mDescriptionPresenter.onViewDetachedFromWindow(
43526d11212c4a66b075807888caacac5ee7fc10dc1Craig Stout                    ((ViewHolder) vh).mDescriptionViewHolder);
43626d11212c4a66b075807888caacac5ee7fc10dc1Craig Stout        }
43726d11212c4a66b075807888caacac5ee7fc10dc1Craig Stout    }
4387ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout}
439