Add support for yesterday header in NUI Voicemail Tab
Currently NUI only supports today and older, however we also need to support yesterday and be consistent with the call log.
Bug: 69858354,72331988
Test: Unit Tests
PiperOrigin-RevId: 183121631
Change-Id: Ica75164c28ee60a2f776287eefd7eed5db08e035
diff --git a/java/com/android/dialer/voicemail/listui/NewVoicemailAdapter.java b/java/com/android/dialer/voicemail/listui/NewVoicemailAdapter.java
index c9bf6e1..5519aa4 100644
--- a/java/com/android/dialer/voicemail/listui/NewVoicemailAdapter.java
+++ b/java/com/android/dialer/voicemail/listui/NewVoicemailAdapter.java
@@ -59,7 +59,7 @@
@interface RowType {
/** A row representing a voicemail alert. */
int VOICEMAIL_ALERT = 1;
- /** Header that displays "Today" or "Older". */
+ /** Header that displays "Today", "Yesterday" or "Older". */
int HEADER = 2;
/** A row representing a voicemail entry. */
int VOICEMAIL_ENTRY = 3;
@@ -70,6 +70,8 @@
/** {@link Integer#MAX_VALUE} when the "Today" header should not be displayed. */
private int todayHeaderPosition = Integer.MAX_VALUE;
+ /** {@link Integer#MAX_VALUE} when the "Yesterday" header should not be displayed. */
+ private int yesterdayHeaderPosition = 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. */
@@ -117,11 +119,44 @@
private void updateHeaderPositions() {
LogUtil.i(
"NewVoicemailAdapter.updateHeaderPositions",
- "before updating todayPos:%d, olderPos:%d, alertPos:%d",
+ "before updating todayPos:%d, yestPos:%d, olderPos:%d, alertPos:%d",
todayHeaderPosition,
+ yesterdayHeaderPosition,
olderHeaderPosition,
voicemailAlertPosition);
+ // If there are no rows to display, set all header positions to MAX_VALUE.
+ if (!cursor.moveToFirst()) {
+ todayHeaderPosition = Integer.MAX_VALUE;
+ yesterdayHeaderPosition = Integer.MAX_VALUE;
+ olderHeaderPosition = Integer.MAX_VALUE;
+ return;
+ }
+
+ long currentTimeMillis = clock.currentTimeMillis();
+
+ int numItemsInToday = 0;
+ int numItemsInYesterday = 0;
+
+ do {
+ long timestamp = VoicemailCursorLoader.getTimestamp(cursor);
+ long dayDifference = CallLogDates.getDayDifference(currentTimeMillis, timestamp);
+ if (dayDifference == 0) {
+ numItemsInToday++;
+ } else if (dayDifference == 1) {
+ numItemsInYesterday++;
+ } else {
+ break;
+ }
+ } while (cursor.moveToNext());
+
+ if (numItemsInToday > 0) {
+ numItemsInToday++; // including the "Today" header;
+ }
+ if (numItemsInYesterday > 0) {
+ numItemsInYesterday++; // including the "Yesterday" header;
+ }
+
int alertOffSet = 0;
if (voicemailAlertPosition != Integer.MAX_VALUE) {
Assert.checkArgument(
@@ -129,37 +164,21 @@
alertOffSet = 1;
}
- // Calculate header adapter positions by reading cursor.
- long currentTimeMillis = clock.currentTimeMillis();
- if (cursor.moveToNext()) {
- long firstTimestamp = VoicemailCursorLoader.getTimestamp(cursor);
- if (CallLogDates.getDayDifference(currentTimeMillis, firstTimestamp) == 0) {
- 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);
+ // Set all header positions.
+ // A header position will be MAX_VALUE if there is no item to be displayed under that header.
+ todayHeaderPosition = numItemsInToday > 0 ? alertOffSet : Integer.MAX_VALUE;
+ yesterdayHeaderPosition =
+ numItemsInYesterday > 0 ? numItemsInToday + alertOffSet : Integer.MAX_VALUE;
+ olderHeaderPosition =
+ !cursor.isAfterLast()
+ ? numItemsInToday + numItemsInYesterday + alertOffSet
+ : Integer.MAX_VALUE;
- if (CallLogDates.getDayDifference(currentTimeMillis, timestamp) == 0) {
- adapterPosition++;
- } else {
- this.olderHeaderPosition = adapterPosition;
- return;
- }
- }
- this.olderHeaderPosition = Integer.MAX_VALUE; // Didn't find any "Older" rows.
- } else {
- this.todayHeaderPosition = Integer.MAX_VALUE; // Didn't find any "Today" rows.
- this.olderHeaderPosition = 0 + alertOffSet;
- }
- } else { // There are no rows, just need to set these because they are final.
- this.todayHeaderPosition = Integer.MAX_VALUE;
- this.olderHeaderPosition = Integer.MAX_VALUE;
- }
LogUtil.i(
"NewVoicemailAdapter.updateHeaderPositions",
- "after updating todayPos:%d, olderPos:%d, alertOffSet:%d, alertPos:%d",
+ "after updating todayPos:%d, yestPos:%d, olderPos:%d, alertOffSet:%d, alertPos:%d",
todayHeaderPosition,
+ yesterdayHeaderPosition,
olderHeaderPosition,
alertOffSet,
voicemailAlertPosition);
@@ -233,6 +252,8 @@
@RowType int viewType = getItemViewType(position);
if (position == todayHeaderPosition) {
headerViewHolder.setHeader(R.string.new_voicemail_header_today);
+ } else if (position == yesterdayHeaderPosition) {
+ headerViewHolder.setHeader(R.string.new_voicemail_header_yesterday);
} else if (position == olderHeaderPosition) {
headerViewHolder.setHeader(R.string.new_voicemail_header_older);
} else {
@@ -272,6 +293,9 @@
if (todayHeaderPosition != Integer.MAX_VALUE && position > todayHeaderPosition) {
previousHeaders++;
}
+ if (yesterdayHeaderPosition != Integer.MAX_VALUE && position > yesterdayHeaderPosition) {
+ previousHeaders++;
+ }
if (olderHeaderPosition != Integer.MAX_VALUE && position > olderHeaderPosition) {
previousHeaders++;
}
@@ -870,6 +894,9 @@
if (todayHeaderPosition != Integer.MAX_VALUE) {
numberOfHeaders++;
}
+ if (yesterdayHeaderPosition != Integer.MAX_VALUE) {
+ numberOfHeaders++;
+ }
if (olderHeaderPosition != Integer.MAX_VALUE) {
numberOfHeaders++;
}
@@ -893,6 +920,9 @@
if (todayHeaderPosition != Integer.MAX_VALUE && position == todayHeaderPosition) {
return RowType.HEADER;
}
+ if (yesterdayHeaderPosition != Integer.MAX_VALUE && position == yesterdayHeaderPosition) {
+ return RowType.HEADER;
+ }
if (olderHeaderPosition != Integer.MAX_VALUE && position == olderHeaderPosition) {
return RowType.HEADER;
}
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 70a5d03..e7373d6 100644
--- a/java/com/android/dialer/voicemail/listui/res/values/strings.xml
+++ b/java/com/android/dialer/voicemail/listui/res/values/strings.xml
@@ -30,8 +30,9 @@
<!-- Header in voicemail tab to group calls from the current day. [CHAR LIMIT=30] -->
<string name="new_voicemail_header_today">Today</string>
-
- <!-- Header in voicemail tab to group calls from before the current day. [CHAR LIMIT=30] -->
+ <!-- Header in voicemail tab to group calls from yesterday. [CHAR LIMIT=30] -->
+ <string name="new_voicemail_header_yesterday">Yesterday</string>
+ <!-- Header in voicemail tab to group calls from before yesterday. [CHAR LIMIT=30] -->
<string name="new_voicemail_header_older">Older</string>
<string name="verizon_terms_and_conditions_title" translatable="false">Turn on visual voicemail</string>