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.dialer.enrichedcall.simulator;
18 
19 import android.support.annotation.NonNull;
20 import android.support.v7.widget.RecyclerView;
21 import android.view.LayoutInflater;
22 import android.view.ViewGroup;
23 import com.android.dialer.common.Assert;
24 import java.util.List;
25 
26 /** Adapter for the RecyclerView in {@link EnrichedCallSimulatorActivity}. */
27 class SessionsAdapter extends RecyclerView.Adapter<SessionViewHolder> {
28 
29   /** List of the string representation of all in-memory sessions */
30   private List<String> sessionStrings;
31 
setSessionStrings(@onNull List<String> sessionStrings)32   void setSessionStrings(@NonNull List<String> sessionStrings) {
33     this.sessionStrings = Assert.isNotNull(sessionStrings);
34   }
35 
36   @Override
onCreateViewHolder(ViewGroup viewGroup, int i)37   public SessionViewHolder onCreateViewHolder(ViewGroup viewGroup, int i) {
38     LayoutInflater inflater = LayoutInflater.from(viewGroup.getContext());
39     return new SessionViewHolder(inflater.inflate(R.layout.session_view_holder, viewGroup, false));
40   }
41 
42   @Override
onBindViewHolder(SessionViewHolder viewHolder, int i)43   public void onBindViewHolder(SessionViewHolder viewHolder, int i) {
44     viewHolder.updateSession(sessionStrings.get(i));
45   }
46 
47   @Override
getItemCount()48   public int getItemCount() {
49     return sessionStrings.size();
50   }
51 }
52