Fix for media thumbnails flickering on model updates.

Only update ImageView contents when they have changed.

Fixes #1004
Fixes #2663
Closes #3184

// FREEBIE
This commit is contained in:
Moxie Marlinspike
2015-05-18 08:38:48 -07:00
parent 636b11abea
commit 082985276f
8 changed files with 74 additions and 56 deletions

View File

@@ -42,12 +42,12 @@ public class AudioSlide extends Slide {
}
@Override
public boolean hasImage() {
public boolean hasImage() {
return true;
}
@Override
public boolean hasAudio() {
public boolean hasAudio() {
return true;
}

View File

@@ -20,6 +20,7 @@ import android.content.Context;
import android.content.res.Resources.Theme;
import android.net.Uri;
import android.support.annotation.DrawableRes;
import android.support.annotation.NonNull;
import android.util.Log;
import org.thoughtcrime.securesms.crypto.MasterSecret;
@@ -36,28 +37,16 @@ public abstract class Slide {
protected final Context context;
protected MasterSecret masterSecret;
public Slide(Context context, PduPart part) {
public Slide(Context context, @NonNull PduPart part) {
this.part = part;
this.context = context;
}
public Slide(Context context, MasterSecret masterSecret, PduPart part) {
public Slide(Context context, @NonNull MasterSecret masterSecret, @NonNull PduPart part) {
this(context, part);
this.masterSecret = masterSecret;
}
protected byte[] getPartData() {
try {
if (part.getData() != null)
return part.getData();
return Util.readFully(PartAuthority.getPartStream(context, masterSecret, part.getDataUri()));
} catch (IOException e) {
Log.w("Slide", e);
return new byte[0];
}
}
public String getContentType() {
return new String(part.getContentType());
}
@@ -107,4 +96,28 @@ public abstract class Slide {
if (size > MmsMediaConstraints.MAX_MESSAGE_SIZE) throw new MediaTooLargeException("Media exceeds maximum message size.");
}
}
@Override
public boolean equals(Object other) {
if (!(other instanceof Slide)) return false;
Slide that = (Slide)other;
return Util.equals(this.getContentType(), that.getContentType()) &&
this.hasAudio() == that.hasAudio() &&
this.hasImage() == that.hasImage() &&
this.hasVideo() == that.hasVideo() &&
this.isDraft() == that.isDraft() &&
Util.equals(this.getUri(), that.getUri()) &&
Util.equals(this.getThumbnailUri(), that.getThumbnailUri());
}
@Override
public int hashCode() {
return Util.hashCode(getContentType(), hasAudio(), hasImage(),
hasVideo(), isDraft(), getUri(), getThumbnailUri());
}
}

View File

@@ -17,16 +17,9 @@
package org.thoughtcrime.securesms.mms;
import android.content.Context;
import android.net.Uri;
import android.util.Log;
import org.thoughtcrime.securesms.crypto.MasterSecret;
import org.thoughtcrime.securesms.util.LRUCache;
import java.io.UnsupportedEncodingException;
import java.lang.ref.SoftReference;
import java.util.Collections;
import java.util.Map;
import ws.com.google.android.mms.ContentType;
import ws.com.google.android.mms.pdu.CharacterSets;
@@ -34,14 +27,6 @@ import ws.com.google.android.mms.pdu.PduPart;
public class TextSlide extends Slide {
private static final int MAX_CACHE_SIZE = 10;
private static final Map<Uri, SoftReference<String>> textCache =
Collections.synchronizedMap(new LRUCache<Uri, SoftReference<String>>(MAX_CACHE_SIZE));
public TextSlide(Context context, MasterSecret masterSecret, PduPart part) {
super(context, masterSecret, part);
}
public TextSlide(Context context, String message) {
super(context, getPartForMessage(message));
}