Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit c6dbda13 authored by Treehugger Robot's avatar Treehugger Robot Committed by Gerrit Code Review
Browse files

Merge "Convert @AutoValue VoicemailEntry to a proto"

parents 393d1df3 67a08ed8
Loading
Loading
Loading
Loading
+3 −3
Original line number Diff line number Diff line
@@ -92,7 +92,7 @@ final class NewVoicemailAdapter extends RecyclerView.Adapter<ViewHolder>

  private final FragmentManager fragmentManager;
  /** A valid id for {@link VoicemailEntry} is greater than 0 */
  private int currentlyExpandedViewHolderId = -1;
  private long currentlyExpandedViewHolderId = -1;

  private VoicemailErrorMessage voicemailErrorMessage;

@@ -114,7 +114,7 @@ final class NewVoicemailAdapter extends RecyclerView.Adapter<ViewHolder>
   * will always ensure there is only (up-to-date) view holder corresponding to a view holder id,
   * unlike the newVoicemailViewHolderSet.
   */
  private final ArrayMap<Integer, NewVoicemailViewHolder> newVoicemailViewHolderArrayMap =
  private final ArrayMap<Long, NewVoicemailViewHolder> newVoicemailViewHolderArrayMap =
      new ArrayMap<>();

  // A single instance of a media player re-used across the expanded view holders.
