diff options
Diffstat (limited to 'java/com/android/dialer/voicemail/listui')
7 files changed, 109 insertions, 9 deletions
diff --git a/java/com/android/dialer/voicemail/listui/NewVoicemailAdapter.java b/java/com/android/dialer/voicemail/listui/NewVoicemailAdapter.java index d50be1ab6..ca0b5dcb0 100644 --- a/java/com/android/dialer/voicemail/listui/NewVoicemailAdapter.java +++ b/java/com/android/dialer/voicemail/listui/NewVoicemailAdapter.java @@ -21,22 +21,25 @@ import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; import com.android.dialer.common.LogUtil; +import com.android.dialer.time.Clock; /** {@link RecyclerView.Adapter} for the new voicemail call log fragment. */ final class NewVoicemailAdapter extends RecyclerView.Adapter<NewVoicemailViewHolder> { private final Cursor cursor; + private final Clock clock; /** @param cursor whose projection is {@link VoicemailCursorLoader.VOICEMAIL_COLUMNS} */ - NewVoicemailAdapter(Cursor cursor) { + NewVoicemailAdapter(Cursor cursor, Clock clock) { this.cursor = cursor; + this.clock = clock; } @Override public NewVoicemailViewHolder onCreateViewHolder(ViewGroup viewGroup, int viewType) { LayoutInflater inflater = LayoutInflater.from(viewGroup.getContext()); View view = inflater.inflate(R.layout.new_voicemail_entry, viewGroup, false); - NewVoicemailViewHolder newVoicemailViewHolder = new NewVoicemailViewHolder(view); + NewVoicemailViewHolder newVoicemailViewHolder = new NewVoicemailViewHolder(view, clock); return newVoicemailViewHolder; } diff --git a/java/com/android/dialer/voicemail/listui/NewVoicemailFragment.java b/java/com/android/dialer/voicemail/listui/NewVoicemailFragment.java index 1912e1e3f..9c1fd8b85 100644 --- a/java/com/android/dialer/voicemail/listui/NewVoicemailFragment.java +++ b/java/com/android/dialer/voicemail/listui/NewVoicemailFragment.java @@ -54,7 +54,7 @@ public final class NewVoicemailFragment extends Fragment implements LoaderCallba public void onLoadFinished(Loader<Cursor> loader, Cursor data) { LogUtil.i("NewVoicemailFragment.onCreateLoader", "cursor size is %d", data.getCount()); recyclerView.setLayoutManager(new LinearLayoutManager(getContext())); - recyclerView.setAdapter(new NewVoicemailAdapter(data)); + recyclerView.setAdapter(new NewVoicemailAdapter(data, System::currentTimeMillis)); } @Override diff --git a/java/com/android/dialer/voicemail/listui/NewVoicemailViewHolder.java b/java/com/android/dialer/voicemail/listui/NewVoicemailViewHolder.java index daa24c86c..8016563ce 100644 --- a/java/com/android/dialer/voicemail/listui/NewVoicemailViewHolder.java +++ b/java/com/android/dialer/voicemail/listui/NewVoicemailViewHolder.java @@ -19,11 +19,13 @@ import android.content.Context; import android.database.Cursor; import android.net.Uri; import android.support.v7.widget.RecyclerView; +import android.text.TextUtils; import android.view.View; import android.widget.QuickContactBadge; import android.widget.TextView; import com.android.dialer.contactphoto.ContactPhotoManager; import com.android.dialer.lettertile.LetterTileDrawable; +import com.android.dialer.time.Clock; import com.android.dialer.voicemail.model.VoicemailEntry; /** {@link RecyclerView.ViewHolder} for the new voicemail tab. */ @@ -31,18 +33,37 @@ final class NewVoicemailViewHolder extends RecyclerView.ViewHolder { private final Context context; private final TextView primaryTextView; + private final TextView secondaryTextView; + private final TextView transcriptionTextView; private final QuickContactBadge quickContactBadge; + private final Clock clock; - NewVoicemailViewHolder(View view) { + NewVoicemailViewHolder(View view, Clock clock) { super(view); this.context = view.getContext(); - primaryTextView = (TextView) view.findViewById(R.id.primary_text); + primaryTextView = view.findViewById(R.id.primary_text); + secondaryTextView = view.findViewById(R.id.secondary_text); + transcriptionTextView = view.findViewById(R.id.transcription_text); quickContactBadge = view.findViewById(R.id.quick_contact_photo); + this.clock = clock; } void bind(Cursor cursor) { VoicemailEntry voicemailEntry = VoicemailCursorLoader.toVoicemailEntry(cursor); primaryTextView.setText(VoicemailEntryText.buildPrimaryVoicemailText(context, voicemailEntry)); + secondaryTextView.setText( + VoicemailEntryText.buildSecondaryVoicemailText(context, clock, voicemailEntry)); + + String voicemailTranscription = voicemailEntry.transcription(); + + if (TextUtils.isEmpty(voicemailTranscription)) { + transcriptionTextView.setVisibility(View.GONE); + transcriptionTextView.setText(null); + } else { + transcriptionTextView.setVisibility(View.VISIBLE); + transcriptionTextView.setText(voicemailTranscription); + } + setPhoto(voicemailEntry); } diff --git a/java/com/android/dialer/voicemail/listui/VoicemailCursorLoader.java b/java/com/android/dialer/voicemail/listui/VoicemailCursorLoader.java index 5a4176542..e371e5ebf 100644 --- a/java/com/android/dialer/voicemail/listui/VoicemailCursorLoader.java +++ b/java/com/android/dialer/voicemail/listui/VoicemailCursorLoader.java @@ -39,8 +39,10 @@ final class VoicemailCursorLoader extends CursorLoader { AnnotatedCallLog.PHOTO_URI, AnnotatedCallLog.PHOTO_ID, AnnotatedCallLog.LOOKUP_URI, + AnnotatedCallLog.DURATION, AnnotatedCallLog.GEOCODED_LOCATION, - AnnotatedCallLog.CALL_TYPE + AnnotatedCallLog.CALL_TYPE, + AnnotatedCallLog.TRANSCRIPTION }; // Indexes for VOICEMAIL_COLUMNS @@ -52,8 +54,10 @@ final class VoicemailCursorLoader extends CursorLoader { private static final int PHOTO_URI = 5; private static final int PHOTO_ID = 6; private static final int LOOKUP_URI = 7; - private static final int GEOCODED_LOCATION = 8; - private static final int CALL_TYPE = 9; + private static final int DURATION = 8; + private static final int GEOCODED_LOCATION = 9; + private static final int CALL_TYPE = 10; + private static final int TRANSCRIPTION = 11; // TODO(zachh): Optimize indexes VoicemailCursorLoader(Context context) { @@ -84,6 +88,8 @@ final class VoicemailCursorLoader extends CursorLoader { .setPhotoUri(cursor.getString(PHOTO_URI)) .setPhotoId(cursor.getLong(PHOTO_ID)) .setLookupUri(cursor.getString(LOOKUP_URI)) + .setDuration(cursor.getLong(DURATION)) + .setTranscription(cursor.getString(TRANSCRIPTION)) .setGeocodedLocation(cursor.getString(GEOCODED_LOCATION)) .setCallType(cursor.getInt(CALL_TYPE)) .build(); diff --git a/java/com/android/dialer/voicemail/listui/VoicemailEntryText.java b/java/com/android/dialer/voicemail/listui/VoicemailEntryText.java index cf2fef253..f59220105 100644 --- a/java/com/android/dialer/voicemail/listui/VoicemailEntryText.java +++ b/java/com/android/dialer/voicemail/listui/VoicemailEntryText.java @@ -18,7 +18,11 @@ package com.android.dialer.voicemail.listui; import android.content.Context; import android.text.TextUtils; +import com.android.dialer.calllogutils.CallLogDates; +import com.android.dialer.common.LogUtil; +import com.android.dialer.time.Clock; import com.android.dialer.voicemail.model.VoicemailEntry; +import java.util.concurrent.TimeUnit; /** * Computes the primary text for voicemail entries. @@ -39,4 +43,66 @@ public class VoicemailEntryText { } return primaryText.toString(); } + + /** + * Uses the new date and location formatting rules to format the location and date in the new + * voicemail tab. + * + * <p>Rules: $Location • Date + * + * <p>Examples: + * + * <p>Jun 20 San Francisco • Now + * + * <p>Markham, ON • Jul 27 + * + * <p>Toledo, OH • 12:15 PM + * + * <p>Date rules: if < 1 minute ago: "Now"; else if today: HH:MM(am|pm); else if < 3 days: day; + * else: MON D * + * + * @return $Location • Date + */ + public static String buildSecondaryVoicemailText( + Context context, Clock clock, VoicemailEntry voicemailEntry) { + return secondaryTextPrefix(context, clock, voicemailEntry); + } + + private static String secondaryTextPrefix( + Context context, Clock clock, VoicemailEntry voicemailEntry) { + StringBuilder secondaryText = new StringBuilder(); + String location = voicemailEntry.geocodedLocation(); + if (!TextUtils.isEmpty(location)) { + secondaryText.append(location); + } + if (secondaryText.length() > 0) { + secondaryText.append(" • "); + } + secondaryText.append( + CallLogDates.newCallLogTimestampLabel( + context, clock.currentTimeMillis(), voicemailEntry.timestamp())); + + long duration = voicemailEntry.duration(); + if (duration >= 0) { + secondaryText.append(" • "); + String formattedDuration = getVoicemailDuration(context, voicemailEntry); + secondaryText.append(formattedDuration); + } + return secondaryText.toString(); + } + + private static String getVoicemailDuration(Context context, VoicemailEntry voicemailEntry) { + long minutes = TimeUnit.SECONDS.toMinutes(voicemailEntry.duration()); + long seconds = voicemailEntry.duration() - TimeUnit.MINUTES.toSeconds(minutes); + + // The format for duration is "MM:SS" and we never expect the duration to be > 5 minutes + // However an incorrect duration could be set by the framework/someone to be >99, and in that + // case cap it at 99, for the UI to still be able to display it in "MM:SS" format. + if (minutes > 99) { + LogUtil.w( + "VoicemailEntryText.getVoicemailDuration", "Duration was %d", voicemailEntry.duration()); + minutes = 99; + } + return context.getString(R.string.voicemailDurationFormat, minutes, seconds); + } } diff --git a/java/com/android/dialer/voicemail/listui/res/layout/new_voicemail_entry.xml b/java/com/android/dialer/voicemail/listui/res/layout/new_voicemail_entry.xml index bc1506751..fe009922e 100644 --- a/java/com/android/dialer/voicemail/listui/res/layout/new_voicemail_entry.xml +++ b/java/com/android/dialer/voicemail/listui/res/layout/new_voicemail_entry.xml @@ -72,6 +72,7 @@ android:layout_marginStart="@dimen/call_log_entry_photo_text_margin"/> </LinearLayout> + <!-- TODO(uabdullah): Fix text cropping issue --> <TextView android:id="@+id/transcription_text" style="@style/SecondaryText" 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 39c368a5a..a7df0ce8f 100644 --- a/java/com/android/dialer/voicemail/listui/res/values/strings.xml +++ b/java/com/android/dialer/voicemail/listui/res/values/strings.xml @@ -14,7 +14,10 @@ ~ See the License for the specific language governing permissions and ~ limitations under the License --> -<resources> +<resources xmlns:xliff="urn:oasis:names:tc:xliff:document:1.2"> <!-- String used to display voicemails from unknown numbers in the voicemail tab. [CHAR LIMIT=30] --> <string name="voicemail_entry_unknown">Unknown</string> + + <!-- Format for duration of voicemails which are displayed when viewing voicemail. For example "01:22" --> + <string name="voicemailDurationFormat"><xliff:g example="10" id="minutes">%1$02d</xliff:g>:<xliff:g example="20" id="seconds">%2$02d</xliff:g></string> </resources>
\ No newline at end of file |