diff --git a/res/drawable-hdpi/ic_amazon.png b/res/drawable-hdpi/ic_amazon.png new file mode 100644 index 0000000000..504f2b1f47 Binary files /dev/null and b/res/drawable-hdpi/ic_amazon.png differ diff --git a/res/drawable-mdpi/ic_amazon.png b/res/drawable-mdpi/ic_amazon.png new file mode 100644 index 0000000000..d1e94ffbc5 Binary files /dev/null and b/res/drawable-mdpi/ic_amazon.png differ diff --git a/res/drawable-xhdpi/ic_amazon.png b/res/drawable-xhdpi/ic_amazon.png new file mode 100644 index 0000000000..e087841db0 Binary files /dev/null and b/res/drawable-xhdpi/ic_amazon.png differ diff --git a/res/drawable-xxhdpi/ic_amazon.png b/res/drawable-xxhdpi/ic_amazon.png new file mode 100644 index 0000000000..050c99ec38 Binary files /dev/null and b/res/drawable-xxhdpi/ic_amazon.png differ diff --git a/res/drawable-xxxhdpi/ic_amazon.png b/res/drawable-xxxhdpi/ic_amazon.png new file mode 100644 index 0000000000..1146472498 Binary files /dev/null and b/res/drawable-xxxhdpi/ic_amazon.png differ diff --git a/src/org/thoughtcrime/securesms/contacts/avatars/ContactPhotoFactory.java b/src/org/thoughtcrime/securesms/contacts/avatars/ContactPhotoFactory.java index 79816268e2..6cebe77f28 100644 --- a/src/org/thoughtcrime/securesms/contacts/avatars/ContactPhotoFactory.java +++ b/src/org/thoughtcrime/securesms/contacts/avatars/ContactPhotoFactory.java @@ -6,6 +6,8 @@ import android.net.Uri; import android.os.Build.VERSION; import android.os.Build.VERSION_CODES; import android.provider.ContactsContract; +import android.support.annotation.DrawableRes; +import android.support.annotation.NonNull; import android.support.annotation.Nullable; import android.text.TextUtils; import android.util.Log; @@ -17,8 +19,9 @@ import org.thoughtcrime.securesms.util.BitmapUtil; import java.io.InputStream; public class ContactPhotoFactory { - private static final String TAG = ContactPhotoFactory.class.getSimpleName(); + private static final String TAG = ContactPhotoFactory.class.getSimpleName(); + public static ContactPhoto getLoadingPhoto() { return new TransparentContactPhoto(); } @@ -28,6 +31,10 @@ public class ContactPhotoFactory { else return new GeneratedContactPhoto("#"); } + public static ContactPhoto getResourceContactPhoto(@DrawableRes int resourceId) { + return new ResourceContactPhoto(resourceId); + } + public static ContactPhoto getDefaultGroupPhoto() { return new ResourceContactPhoto(R.drawable.ic_group_white_24dp); } diff --git a/src/org/thoughtcrime/securesms/contacts/avatars/ResourceContactPhoto.java b/src/org/thoughtcrime/securesms/contacts/avatars/ResourceContactPhoto.java index a261004e2f..cd1c3763c0 100644 --- a/src/org/thoughtcrime/securesms/contacts/avatars/ResourceContactPhoto.java +++ b/src/org/thoughtcrime/securesms/contacts/avatars/ResourceContactPhoto.java @@ -6,6 +6,7 @@ import android.graphics.ColorFilter; import android.graphics.PorterDuff; import android.graphics.drawable.Drawable; import android.graphics.drawable.LayerDrawable; +import android.support.annotation.DrawableRes; import android.support.v4.graphics.ColorUtils; import android.widget.ImageView; @@ -16,7 +17,7 @@ public class ResourceContactPhoto implements ContactPhoto { private final int resourceId; - ResourceContactPhoto(int resourceId) { + ResourceContactPhoto(@DrawableRes int resourceId) { this.resourceId = resourceId; } diff --git a/src/org/thoughtcrime/securesms/database/CanonicalAddressDatabase.java b/src/org/thoughtcrime/securesms/database/CanonicalAddressDatabase.java index 4fa4a783d1..b440748ef9 100644 --- a/src/org/thoughtcrime/securesms/database/CanonicalAddressDatabase.java +++ b/src/org/thoughtcrime/securesms/database/CanonicalAddressDatabase.java @@ -22,6 +22,7 @@ import android.database.Cursor; import android.database.sqlite.SQLiteDatabase; import android.database.sqlite.SQLiteDatabase.CursorFactory; import android.database.sqlite.SQLiteOpenHelper; +import android.support.annotation.NonNull; import android.telephony.PhoneNumberUtils; import android.text.TextUtils; import android.util.Log; @@ -97,7 +98,7 @@ public class CanonicalAddressDatabase { } } - public String getAddressFromId(long id) { + public @NonNull String getAddressFromId(long id) { String cachedAddress = idCache.get(id); if (cachedAddress != null) diff --git a/src/org/thoughtcrime/securesms/recipients/RecipientProvider.java b/src/org/thoughtcrime/securesms/recipients/RecipientProvider.java index 83374da6a0..c50a011080 100644 --- a/src/org/thoughtcrime/securesms/recipients/RecipientProvider.java +++ b/src/org/thoughtcrime/securesms/recipients/RecipientProvider.java @@ -25,7 +25,9 @@ import android.support.annotation.NonNull; import android.support.annotation.Nullable; import android.util.Log; +import org.thoughtcrime.securesms.R; import org.thoughtcrime.securesms.color.MaterialColor; +import org.thoughtcrime.securesms.contacts.avatars.ContactColors; import org.thoughtcrime.securesms.contacts.avatars.ContactPhoto; import org.thoughtcrime.securesms.contacts.avatars.ContactPhotoFactory; import org.thoughtcrime.securesms.database.CanonicalAddressDatabase; @@ -40,7 +42,7 @@ import org.whispersystems.libaxolotl.util.guava.Optional; import java.io.IOException; import java.util.Arrays; -import java.util.Collections; +import java.util.HashMap; import java.util.LinkedList; import java.util.List; import java.util.Map; @@ -62,6 +64,12 @@ public class RecipientProvider { PhoneLookup.NUMBER }; + private static final Map STATIC_DETAILS = new HashMap() {{ + put("262966", new RecipientDetails("Amazon", "262966", null, + ContactPhotoFactory.getResourceContactPhoto(R.drawable.ic_amazon), + ContactColors.UNKNOWN_COLOR)); + }}; + Recipient getRecipient(Context context, long recipientId, boolean asynchronous) { Recipient cachedRecipient = recipientCache.get(recipientId); if (cachedRecipient != null && !cachedRecipient.isStale()) return cachedRecipient; @@ -102,7 +110,7 @@ public class RecipientProvider { private @NonNull ListenableFutureTask getRecipientDetailsAsync(final Context context, final long recipientId, - final String number) + final @NonNull String number) { Callable task = new Callable() { @Override @@ -116,12 +124,12 @@ public class RecipientProvider { return future; } - private @NonNull RecipientDetails getRecipientDetailsSync(Context context, long recipientId, String number) { + private @NonNull RecipientDetails getRecipientDetailsSync(Context context, long recipientId, @NonNull String number) { if (GroupUtil.isEncodedGroup(number)) return getGroupRecipientDetails(context, number); else return getIndividualRecipientDetails(context, recipientId, number); } - private @NonNull RecipientDetails getIndividualRecipientDetails(Context context, long recipientId, String number) { + private @NonNull RecipientDetails getIndividualRecipientDetails(Context context, long recipientId, @NonNull String number) { Optional preferences = DatabaseFactory.getRecipientPreferenceDatabase(context).getRecipientsPreferences(new long[]{recipientId}); MaterialColor color = preferences.isPresent() ? preferences.get().getColor() : null; Uri uri = Uri.withAppendedPath(PhoneLookup.CONTENT_FILTER_URI, Uri.encode(number)); @@ -143,7 +151,8 @@ public class RecipientProvider { cursor.close(); } - return new RecipientDetails(null, number, null, ContactPhotoFactory.getDefaultContactPhoto(null), color); + if (STATIC_DETAILS.containsKey(number)) return STATIC_DETAILS.get(number); + else return new RecipientDetails(null, number, null, ContactPhotoFactory.getDefaultContactPhoto(null), color); } private @NonNull RecipientDetails getGroupRecipientDetails(Context context, String groupId) {