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

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

Merge "Updating ContactGridManager to use GlidePhotoManager for more efficient...

Merge "Updating ContactGridManager to use GlidePhotoManager for more efficient contact photo creation. If the photoUri does not exist, GlidePhotoManagerImpl will create the needed LetterTileDrawable to use in the contact photo's place."
parents 1bff1f6f 55cd2634
Loading
Loading
Loading
Loading
+66 −25
Original line number Diff line number Diff line
@@ -35,6 +35,9 @@ import android.widget.TextView;
import android.widget.ViewAnimator;
import com.android.dialer.common.Assert;
import com.android.dialer.common.LogUtil;
import com.android.dialer.configprovider.ConfigProviderBindings;
import com.android.dialer.glidephotomanager.GlidePhotoManagerComponent;
import com.android.dialer.glidephotomanager.PhotoInfo;
import com.android.dialer.lettertile.LetterTileDrawable;
import com.android.dialer.util.DrawableConverter;
import com.android.incallui.incall.protocol.ContactPhotoType;
@@ -215,7 +218,8 @@ public class ContactGridManager {
    }

    boolean hasPhoto =
        primaryInfo.photo() != null && primaryInfo.photoType() == ContactPhotoType.CONTACT;
        (primaryInfo.photo() != null || primaryInfo.photoUri() != null)
            && primaryInfo.photoType() == ContactPhotoType.CONTACT;
    if (!hasPhoto && !showAnonymousAvatar) {
      avatarImageView.setVisibility(View.GONE);
      return false;
@@ -297,15 +301,55 @@ public class ContactGridManager {
      if (hideAvatar) {
        avatarImageView.setVisibility(View.GONE);
      } else if (avatarSize > 0 && updateAvatarVisibility()) {
        if (ConfigProviderBindings.get(context).getBoolean("enable_glide_photo", false)) {
          loadPhotoWithGlide();
        } else {
          loadPhotoWithLegacy();
        }
      }
    }
  }

  private void loadPhotoWithGlide() {
    PhotoInfo.Builder photoInfoBuilder =
        PhotoInfo.newBuilder()
            .setIsBusiness(primaryInfo.photoType() == ContactPhotoType.BUSINESS)
            .setIsVoicemail(primaryCallState.isVoiceMailNumber())
            .setIsSpam(primaryInfo.isSpam());

    // Contact has a name, that is a number.
    if (primaryInfo.nameIsNumber() && primaryInfo.number() != null) {
      photoInfoBuilder.setName(primaryInfo.number());
    } else if (primaryInfo.name() != null) {
      photoInfoBuilder.setName(primaryInfo.name());
    }

    if (primaryInfo.number() != null) {
      photoInfoBuilder.setFormattedNumber(primaryInfo.number());
    }

    if (primaryInfo.photoUri() != null) {
      photoInfoBuilder.setPhotoUri(primaryInfo.photoUri().toString());
    }

    if (primaryInfo.contactInfoLookupKey() != null) {
      photoInfoBuilder.setLookupUri(primaryInfo.contactInfoLookupKey());
    }

    GlidePhotoManagerComponent.get(context)
        .glidePhotoManager()
        .loadContactPhoto(avatarImageView, photoInfoBuilder.build());
  }

  private void loadPhotoWithLegacy() {
    boolean hasPhoto =
        primaryInfo.photo() != null && primaryInfo.photoType() == ContactPhotoType.CONTACT;
        // Contact has a photo, don't render a letter tile.
    if (hasPhoto) {
      avatarImageView.setBackground(
          DrawableConverter.getRoundedDrawable(
              context, primaryInfo.photo(), avatarSize, avatarSize));
          // Contact has a name, that isn't a number.
    } else {
      // Contact has a photo, don't render a letter tile.
      letterTile.setCanonicalDialerLetterTileDetails(
          primaryInfo.name(),
          primaryInfo.contactInfoLookupKey(),
@@ -324,9 +368,6 @@ public class ContactGridManager {
      avatarImageView.setBackground(letterTile);
    }
  }
    }
  }

  /**
   * Updates row 2. For example:
   *
+7 −0
Original line number Diff line number Diff line
@@ -17,6 +17,7 @@
package com.android.incallui.incall.protocol;

import android.graphics.drawable.Drawable;
import android.net.Uri;
import android.support.annotation.Nullable;
import com.android.dialer.common.LogUtil;
import com.android.dialer.multimedia.MultimediaData;
@@ -43,6 +44,9 @@ public abstract class PrimaryInfo {
  @Nullable
  public abstract Drawable photo();

  @Nullable
  public abstract Uri photoUri();

  @ContactPhotoType
  public abstract int photoType();

@@ -73,6 +77,7 @@ public abstract class PrimaryInfo {
  public static Builder builder() {
    return new AutoValue_PrimaryInfo.Builder();
  }

  /** Builder class for primary call info. */
  @AutoValue.Builder
  public abstract static class Builder {
@@ -88,6 +93,8 @@ public abstract class PrimaryInfo {

    public abstract Builder setPhoto(Drawable photo);

    public abstract Builder setPhotoUri(Uri photoUri);

    public abstract Builder setPhotoType(@ContactPhotoType int photoType);

    public abstract Builder setIsSipCall(boolean isSipCall);