Implement basic bottom sheet in NUI Voicemail tab.

Implement the basic bottom sheet that displays name, location add to contacts, send a message and copy number option.

Bug: 64882313,70682949
Test: Unit test, additional unit tests in the next CL that will implement calling from bottom sheet.
PiperOrigin-RevId: 179212401
Change-Id: I23281587a0d42cea595e4dc1608f997036e2dbd0
diff --git a/java/com/android/dialer/calllog/ui/menu/Modules.java b/java/com/android/dialer/calllog/ui/menu/Modules.java
index 97b0483..d50d8d3 100644
--- a/java/com/android/dialer/calllog/ui/menu/Modules.java
+++ b/java/com/android/dialer/calllog/ui/menu/Modules.java
@@ -54,8 +54,10 @@
       modules.add(new DividerModule());
     }
 
+
     // TODO(zachh): Module for blocking/unblocking spam.
     // TODO(zachh): Module for CallComposer.
+
     SharedModules.maybeAddModuleForCopyingNumber(context, modules, originalNumber);
 
     // TODO(zachh): Revisit if DialerContact is the best thing to pass to CallDetails; could
diff --git a/java/com/android/dialer/voicemail/listui/NewVoicemailViewHolder.java b/java/com/android/dialer/voicemail/listui/NewVoicemailViewHolder.java
index bc23288..24bed0f 100644
--- a/java/com/android/dialer/voicemail/listui/NewVoicemailViewHolder.java
+++ b/java/com/android/dialer/voicemail/listui/NewVoicemailViewHolder.java
@@ -27,6 +27,7 @@
 import android.text.TextUtils;
 import android.view.View;
 import android.view.View.OnClickListener;
+import android.widget.ImageView;
 import android.widget.QuickContactBadge;
 import android.widget.TextView;
 import com.android.dialer.calllog.database.contract.AnnotatedCallLogContract.AnnotatedCallLog;
@@ -35,6 +36,7 @@
 import com.android.dialer.contactphoto.ContactPhotoManager;
 import com.android.dialer.lettertile.LetterTileDrawable;
 import com.android.dialer.time.Clock;
+import com.android.dialer.voicemail.listui.menu.NewVoicemailMenu;
 import com.android.dialer.voicemail.model.VoicemailEntry;
 
 /** {@link RecyclerView.ViewHolder} for the new voicemail tab. */
@@ -46,6 +48,7 @@
   private final TextView transcriptionTextView;
   private final QuickContactBadge quickContactBadge;
   private final NewVoicemailMediaPlayerView mediaPlayerView;
+  private final ImageView menuButton;
   private final Clock clock;
   private boolean isViewHolderExpanded;
   private int viewHolderId;
@@ -63,6 +66,7 @@
     transcriptionTextView = view.findViewById(R.id.transcription_text);
     quickContactBadge = view.findViewById(R.id.quick_contact_photo);
     mediaPlayerView = view.findViewById(R.id.new_voicemail_media_player);
+    menuButton = view.findViewById(R.id.menu_button);
     this.clock = clock;
     voicemailViewHolderListener = newVoicemailViewHolderListener;
 
@@ -121,6 +125,9 @@
     }
 
     itemView.setOnClickListener(this);
+    menuButton.setOnClickListener(
+        NewVoicemailMenu.createOnClickListener(context, voicemailEntryOfViewHolder));
+
     setPhoto(voicemailEntryOfViewHolder);
 
     // Update the expanded/collapsed state of this view holder