@@ -440,7 +440,7 @@ final class NewVoicemailAdapter extends RecyclerView.Adapter<ViewHolder>

    if (!newVoicemailViewHolderArrayMap.isEmpty()) {
      String ids = "";
      for (int id : newVoicemailViewHolderArrayMap.keySet()) {
      for (long id : newVoicemailViewHolderArrayMap.keySet()) {
        ids = ids + id + " ";
      }
      LogUtil.i("NewVoicemailAdapter.printArrayMap", "ids are " + ids);
+4 −4
Original line number Diff line number Diff line
@@ -154,11 +154,11 @@ public final class NewVoicemailMediaPlayerView extends LinearLayout {
      NewVoicemailViewHolderListener listener) {

    Assert.isNotNull(voicemailEntryFromAdapter);
    Uri uri = Uri.parse(voicemailEntryFromAdapter.voicemailUri());
    Uri uri = Uri.parse(voicemailEntryFromAdapter.getVoicemailUri());

    numberVoicemailFrom = voicemailEntryFromAdapter.number().getNormalizedNumber();
    phoneAccountId = voicemailEntryFromAdapter.phoneAccountId();
    phoneAccountComponentName = voicemailEntryFromAdapter.phoneAccountComponentName();
    numberVoicemailFrom = voicemailEntryFromAdapter.getNumber().getNormalizedNumber();
    phoneAccountId = voicemailEntryFromAdapter.getPhoneAccountId();
    phoneAccountComponentName = voicemailEntryFromAdapter.getPhoneAccountComponentName();

    Assert.isNotNull(viewHolder);
    Assert.isNotNull(uri);
+21 −24
Original line number Diff line number Diff line
@@ -45,7 +45,6 @@ import com.android.dialer.common.concurrent.DialerExecutor.Worker;
import com.android.dialer.common.concurrent.DialerExecutorComponent;
import com.android.dialer.compat.android.provider.VoicemailCompat;
import com.android.dialer.glidephotomanager.GlidePhotoManager;
import com.android.dialer.glidephotomanager.PhotoInfo;
import com.android.dialer.time.Clock;
import com.android.dialer.voicemail.listui.menu.NewVoicemailMenu;
import com.android.dialer.voicemail.model.VoicemailEntry;
@@ -64,7 +63,7 @@ final class NewVoicemailViewHolder extends RecyclerView.ViewHolder implements On
  private final ImageView menuButton;
  private final Clock clock;
  private boolean isViewHolderExpanded;
  private int viewHolderId;
  private long viewHolderId;
  private VoicemailEntry voicemailEntryOfViewHolder;
  @NonNull private Uri viewHolderVoicemailUri;
  private final NewVoicemailViewHolderListener voicemailViewHolderListener;
@@ -117,7 +116,7 @@ final class NewVoicemailViewHolder extends RecyclerView.ViewHolder implements On
      FragmentManager fragmentManager,
      NewVoicemailMediaPlayer mediaPlayer,
      int position,
      int currentlyExpandedViewHolderId) {
      long currentlyExpandedViewHolderId) {

    LogUtil.i(
        "NewVoicemailViewHolder.bindViewHolderValuesFromAdapter",
@@ -128,16 +127,16 @@ final class NewVoicemailViewHolder extends RecyclerView.ViewHolder implements On
        cursor.getCount());

    voicemailEntryOfViewHolder = VoicemailCursorLoader.toVoicemailEntry(cursor);
    viewHolderId = voicemailEntryOfViewHolder.id();
    viewHolderId = voicemailEntryOfViewHolder.getId();
    LogUtil.i(
        "NewVoicemailViewHolder.bindViewHolderValuesFromAdapter", "viewholderId:%d", viewHolderId);
    viewHolderVoicemailUri = Uri.parse(voicemailEntryOfViewHolder.voicemailUri());
    viewHolderVoicemailUri = Uri.parse(voicemailEntryOfViewHolder.getVoicemailUri());
    primaryTextView.setText(
        VoicemailEntryText.buildPrimaryVoicemailText(context, voicemailEntryOfViewHolder));
    secondaryTextView.setText(
        VoicemailEntryText.buildSecondaryVoicemailText(context, clock, voicemailEntryOfViewHolder));

    String voicemailTranscription = voicemailEntryOfViewHolder.transcription();
    String voicemailTranscription = voicemailEntryOfViewHolder.getTranscription();

    if (TextUtils.isEmpty(voicemailTranscription)) {
      transcriptionTextView.setVisibility(GONE);
@@ -204,10 +203,10 @@ final class NewVoicemailViewHolder extends RecyclerView.ViewHolder implements On
    LogUtil.v(
        "NewVoicemailViewHolder.boldViewHolderIfUnread",
        "id:%d, isRead:%d",
        voicemailEntryOfViewHolder.id(),
        voicemailEntryOfViewHolder.isRead());
        voicemailEntryOfViewHolder.getId(),
        voicemailEntryOfViewHolder.getIsRead());

    if (voicemailEntryOfViewHolder.isRead() == 0) {
    if (voicemailEntryOfViewHolder.getIsRead() == 0) {
      primaryTextView.setTypeface(Typeface.DEFAULT, Typeface.BOLD);
      secondaryTextView.setTypeface(Typeface.DEFAULT, Typeface.BOLD);
      transcriptionTextView.setTypeface(Typeface.DEFAULT, Typeface.BOLD);
@@ -215,13 +214,11 @@ final class NewVoicemailViewHolder extends RecyclerView.ViewHolder implements On
  }

  private void setPhoto(VoicemailEntry voicemailEntry) {
    PhotoInfo.Builder photoInfoBuilder =
        NumberAttributesConverter.toPhotoInfoBuilder(voicemailEntry.numberAttributes());
    if (!TextUtils.isEmpty(voicemailEntry.formattedNumber())) {
      photoInfoBuilder.setFormattedNumber(voicemailEntry.formattedNumber());
    }

    glidePhotoManager.loadQuickContactBadge(quickContactBadge, photoInfoBuilder.build());
    glidePhotoManager.loadQuickContactBadge(
        quickContactBadge,
        NumberAttributesConverter.toPhotoInfoBuilder(voicemailEntry.getNumberAttributes())
            .setFormattedNumber(voicemailEntry.getFormattedNumber())
            .build());
  }

  void collapseViewHolder() {
@@ -293,9 +290,9 @@ final class NewVoicemailViewHolder extends RecyclerView.ViewHolder implements On

    Assert.isNotNull(voicemailViewHolderListener);
    Assert.checkArgument(
        voicemailEntry.id() == viewHolderId, "ensure that the adapter binding has taken place");
        voicemailEntry.getId() == viewHolderId, "ensure that the adapter binding has taken place");
    Assert.checkArgument(
        Uri.parse(voicemailEntry.voicemailUri()).equals(viewHolderVoicemailUri),
        Uri.parse(voicemailEntry.getVoicemailUri()).equals(viewHolderVoicemailUri),
        "ensure that the adapter binding has taken place");
    LogUtil.i(
        "NewVoicemailViewHolder.expandAndBindViewHolderAndMediaPlayerViewWithAdapterValues",
@@ -305,15 +302,15 @@ final class NewVoicemailViewHolder extends RecyclerView.ViewHolder implements On
        isViewHolderExpanded,
        String.valueOf(viewHolderVoicemailUri),
        String.valueOf(mediaPlayerView.getVoicemailUri()),
        voicemailEntry.isRead());
        voicemailEntry.getIsRead());

    if (voicemailEntry.isRead() == 0) {
    if (voicemailEntry.getIsRead() == 0) {
      // update as read.
      primaryTextView.setTypeface(Typeface.DEFAULT, Typeface.NORMAL);
      secondaryTextView.setTypeface(Typeface.DEFAULT, Typeface.NORMAL);
      transcriptionTextView.setTypeface(Typeface.DEFAULT, Typeface.NORMAL);

      Uri uri = Uri.parse(voicemailEntry.voicemailUri());
      Uri uri = Uri.parse(voicemailEntry.getVoicemailUri());

      Worker<Pair<Context, Uri>, Integer> markVoicemailRead = this::markVoicemailAsRead;
      SuccessListener<Integer> markedAsReadVoicemailCallBack = this::onVoicemailMarkedAsRead;
@@ -344,8 +341,8 @@ final class NewVoicemailViewHolder extends RecyclerView.ViewHolder implements On
  }

  private void updateBrandingText(VoicemailEntry voicemailEntry) {
    if (voicemailEntry.transcriptionState() == VoicemailCompat.TRANSCRIPTION_AVAILABLE
        && !TextUtils.isEmpty(voicemailEntry.transcription())) {
    if (voicemailEntry.getTranscriptionState() == VoicemailCompat.TRANSCRIPTION_AVAILABLE
        && !TextUtils.isEmpty(voicemailEntry.getTranscription())) {
      transcriptionBrandingTextView.setVisibility(VISIBLE);
    } else {
      transcriptionBrandingTextView.setVisibility(GONE);
@@ -435,7 +432,7 @@ final class NewVoicemailViewHolder extends RecyclerView.ViewHolder implements On
    return isViewHolderExpanded;
  }

  public int getViewHolderId() {
  public long getViewHolderId() {
    return viewHolderId;
  }

+43 −16
Original line number Diff line number Diff line
@@ -20,6 +20,7 @@ import android.content.Context;
import android.database.Cursor;
import android.provider.CallLog.Calls;
import android.support.v4.content.CursorLoader;
import android.text.TextUtils;
import com.android.dialer.DialerPhoneNumber;
import com.android.dialer.NumberAttributes;
import com.android.dialer.calllog.database.contract.AnnotatedCallLogContract.AnnotatedCallLog;
@@ -99,22 +100,48 @@ final class VoicemailCursorLoader extends CursorLoader {
        "CP2 info incomplete for number: %s",
        LogUtil.sanitizePii(number.getNormalizedNumber()));

    return VoicemailEntry.builder()
    VoicemailEntry.Builder voicemailEntryBuilder =
        VoicemailEntry.newBuilder()
            .setId(cursor.getInt(ID))
            .setTimestamp(cursor.getLong(TIMESTAMP))
            .setNumber(number)
        .setFormattedNumber(cursor.getString(FORMATTED_NUMBER))
            .setDuration(cursor.getLong(DURATION))
        .setTranscription(cursor.getString(TRANSCRIPTION))
        .setVoicemailUri(cursor.getString(VOICEMAIL_URI))
        .setGeocodedLocation(cursor.getString(GEOCODED_LOCATION))
            .setCallType(cursor.getInt(CALL_TYPE))
            .setIsRead(cursor.getInt(IS_READ))
            .setNumberAttributes(numberAttributes)
        .setTranscriptionState(cursor.getInt(TRANSCRIPTION_STATE))
        .setPhoneAccountComponentName(cursor.getString(PHONE_ACCOUNT_COMPONENT_NAME))
        .setPhoneAccountId(cursor.getString(PHONE_ACCOUNT_ID))
        .build();
            .setTranscriptionState(cursor.getInt(TRANSCRIPTION_STATE));

    String formattedNumber = cursor.getString(FORMATTED_NUMBER);
    if (!TextUtils.isEmpty(formattedNumber)) {
      voicemailEntryBuilder.setFormattedNumber(formattedNumber);
    }

    String geocodedLocation = cursor.getString(GEOCODED_LOCATION);
    if (!TextUtils.isEmpty(geocodedLocation)) {
      voicemailEntryBuilder.setGeocodedLocation(geocodedLocation);
    }

    String transcription = cursor.getString(TRANSCRIPTION);
    if (!TextUtils.isEmpty(transcription)) {
      voicemailEntryBuilder.setTranscription(transcription);
    }

    String voicemailUri = cursor.getString(VOICEMAIL_URI);
    if (!TextUtils.isEmpty(voicemailUri)) {
      voicemailEntryBuilder.setVoicemailUri(voicemailUri);
    }

    String phoneAccountComponentName = cursor.getString(PHONE_ACCOUNT_COMPONENT_NAME);
    if (!TextUtils.isEmpty(phoneAccountComponentName)) {
      voicemailEntryBuilder.setPhoneAccountComponentName(phoneAccountComponentName);
    }

    String phoneAccountId = cursor.getString(PHONE_ACCOUNT_ID);
    if (!TextUtils.isEmpty(phoneAccountId)) {
      voicemailEntryBuilder.setPhoneAccountId(phoneAccountId);
    }

    return voicemailEntryBuilder.build();
  }

  static long getTimestamp(Cursor cursor) {
+12 −10
Original line number Diff line number Diff line
@@ -33,10 +33,10 @@ public class VoicemailEntryText {

  public static String buildPrimaryVoicemailText(Context context, VoicemailEntry data) {
    StringBuilder primaryText = new StringBuilder();
    if (!TextUtils.isEmpty(data.numberAttributes().getName())) {
      primaryText.append(data.numberAttributes().getName());
    } else if (!TextUtils.isEmpty(data.formattedNumber())) {
      primaryText.append(data.formattedNumber());
    if (!TextUtils.isEmpty(data.getNumberAttributes().getName())) {
      primaryText.append(data.getNumberAttributes().getName());
    } else if (!TextUtils.isEmpty(data.getFormattedNumber())) {
      primaryText.append(data.getFormattedNumber());
    } else {
      // TODO(uabdullah): Handle CallLog.Calls.PRESENTATION_*, including Verizon restricted numbers.
      primaryText.append(context.getText(R.string.voicemail_entry_unknown));
@@ -71,7 +71,7 @@ public class VoicemailEntryText {
  private static String secondaryTextPrefix(
      Context context, Clock clock, VoicemailEntry voicemailEntry) {
    StringBuilder secondaryText = new StringBuilder();
    String location = voicemailEntry.geocodedLocation();
    String location = voicemailEntry.getGeocodedLocation();
    if (!TextUtils.isEmpty(location)) {
      secondaryText.append(location);
    }
@@ -80,9 +80,9 @@ public class VoicemailEntryText {
    }
    secondaryText.append(
        CallLogDates.newCallLogTimestampLabel(
            context, clock.currentTimeMillis(), voicemailEntry.timestamp()));
            context, clock.currentTimeMillis(), voicemailEntry.getTimestamp()));

    long duration = voicemailEntry.duration();
    long duration = voicemailEntry.getDuration();
    if (duration >= 0) {
      secondaryText.append(" • ");
      String formattedDuration = getVoicemailDuration(context, voicemailEntry);
@@ -92,15 +92,17 @@ public class VoicemailEntryText {
  }

  static String getVoicemailDuration(Context context, VoicemailEntry voicemailEntry) {
    long minutes = TimeUnit.SECONDS.toMinutes(voicemailEntry.duration());
    long seconds = voicemailEntry.duration() - TimeUnit.MINUTES.toSeconds(minutes);
    long minutes = TimeUnit.SECONDS.toMinutes(voicemailEntry.getDuration());
    long seconds = voicemailEntry.getDuration() - 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());
          "VoicemailEntryText.getVoicemailDuration",
          "Duration was %d",
          voicemailEntry.getDuration());
      minutes = 99;
    }
    return context.getString(R.string.voicemailDurationFormat, minutes, seconds);
Loading