• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright 2018 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.media.browse;
18 
19 import android.content.Context;
20 import android.support.v7.widget.RecyclerView;
21 import android.view.View;
22 import android.view.ViewGroup;
23 import android.widget.ImageView;
24 import android.widget.TextView;
25 
26 import com.android.car.media.common.MediaItemMetadata;
27 
28 /**
29  * Generic {@link RecyclerView.ViewHolder} to use for all views in the {@link BrowseAdapter}
30  */
31 class BrowseViewHolder extends RecyclerView.ViewHolder {
32     final TextView mTitle;
33     final TextView mSubtitle;
34     final ImageView mAlbumArt;
35     final ViewGroup mContainer;
36 
37     /**
38      * Creates a {@link BrowseViewHolder} for the given view.
39      */
BrowseViewHolder(View itemView)40     BrowseViewHolder(View itemView) {
41         super(itemView);
42         mTitle = itemView.findViewById(com.android.car.media.R.id.title);
43         mSubtitle = itemView.findViewById(com.android.car.media.R.id.subtitle);
44         mAlbumArt = itemView.findViewById(com.android.car.media.R.id.thumbnail);
45         mContainer = itemView.findViewById(com.android.car.media.R.id.container);
46     }
47 
48     /**
49      * Updates this {@link BrowseViewHolder} with the given data
50      */
bind(Context context, BrowseViewData data)51     public void bind(Context context, BrowseViewData data) {
52         if (mTitle != null) {
53             mTitle.setText(data.mText != null
54                     ? data.mText : data.mMediaItem != null
55                     ? data.mMediaItem.getTitle()
56                     : null);
57         }
58         if (mSubtitle != null) {
59             mSubtitle.setText(data.mMediaItem != null
60                     ? data.mMediaItem.getSubtitle()
61                     : null);
62             mSubtitle.setVisibility(data.mMediaItem != null && data.mMediaItem.getSubtitle() != null
63                     && !data.mMediaItem.getSubtitle().toString().isEmpty()
64                     ? View.VISIBLE
65                     : View.GONE);
66         }
67         if (mAlbumArt != null) {
68             MediaItemMetadata.updateImageView(context, data.mMediaItem, mAlbumArt, 0);
69         }
70         if (mContainer != null && data.mOnClickListener != null) {
71             mContainer.setOnClickListener(data.mOnClickListener);
72         }
73     }
74 }
75