2015-03-31 22:44:41 +00:00
|
|
|
package org.thoughtcrime.securesms.mms;
|
|
|
|
|
|
|
|
import android.content.Context;
|
|
|
|
import android.net.Uri;
|
2015-11-27 22:45:07 +00:00
|
|
|
import android.support.annotation.NonNull;
|
2015-03-31 22:44:41 +00:00
|
|
|
|
|
|
|
import com.bumptech.glide.load.data.DataFetcher;
|
|
|
|
import com.bumptech.glide.load.model.GenericLoaderFactory;
|
|
|
|
import com.bumptech.glide.load.model.ModelLoader;
|
|
|
|
import com.bumptech.glide.load.model.ModelLoaderFactory;
|
|
|
|
import com.bumptech.glide.load.model.stream.StreamModelLoader;
|
|
|
|
|
|
|
|
import org.thoughtcrime.securesms.crypto.MasterSecret;
|
|
|
|
import org.thoughtcrime.securesms.mms.DecryptableStreamUriLoader.DecryptableUri;
|
|
|
|
|
|
|
|
import java.io.InputStream;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* A {@link ModelLoader} for translating uri models into {@link InputStream} data. Capable of handling 'http',
|
|
|
|
* 'https', 'android.resource', 'content', and 'file' schemes. Unsupported schemes will throw an exception in
|
|
|
|
* {@link #getResourceFetcher(Uri, int, int)}.
|
|
|
|
*/
|
|
|
|
public class DecryptableStreamUriLoader implements StreamModelLoader<DecryptableUri> {
|
|
|
|
private final Context context;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* THe default factory for {@link com.bumptech.glide.load.model.stream.StreamUriLoader}s.
|
|
|
|
*/
|
|
|
|
public static class Factory implements ModelLoaderFactory<DecryptableUri, InputStream> {
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public StreamModelLoader<DecryptableUri> build(Context context, GenericLoaderFactory factories) {
|
|
|
|
return new DecryptableStreamUriLoader(context);
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void teardown() {
|
|
|
|
// Do nothing.
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public DecryptableStreamUriLoader(Context context) {
|
|
|
|
this.context = context;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public DataFetcher<InputStream> getResourceFetcher(DecryptableUri model, int width, int height) {
|
|
|
|
return new DecryptableStreamLocalUriFetcher(context, model.masterSecret, model.uri);
|
|
|
|
}
|
|
|
|
|
|
|
|
public static class DecryptableUri {
|
2015-11-27 22:45:07 +00:00
|
|
|
public @NonNull MasterSecret masterSecret;
|
|
|
|
public @NonNull Uri uri;
|
2015-03-31 22:44:41 +00:00
|
|
|
|
2015-11-27 22:45:07 +00:00
|
|
|
public DecryptableUri(@NonNull MasterSecret masterSecret, @NonNull Uri uri) {
|
2015-03-31 22:44:41 +00:00
|
|
|
this.masterSecret = masterSecret;
|
|
|
|
this.uri = uri;
|
|
|
|
}
|
2015-11-27 22:45:07 +00:00
|
|
|
|
|
|
|
@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();
|
|
|
|
}
|
2015-03-31 22:44:41 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|