Fixing race condition and other mistakes. Fixes #1603.

// FREEBIE
This commit is contained in:
Lukas Barth 2014-06-21 15:31:45 +02:00 committed by Moxie Marlinspike
parent db1d846833
commit 2d9cd8eb52
2 changed files with 23 additions and 12 deletions

View File

@ -78,6 +78,7 @@ public class Recipient implements Parcelable, CanonicalRecipient {
Recipient.this.contactUri = result.contactUri; Recipient.this.contactUri = result.contactUri;
Recipient.this.contactPhoto = result.avatar; Recipient.this.contactPhoto = result.avatar;
Recipient.this.circleCroppedContactPhoto = result.croppedAvatar; Recipient.this.circleCroppedContactPhoto = result.croppedAvatar;
localListeners = (HashSet<RecipientModifiedListener>) listeners.clone(); localListeners = (HashSet<RecipientModifiedListener>) listeners.clone();
listeners.clear(); listeners.clear();
} }
@ -94,12 +95,15 @@ public class Recipient implements Parcelable, CanonicalRecipient {
}); });
} }
Recipient(String name, String number, long recipientId, Uri contactUri, Bitmap contactPhoto) { Recipient(String name, String number, long recipientId, Uri contactUri, Bitmap contactPhoto,
this.number = number; Bitmap circleCroppedContactPhoto)
this.recipientId = recipientId; {
this.contactUri = contactUri; this.number = number;
this.name = name; this.recipientId = recipientId;
this.contactPhoto = contactPhoto; this.contactUri = contactUri;
this.name = name;
this.contactPhoto = contactPhoto;
this.circleCroppedContactPhoto = circleCroppedContactPhoto;
} }
public Recipient(Parcel in) { public Recipient(Parcel in) {
@ -185,7 +189,9 @@ public class Recipient implements Parcelable, CanonicalRecipient {
} }
public static Recipient getUnknownRecipient(Context context) { public static Recipient getUnknownRecipient(Context context) {
return new Recipient("Unknown", "Unknown", -1, null, ContactPhotoFactory.getDefaultContactPhoto(context)); return new Recipient("Unknown", "Unknown", -1, null,
ContactPhotoFactory.getDefaultContactPhoto(context),
ContactPhotoFactory.getDefaultContactPhotoCropped(context));
} }
@Override @Override

View File

@ -72,12 +72,17 @@ public class RecipientProvider {
else details = getRecipientDetails(context, number); else details = getRecipientDetails(context, number);
if (details != null) { if (details != null) {
recipient = new Recipient(details.name, number, recipientId, details.contactUri, details.avatar); recipient = new Recipient(details.name, number, recipientId, details.contactUri, details.avatar,
details.croppedAvatar);
} else { } else {
final Bitmap defaultPhoto = isGroupRecipient final Bitmap defaultPhoto = isGroupRecipient
? ContactPhotoFactory.getDefaultGroupPhoto(context) ? ContactPhotoFactory.getDefaultGroupPhoto(context)
: ContactPhotoFactory.getDefaultContactPhoto(context); : ContactPhotoFactory.getDefaultContactPhoto(context);
recipient = new Recipient(null, number, recipientId, null, defaultPhoto); final Bitmap defaultCroppedPhoto = isGroupRecipient
? ContactPhotoFactory.getDefaultGroupPhotoCropped(context)
: ContactPhotoFactory.getDefaultContactPhotoCropped(context);
recipient = new Recipient(null, number, recipientId, null, defaultPhoto, defaultCroppedPhoto);
} }
recipientCache.put(recipientId, recipient); recipientCache.put(recipientId, recipient);