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.dialer.calllog.ui; 18 19 import android.support.v7.widget.RecyclerView.ViewHolder; 20 import android.text.method.LinkMovementMethod; 21 import android.view.View; 22 import android.widget.Button; 23 import android.widget.ImageView; 24 import android.widget.TextView; 25 import com.android.dialer.promotion.Promotion; 26 27 /** ViewHolder for {@link NewCallLogAdapter} to display the Duo disclosure card. */ 28 public class PromotionCardViewHolder extends ViewHolder { 29 30 /** Listener to be called when promotion card is dismissed. */ 31 interface DismissListener { onDismiss()32 void onDismiss(); 33 } 34 35 private final Button okButton; 36 private final Promotion promotion; 37 PromotionCardViewHolder(View itemView, Promotion promotion)38 PromotionCardViewHolder(View itemView, Promotion promotion) { 39 super(itemView); 40 this.promotion = promotion; 41 42 ImageView iconView = itemView.findViewById(R.id.new_call_log_promotion_card_icon); 43 iconView.setImageResource(promotion.getIconRes()); 44 45 TextView cardTitleView = itemView.findViewById(R.id.new_call_log_promotion_card_title); 46 cardTitleView.setText(promotion.getTitle()); 47 48 TextView cardDetailsView = itemView.findViewById(R.id.new_call_log_promotion_card_details); 49 cardDetailsView.setText(promotion.getDetails()); 50 cardDetailsView.setMovementMethod(LinkMovementMethod.getInstance()); // make the link clickable 51 52 // Obtain a reference to the "OK, got it" button. 53 okButton = itemView.findViewById(R.id.new_call_log_promotion_card_ok); 54 } 55 setDismissListener(DismissListener listener)56 void setDismissListener(DismissListener listener) { 57 okButton.setOnClickListener( 58 v -> { 59 promotion.dismiss(); 60 listener.onDismiss(); 61 }); 62 } 63 } 64