Show empty view when there are no voicemails

When there are no voicemails to be shown, we show an empty view. This is done by hiding the recycler view and showing the empty view. Similarly when a voicemail is present, we hide the empty view and then show the recycler view.

Bug: 25661977
Test: Unit Tests
PiperOrigin-RevId: 187396952
Change-Id: Ifa718fb05c1be37aabdf4c91bc2c1653357565b2
diff --git a/java/com/android/dialer/voicemail/listui/NewVoicemailFragment.java b/java/com/android/dialer/voicemail/listui/NewVoicemailFragment.java
index 9296d04..6d71dad 100644
--- a/java/com/android/dialer/voicemail/listui/NewVoicemailFragment.java
+++ b/java/com/android/dialer/voicemail/listui/NewVoicemailFragment.java
@@ -30,6 +30,7 @@
 import android.view.LayoutInflater;
 import android.view.View;
 import android.view.ViewGroup;
+import android.widget.FrameLayout;
 import com.android.dialer.calllog.CallLogComponent;
 import com.android.dialer.calllog.RefreshAnnotatedCallLogReceiver;
 import com.android.dialer.common.LogUtil;
@@ -38,6 +39,7 @@
 import com.android.dialer.glidephotomanager.GlidePhotoManagerComponent;
 import com.android.dialer.voicemail.listui.error.VoicemailStatus;
 import com.android.dialer.voicemailstatus.VoicemailStatusQuery;
+import com.android.dialer.widget.EmptyContentView;
 import com.android.voicemail.VoicemailComponent;
 import com.google.common.collect.ImmutableList;
 import com.google.common.util.concurrent.ListenableFuture;
@@ -52,6 +54,11 @@
   private RefreshAnnotatedCallLogReceiver refreshAnnotatedCallLogReceiver;
   private UiListener<ImmutableList<VoicemailStatus>> queryVoicemailStatusTableListener;
 
+  // View required to show/hide recycler and empty views
+  FrameLayout fragmentRootFrameLayout;
+
+  private EmptyContentView emptyContentView;
+
   public NewVoicemailFragment() {
     LogUtil.enterBlock("NewVoicemailFragment.NewVoicemailFragment");
   }
@@ -147,10 +154,14 @@
   public View onCreateView(
       LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
     LogUtil.enterBlock("NewVoicemailFragment.onCreateView");
-    View view = inflater.inflate(R.layout.new_voicemail_call_log_fragment, container, false);
-    recyclerView = view.findViewById(R.id.new_voicemail_call_log_recycler_view);
+
+    fragmentRootFrameLayout =
+        (FrameLayout) inflater.inflate(R.layout.new_voicemail_call_log_fragment, container, false);
+    recyclerView = fragmentRootFrameLayout.findViewById(R.id.new_voicemail_call_log_recycler_view);
+
+    emptyContentView = fragmentRootFrameLayout.findViewById(R.id.empty_content_view);
     getLoaderManager().restartLoader(0, null, this);
-    return view;
+    return fragmentRootFrameLayout;
   }
 
   @Override
@@ -162,6 +173,12 @@
   @Override
   public void onLoadFinished(Loader<Cursor> loader, Cursor data) {
     LogUtil.i("NewVoicemailFragment.onLoadFinished", "cursor size is %d", data.getCount());
+    if (data.getCount() == 0) {
+      showEmptyVoicemailFragmentView();
+      return;
+    }
+    showView(recyclerView);
+
     if (recyclerView.getAdapter() == null) {
       recyclerView.setLayoutManager(new LinearLayoutManager(getContext()));
       // TODO(uabdullah): Replace getActivity().getFragmentManager() with getChildFragment()
@@ -182,9 +199,24 @@
           recyclerView.getAdapter());
       ((NewVoicemailAdapter) recyclerView.getAdapter()).updateCursor(data);
       ((NewVoicemailAdapter) recyclerView.getAdapter()).checkAndPlayVoicemail();
+      queryAndUpdateVoicemailStatusAlert();
     }
+  }
 
