blob: 7f4ac80522e92eb2f8b50aa47bc980a9718fc1d5 [file] [log] [blame]
uabdullah4dc34a82017-12-15 10:45:50 -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 */
16
17package com.android.dialer.voicemail.listui.menu;
18
19import android.content.Context;
20import android.text.TextUtils;
21import com.android.dialer.contactactions.ContactPrimaryActionInfo;
22import com.android.dialer.contactactions.ContactPrimaryActionInfo.PhotoInfo;
23import com.android.dialer.lettertile.LetterTileDrawable;
24import com.android.dialer.voicemail.model.VoicemailEntry;
25
26/** Configures the primary action row (top row) for theottom sheet for the Voicemail Tab */
27final class PrimaryAction {
28
29 // TODO(uabdullah): Need to do the following:
30 // setIsVideo - check if is passing in voicemailEntry.features() is required
31 // setLookupUri - check if passing in voicemailEntry.lookupUri() is required
32 // setIntent - allow video calling
33 // setPrimaryText - check in with UX
34 // setSecondaryText - check in with UX
35 static ContactPrimaryActionInfo fromVoicemailEntry(
36 Context context, VoicemailEntry voicemailEntry) {
37 return ContactPrimaryActionInfo.builder()
38 .setNumber(voicemailEntry.number())
39 .setPhotoInfo(
40 PhotoInfo.builder()
41 .setPhotoId(voicemailEntry.photoId())
42 .setPhotoUri(voicemailEntry.photoUri())
43 .setIsVideo(false)
44 .setContactType(
45 LetterTileDrawable.TYPE_DEFAULT) // TODO(uabdullah): Use proper type.
46 .setDisplayName(voicemailEntry.name())
47 .build())
48 .setPrimaryText(buildPrimaryVoicemailText(context, voicemailEntry))
49 .setSecondaryText(buildSecondaryVoicemailText(voicemailEntry))
50 .build();
51 }
52
53 private static CharSequence buildSecondaryVoicemailText(VoicemailEntry voicemailEntry) {
54 return voicemailEntry.geocodedLocation();
55 }
56
57 public static String buildPrimaryVoicemailText(Context context, VoicemailEntry data) {
58 StringBuilder primaryText = new StringBuilder();
59 if (!TextUtils.isEmpty(data.name())) {
60 primaryText.append(data.name());
61 } else if (!TextUtils.isEmpty(data.formattedNumber())) {
62 primaryText.append(data.formattedNumber());
63 } else {
64 // TODO(uabdullah): Handle CallLog.Calls.PRESENTATION_*, including Verizon restricted numbers.
65 // primaryText.append(context.getText(R.string.voicemail_unknown));
66 // TODO(uabdullah): Figure out why http://gpaste/5980163120562176 error when using string
67 primaryText.append("Unknown");
68 }
69 return primaryText.toString();
70 }
71}