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 */ 16package com.google.android.car.diagnosticverifier; 17 18import android.content.Context; 19import android.support.v7.widget.RecyclerView; 20import android.view.LayoutInflater; 21import android.view.View; 22import android.view.ViewGroup; 23import android.widget.TextView; 24 25import java.util.List; 26 27/** 28 * A recycler view adapter for verification result messages 29 */ 30public class VerificationResultAdapter extends 31 RecyclerView.Adapter<VerificationResultAdapter.VerificationResultViewHolder> { 32 33 private List<String> mResultMessages; 34 35 @Override 36 public VerificationResultViewHolder onCreateViewHolder(ViewGroup viewGroup, int viewType) { 37 Context context = viewGroup.getContext(); 38 int messageItemLayoutId = R.layout.result_message_item; 39 LayoutInflater inflater = LayoutInflater.from(context); 40 boolean shouldAttachToParentImmediately = false; 41 42 View view = inflater.inflate( 43 messageItemLayoutId, viewGroup, shouldAttachToParentImmediately); 44 return new VerificationResultViewHolder(view); 45 } 46 47 @Override 48 public void onBindViewHolder(VerificationResultViewHolder verificationResultViewHolder, int i) { 49 String resultMessage = mResultMessages.get(i); 50 verificationResultViewHolder.mResultMessageTextView.setText(resultMessage); 51 } 52 53 @Override 54 public int getItemCount() { 55 if (mResultMessages == null) { 56 return 0; 57 } 58 return mResultMessages.size(); 59 } 60 61 public void setResultMessages(List<String> resultMessages) { 62 mResultMessages = resultMessages; 63 notifyDataSetChanged(); 64 } 65 66 public class VerificationResultViewHolder extends RecyclerView.ViewHolder { 67 public final TextView mResultMessageTextView; 68 69 public VerificationResultViewHolder(View view) { 70 super(view); 71 mResultMessageTextView = (TextView) view.findViewById(R.id.result_message); 72 } 73 } 74} 75