Initial setup of voicemail error messages
This CL setups the initial adapter logic to be able to display voicemail error messages.
The errors and the code to display those errors will be shown in a follow up CL.
Bug: 71700117
Test: N/A
PiperOrigin-RevId: 181210330
Change-Id: I5b9e9e675ad7a4825692fb93ca4237d05b0407f0
diff --git a/java/com/android/dialer/voicemail/listui/NewVoicemailAdapter.java b/java/com/android/dialer/voicemail/listui/NewVoicemailAdapter.java
index 93d5cda..32c5b69 100644
--- a/java/com/android/dialer/voicemail/listui/NewVoicemailAdapter.java
+++ b/java/com/android/dialer/voicemail/listui/NewVoicemailAdapter.java
@@ -55,12 +55,14 @@
/** IntDef for the different types of rows that can be shown in the call log. */
@Retention(RetentionPolicy.SOURCE)
- @IntDef({RowType.HEADER, RowType.VOICEMAIL_ENTRY})
+ @IntDef({RowType.HEADER, RowType.VOICEMAIL_ENTRY, RowType.VOICEMAIL_ALERT})
@interface RowType {
+ /** A row representing a voicemail alert. */
+ int VOICEMAIL_ALERT = 1;
/** Header that displays "Today" or "Older". */
- int HEADER = 1;
+ int HEADER = 2;
/** A row representing a voicemail entry. */
- int VOICEMAIL_ENTRY = 2;
+ int VOICEMAIL_ENTRY = 3;
}
private Cursor cursor;
@@ -70,6 +72,8 @@
private int todayHeaderPosition = Integer.MAX_VALUE;
/** {@link Integer#MAX_VALUE} when the "Older" header should not be displayed. */
private int olderHeaderPosition = Integer.MAX_VALUE;
+ /** {@link Integer#MAX_VALUE} when the voicemail alert message should not be displayed. */
+ private int voicemailAlertPosition = Integer.MAX_VALUE;
private final FragmentManager fragmentManager;
/** A valid id for {@link VoicemailEntry} is greater than 0 */
@@ -113,16 +117,26 @@
private void updateHeaderPositions() {
LogUtil.i(
"NewVoicemailAdapter.updateHeaderPositions",
- "before updating todayPos:%d, olderPos:%d",
+ "before updating todayPos:%d, olderPos:%d, alertPos:%d",
todayHeaderPosition,
- olderHeaderPosition);
+ olderHeaderPosition,
+ voicemailAlertPosition);
+
+ int alertOffSet = 0;
+ if (voicemailAlertPosition != Integer.MAX_VALUE) {
+ Assert.checkArgument(
+ voicemailAlertPosition == 0, "voicemail alert can only be 0, when showing");
+ alertOffSet = 1;
+ }
+
// Calculate header adapter positions by reading cursor.
long currentTimeMillis = clock.currentTimeMillis();
if (cursor.moveToNext()) {
long firstTimestamp = VoicemailCursorLoader.getTimestamp(cursor);
if (CallLogDates.isSameDay(currentTimeMillis, firstTimestamp)) {
- this.todayHeaderPosition = 0;
- int adapterPosition = 2; // Accounted for "Today" header and first row.
+ this.todayHeaderPosition = 0 + alertOffSet;
+ int adapterPosition =
+ 2 + alertOffSet; // Accounted for the "Alert", "Today" header and first row.
while (cursor.moveToNext()) {
long timestamp = VoicemailCursorLoader.getTimestamp(cursor);
@@ -144,9 +158,11 @@
}
LogUtil.i(
"NewVoicemailAdapter.updateHeaderPositions",
- "after updating todayPos:%d, olderPos:%d",
+ "after updating todayPos:%d, olderPos:%d, alertOffSet:%d, alertPos:%d",
todayHeaderPosition,
- olderHeaderPosition);
+ olderHeaderPosition,
+ alertOffSet,
+ voicemailAlertPosition);
}
private void initializeMediaPlayerListeners() {
@@ -169,6 +185,9 @@
LayoutInflater inflater = LayoutInflater.from(viewGroup.getContext());
View view;
switch (viewType) {
+ case RowType.VOICEMAIL_ALERT:
+ view = inflater.inflate(R.layout.new_voicemail_entry_alert, viewGroup, false);
+ return new NewVoicemailAlertViewHolder(view);
case RowType.HEADER:
view = inflater.inflate(R.layout.new_voicemail_entry_header, viewGroup, false);
return new NewVoicemailHeaderViewHolder(view);
@@ -223,14 +242,33 @@
return;
}
+ if (viewHolder instanceof NewVoicemailAlertViewHolder) {
+ LogUtil.i(
+ "NewVoicemailAdapter.onBindViewHolder", "view holder at pos:%d is a alert", position);
+ NewVoicemailAlertViewHolder alertViewHolder = (NewVoicemailAlertViewHolder) viewHolder;
+ @RowType int viewType = getItemViewType(position);
+ Assert.checkArgument(position == 0);
+ if (position == voicemailAlertPosition) {
+ // TODO(a bug): Update this with the alert messages
+ alertViewHolder.setHeader("Temporary placeholder, update this with the alert messages");
+ } else {
+ throw Assert.createIllegalStateFailException(
+ "Unexpected view type " + viewType + " at position: " + position);
+ }
+ return;
+ }
+
LogUtil.i(
"NewVoicemailAdapter.onBindViewHolder",
- "view holder at pos:%d is a not a header",
+ "view holder at pos:%d is a not a header or an alert",
position);
NewVoicemailViewHolder newVoicemailViewHolder = (NewVoicemailViewHolder) viewHolder;
int previousHeaders = 0;
+ if (voicemailAlertPosition != Integer.MAX_VALUE && position > voicemailAlertPosition) {
+ previousHeaders++;
+ }
if (todayHeaderPosition != Integer.MAX_VALUE && position > todayHeaderPosition) {
previousHeaders++;
}
@@ -826,6 +864,9 @@
// TODO(uabdullah): a bug Remove logging, temporarily here for debugging.
LogUtil.enterBlock("NewVoicemailAdapter.getItemCount");
int numberOfHeaders = 0;
+ if (voicemailAlertPosition != Integer.MAX_VALUE) {
+ numberOfHeaders++;
+ }
if (todayHeaderPosition != Integer.MAX_VALUE) {
numberOfHeaders++;
}
@@ -846,6 +887,9 @@
@Override
public int getItemViewType(int position) {
LogUtil.enterBlock("NewVoicemailAdapter.getItemViewType");
+ if (voicemailAlertPosition != Integer.MAX_VALUE && position == voicemailAlertPosition) {
+ return RowType.VOICEMAIL_ALERT;
+ }
if (todayHeaderPosition != Integer.MAX_VALUE && position == todayHeaderPosition) {
return RowType.HEADER;
}
diff --git a/java/com/android/dialer/voicemail/listui/NewVoicemailAlertViewHolder.java b/java/com/android/dialer/voicemail/listui/NewVoicemailAlertViewHolder.java
new file mode 100644
index 0000000..ec603b5
--- /dev/null
+++ b/java/com/android/dialer/voicemail/listui/NewVoicemailAlertViewHolder.java
@@ -0,0 +1,36 @@
+/*
+ * Copyright (C) 2018 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;
+
+import android.support.v7.widget.RecyclerView.ViewHolder;
+import android.view.View;
+import android.widget.TextView;
+
+/** ViewHolder for {@link NewVoicemailAdapter} to display voicemail error states. */
+final class NewVoicemailAlertViewHolder extends ViewHolder {
+
+ private final TextView errorTextView;
+
+ NewVoicemailAlertViewHolder(View view) {
+ super(view);
+ errorTextView = view.findViewById(R.id.new_voicemail_alert_text);
+ }
+
+ void setHeader(String error) {
+ errorTextView.setText(error);
+ }
+}
diff --git a/java/com/android/dialer/voicemail/listui/res/layout/new_voicemail_entry_alert.xml b/java/com/android/dialer/voicemail/listui/res/layout/new_voicemail_entry_alert.xml
new file mode 100644
index 0000000..e8dcd02
--- /dev/null
+++ b/java/com/android/dialer/voicemail/listui/res/layout/new_voicemail_entry_alert.xml
@@ -0,0 +1,30 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!--
+ ~ 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
+ -->
+<RelativeLayout
+ xmlns:android="http://schemas.android.com/apk/res/android"
+ android:height="48dp"
+ android:layout_width="match_parent"
+ android:layout_height="wrap_content">
+ <!-- TODO(uabdullah): Confirm with UX on mocks -->
+ <TextView
+ android:id="@+id/new_voicemail_alert_text"
+ style="@style/SecondaryText"
+ android:layout_width="wrap_content"
+ android:layout_height="wrap_content"
+ android:layout_marginStart="@dimen/voicemail_header_margin_start"
+ android:layout_centerVertical="true"/>
+</RelativeLayout>