blob: b9938acb006839a0e0ef27482e4c59ce7291652a [file] [log] [blame]
kevinjm2c107da2017-09-14 15:35:03 -07001/*
2 * Copyright (C) 2017 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
17package com.android.car.list;
18
19import android.support.v7.widget.RecyclerView;
20import android.view.LayoutInflater;
21import android.view.View;
22import android.view.ViewGroup;
23import android.widget.TextView;
24
25import com.android.car.list.R;
26
27/**
28 * Contains logic for a line item represents text only view of a title.
29 */
30public class SingleTextLineItem
31 extends TypedPagedListAdapter.LineItem<SingleTextLineItem.ViewHolder> {
32 private final CharSequence mTitle;
33
34 /**
35 * Construct SingleTextLineItem with title.
36 */
37 public SingleTextLineItem(CharSequence title) {
38 mTitle = title;
39 }
40
41 @Override
42 public int getType() {
43 return SINGLE_TEXT_TYPE;
44 }
45
46 @Override
47 public void bindViewHolder(ViewHolder viewHolder) {
48 super.bindViewHolder(viewHolder);
49 viewHolder.titleView.setText(mTitle);
50 }
51
52 /**
53 * ViewHolder that contains the title of the SingleTextLineItem
54 */
55 public static class ViewHolder extends RecyclerView.ViewHolder {
56 public final TextView titleView;
57
58 public ViewHolder(View view) {
59 super(view);
60 titleView = view.findViewById(R.id.title);
61 }
62 }
63
64 /**
65 * Creates ViewHolder with the elements of SingleTextLineItem
66 */
67 public static RecyclerView.ViewHolder createViewHolder(ViewGroup parent) {
68 return new ViewHolder(LayoutInflater.from(parent.getContext())
69 .inflate(R.layout.single_text_line_item, parent, false));
70 }
71
72 @Override
73 public CharSequence getDesc() {
74 return null;
75 }
76
77 @Override
78 public boolean isExpandable() {
79 return false;
80 }
81
82 @Override
83 public boolean isClickable() {
84 return true;
85 }
86}