1/*
2 * Copyright (C) 2015 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.android.support.car.lenspicker;
17
18import android.content.Context;
19import android.support.v7.widget.RecyclerView;
20import android.text.TextUtils;
21import android.view.View;
22import android.widget.ImageView;
23import android.widget.TextView;
24
25/**
26 * A view that renders a single row in the lens picker list
27 */
28public class LensPickerRow extends RecyclerView.ViewHolder {
29    private final View mCardView;
30    private final ImageView mIconView;
31    private final TextView mTitleView;
32
33    public LensPickerRow(View itemView) {
34        super(itemView);
35        mCardView = itemView.findViewById(R.id.stream_card);
36        mIconView = (ImageView) itemView.findViewById(R.id.icon);
37        mTitleView = (TextView) itemView.findViewById(R.id.text);
38    }
39
40    public void bind(Context context, LensPickerItem item,
41            LensPickerSelectionHandler selectionHandler) {
42        String label = item.getLabel();
43        if (TextUtils.isEmpty(label)) {
44            label = context.getString(R.string.unknown_provider_name);
45        }
46        mTitleView.setText(label);
47        mIconView.setImageDrawable(item.getIcon());
48
49        if (selectionHandler != null) {
50            mCardView.setOnClickListener(v -> selectionHandler.onActivitySelected(item));
51        }
52    }
53}
54