1 /*
2  * Copyright (C) 2020 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.dialer.ui.activecall;
18 
19 import android.content.Context;
20 import android.view.LayoutInflater;
21 import android.view.View;
22 import android.view.ViewGroup;
23 
24 import androidx.annotation.NonNull;
25 import androidx.recyclerview.widget.RecyclerView;
26 
27 import com.android.car.dialer.R;
28 import com.android.car.telephony.common.CallDetail;
29 
30 import java.util.ArrayList;
31 import java.util.List;
32 
33 /**
34  * Adapter for holding user profiles of a conference.
35  */
36 public class ConferenceProfileAdapter extends RecyclerView.Adapter<ConferenceProfileViewHolder> {
37 
38     private Context mContext;
39     private List<CallDetail> mConferenceList = new ArrayList<>();
40 
ConferenceProfileAdapter(Context context)41     public ConferenceProfileAdapter(Context context) {
42         mContext = context;
43     }
44 
45     /**
46      * Sets {@link #mConferenceList} based on live data.
47      */
setConferenceList(List<CallDetail> list)48     public void setConferenceList(List<CallDetail> list) {
49         mConferenceList.clear();
50         if (list != null) {
51             mConferenceList.addAll(list);
52         }
53         notifyDataSetChanged();
54     }
55 
56     @NonNull
57     @Override
onCreateViewHolder(@onNull ViewGroup viewGroup, int i)58     public ConferenceProfileViewHolder onCreateViewHolder(@NonNull ViewGroup viewGroup, int i) {
59         View view = LayoutInflater.from(mContext).inflate(R.layout.user_profile_list_item,
60                 viewGroup, false);
61         return new ConferenceProfileViewHolder(view);
62     }
63 
64     @Override
onBindViewHolder(@onNull ConferenceProfileViewHolder conferenceProfileViewHolder, int i)65     public void onBindViewHolder(@NonNull ConferenceProfileViewHolder conferenceProfileViewHolder,
66             int i) {
67         conferenceProfileViewHolder.bind(mConferenceList.get(i));
68     }
69 
70     @Override
getItemCount()71     public int getItemCount() {
72         return mConferenceList.size();
73     }
74 }
75