1 /* 2 * Copyright (c) 2016, The Android Open Source Project 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 package com.android.car.overview; 17 18 import android.content.Context; 19 import android.support.annotation.CallSuper; 20 import android.support.v7.widget.RecyclerView; 21 import android.view.View; 22 import com.android.car.stream.StreamCard; 23 24 /** 25 * A base {@link RecyclerView.ViewHolder} for binding by the {@link StreamAdapter}. 26 */ 27 public abstract class StreamViewHolder extends RecyclerView.ViewHolder { 28 protected View mActionContainer; 29 protected Context mContext; 30 StreamViewHolder(Context context, View itemView)31 public StreamViewHolder(Context context, View itemView) { 32 super(itemView); 33 mContext = context; 34 mActionContainer = itemView.findViewById(R.id.primary_action_container); 35 if (mActionContainer == null) { 36 throw new IllegalStateException("primary_action_container not found in layout." + 37 " Cards must have an affordance for the a primary action."); 38 } 39 } 40 41 /** 42 * Bind a {@link StreamCard} to the views being held by this {@link RecyclerView.ViewHolder} 43 * @param card 44 */ 45 @CallSuper bindStreamCard(StreamCard card)46 public void bindStreamCard(StreamCard card) { 47 resetViews(); 48 } 49 resetViews()50 protected abstract void resetViews(); 51 } 52