Skip to content

Commit

Permalink
add equals/hashCode to glide models
Browse files Browse the repository at this point in the history
// FREEBIE
  • Loading branch information
mcginty committed Nov 27, 2015
1 parent e83827a commit c3ce4c4
Show file tree
Hide file tree
Showing 4 changed files with 44 additions and 9 deletions.
5 changes: 3 additions & 2 deletions src/org/thoughtcrime/securesms/components/ThumbnailView.java
Original file line number Diff line number Diff line change
Expand Up @@ -160,9 +160,10 @@ private boolean isContextValid() {
}

private GenericRequestBuilder buildThumbnailGlideRequest(@NonNull Slide slide, @NonNull MasterSecret masterSecret) {
@SuppressWarnings("ConstantConditions")
DrawableRequestBuilder<DecryptableUri> builder = Glide.with(getContext()).load(new DecryptableUri(masterSecret, slide.getThumbnailUri()))
.crossFade()
.transform(new RoundedCorners(getContext(), true, radius, backgroundColorHint));
.crossFade()
.transform(new RoundedCorners(getContext(), true, radius, backgroundColorHint));

if (slide.isInProgress()) return builder;
else return builder.error(R.drawable.ic_missing_thumbnail_picture);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ public AttachmentDatabase(Context context, SQLiteOpenHelper databaseHelper) {
try {
InputStream generatedStream = thumbnailExecutor.submit(new ThumbnailFetchCallable(masterSecret, attachmentId)).get();

if (generatedStream == null) throw new IOException("No thumbnail stream available: " + attachmentId);
if (generatedStream == null) throw new FileNotFoundException("No thumbnail stream available: " + attachmentId);
else return generatedStream;
} catch (InterruptedException ie) {
throw new AssertionError("interrupted");
Expand Down
23 changes: 20 additions & 3 deletions src/org/thoughtcrime/securesms/mms/AttachmentStreamUriLoader.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import android.content.Context;
import android.net.Uri;
import android.support.annotation.NonNull;

import com.bumptech.glide.load.data.DataFetcher;
import com.bumptech.glide.load.model.GenericLoaderFactory;
Expand Down Expand Up @@ -51,13 +52,29 @@ public DataFetcher<InputStream> getResourceFetcher(AttachmentModel model, int wi
}

public static class AttachmentModel {
public File attachment;
public byte[] key;
public @NonNull File attachment;
public @NonNull byte[] key;

public AttachmentModel(File attachment, byte[] key) {
public AttachmentModel(@NonNull File attachment, @NonNull byte[] key) {
this.attachment = attachment;
this.key = key;
}

@Override
public boolean equals(Object o) {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;

AttachmentModel that = (AttachmentModel)o;

return attachment.equals(that.attachment);

}

@Override
public int hashCode() {
return attachment.hashCode();
}
}
}

23 changes: 20 additions & 3 deletions src/org/thoughtcrime/securesms/mms/DecryptableStreamUriLoader.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import android.content.Context;
import android.net.Uri;
import android.support.annotation.NonNull;

import com.bumptech.glide.load.data.DataFetcher;
import com.bumptech.glide.load.model.GenericLoaderFactory;
Expand Down Expand Up @@ -48,13 +49,29 @@ public DataFetcher<InputStream> getResourceFetcher(DecryptableUri model, int wid
}

public static class DecryptableUri {
public MasterSecret masterSecret;
public Uri uri;
public @NonNull MasterSecret masterSecret;
public @NonNull Uri uri;

public DecryptableUri(MasterSecret masterSecret, Uri uri) {
public DecryptableUri(@NonNull MasterSecret masterSecret, @NonNull Uri uri) {
this.masterSecret = masterSecret;
this.uri = uri;
}

@Override
public boolean equals(Object o) {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;

DecryptableUri that = (DecryptableUri)o;

return uri.equals(that.uri);

}

@Override
public int hashCode() {
return uri.hashCode();
}
}
}

0 comments on commit c3ce4c4

Please sign in to comment.