AbstractDetailsDescriptionPresenter.java revision a83005b70853ea52c5d98910762344de16b850a8
1/* 2 * Copyright (C) 2014 The Android Open Source Project 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except 5 * in compliance with the License. You may obtain a copy of the License at 6 * 7 * http://www.apache.org/licenses/LICENSE-2.0 8 * 9 * Unless required by applicable law or agreed to in writing, software distributed under the License 10 * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express 11 * or implied. See the License for the specific language governing permissions and limitations under 12 * the License. 13 */ 14package android.support.v17.leanback.widget; 15 16import android.support.v17.leanback.R; 17import android.view.LayoutInflater; 18import android.view.View; 19import android.view.ViewGroup; 20import android.widget.TextView; 21 22/** 23 * An abstract {@link Presenter} for rendering a detailed description of an 24 * item. Typically this Presenter will be used in a DetailsOveriewRowPresenter. 25 * 26 * <p>Subclasses will override {@link #onBindDescription} to implement the data 27 * binding for this Presenter. 28 */ 29public abstract class AbstractDetailsDescriptionPresenter extends Presenter { 30 31 public static class ViewHolder extends Presenter.ViewHolder { 32 private final TextView mTitle; 33 private final TextView mSubtitle; 34 private final TextView mBody; 35 36 public ViewHolder(View view) { 37 super(view); 38 mTitle = (TextView) view.findViewById(R.id.lb_details_description_title); 39 mSubtitle = (TextView) view.findViewById(R.id.lb_details_description_subtitle); 40 mBody = (TextView) view.findViewById(R.id.lb_details_description_body); 41 } 42 43 public TextView getTitle() { 44 return mTitle; 45 } 46 47 public TextView getSubtitle() { 48 return mSubtitle; 49 } 50 51 public TextView getBody() { 52 return mBody; 53 } 54 } 55 56 public final ViewHolder onCreateViewHolder(ViewGroup parent) { 57 View v = LayoutInflater.from(parent.getContext()) 58 .inflate(R.layout.lb_details_description, parent, false); 59 return new ViewHolder(v); 60 } 61 62 public final void onBindViewHolder(Presenter.ViewHolder viewHolder, Object item) { 63 ViewHolder vh = (ViewHolder) viewHolder; 64 DetailsOverviewRow row = (DetailsOverviewRow) item; 65 onBindDescription(vh, row); 66 } 67 68 /** 69 * Binds the data from the DetailsOverviewRow to the ViewHolder. The item 70 * being described in this row is accessible via the row's {@link 71 * DetailsOverviewRow#getItem getItem} method. 72 * 73 * @param vh The ViewHolder for this details description view. 74 * @param row The DetailsOverviewRow being presented. 75 */ 76 protected abstract void onBindDescription(ViewHolder vh, DetailsOverviewRow row); 77 78 public void onUnbindViewHolder(Presenter.ViewHolder viewHolder) {} 79} 80