-    queryAndUpdateVoicemailStatusAlert();
+  /** Shows the view when there are no voicemails to be displayed * */
+  private void showEmptyVoicemailFragmentView() {
+    LogUtil.enterBlock("NewVoicemailFragmentListener.showEmptyVoicemailFragmentView");
+
+    showView(emptyContentView);
+
+    emptyContentView.setDescription((R.string.empty_voicemail_tab_text));
+    emptyContentView.setImage(R.drawable.quantum_ic_schedule_vd_theme_24);
+  }
+
+  private void showView(View view) {
+    LogUtil.i("NewVoicemailFragmentListener.showView", "Showing view: " + view);
+    emptyContentView.setVisibility(view == emptyContentView ? View.VISIBLE : View.GONE);
+    recyclerView.setVisibility(view == recyclerView ? View.VISIBLE : View.GONE);
   }
 
   private void registerRefreshAnnotatedCallLogReceiver() {
diff --git a/java/com/android/dialer/voicemail/listui/res/layout/new_voicemail_call_log_fragment.xml b/java/com/android/dialer/voicemail/listui/res/layout/new_voicemail_call_log_fragment.xml
index 9daa3e1..fd9e0f2 100644
--- a/java/com/android/dialer/voicemail/listui/res/layout/new_voicemail_call_log_fragment.xml
+++ b/java/com/android/dialer/voicemail/listui/res/layout/new_voicemail_call_log_fragment.xml
@@ -15,21 +15,35 @@
   ~ limitations under the License
   -->
 
-
 <FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
-    android:id="@+id/fragment_my_frame_layout"
-    android:layout_width="wrap_content"
-    android:layout_height="wrap_content"
+    android:id="@+id/new_voicemail_frame_layout"
+    android:layout_width="match_parent"
+    android:layout_height="match_parent"
     android:orientation="vertical">
-  <include layout="@layout/voicemail_tos_fragment"/>
 
   <android.support.v7.widget.RecyclerView
       xmlns:android="http://schemas.android.com/apk/res/android"
       android:id="@+id/new_voicemail_call_log_recycler_view"
       android:layout_width="match_parent"
       android:layout_height="match_parent"
-      android:background="@color/background_dialer_light"
       android:paddingBottom="@dimen/floating_action_button_list_bottom_padding"
-      android:clipToPadding="false"/>
+      android:background="@color/background_dialer_light"
+      android:clipToPadding="false"
+      android:visibility="gone"
+      />
+
+
+  <FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
+      android:layout_width="match_parent"
+      android:layout_height="match_parent">
+
+    <com.android.dialer.widget.EmptyContentView
+        android:id="@+id/empty_content_view"
+        android:layout_width="match_parent"
+        android:layout_height="wrap_content"
+        android:layout_gravity="center"
+        android:visibility="gone"/>
+
+  </FrameLayout>
 
 </FrameLayout>
diff --git a/java/com/android/dialer/voicemail/listui/res/values/strings.xml b/java/com/android/dialer/voicemail/listui/res/values/strings.xml
index db33c19..d12a71e 100644
--- a/java/com/android/dialer/voicemail/listui/res/values/strings.xml
+++ b/java/com/android/dialer/voicemail/listui/res/values/strings.xml
@@ -57,4 +57,7 @@
   <!-- Label indicating who provided the voicemail transcription [CHAR LIMIT=64] -->
   <string name="voicemail_transcription_branding_text">Transcribed by Google</string>
 
+  <!-- Text displayed when the list of voicemails is empty [CHAR LIMIT=NONE] -->
+  <string name="empty_voicemail_tab_text">Your voicemail inbox is empty.</string>
+
 </resources>
diff --git a/java/com/android/dialer/widget/res/layout/empty_content_view.xml b/java/com/android/dialer/widget/res/layout/empty_content_view.xml
index 1777443..9aac6f4 100644
--- a/java/com/android/dialer/widget/res/layout/empty_content_view.xml
+++ b/java/com/android/dialer/widget/res/layout/empty_content_view.xml
@@ -18,7 +18,7 @@
   <ImageView
     android:id="@+id/empty_list_view_image"
     android:layout_width="match_parent"
-    android:layout_height="wrap_content"
+    android:layout_height="108dp"
     android:gravity="center_horizontal"/>
 
   <TextView