1 /* 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 17 package com.android.car.settings.common; 18 19 import android.support.v7.widget.RecyclerView; 20 import android.view.LayoutInflater; 21 import android.view.View; 22 import android.view.ViewGroup; 23 import android.widget.TextView; 24 import com.android.car.settings.R; 25 26 /** 27 * Contains logic for a line item represents text only view of a title and a description. 28 */ 29 public abstract class TextLineItem extends TypedPagedListAdapter.LineItem<TextLineItem.ViewHolder> { 30 private final CharSequence mTitle; 31 32 private View.OnClickListener mOnClickListener = (v) -> onClick(); 33 34 public TextLineItem(CharSequence title) { 35 mTitle = title; 36 } 37 38 @Override 39 public int getType() { 40 return TEXT_TYPE; 41 } 42 43 @Override 44 public void bindViewHolder(ViewHolder viewHolder) { 45 viewHolder.titleView.setText(mTitle); 46 viewHolder.descView.setText(getDesc()); 47 viewHolder.itemView.setOnClickListener(mOnClickListener); 48 viewHolder.itemView.setEnabled(isEnabled()); 49 } 50 51 static class ViewHolder extends RecyclerView.ViewHolder { 52 final TextView titleView; 53 final TextView descView; 54 55 public ViewHolder(View view) { 56 super(view); 57 titleView = (TextView) view.findViewById(R.id.title); 58 descView = (TextView) view.findViewById(R.id.desc); 59 } 60 } 61 62 public static RecyclerView.ViewHolder createViewHolder(ViewGroup parent) { 63 View v = LayoutInflater.from(parent.getContext()) 64 .inflate(R.layout.text_line_item, parent, false); 65 return new ViewHolder(v); 66 } 67 68 public abstract void onClick(); 69 70 public abstract boolean isEnabled(); 71 } 72