PlaybackControlsRowPresenter.java revision 60bb6af2e336072921f5d3c3861e86b3cc6241b3
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; 2260bb6af2e336072921f5d3c3861e86b3cc6241b3Craig Stoutimport android.view.KeyEvent; 237ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stoutimport android.view.LayoutInflater; 247ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stoutimport android.view.View; 257ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stoutimport android.view.ViewGroup; 267ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stoutimport android.view.ViewGroup.LayoutParams; 277ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stoutimport android.view.ViewGroup.MarginLayoutParams; 287ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stoutimport android.widget.ImageView; 297ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout 307ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout/** 317ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout * A PlaybackControlsRowPresenter renders a {@link PlaybackControlsRow} to display a 327ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout * series of playback control buttons. Typically this row will be the first row in a fragment 337ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout * such as the {@link android.support.v17.leanback.app.PlaybackOverlayFragment 347ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout * PlaybackControlsFragment}. 357ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout */ 367ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stoutpublic class PlaybackControlsRowPresenter extends RowPresenter { 377ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout 38cf992de2d34abb8228dc6cb39fffe97346823a37Craig Stout static class BoundData extends PlaybackControlsPresenter.BoundData { 39cf992de2d34abb8228dc6cb39fffe97346823a37Craig Stout ViewHolder mRowViewHolder; 40cf992de2d34abb8228dc6cb39fffe97346823a37Craig Stout } 41cf992de2d34abb8228dc6cb39fffe97346823a37Craig Stout 427ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout /** 437ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout * A ViewHolder for the PlaybackControlsRow. 447ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout */ 456dca725412977bb56b933bdec120e31909233cdbCraig Stout public class ViewHolder extends RowPresenter.ViewHolder { 466b2e5b5117f1b8dfafbd81b995bb423ab0297564Craig Stout public final Presenter.ViewHolder mDescriptionViewHolder; 477ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout final ViewGroup mCard; 487ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout final ImageView mImageView; 497ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout final ViewGroup mDescriptionDock; 507ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout final ViewGroup mControlsDock; 517ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout final ViewGroup mSecondaryControlsDock; 527ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout final View mSpacer; 53d20507e0f5ac7ad021f42ca87c294787246f0591Craig Stout final View mBottomSpacer; 54adf55abedd17eb9484d03da4b521209f15724f1fCraig Stout View mBgView; 557ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout int mCardHeight; 567ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout int mControlsDockMarginStart; 577ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout int mControlsDockMarginEnd; 586dca725412977bb56b933bdec120e31909233cdbCraig Stout PlaybackControlsPresenter.ViewHolder mControlsVh; 597ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout Presenter.ViewHolder mSecondaryControlsVh; 60cf992de2d34abb8228dc6cb39fffe97346823a37Craig Stout BoundData mControlsBoundData = new BoundData(); 61cf992de2d34abb8228dc6cb39fffe97346823a37Craig Stout BoundData mSecondaryBoundData = new BoundData(); 62cf992de2d34abb8228dc6cb39fffe97346823a37Craig Stout Presenter.ViewHolder mSelectedViewHolder; 63cf992de2d34abb8228dc6cb39fffe97346823a37Craig Stout Object mSelectedItem; 644cc255c1c9ce5f3a718970b6e0be2c3ae6abf9edCraig Stout final PlaybackControlsRow.OnPlaybackStateChangedListener mListener = 656dca725412977bb56b933bdec120e31909233cdbCraig Stout new PlaybackControlsRow.OnPlaybackStateChangedListener() { 664cc255c1c9ce5f3a718970b6e0be2c3ae6abf9edCraig Stout @Override 674cc255c1c9ce5f3a718970b6e0be2c3ae6abf9edCraig Stout public void onCurrentTimeChanged(int ms) { 684cc255c1c9ce5f3a718970b6e0be2c3ae6abf9edCraig Stout mPlaybackControlsPresenter.setCurrentTime(mControlsVh, ms); 694cc255c1c9ce5f3a718970b6e0be2c3ae6abf9edCraig Stout } 704cc255c1c9ce5f3a718970b6e0be2c3ae6abf9edCraig Stout @Override 714cc255c1c9ce5f3a718970b6e0be2c3ae6abf9edCraig Stout public void onBufferedProgressChanged(int ms) { 724cc255c1c9ce5f3a718970b6e0be2c3ae6abf9edCraig Stout mPlaybackControlsPresenter.setSecondaryProgress(mControlsVh, ms); 734cc255c1c9ce5f3a718970b6e0be2c3ae6abf9edCraig Stout } 744cc255c1c9ce5f3a718970b6e0be2c3ae6abf9edCraig Stout }; 757ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout 766b2e5b5117f1b8dfafbd81b995bb423ab0297564Craig Stout ViewHolder(View rootView, Presenter descriptionPresenter) { 777ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout super(rootView); 787ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout mCard = (ViewGroup) rootView.findViewById(R.id.controls_card); 797ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout mImageView = (ImageView) rootView.findViewById(R.id.image); 807ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout mDescriptionDock = (ViewGroup) rootView.findViewById(R.id.description_dock); 817ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout mControlsDock = (ViewGroup) rootView.findViewById(R.id.controls_dock); 827ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout mSecondaryControlsDock = 837ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout (ViewGroup) rootView.findViewById(R.id.secondary_controls_dock); 847ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout mSpacer = rootView.findViewById(R.id.spacer); 85d20507e0f5ac7ad021f42ca87c294787246f0591Craig Stout mBottomSpacer = rootView.findViewById(R.id.bottom_spacer); 866b2e5b5117f1b8dfafbd81b995bb423ab0297564Craig Stout mDescriptionViewHolder = descriptionPresenter == null ? null : 876b2e5b5117f1b8dfafbd81b995bb423ab0297564Craig Stout descriptionPresenter.onCreateViewHolder(mDescriptionDock); 886b2e5b5117f1b8dfafbd81b995bb423ab0297564Craig Stout if (mDescriptionViewHolder != null) { 896b2e5b5117f1b8dfafbd81b995bb423ab0297564Craig Stout mDescriptionDock.addView(mDescriptionViewHolder.view); 906b2e5b5117f1b8dfafbd81b995bb423ab0297564Craig Stout } 917ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout } 927ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout 93cf992de2d34abb8228dc6cb39fffe97346823a37Craig Stout void dispatchItemSelection() { 94cf992de2d34abb8228dc6cb39fffe97346823a37Craig Stout if (!isSelected()) { 95cf992de2d34abb8228dc6cb39fffe97346823a37Craig Stout return; 96cf992de2d34abb8228dc6cb39fffe97346823a37Craig Stout } 97cf992de2d34abb8228dc6cb39fffe97346823a37Craig Stout if (mSelectedViewHolder == null) { 98cf992de2d34abb8228dc6cb39fffe97346823a37Craig Stout if (getOnItemSelectedListener() != null) { 99cf992de2d34abb8228dc6cb39fffe97346823a37Craig Stout getOnItemSelectedListener().onItemSelected(null, getRow()); 100cf992de2d34abb8228dc6cb39fffe97346823a37Craig Stout } 101cf992de2d34abb8228dc6cb39fffe97346823a37Craig Stout if (getOnItemViewSelectedListener() != null) { 102cf992de2d34abb8228dc6cb39fffe97346823a37Craig Stout getOnItemViewSelectedListener().onItemSelected(null, null, 103cf992de2d34abb8228dc6cb39fffe97346823a37Craig Stout ViewHolder.this, getRow()); 104cf992de2d34abb8228dc6cb39fffe97346823a37Craig Stout } 105cf992de2d34abb8228dc6cb39fffe97346823a37Craig Stout } else { 106cf992de2d34abb8228dc6cb39fffe97346823a37Craig Stout if (getOnItemSelectedListener() != null) { 107cf992de2d34abb8228dc6cb39fffe97346823a37Craig Stout getOnItemSelectedListener().onItemSelected(mSelectedItem, getRow()); 108cf992de2d34abb8228dc6cb39fffe97346823a37Craig Stout } 109cf992de2d34abb8228dc6cb39fffe97346823a37Craig Stout if (getOnItemViewSelectedListener() != null) { 110cf992de2d34abb8228dc6cb39fffe97346823a37Craig Stout getOnItemViewSelectedListener().onItemSelected(mSelectedViewHolder, mSelectedItem, 111cf992de2d34abb8228dc6cb39fffe97346823a37Craig Stout ViewHolder.this, getRow()); 112cf992de2d34abb8228dc6cb39fffe97346823a37Craig Stout } 113cf992de2d34abb8228dc6cb39fffe97346823a37Craig Stout } 114cf992de2d34abb8228dc6cb39fffe97346823a37Craig Stout }; 115cf992de2d34abb8228dc6cb39fffe97346823a37Craig Stout 116cf992de2d34abb8228dc6cb39fffe97346823a37Craig Stout Presenter getPresenter(boolean primary) { 1177ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout ObjectAdapter adapter = primary ? 1187ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout ((PlaybackControlsRow) getRow()).getPrimaryActionsAdapter() : 1197ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout ((PlaybackControlsRow) getRow()).getSecondaryActionsAdapter(); 1205dac2c723e1d50da356170a6f372dcbab1a7d83cCraig Stout if (adapter == null) { 1215dac2c723e1d50da356170a6f372dcbab1a7d83cCraig Stout return null; 1225dac2c723e1d50da356170a6f372dcbab1a7d83cCraig Stout } 1237ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout if (adapter.getPresenterSelector() instanceof ControlButtonPresenterSelector) { 1247ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout ControlButtonPresenterSelector selector = 1257ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout (ControlButtonPresenterSelector) adapter.getPresenterSelector(); 1267ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout return primary ? selector.getPrimaryPresenter() : 1277ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout selector.getSecondaryPresenter(); 1287ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout } 129cf992de2d34abb8228dc6cb39fffe97346823a37Craig Stout return adapter.getPresenter(adapter.size() > 0 ? adapter.get(0) : null); 1307ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout } 131adf55abedd17eb9484d03da4b521209f15724f1fCraig Stout 132adf55abedd17eb9484d03da4b521209f15724f1fCraig Stout void setBackground(View view) { 133adf55abedd17eb9484d03da4b521209f15724f1fCraig Stout if (mBgView != null) { 1344f34a05cdf73b68c3b2eb8678f740ab15225126aCraig Stout RoundedRectHelper.getInstance().clearBackground(mBgView); 135c62efa44831b1c60dcbdfd968735e27ac8294439Craig Stout ShadowHelper.getInstance().setZ(mBgView, 0); 136adf55abedd17eb9484d03da4b521209f15724f1fCraig Stout } 137adf55abedd17eb9484d03da4b521209f15724f1fCraig Stout mBgView = view; 1384f34a05cdf73b68c3b2eb8678f740ab15225126aCraig Stout RoundedRectHelper.getInstance().setRoundedRectBackground(view, mBackgroundColorSet ? 139adf55abedd17eb9484d03da4b521209f15724f1fCraig Stout mBackgroundColor : getDefaultBackgroundColor(view.getContext())); 140c62efa44831b1c60dcbdfd968735e27ac8294439Craig Stout 141c62efa44831b1c60dcbdfd968735e27ac8294439Craig Stout if (sShadowZ == 0) { 142c62efa44831b1c60dcbdfd968735e27ac8294439Craig Stout sShadowZ = view.getResources().getDimensionPixelSize( 143c62efa44831b1c60dcbdfd968735e27ac8294439Craig Stout R.dimen.lb_playback_controls_z); 144c62efa44831b1c60dcbdfd968735e27ac8294439Craig Stout } 145c62efa44831b1c60dcbdfd968735e27ac8294439Craig Stout ShadowHelper.getInstance().setZ(view, sShadowZ); 146adf55abedd17eb9484d03da4b521209f15724f1fCraig Stout } 1477ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout } 1487ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout 1497ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout private int mBackgroundColor = Color.TRANSPARENT; 1507ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout private boolean mBackgroundColorSet; 1516dca725412977bb56b933bdec120e31909233cdbCraig Stout private int mProgressColor = Color.TRANSPARENT; 1526dca725412977bb56b933bdec120e31909233cdbCraig Stout private boolean mProgressColorSet; 1537ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout private boolean mSecondaryActionsHidden; 1547ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout private Presenter mDescriptionPresenter; 1557ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout private PlaybackControlsPresenter mPlaybackControlsPresenter; 1567ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout private ControlBarPresenter mSecondaryControlsPresenter; 157cf992de2d34abb8228dc6cb39fffe97346823a37Craig Stout private OnActionClickedListener mOnActionClickedListener; 158c62efa44831b1c60dcbdfd968735e27ac8294439Craig Stout private static float sShadowZ; 159cf992de2d34abb8228dc6cb39fffe97346823a37Craig Stout 160cf992de2d34abb8228dc6cb39fffe97346823a37Craig Stout private final OnControlSelectedListener mOnControlSelectedListener = 161cf992de2d34abb8228dc6cb39fffe97346823a37Craig Stout new OnControlSelectedListener() { 162cf992de2d34abb8228dc6cb39fffe97346823a37Craig Stout @Override 163cf992de2d34abb8228dc6cb39fffe97346823a37Craig Stout public void onControlSelected(Presenter.ViewHolder itemViewHolder, Object item, 164cf992de2d34abb8228dc6cb39fffe97346823a37Craig Stout ControlBarPresenter.BoundData data) { 165cf992de2d34abb8228dc6cb39fffe97346823a37Craig Stout ViewHolder vh = ((BoundData) data).mRowViewHolder; 166cf992de2d34abb8228dc6cb39fffe97346823a37Craig Stout if (vh.mSelectedViewHolder != itemViewHolder || vh.mSelectedItem != item) { 167cf992de2d34abb8228dc6cb39fffe97346823a37Craig Stout vh.mSelectedViewHolder = itemViewHolder; 168cf992de2d34abb8228dc6cb39fffe97346823a37Craig Stout vh.mSelectedItem = item; 169cf992de2d34abb8228dc6cb39fffe97346823a37Craig Stout vh.dispatchItemSelection(); 170cf992de2d34abb8228dc6cb39fffe97346823a37Craig Stout } 171cf992de2d34abb8228dc6cb39fffe97346823a37Craig Stout } 172cf992de2d34abb8228dc6cb39fffe97346823a37Craig Stout }; 173cf992de2d34abb8228dc6cb39fffe97346823a37Craig Stout 174cf992de2d34abb8228dc6cb39fffe97346823a37Craig Stout private final OnControlClickedListener mOnControlClickedListener = 175cf992de2d34abb8228dc6cb39fffe97346823a37Craig Stout new OnControlClickedListener() { 176cf992de2d34abb8228dc6cb39fffe97346823a37Craig Stout @Override 177cf992de2d34abb8228dc6cb39fffe97346823a37Craig Stout public void onControlClicked(Presenter.ViewHolder itemViewHolder, Object item, 178cf992de2d34abb8228dc6cb39fffe97346823a37Craig Stout ControlBarPresenter.BoundData data) { 179cf992de2d34abb8228dc6cb39fffe97346823a37Craig Stout ViewHolder vh = ((BoundData) data).mRowViewHolder; 180cf992de2d34abb8228dc6cb39fffe97346823a37Craig Stout if (getOnItemClickedListener() != null) { 181cf992de2d34abb8228dc6cb39fffe97346823a37Craig Stout getOnItemClickedListener().onItemClicked(item, vh.getRow()); 182cf992de2d34abb8228dc6cb39fffe97346823a37Craig Stout } 183cf992de2d34abb8228dc6cb39fffe97346823a37Craig Stout if (getOnItemViewClickedListener() != null) { 184cf992de2d34abb8228dc6cb39fffe97346823a37Craig Stout getOnItemViewClickedListener().onItemClicked(itemViewHolder, item, 185cf992de2d34abb8228dc6cb39fffe97346823a37Craig Stout vh, vh.getRow()); 186cf992de2d34abb8228dc6cb39fffe97346823a37Craig Stout } 187cf992de2d34abb8228dc6cb39fffe97346823a37Craig Stout if (mOnActionClickedListener != null && item instanceof Action) { 188cf992de2d34abb8228dc6cb39fffe97346823a37Craig Stout mOnActionClickedListener.onActionClicked((Action) item); 189cf992de2d34abb8228dc6cb39fffe97346823a37Craig Stout } 190cf992de2d34abb8228dc6cb39fffe97346823a37Craig Stout } 191cf992de2d34abb8228dc6cb39fffe97346823a37Craig Stout }; 1927ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout 1937ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout /** 1947ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout * Constructor for a PlaybackControlsRowPresenter. 1957ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout * 1967ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout * @param descriptionPresenter Presenter for displaying item details. 1977ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout */ 1987ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout public PlaybackControlsRowPresenter(Presenter descriptionPresenter) { 1997ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout setHeaderPresenter(null); 2007ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout setSelectEffectEnabled(false); 2017ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout 2027ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout mDescriptionPresenter = descriptionPresenter; 2037ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout mPlaybackControlsPresenter = new PlaybackControlsPresenter(R.layout.lb_playback_controls); 2047ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout mSecondaryControlsPresenter = new ControlBarPresenter(R.layout.lb_control_bar); 205cf992de2d34abb8228dc6cb39fffe97346823a37Craig Stout 206cf992de2d34abb8228dc6cb39fffe97346823a37Craig Stout mPlaybackControlsPresenter.setOnControlSelectedListener(mOnControlSelectedListener); 207cf992de2d34abb8228dc6cb39fffe97346823a37Craig Stout mSecondaryControlsPresenter.setOnControlSelectedListener(mOnControlSelectedListener); 208cf992de2d34abb8228dc6cb39fffe97346823a37Craig Stout mPlaybackControlsPresenter.setOnControlClickedListener(mOnControlClickedListener); 209cf992de2d34abb8228dc6cb39fffe97346823a37Craig Stout mSecondaryControlsPresenter.setOnControlClickedListener(mOnControlClickedListener); 2107ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout } 2117ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout 2127ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout /** 2137ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout * Constructor for a PlaybackControlsRowPresenter. 2147ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout */ 2157ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout public PlaybackControlsRowPresenter() { 2167ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout this(null); 2177ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout } 2187ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout 2197ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout /** 2207ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout * Sets the listener for {@link Action} click events. 2217ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout */ 2227ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout public void setOnActionClickedListener(OnActionClickedListener listener) { 223cf992de2d34abb8228dc6cb39fffe97346823a37Craig Stout mOnActionClickedListener = listener; 2247ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout } 2257ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout 2267ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout /** 2277ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout * Gets the listener for {@link Action} click events. 2287ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout */ 2297ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout public OnActionClickedListener getOnActionClickedListener() { 230cf992de2d34abb8228dc6cb39fffe97346823a37Craig Stout return mOnActionClickedListener; 2317ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout } 2327ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout 2337ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout /** 2347ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout * Sets the background color. If not set, a default from the theme will be used. 2357ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout */ 2367ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout public void setBackgroundColor(int color) { 2377ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout mBackgroundColor = color; 2387ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout mBackgroundColorSet = true; 2397ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout } 2407ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout 2417ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout /** 2427ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout * Returns the background color. If no background color was set, transparent 2437ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout * is returned. 2447ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout */ 2457ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout public int getBackgroundColor() { 2467ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout return mBackgroundColor; 2477ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout } 2487ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout 2497ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout /** 2506dca725412977bb56b933bdec120e31909233cdbCraig Stout * Sets the primary color for the progress bar. If not set, a default from 2516dca725412977bb56b933bdec120e31909233cdbCraig Stout * the theme will be used. 2526dca725412977bb56b933bdec120e31909233cdbCraig Stout */ 2536dca725412977bb56b933bdec120e31909233cdbCraig Stout public void setProgressColor(int color) { 2546dca725412977bb56b933bdec120e31909233cdbCraig Stout mProgressColor = color; 2556dca725412977bb56b933bdec120e31909233cdbCraig Stout mProgressColorSet = true; 2566dca725412977bb56b933bdec120e31909233cdbCraig Stout } 2576dca725412977bb56b933bdec120e31909233cdbCraig Stout 2586dca725412977bb56b933bdec120e31909233cdbCraig Stout /** 2596dca725412977bb56b933bdec120e31909233cdbCraig Stout * Returns the primary color for the progress bar. If no color was set, transparent 2606dca725412977bb56b933bdec120e31909233cdbCraig Stout * is returned. 2616dca725412977bb56b933bdec120e31909233cdbCraig Stout */ 2626dca725412977bb56b933bdec120e31909233cdbCraig Stout public int getProgressColor() { 2636dca725412977bb56b933bdec120e31909233cdbCraig Stout return mProgressColor; 2646dca725412977bb56b933bdec120e31909233cdbCraig Stout } 2656dca725412977bb56b933bdec120e31909233cdbCraig Stout 2666dca725412977bb56b933bdec120e31909233cdbCraig Stout /** 2677ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout * Sets the secondary actions to be hidden behind a "more actions" button. 2687ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout * When "more actions" is selected, the primary actions are replaced with 2697ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout * the secondary actions. 2707ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout */ 2717ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout public void setSecondaryActionsHidden(boolean hidden) { 2727ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout mSecondaryActionsHidden = hidden; 2737ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout } 2747ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout 2757ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout /** 2767ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout * Returns true if secondary actions are hidden. 2777ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout */ 2787ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout public boolean areSecondaryActionsHidden() { 2797ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout return mSecondaryActionsHidden; 2807ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout } 2817ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout 282d20507e0f5ac7ad021f42ca87c294787246f0591Craig Stout /** 283d20507e0f5ac7ad021f42ca87c294787246f0591Craig Stout * Shows or hides space at the bottom of the playback controls row. 284d20507e0f5ac7ad021f42ca87c294787246f0591Craig Stout * This allows the row to hug the bottom of the display when no 285d20507e0f5ac7ad021f42ca87c294787246f0591Craig Stout * other rows are present. 286d20507e0f5ac7ad021f42ca87c294787246f0591Craig Stout */ 287d20507e0f5ac7ad021f42ca87c294787246f0591Craig Stout public void showBottomSpace(ViewHolder vh, boolean show) { 288d20507e0f5ac7ad021f42ca87c294787246f0591Craig Stout vh.mBottomSpacer.setVisibility(show ? View.VISIBLE : View.GONE); 289d20507e0f5ac7ad021f42ca87c294787246f0591Craig Stout } 290d20507e0f5ac7ad021f42ca87c294787246f0591Craig Stout 291aa67105babce5fb14e1f39b57d4c84ce634afa62Craig Stout /** 292aa67105babce5fb14e1f39b57d4c84ce634afa62Craig Stout * Display the primary actions. 293aa67105babce5fb14e1f39b57d4c84ce634afa62Craig Stout */ 294aa67105babce5fb14e1f39b57d4c84ce634afa62Craig Stout public void showPrimaryActions(ViewHolder vh) { 295aa67105babce5fb14e1f39b57d4c84ce634afa62Craig Stout mPlaybackControlsPresenter.showPrimaryActions(vh.mControlsVh); 296aa67105babce5fb14e1f39b57d4c84ce634afa62Craig Stout } 297aa67105babce5fb14e1f39b57d4c84ce634afa62Craig Stout 2987ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout private int getDefaultBackgroundColor(Context context) { 2997ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout TypedValue outValue = new TypedValue(); 3007ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout context.getTheme().resolveAttribute(R.attr.defaultBrandColor, outValue, true); 3017ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout return context.getResources().getColor(outValue.resourceId); 3027ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout } 3037ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout 3046dca725412977bb56b933bdec120e31909233cdbCraig Stout private int getDefaultProgressColor(Context context) { 3056dca725412977bb56b933bdec120e31909233cdbCraig Stout TypedValue outValue = new TypedValue(); 3066dca725412977bb56b933bdec120e31909233cdbCraig Stout context.getTheme().resolveAttribute(R.attr.playbackProgressPrimaryColor, outValue, true); 3076dca725412977bb56b933bdec120e31909233cdbCraig Stout return context.getResources().getColor(outValue.resourceId); 3086dca725412977bb56b933bdec120e31909233cdbCraig Stout } 3096dca725412977bb56b933bdec120e31909233cdbCraig Stout 3107ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout @Override 3117ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout protected RowPresenter.ViewHolder createRowViewHolder(ViewGroup parent) { 3127ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout View v = LayoutInflater.from(parent.getContext()) 3137ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout .inflate(R.layout.lb_playback_controls_row, parent, false); 3146b2e5b5117f1b8dfafbd81b995bb423ab0297564Craig Stout ViewHolder vh = new ViewHolder(v, mDescriptionPresenter); 3157ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout initRow(vh); 3167ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout return vh; 3177ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout } 3187ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout 31960bb6af2e336072921f5d3c3861e86b3cc6241b3Craig Stout private void initRow(final ViewHolder vh) { 3207ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout vh.mCardHeight = vh.mCard.getLayoutParams().height; 3217ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout 3227ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout MarginLayoutParams lp = (MarginLayoutParams) vh.mControlsDock.getLayoutParams(); 3237ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout vh.mControlsDockMarginStart = lp.getMarginStart(); 3247ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout vh.mControlsDockMarginEnd = lp.getMarginEnd(); 3257ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout 3266dca725412977bb56b933bdec120e31909233cdbCraig Stout vh.mControlsVh = (PlaybackControlsPresenter.ViewHolder) 3276dca725412977bb56b933bdec120e31909233cdbCraig Stout mPlaybackControlsPresenter.onCreateViewHolder(vh.mControlsDock); 3286dca725412977bb56b933bdec120e31909233cdbCraig Stout mPlaybackControlsPresenter.setProgressColor(vh.mControlsVh, 3296dca725412977bb56b933bdec120e31909233cdbCraig Stout mProgressColorSet ? mProgressColor : 3306dca725412977bb56b933bdec120e31909233cdbCraig Stout getDefaultProgressColor(vh.mControlsDock.getContext())); 3317ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout vh.mControlsDock.addView(vh.mControlsVh.view); 3327ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout 3337ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout vh.mSecondaryControlsVh = 3347ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout mSecondaryControlsPresenter.onCreateViewHolder(vh.mSecondaryControlsDock); 3357ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout if (!mSecondaryActionsHidden) { 3367ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout vh.mSecondaryControlsDock.addView(vh.mSecondaryControlsVh.view); 3377ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout } 33860bb6af2e336072921f5d3c3861e86b3cc6241b3Craig Stout ((PlaybackControlsRowView) vh.view).setOnUnhandledKeyListener( 33960bb6af2e336072921f5d3c3861e86b3cc6241b3Craig Stout new PlaybackControlsRowView.OnUnhandledKeyListener() { 34060bb6af2e336072921f5d3c3861e86b3cc6241b3Craig Stout @Override 34160bb6af2e336072921f5d3c3861e86b3cc6241b3Craig Stout public boolean onUnhandledKey(KeyEvent event) { 34260bb6af2e336072921f5d3c3861e86b3cc6241b3Craig Stout if (vh.getOnKeyListener() != null) { 34360bb6af2e336072921f5d3c3861e86b3cc6241b3Craig Stout if (vh.getOnKeyListener().onKey(vh.view, event.getKeyCode(), event)) { 34460bb6af2e336072921f5d3c3861e86b3cc6241b3Craig Stout return true; 34560bb6af2e336072921f5d3c3861e86b3cc6241b3Craig Stout } 34660bb6af2e336072921f5d3c3861e86b3cc6241b3Craig Stout } 34760bb6af2e336072921f5d3c3861e86b3cc6241b3Craig Stout return false; 34860bb6af2e336072921f5d3c3861e86b3cc6241b3Craig Stout } 34960bb6af2e336072921f5d3c3861e86b3cc6241b3Craig Stout }); 3507ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout } 3517ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout 3527ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout @Override 3537ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout protected void onBindRowViewHolder(RowPresenter.ViewHolder holder, Object item) { 3547ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout super.onBindRowViewHolder(holder, item); 3557ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout 3567ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout ViewHolder vh = (ViewHolder) holder; 3577ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout PlaybackControlsRow row = (PlaybackControlsRow) vh.getRow(); 3587ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout 3597ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout mPlaybackControlsPresenter.enableSecondaryActions(mSecondaryActionsHidden); 3607ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout 3617ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout if (row.getItem() == null) { 3627ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout LayoutParams lp = vh.mCard.getLayoutParams(); 3637ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout lp.height = LayoutParams.WRAP_CONTENT; 3647ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout vh.mCard.setLayoutParams(lp); 3657ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout vh.mDescriptionDock.setVisibility(View.GONE); 3667ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout vh.mSpacer.setVisibility(View.GONE); 3677ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout } else { 3687ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout LayoutParams lp = vh.mCard.getLayoutParams(); 3697ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout lp.height = vh.mCardHeight; 3707ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout vh.mCard.setLayoutParams(lp); 3717ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout vh.mDescriptionDock.setVisibility(View.VISIBLE); 3726b2e5b5117f1b8dfafbd81b995bb423ab0297564Craig Stout if (vh.mDescriptionViewHolder != null) { 3736b2e5b5117f1b8dfafbd81b995bb423ab0297564Craig Stout mDescriptionPresenter.onBindViewHolder(vh.mDescriptionViewHolder, row.getItem()); 3747ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout } 3757ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout vh.mSpacer.setVisibility(View.VISIBLE); 3767ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout } 3777ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout 3787ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout MarginLayoutParams lp = (MarginLayoutParams) vh.mControlsDock.getLayoutParams(); 3797ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout if (row.getImageDrawable() == null || row.getItem() == null) { 3805dac2c723e1d50da356170a6f372dcbab1a7d83cCraig Stout vh.mImageView.setImageDrawable(null); 381adf55abedd17eb9484d03da4b521209f15724f1fCraig Stout vh.setBackground(vh.mControlsDock); 3827ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout lp.setMarginStart(0); 3837ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout lp.setMarginEnd(0); 384e5b67be786d519377ae275ef76f3ad72187183d5Craig Stout mPlaybackControlsPresenter.enableTimeMargins(vh.mControlsVh, true); 3857ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout } else { 3867ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout vh.mImageView.setImageDrawable(row.getImageDrawable()); 387adf55abedd17eb9484d03da4b521209f15724f1fCraig Stout vh.setBackground(vh.mCard); 3887ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout lp.setMarginStart(vh.mControlsDockMarginStart); 3897ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout lp.setMarginEnd(vh.mControlsDockMarginEnd); 390e5b67be786d519377ae275ef76f3ad72187183d5Craig Stout mPlaybackControlsPresenter.enableTimeMargins(vh.mControlsVh, false); 3917ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout } 3927ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout vh.mControlsDock.setLayoutParams(lp); 3937ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout 3947ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout vh.mControlsBoundData.adapter = row.getPrimaryActionsAdapter(); 3957ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout vh.mControlsBoundData.secondaryActionsAdapter = row.getSecondaryActionsAdapter(); 396cf992de2d34abb8228dc6cb39fffe97346823a37Craig Stout vh.mControlsBoundData.presenter = vh.getPresenter(true); 397cf992de2d34abb8228dc6cb39fffe97346823a37Craig Stout vh.mControlsBoundData.mRowViewHolder = vh; 3987ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout mPlaybackControlsPresenter.onBindViewHolder(vh.mControlsVh, vh.mControlsBoundData); 3997ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout 4007ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout vh.mSecondaryBoundData.adapter = row.getSecondaryActionsAdapter(); 401cf992de2d34abb8228dc6cb39fffe97346823a37Craig Stout vh.mSecondaryBoundData.presenter = vh.getPresenter(false); 402cf992de2d34abb8228dc6cb39fffe97346823a37Craig Stout vh.mSecondaryBoundData.mRowViewHolder = vh; 4037ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout mSecondaryControlsPresenter.onBindViewHolder(vh.mSecondaryControlsVh, 4047ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout vh.mSecondaryBoundData); 4056dca725412977bb56b933bdec120e31909233cdbCraig Stout 4066dca725412977bb56b933bdec120e31909233cdbCraig Stout mPlaybackControlsPresenter.setTotalTime(vh.mControlsVh, row.getTotalTime()); 4076dca725412977bb56b933bdec120e31909233cdbCraig Stout mPlaybackControlsPresenter.setCurrentTime(vh.mControlsVh, row.getCurrentTime()); 4086dca725412977bb56b933bdec120e31909233cdbCraig Stout mPlaybackControlsPresenter.setSecondaryProgress(vh.mControlsVh, row.getBufferedProgress()); 4096dca725412977bb56b933bdec120e31909233cdbCraig Stout row.setOnPlaybackStateChangedListener(vh.mListener); 4107ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout } 4117ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout 4127ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout @Override 4137ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout protected void onUnbindRowViewHolder(RowPresenter.ViewHolder holder) { 4147ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout ViewHolder vh = (ViewHolder) holder; 4156dca725412977bb56b933bdec120e31909233cdbCraig Stout PlaybackControlsRow row = (PlaybackControlsRow) vh.getRow(); 4166dca725412977bb56b933bdec120e31909233cdbCraig Stout 4176b2e5b5117f1b8dfafbd81b995bb423ab0297564Craig Stout if (vh.mDescriptionViewHolder != null) { 4186b2e5b5117f1b8dfafbd81b995bb423ab0297564Craig Stout mDescriptionPresenter.onUnbindViewHolder(vh.mDescriptionViewHolder); 4197ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout } 4207ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout mPlaybackControlsPresenter.onUnbindViewHolder(vh.mControlsVh); 4217ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout mSecondaryControlsPresenter.onUnbindViewHolder(vh.mSecondaryControlsVh); 4226dca725412977bb56b933bdec120e31909233cdbCraig Stout row.setOnPlaybackStateChangedListener(null); 4236dca725412977bb56b933bdec120e31909233cdbCraig Stout 4246dca725412977bb56b933bdec120e31909233cdbCraig Stout super.onUnbindRowViewHolder(holder); 4257ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout } 426cf992de2d34abb8228dc6cb39fffe97346823a37Craig Stout 427cf992de2d34abb8228dc6cb39fffe97346823a37Craig Stout protected void onRowViewSelected(RowPresenter.ViewHolder vh, boolean selected) { 428cf992de2d34abb8228dc6cb39fffe97346823a37Craig Stout super.onRowViewSelected(vh, selected); 429cf992de2d34abb8228dc6cb39fffe97346823a37Craig Stout if (selected) { 430cf992de2d34abb8228dc6cb39fffe97346823a37Craig Stout ((ViewHolder) vh).dispatchItemSelection(); 431cf992de2d34abb8228dc6cb39fffe97346823a37Craig Stout } 432cf992de2d34abb8228dc6cb39fffe97346823a37Craig Stout } 43326d11212c4a66b075807888caacac5ee7fc10dc1Craig Stout 43426d11212c4a66b075807888caacac5ee7fc10dc1Craig Stout @Override 43526d11212c4a66b075807888caacac5ee7fc10dc1Craig Stout protected void onRowViewAttachedToWindow(RowPresenter.ViewHolder vh) { 43626d11212c4a66b075807888caacac5ee7fc10dc1Craig Stout super.onRowViewAttachedToWindow(vh); 43726d11212c4a66b075807888caacac5ee7fc10dc1Craig Stout if (mDescriptionPresenter != null) { 43826d11212c4a66b075807888caacac5ee7fc10dc1Craig Stout mDescriptionPresenter.onViewAttachedToWindow( 43926d11212c4a66b075807888caacac5ee7fc10dc1Craig Stout ((ViewHolder) vh).mDescriptionViewHolder); 44026d11212c4a66b075807888caacac5ee7fc10dc1Craig Stout } 44126d11212c4a66b075807888caacac5ee7fc10dc1Craig Stout } 44226d11212c4a66b075807888caacac5ee7fc10dc1Craig Stout 44326d11212c4a66b075807888caacac5ee7fc10dc1Craig Stout @Override 44426d11212c4a66b075807888caacac5ee7fc10dc1Craig Stout protected void onRowViewDetachedFromWindow(RowPresenter.ViewHolder vh) { 44526d11212c4a66b075807888caacac5ee7fc10dc1Craig Stout super.onRowViewDetachedFromWindow(vh); 44626d11212c4a66b075807888caacac5ee7fc10dc1Craig Stout if (mDescriptionPresenter != null) { 44726d11212c4a66b075807888caacac5ee7fc10dc1Craig Stout mDescriptionPresenter.onViewDetachedFromWindow( 44826d11212c4a66b075807888caacac5ee7fc10dc1Craig Stout ((ViewHolder) vh).mDescriptionViewHolder); 44926d11212c4a66b075807888caacac5ee7fc10dc1Craig Stout } 45026d11212c4a66b075807888caacac5ee7fc10dc1Craig Stout } 4517ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout} 452