blob: a8f9267c7df1cb411699697da440773c55839362 [file] [log] [blame]
Jon Miranda16ea1b12017-12-12 14:52:48 -08001/*
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 */
16package com.android.wallpaper.picker.individual;
17
18import android.app.Activity;
19import android.graphics.drawable.Drawable;
20import android.support.v7.widget.RecyclerView.ViewHolder;
21import android.view.View;
22import android.widget.ImageView;
23import android.widget.RelativeLayout;
24import android.widget.TextView;
25
26import com.android.wallpaper.R;
27import com.android.wallpaper.model.WallpaperInfo;
28
29import java.util.List;
30
31/**
32 * Base class for ViewHolders for individual wallpaper tiles.
33 */
34abstract class IndividualHolder extends ViewHolder {
35 protected Activity mActivity;
36 protected RelativeLayout mTileLayout;
37 protected ImageView mThumbnailView;
38 protected ImageView mOverlayIconView;
39 protected TextView mTitleView;
40 protected WallpaperInfo mWallpaper;
41
42 public IndividualHolder(Activity hostActivity, int tileHeightPx, View itemView) {
43 super(itemView);
44
45 mActivity = hostActivity;
46 mTileLayout = (RelativeLayout) itemView.findViewById(R.id.tile);
47 mThumbnailView = (ImageView) itemView.findViewById(R.id.thumbnail);
48 mOverlayIconView = (ImageView) itemView.findViewById(R.id.overlay_icon);
49 mTitleView = (TextView) itemView.findViewById(R.id.title);
50
51 mTileLayout.getLayoutParams().height = tileHeightPx;
52 itemView.getLayoutParams().height = tileHeightPx;
53 }
54
55 /**
56 * Binds the given wallpaper to this IndividualHolder.
57 */
58 public void bindWallpaper(WallpaperInfo wallpaper) {
59 mWallpaper = wallpaper;
60
61 String title = wallpaper.getTitle(mActivity);
62
63 List<String> attributions = wallpaper.getAttributions(mActivity);
64 String firstAttribution = attributions.size() > 0 ? attributions.get(0) : null;
65
66 if (title != null) {
67 mTitleView.setText(title);
68 mTitleView.setVisibility(View.VISIBLE);
69 mTileLayout.setContentDescription(title);
70 } else if (firstAttribution != null) {
71 mTileLayout.setContentDescription(firstAttribution);
72 }
73
74 Drawable overlayIcon = wallpaper.getOverlayIcon(mActivity);
75 if (overlayIcon != null) {
76 mOverlayIconView.setImageDrawable(overlayIcon);
77 } else {
78 wallpaper.getThumbAsset(
79 mActivity.getApplicationContext()).loadDrawable(mActivity, mThumbnailView,
80 mActivity.getResources().getColor(R.color.secondary_color));
81 }
82 }
83}