uabdullah | 4dc34a8 | 2017-12-15 10:45:50 -0800 | [diff] [blame^] | 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.voicemail.listui.menu; |
| 18 | |
| 19 | import android.content.Context; |
| 20 | import android.text.TextUtils; |
| 21 | import com.android.dialer.contactactions.ContactPrimaryActionInfo; |
| 22 | import com.android.dialer.contactactions.ContactPrimaryActionInfo.PhotoInfo; |
| 23 | import com.android.dialer.lettertile.LetterTileDrawable; |
| 24 | import com.android.dialer.voicemail.model.VoicemailEntry; |
| 25 | |
| 26 | /** Configures the primary action row (top row) for theottom sheet for the Voicemail Tab */ |
| 27 | final 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 | } |