1 /* 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 */ 16 17 package com.android.dialer.calldetails; 18 19 import android.content.Context; 20 import android.content.Intent; 21 import android.support.v7.widget.RecyclerView; 22 import android.text.TextUtils; 23 import android.view.View; 24 import android.view.View.OnClickListener; 25 import com.android.dialer.clipboard.ClipboardUtils; 26 import com.android.dialer.common.Assert; 27 import com.android.dialer.logging.DialerImpression; 28 import com.android.dialer.logging.Logger; 29 import com.android.dialer.logging.UiAction; 30 import com.android.dialer.performancereport.PerformanceReport; 31 import com.android.dialer.util.CallUtil; 32 import com.android.dialer.util.DialerUtils; 33 34 /** ViewHolder container for {@link CallDetailsActivity} footer. */ 35 final class CallDetailsFooterViewHolder extends RecyclerView.ViewHolder implements OnClickListener { 36 37 private final ReportCallIdListener reportCallIdListener; 38 private final DeleteCallDetailsListener deleteCallDetailsListener; 39 private final View copy; 40 private final View edit; 41 private final View reportCallerId; 42 private final View delete; 43 44 private String number; 45 46 CallDetailsFooterViewHolder( 47 View view, 48 ReportCallIdListener reportCallIdListener, 49 DeleteCallDetailsListener deleteCallDetailsListener) { 50 super(view); 51 this.reportCallIdListener = reportCallIdListener; 52 this.deleteCallDetailsListener = deleteCallDetailsListener; 53 copy = view.findViewById(R.id.call_detail_action_copy); 54 edit = view.findViewById(R.id.call_detail_action_edit_before_call); 55 reportCallerId = view.findViewById(R.id.call_detail_action_report_caller_id); 56 delete = view.findViewById(R.id.call_detail_action_delete); 57 copy.setOnClickListener(this); 58 edit.setOnClickListener(this); 59 reportCallerId.setOnClickListener(this); 60 delete.setOnClickListener(this); 61 } 62 63 public void setPhoneNumber(String number) { 64 this.number = number; 65 if (TextUtils.isEmpty(number)) { 66 copy.setVisibility(View.GONE); 67 edit.setVisibility(View.GONE); 68 } else if (reportCallIdListener.canReportCallerId(number)) { 69 reportCallerId.setVisibility(View.VISIBLE); 70 } 71 } 72 73 @Override 74 public void onClick(View view) { 75 Context context = view.getContext(); 76 if (view == copy) { 77 PerformanceReport.recordClick(UiAction.Type.COPY_NUMBER_IN_CALL_DETAIL); 78 79 Logger.get(context).logImpression(DialerImpression.Type.CALL_DETAILS_COPY_NUMBER); 80 ClipboardUtils.copyText(context, null, number, true); 81 } else if (view == edit) { 82 PerformanceReport.recordClick(UiAction.Type.EDIT_NUMBER_BEFORE_CALL_IN_CALL_DETAIL); 83 // Dialpad will be filled with this number, but we don't want to record it as user action 84 PerformanceReport.setIgnoreActionOnce(UiAction.Type.TEXT_CHANGE_WITH_INPUT); 85 86 Logger.get(context).logImpression(DialerImpression.Type.CALL_DETAILS_EDIT_BEFORE_CALL); 87 Intent dialIntent = new Intent(Intent.ACTION_DIAL, CallUtil.getCallUri(number)); 88 DialerUtils.startActivityWithErrorToast(context, dialIntent); 89 } else if (view == reportCallerId) { 90 reportCallIdListener.reportCallId(number); 91 } else if (view == delete) { 92 deleteCallDetailsListener.delete(); 93 } else { 94 Assert.fail("View on click not implemented: " + view); 95 } 96 } 97 98 /** Listener for reporting caller id */ 99 interface ReportCallIdListener { 100 101 /** Tell listener that the user requested to report caller id info as inaccurate. */ 102 void reportCallId(String number); 103 104 /** returns true if the number can be reported as inaccurate. */ 105 boolean canReportCallerId(String number); 106 } 107 108 /** Listener for deleting call details */ 109 interface DeleteCallDetailsListener { 110 111 /** Delete call details */ 112 void delete(); 113 } 114 } 115