PlaybackControlsRowPresenter.java revision 7ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7
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; 177ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stoutimport android.content.Context; 187ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stoutimport android.graphics.Color; 197ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stoutimport android.util.TypedValue; 207ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stoutimport android.view.LayoutInflater; 217ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stoutimport android.view.View; 227ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stoutimport android.view.ViewGroup; 237ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stoutimport android.view.ViewGroup.LayoutParams; 247ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stoutimport android.view.ViewGroup.MarginLayoutParams; 257ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stoutimport android.widget.ImageView; 267ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout 277ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout/** 287ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout * A PlaybackControlsRowPresenter renders a {@link PlaybackControlsRow} to display a 297ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout * series of playback control buttons. Typically this row will be the first row in a fragment 307ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout * such as the {@link android.support.v17.leanback.app.PlaybackOverlayFragment 317ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout * PlaybackControlsFragment}. 327ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout */ 337ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stoutpublic class PlaybackControlsRowPresenter extends RowPresenter { 347ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout 357ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout /** 367ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout * A ViewHolder for the PlaybackControlsRow. 377ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout */ 387ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout public static class ViewHolder extends RowPresenter.ViewHolder { 397ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout final ViewGroup mCard; 407ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout final ImageView mImageView; 417ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout final ViewGroup mDescriptionDock; 427ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout final ViewGroup mControlsDock; 437ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout final ViewGroup mSecondaryControlsDock; 447ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout final View mSpacer; 457ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout int mCardHeight; 467ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout int mControlsDockMarginStart; 477ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout int mControlsDockMarginEnd; 487ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout Presenter.ViewHolder mDescriptionVh; 497ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout Presenter.ViewHolder mControlsVh; 507ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout Presenter.ViewHolder mSecondaryControlsVh; 517ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout PlaybackControlsPresenter.BoundData mControlsBoundData = 527ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout new PlaybackControlsPresenter.BoundData(); 537ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout ControlBarPresenter.BoundData mSecondaryBoundData = new ControlBarPresenter.BoundData(); 547ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout 557ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout ViewHolder(View rootView) { 567ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout super(rootView); 577ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout mCard = (ViewGroup) rootView.findViewById(R.id.controls_card); 587ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout mImageView = (ImageView) rootView.findViewById(R.id.image); 597ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout mDescriptionDock = (ViewGroup) rootView.findViewById(R.id.description_dock); 607ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout mControlsDock = (ViewGroup) rootView.findViewById(R.id.controls_dock); 617ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout mSecondaryControlsDock = 627ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout (ViewGroup) rootView.findViewById(R.id.secondary_controls_dock); 637ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout mSpacer = rootView.findViewById(R.id.spacer); 647ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout } 657ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout 667ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout Presenter getPresenter(Object item, boolean primary) { 677ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout ObjectAdapter adapter = primary ? 687ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout ((PlaybackControlsRow) getRow()).getPrimaryActionsAdapter() : 697ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout ((PlaybackControlsRow) getRow()).getSecondaryActionsAdapter(); 707ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout if (adapter.getPresenterSelector() instanceof ControlButtonPresenterSelector) { 717ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout ControlButtonPresenterSelector selector = 727ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout (ControlButtonPresenterSelector) adapter.getPresenterSelector(); 737ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout return primary ? selector.getPrimaryPresenter() : 747ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout selector.getSecondaryPresenter(); 757ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout } 767ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout return adapter.getPresenter(item); 777ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout } 787ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout } 797ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout 807ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout private int mBackgroundColor = Color.TRANSPARENT; 817ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout private boolean mBackgroundColorSet; 827ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout private boolean mSecondaryActionsHidden; 837ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout private Presenter mDescriptionPresenter; 847ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout private PlaybackControlsPresenter mPlaybackControlsPresenter; 857ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout private ControlBarPresenter mSecondaryControlsPresenter; 867ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout 877ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout /** 887ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout * Constructor for a PlaybackControlsRowPresenter. 897ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout * 907ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout * @param descriptionPresenter Presenter for displaying item details. 917ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout */ 927ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout public PlaybackControlsRowPresenter(Presenter descriptionPresenter) { 937ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout setHeaderPresenter(null); 947ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout setSelectEffectEnabled(false); 957ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout 967ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout mDescriptionPresenter = descriptionPresenter; 977ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout mPlaybackControlsPresenter = new PlaybackControlsPresenter(R.layout.lb_playback_controls); 987ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout mSecondaryControlsPresenter = new ControlBarPresenter(R.layout.lb_control_bar); 997ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout } 1007ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout 1017ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout /** 1027ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout * Constructor for a PlaybackControlsRowPresenter. 1037ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout */ 1047ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout public PlaybackControlsRowPresenter() { 1057ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout this(null); 1067ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout } 1077ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout 1087ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout /** 1097ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout * Sets the listener for {@link Action} click events. 1107ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout */ 1117ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout public void setOnActionClickedListener(OnActionClickedListener listener) { 1127ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout mPlaybackControlsPresenter.setOnActionClickedListener(listener); 1137ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout mSecondaryControlsPresenter.setOnActionClickedListener(listener); 1147ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout } 1157ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout 1167ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout /** 1177ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout * Gets the listener for {@link Action} click events. 1187ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout */ 1197ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout public OnActionClickedListener getOnActionClickedListener() { 1207ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout return mPlaybackControlsPresenter.getOnActionClickedListener(); 1217ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout } 1227ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout 1237ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout /** 1247ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout * Sets the background color. If not set, a default from the theme will be used. 1257ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout */ 1267ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout public void setBackgroundColor(int color) { 1277ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout mBackgroundColor = color; 1287ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout mBackgroundColorSet = true; 1297ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout } 1307ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout 1317ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout /** 1327ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout * Returns the background color. If no background color was set, transparent 1337ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout * is returned. 1347ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout */ 1357ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout public int getBackgroundColor() { 1367ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout return mBackgroundColor; 1377ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout } 1387ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout 1397ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout /** 1407ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout * Sets the secondary actions to be hidden behind a "more actions" button. 1417ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout * When "more actions" is selected, the primary actions are replaced with 1427ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout * the secondary actions. 1437ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout */ 1447ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout public void setSecondaryActionsHidden(boolean hidden) { 1457ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout mSecondaryActionsHidden = hidden; 1467ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout } 1477ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout 1487ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout /** 1497ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout * Returns true if secondary actions are hidden. 1507ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout */ 1517ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout public boolean areSecondaryActionsHidden() { 1527ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout return mSecondaryActionsHidden; 1537ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout } 1547ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout 1557ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout private int getDefaultBackgroundColor(Context context) { 1567ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout TypedValue outValue = new TypedValue(); 1577ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout context.getTheme().resolveAttribute(R.attr.defaultBrandColor, outValue, true); 1587ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout return context.getResources().getColor(outValue.resourceId); 1597ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout } 1607ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout 1617ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout @Override 1627ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout protected RowPresenter.ViewHolder createRowViewHolder(ViewGroup parent) { 1637ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout View v = LayoutInflater.from(parent.getContext()) 1647ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout .inflate(R.layout.lb_playback_controls_row, parent, false); 1657ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout ViewHolder vh = new ViewHolder(v); 1667ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout initRow(vh); 1677ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout return vh; 1687ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout } 1697ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout 1707ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout private void initRow(ViewHolder vh) { 1717ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout vh.mCardHeight = vh.mCard.getLayoutParams().height; 1727ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout 1737ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout MarginLayoutParams lp = (MarginLayoutParams) vh.mControlsDock.getLayoutParams(); 1747ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout vh.mControlsDockMarginStart = lp.getMarginStart(); 1757ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout vh.mControlsDockMarginEnd = lp.getMarginEnd(); 1767ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout 1777ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout if (mDescriptionPresenter != null) { 1787ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout vh.mDescriptionVh = mDescriptionPresenter.onCreateViewHolder(vh.mDescriptionDock); 1797ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout vh.mDescriptionDock.addView(vh.mDescriptionVh.view); 1807ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout } 1817ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout 1827ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout vh.mControlsVh = mPlaybackControlsPresenter.onCreateViewHolder(vh.mControlsDock); 1837ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout vh.mControlsDock.addView(vh.mControlsVh.view); 1847ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout 1857ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout vh.mSecondaryControlsVh = 1867ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout mSecondaryControlsPresenter.onCreateViewHolder(vh.mSecondaryControlsDock); 1877ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout if (!mSecondaryActionsHidden) { 1887ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout vh.mSecondaryControlsDock.addView(vh.mSecondaryControlsVh.view); 1897ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout } 1907ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout } 1917ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout 1927ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout private void setBackground(View view) { 1937ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout view.setBackgroundColor(mBackgroundColorSet ? 1947ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout mBackgroundColor : getDefaultBackgroundColor(view.getContext())); 1957ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout ShadowHelper.getInstance().setZ(view, 0f); 1967ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout } 1977ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout 1987ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout @Override 1997ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout protected void onBindRowViewHolder(RowPresenter.ViewHolder holder, Object item) { 2007ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout super.onBindRowViewHolder(holder, item); 2017ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout 2027ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout ViewHolder vh = (ViewHolder) holder; 2037ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout PlaybackControlsRow row = (PlaybackControlsRow) vh.getRow(); 2047ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout 2057ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout mPlaybackControlsPresenter.enableSecondaryActions(mSecondaryActionsHidden); 2067ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout 2077ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout if (row.getItem() == null) { 2087ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout LayoutParams lp = vh.mCard.getLayoutParams(); 2097ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout lp.height = LayoutParams.WRAP_CONTENT; 2107ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout vh.mCard.setLayoutParams(lp); 2117ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout vh.mDescriptionDock.setVisibility(View.GONE); 2127ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout vh.mSpacer.setVisibility(View.GONE); 2137ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout } else { 2147ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout LayoutParams lp = vh.mCard.getLayoutParams(); 2157ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout lp.height = vh.mCardHeight; 2167ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout vh.mCard.setLayoutParams(lp); 2177ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout vh.mDescriptionDock.setVisibility(View.VISIBLE); 2187ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout if (vh.mDescriptionVh != null) { 2197ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout mDescriptionPresenter.onBindViewHolder(vh.mDescriptionVh, row.getItem()); 2207ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout } 2217ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout vh.mSpacer.setVisibility(View.VISIBLE); 2227ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout } 2237ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout 2247ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout MarginLayoutParams lp = (MarginLayoutParams) vh.mControlsDock.getLayoutParams(); 2257ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout if (row.getImageDrawable() == null || row.getItem() == null) { 2267ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout setBackground(vh.mControlsDock); 2277ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout vh.mCard.setBackgroundColor(Color.TRANSPARENT); 2287ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout lp.setMarginStart(0); 2297ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout lp.setMarginEnd(0); 2307ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout } else { 2317ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout vh.mImageView.setImageDrawable(row.getImageDrawable()); 2327ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout setBackground(vh.mCard); 2337ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout vh.mControlsDock.setBackgroundColor(Color.TRANSPARENT); 2347ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout lp.setMarginStart(vh.mControlsDockMarginStart); 2357ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout lp.setMarginEnd(vh.mControlsDockMarginEnd); 2367ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout } 2377ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout vh.mControlsDock.setLayoutParams(lp); 2387ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout 2397ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout vh.mControlsBoundData.adapter = row.getPrimaryActionsAdapter(); 2407ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout vh.mControlsBoundData.secondaryActionsAdapter = row.getSecondaryActionsAdapter(); 2417ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout vh.mControlsBoundData.presenter = vh.getPresenter( 2427ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout row.getPrimaryActionsAdapter().get(0), true); 2437ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout mPlaybackControlsPresenter.onBindViewHolder(vh.mControlsVh, vh.mControlsBoundData); 2447ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout 2457ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout vh.mSecondaryBoundData.adapter = row.getSecondaryActionsAdapter(); 2467ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout vh.mSecondaryBoundData.presenter = vh.getPresenter( 2477ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout row.getSecondaryActionsAdapter().get(0), false); 2487ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout mSecondaryControlsPresenter.onBindViewHolder(vh.mSecondaryControlsVh, 2497ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout vh.mSecondaryBoundData); 2507ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout } 2517ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout 2527ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout @Override 2537ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout protected void onUnbindRowViewHolder(RowPresenter.ViewHolder holder) { 2547ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout super.onUnbindRowViewHolder(holder); 2557ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout 2567ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout ViewHolder vh = (ViewHolder) holder; 2577ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout if (vh.mDescriptionVh != null) { 2587ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout mDescriptionPresenter.onUnbindViewHolder(vh.mDescriptionVh); 2597ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout } 2607ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout mPlaybackControlsPresenter.onUnbindViewHolder(vh.mControlsVh); 2617ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout mSecondaryControlsPresenter.onUnbindViewHolder(vh.mSecondaryControlsVh); 2627ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout } 2637ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout} 264