Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add equals/hashCode to glide models #4737

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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();
}
}
}