1 /* 2 * Copyright (C) 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.settings.homepage.contextualcards.legacysuggestion; 18 19 import android.content.Context; 20 import android.view.View; 21 import android.widget.ImageView; 22 import android.widget.TextView; 23 24 import androidx.annotation.LayoutRes; 25 import androidx.recyclerview.widget.RecyclerView; 26 27 import com.android.settings.R; 28 import com.android.settings.homepage.contextualcards.ContextualCard; 29 import com.android.settings.homepage.contextualcards.ContextualCardController; 30 import com.android.settings.homepage.contextualcards.ContextualCardRenderer; 31 import com.android.settings.homepage.contextualcards.ControllerRendererPool; 32 33 public class LegacySuggestionContextualCardRenderer implements ContextualCardRenderer { 34 35 @LayoutRes 36 public static final int VIEW_TYPE = R.layout.legacy_suggestion_tile; 37 38 private final Context mContext; 39 private final ControllerRendererPool mControllerRendererPool; 40 LegacySuggestionContextualCardRenderer(Context context, ControllerRendererPool controllerRendererPool)41 public LegacySuggestionContextualCardRenderer(Context context, 42 ControllerRendererPool controllerRendererPool) { 43 mContext = context; 44 mControllerRendererPool = controllerRendererPool; 45 } 46 47 @Override createViewHolder(View view, @LayoutRes int viewType)48 public RecyclerView.ViewHolder createViewHolder(View view, @LayoutRes int viewType) { 49 return new LegacySuggestionViewHolder(view); 50 } 51 52 @Override bindView(RecyclerView.ViewHolder holder, ContextualCard card)53 public void bindView(RecyclerView.ViewHolder holder, ContextualCard card) { 54 final LegacySuggestionViewHolder vh = (LegacySuggestionViewHolder) holder; 55 final ContextualCardController controller = mControllerRendererPool 56 .getController(mContext, card.getCardType()); 57 vh.icon.setImageDrawable(card.getIconDrawable()); 58 vh.title.setText(card.getTitleText()); 59 vh.summary.setText(card.getSummaryText()); 60 vh.itemView.setOnClickListener(v -> controller.onPrimaryClick(card)); 61 vh.closeButton.setOnClickListener(v -> controller.onDismissed(card)); 62 } 63 64 private static class LegacySuggestionViewHolder extends RecyclerView.ViewHolder { 65 66 public final ImageView icon; 67 public final TextView title; 68 public final TextView summary; 69 public final View closeButton; 70 LegacySuggestionViewHolder(View itemView)71 public LegacySuggestionViewHolder(View itemView) { 72 super(itemView); 73 icon = itemView.findViewById(android.R.id.icon); 74 title = itemView.findViewById(android.R.id.title); 75 summary = itemView.findViewById(android.R.id.summary); 76 closeButton = itemView.findViewById(R.id.close_button); 77 } 78 } 79 } 80 81