diff --git a/java/com/android/dialer/voicemail/listui/menu/AndroidManifest.xml b/java/com/android/dialer/voicemail/listui/menu/AndroidManifest.xml
new file mode 100644
index 0000000..07d4d22
--- /dev/null
+++ b/java/com/android/dialer/voicemail/listui/menu/AndroidManifest.xml
@@ -0,0 +1,16 @@
+<!--
+ ~ Copyright (C) 2017 The Android Open Source Project
+ ~
+ ~ Licensed under the Apache License, Version 2.0 (the "License");
+ ~ you may not use this file except in compliance with the License.
+ ~ You may obtain a copy of the License at
+ ~
+ ~      http://www.apache.org/licenses/LICENSE-2.0
+ ~
+ ~ Unless required by applicable law or agreed to in writing, software
+ ~ distributed under the License is distributed on an "AS IS" BASIS,
+ ~ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ ~ See the License for the specific language governing permissions and
+ ~ limitations under the License
+ -->
+<manifest package="com.android.dialer.voicemail.listui.menu"/>
\ No newline at end of file
diff --git a/java/com/android/dialer/voicemail/listui/menu/Modules.java b/java/com/android/dialer/voicemail/listui/menu/Modules.java
new file mode 100644
index 0000000..bb98d76
--- /dev/null
+++ b/java/com/android/dialer/voicemail/listui/menu/Modules.java
@@ -0,0 +1,59 @@
+/*
+ * Copyright (C) 2017 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License
+ */
+
+package com.android.dialer.voicemail.listui.menu;
+
+import android.content.Context;
+import com.android.dialer.contactactions.ContactActionModule;
+import com.android.dialer.contactactions.DividerModule;
+import com.android.dialer.contactactions.SharedModules;
+import com.android.dialer.voicemail.model.VoicemailEntry;
+import java.util.ArrayList;
+import java.util.List;
+
+/**
+ * Configures the modules for the voicemail bottom sheet; these are the rows below the top row
+ * (primary action) in the bottom sheet.
+ */
+final class Modules {
+
+  static List<ContactActionModule> fromVoicemailEntry(
+      Context context, VoicemailEntry voicemailEntry) {
+    // Conditionally add each module, which are items in the bottom sheet's menu.
+    List<ContactActionModule> modules = new ArrayList<>();
+
+    // TODO(uabdullah): Handle maybeAddModuleForVideoOrAudioCall(context, modules, row);
+    SharedModules.maybeAddModuleForAddingToContacts(
+        context,
+        modules,
+        voicemailEntry.number(),
+        voicemailEntry.name(),
+        voicemailEntry.lookupUri());
+
+    String originalNumber = voicemailEntry.number().getRawInput().getNumber();
+    SharedModules.maybeAddModuleForSendingTextMessage(context, modules, originalNumber);
+
+    if (!modules.isEmpty()) {
+      modules.add(new DividerModule());
+    }
+
+    // TODO(zachh): Module for blocking/unblocking spam.
+    // TODO(zachh): Module for CallComposer.
+    SharedModules.maybeAddModuleForCopyingNumber(context, modules, originalNumber);
+
+    return modules;
+  }
+}
diff --git a/java/com/android/dialer/voicemail/listui/menu/NewVoicemailMenu.java b/java/com/android/dialer/voicemail/listui/menu/NewVoicemailMenu.java
new file mode 100644
index 0000000..9af8de6
--- /dev/null
+++ b/java/com/android/dialer/voicemail/listui/menu/NewVoicemailMenu.java
@@ -0,0 +1,36 @@
+/*
+ * Copyright (C) 2017 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License
+ */
+
+package com.android.dialer.voicemail.listui.menu;
+
+import android.content.Context;
+import android.view.View;
+import com.android.dialer.contactactions.ContactActionBottomSheet;
+import com.android.dialer.voicemail.model.VoicemailEntry;
+
+/** Handles configuration of the bottom sheet menus for voicemail entries. */
+public final class NewVoicemailMenu {
+
+  /** Creates and returns the OnClickListener which opens the menu for the provided row. */
+  public static View.OnClickListener createOnClickListener(
+      Context context, VoicemailEntry voicemailEntry) {
+    return (view) ->
+        ContactActionBottomSheet.show(
+            context,
+            PrimaryAction.fromVoicemailEntry(context, voicemailEntry),
+            Modules.fromVoicemailEntry(context, voicemailEntry));
+  }
+}
diff --git a/java/com/android/dialer/voicemail/listui/menu/PrimaryAction.java b/java/com/android/dialer/voicemail/listui/menu/PrimaryAction.java
new file mode 100644
index 0000000..7f4ac80
--- /dev/null
+++ b/java/com/android/dialer/voicemail/listui/menu/PrimaryAction.java
@@ -0,0 +1,71 @@
+/*
+ * Copyright (C) 2017 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License
+ */
+
+package com.android.dialer.voicemail.listui.menu;
+
+import android.content.Context;
+import android.text.TextUtils;
+import com.android.dialer.contactactions.ContactPrimaryActionInfo;
+import com.android.dialer.contactactions.ContactPrimaryActionInfo.PhotoInfo;
+import com.android.dialer.lettertile.LetterTileDrawable;
+import com.android.dialer.voicemail.model.VoicemailEntry;
+
+/** Configures the primary action row (top row) for theottom sheet for the Voicemail Tab */
+final class PrimaryAction {
+
+  // TODO(uabdullah): Need to do the following:
+  // setIsVideo - check if is passing in voicemailEntry.features() is required
+  // setLookupUri - check if passing in voicemailEntry.lookupUri() is required
+  // setIntent - allow video calling
+  // setPrimaryText - check in with UX
+  // setSecondaryText - check in with UX
+  static ContactPrimaryActionInfo fromVoicemailEntry(
+      Context context, VoicemailEntry voicemailEntry) {
+    return ContactPrimaryActionInfo.builder()
+        .setNumber(voicemailEntry.number())
+        .setPhotoInfo(
+            PhotoInfo.builder()
+                .setPhotoId(voicemailEntry.photoId())
+                .setPhotoUri(voicemailEntry.photoUri())
+                .setIsVideo(false)
+                .setContactType(
+                    LetterTileDrawable.TYPE_DEFAULT) // TODO(uabdullah): Use proper type.
+                .setDisplayName(voicemailEntry.name())
+                .build())
+        .setPrimaryText(buildPrimaryVoicemailText(context, voicemailEntry))
+        .setSecondaryText(buildSecondaryVoicemailText(voicemailEntry))
+        .build();
+  }
+
+  private static CharSequence buildSecondaryVoicemailText(VoicemailEntry voicemailEntry) {
+    return voicemailEntry.geocodedLocation();
+  }
+
+  public static String buildPrimaryVoicemailText(Context context, VoicemailEntry data) {
+    StringBuilder primaryText = new StringBuilder();
+    if (!TextUtils.isEmpty(data.name())) {
+      primaryText.append(data.name());
+    } else if (!TextUtils.isEmpty(data.formattedNumber())) {
+      primaryText.append(data.formattedNumber());
+    } else {
+      // TODO(uabdullah): Handle CallLog.Calls.PRESENTATION_*, including Verizon restricted numbers.
+      // primaryText.append(context.getText(R.string.voicemail_unknown));
+      // TODO(uabdullah): Figure out why http://gpaste/5980163120562176 error when using string
+      primaryText.append("Unknown");
+    }
+    return primaryText.toString();
+  }
+}
diff --git a/packages.mk b/packages.mk
index ce425a9..a1cf7fc 100644
--- a/packages.mk
+++ b/packages.mk
@@ -55,6 +55,7 @@
 	com.android.dialer.theme \
 	com.android.dialer.util \
 	com.android.dialer.voicemail.listui \
+	com.android.dialer.voicemail.listui.menu \
 	com.android.dialer.voicemail.settings \
 	com.android.dialer.voicemailstatus \
 	com.android.dialer.widget \