Home | History | Annotate | Download | only in volume
      1 /*
      2  * Copyright (C) 2019 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.systemui.volume;
     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.recyclerview.widget.RecyclerView;
     25 
     26 import com.android.systemui.R;
     27 
     28 import java.util.List;
     29 
     30 /** The {@link RecyclerView.Adapter} to show the volume items in the sysUI volume dialog. */
     31 public class CarVolumeItemAdapter extends
     32         RecyclerView.Adapter<CarVolumeItem.CarVolumeItemViewHolder> {
     33 
     34     private final Context mContext;
     35     private final List<CarVolumeItem> mItems;
     36 
     37     public CarVolumeItemAdapter(Context context, List<CarVolumeItem> items) {
     38         mContext = context;
     39         mItems = items;
     40     }
     41 
     42     @Override
     43     public CarVolumeItem.CarVolumeItemViewHolder onCreateViewHolder(ViewGroup parent,
     44             int viewType) {
     45         LayoutInflater inflater = LayoutInflater.from(mContext);
     46         View view = inflater.inflate(R.layout.car_volume_item, parent, false);
     47         return new CarVolumeItem.CarVolumeItemViewHolder(view);
     48     }
     49 
     50     @Override
     51     public void onBindViewHolder(CarVolumeItem.CarVolumeItemViewHolder holder, int position) {
     52         mItems.get(position).bind(holder);
     53     }
     54 
     55     @Override
     56     public int getItemCount() {
     57         return mItems.size();
     58     }
     59 }
     60