From 70fedf8d6caee1177ee891bbfff404dc48867c16 Mon Sep 17 00:00:00 2001 From: mdooley Date: Thu, 23 Nov 2017 08:31:05 -0800 Subject: Adding transcription rating feedback Allow users who have agreed to donate their voicemails to also provide transcription quality feedback. screenshot: https://drive.google.com/open?id=0B9o_KvtLkcuIajVtdFN3Y0Qydmx2NXJYN2N3OVA3N0h5UEdR Bug: 68712148 Test: manual and new unit tests PiperOrigin-RevId: 176774942 Change-Id: I08b9afbbefaedfb0de5199038a1d2769bd983855 --- .../dialer/app/calllog/PhoneCallDetailsHelper.java | 81 ++++++++++++++++++++-- 1 file changed, 74 insertions(+), 7 deletions(-) (limited to 'java/com/android/dialer/app/calllog/PhoneCallDetailsHelper.java') diff --git a/java/com/android/dialer/app/calllog/PhoneCallDetailsHelper.java b/java/com/android/dialer/app/calllog/PhoneCallDetailsHelper.java index ad931e87a..3898d1f24 100644 --- a/java/com/android/dialer/app/calllog/PhoneCallDetailsHelper.java +++ b/java/com/android/dialer/app/calllog/PhoneCallDetailsHelper.java @@ -19,30 +19,39 @@ package com.android.dialer.app.calllog; import android.content.Context; import android.content.res.Resources; import android.graphics.Typeface; +import android.net.Uri; import android.provider.CallLog.Calls; import android.provider.ContactsContract.CommonDataKinds.Phone; import android.support.v4.content.ContextCompat; import android.telecom.PhoneAccount; +import android.telecom.PhoneAccountHandle; import android.text.TextUtils; import android.text.format.DateUtils; import android.text.util.Linkify; +import android.view.Gravity; import android.view.View; import android.widget.TextView; +import android.widget.Toast; import com.android.dialer.app.R; import com.android.dialer.app.calllog.calllogcache.CallLogCache; import com.android.dialer.calllogutils.PhoneCallDetails; +import com.android.dialer.common.LogUtil; import com.android.dialer.compat.android.provider.VoicemailCompat; import com.android.dialer.logging.ContactSource; import com.android.dialer.oem.MotorolaUtils; import com.android.dialer.phonenumberutil.PhoneNumberHelper; import com.android.dialer.util.DialerUtils; +import com.android.voicemail.VoicemailComponent; +import com.android.voicemail.impl.transcribe.TranscriptionRatingHelper; +import com.google.internal.communications.voicemailtranscription.v1.TranscriptionRatingValue; import java.util.ArrayList; import java.util.Calendar; import java.util.concurrent.TimeUnit; /** Helper class to fill in the views in {@link PhoneCallDetailsViews}. */ -public class PhoneCallDetailsHelper { - +public class PhoneCallDetailsHelper + implements TranscriptionRatingHelper.SuccessListener, + TranscriptionRatingHelper.FailureListener { /** The maximum number of icons will be shown to represent the call types in a group. */ private static final int MAX_CALL_TYPE_ICONS = 3; @@ -152,13 +161,16 @@ public class PhoneCallDetailsHelper { String transcript = ""; String branding = ""; + boolean showRatingPrompt = false; if (!TextUtils.isEmpty(details.transcription)) { transcript = details.transcription; - // Set the branding text if the voicemail was transcribed by google - // TODO(mdooley): the transcription state is only set by the google transcription code, - // but a better solution would be to check the SOURCE_PACKAGE - if (details.transcriptionState == VoicemailCompat.TRANSCRIPTION_AVAILABLE) { + // Show a transcription quality rating prompt or set the branding text if the voicemail was + // transcribed by google + if (shouldShowTranscriptionRating(details.transcriptionState, details.accountHandle)) { + showRatingPrompt = true; + } else if (details.transcriptionState == VoicemailCompat.TRANSCRIPTION_AVAILABLE + || details.transcriptionState == VoicemailCompat.TRANSCRIPTION_AVAILABLE_AND_RATED) { branding = mResources.getString(R.string.voicemail_transcription_branding_text); } } else { @@ -183,7 +195,28 @@ public class PhoneCallDetailsHelper { } views.voicemailTranscriptionView.setText(transcript); - views.voicemailTranscriptionBrandingView.setText(branding); + if (showRatingPrompt) { + views.voicemailTranscriptionBrandingView.setVisibility(View.GONE); + + View ratingView = views.voicemailTranscriptionRatingView; + ratingView.setVisibility(View.VISIBLE); + ratingView + .findViewById(R.id.voicemail_transcription_rating_good) + .setOnClickListener( + view -> + recordTranscriptionRating( + TranscriptionRatingValue.GOOD_TRANSCRIPTION, details)); + ratingView + .findViewById(R.id.voicemail_transcription_rating_bad) + .setOnClickListener( + view -> + recordTranscriptionRating(TranscriptionRatingValue.BAD_TRANSCRIPTION, details)); + } else { + views.voicemailTranscriptionRatingView.setVisibility(View.GONE); + + views.voicemailTranscriptionBrandingView.setVisibility(View.VISIBLE); + views.voicemailTranscriptionBrandingView.setText(branding); + } } // Bold if not read @@ -198,6 +231,40 @@ public class PhoneCallDetailsHelper { details.isRead ? R.color.call_log_detail_color : R.color.call_log_unread_text_color)); } + private boolean shouldShowTranscriptionRating( + int transcriptionState, PhoneAccountHandle account) { + // TODO(mdooley): add a configurable random element here? + return transcriptionState == VoicemailCompat.TRANSCRIPTION_AVAILABLE + && VoicemailComponent.get(mContext) + .getVoicemailClient() + .isVoicemailDonationEnabled(mContext, account); + } + + private void recordTranscriptionRating( + TranscriptionRatingValue ratingValue, PhoneCallDetails details) { + LogUtil.enterBlock("PhoneCallDetailsHelper.recordTranscriptionRating"); + TranscriptionRatingHelper.sendRating( + mContext, + ratingValue, + Uri.parse(details.voicemailUri), + this::onRatingSuccess, + this::onRatingFailure); + } + + @Override + public void onRatingSuccess(Uri voicemailUri) { + LogUtil.enterBlock("PhoneCallDetailsHelper.onRatingSuccess"); + Toast toast = + Toast.makeText(mContext, R.string.voicemail_transcription_rating_thanks, Toast.LENGTH_LONG); + toast.setGravity(Gravity.BOTTOM | Gravity.CENTER_HORIZONTAL, 0, 50); + toast.show(); + } + + @Override + public void onRatingFailure(Throwable t) { + LogUtil.e("PhoneCallDetailsHelper.onRatingFailure", "failed to send rating", t); + } + /** * Builds a string containing the call location and date. For voicemail logs only the call date is * returned because location information is displayed in the call action button -- cgit v1.2.3