mirror of
https://github.com/oxen-io/session-android.git
synced 2025-10-25 12:48:33 +00:00
Update to glide 4.x
// FREEBIE
This commit is contained in:
@@ -5,32 +5,34 @@ import android.content.Context;
|
||||
import android.support.annotation.NonNull;
|
||||
|
||||
import com.bumptech.glide.Priority;
|
||||
import com.bumptech.glide.load.DataSource;
|
||||
import com.bumptech.glide.load.data.DataFetcher;
|
||||
|
||||
import org.thoughtcrime.securesms.database.Address;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.FileInputStream;
|
||||
import java.io.FileNotFoundException;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
|
||||
public class AvatarPhotoUriFetcher implements DataFetcher<InputStream> {
|
||||
class AvatarPhotoUriFetcher implements DataFetcher<InputStream> {
|
||||
|
||||
private final Context context;
|
||||
private final Address address;
|
||||
|
||||
private InputStream inputStream;
|
||||
|
||||
public AvatarPhotoUriFetcher(@NonNull Context context, @NonNull Address address) {
|
||||
AvatarPhotoUriFetcher(@NonNull Context context, @NonNull Address address) {
|
||||
this.context = context.getApplicationContext();
|
||||
this.address = address;
|
||||
}
|
||||
|
||||
@Override
|
||||
public InputStream loadData(Priority priority) throws IOException {
|
||||
inputStream = AvatarHelper.getInputStreamFor(context, address);
|
||||
return inputStream;
|
||||
public void loadData(Priority priority, DataCallback<? super InputStream> callback) {
|
||||
try {
|
||||
inputStream = AvatarHelper.getInputStreamFor(context, address);
|
||||
callback.onDataReady(inputStream);
|
||||
} catch (IOException e) {
|
||||
callback.onLoadFailed(e);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -40,13 +42,20 @@ public class AvatarPhotoUriFetcher implements DataFetcher<InputStream> {
|
||||
} catch (IOException e) {}
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getId() {
|
||||
return address.serialize();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void cancel() {
|
||||
|
||||
}
|
||||
|
||||
@NonNull
|
||||
@Override
|
||||
public Class<InputStream> getDataClass() {
|
||||
return InputStream.class;
|
||||
}
|
||||
|
||||
@NonNull
|
||||
@Override
|
||||
public DataSource getDataSource() {
|
||||
return DataSource.LOCAL;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -3,24 +3,48 @@ package org.thoughtcrime.securesms.profiles;
|
||||
|
||||
import android.content.Context;
|
||||
import android.support.annotation.NonNull;
|
||||
import android.support.annotation.Nullable;
|
||||
|
||||
import com.bumptech.glide.load.data.DataFetcher;
|
||||
import com.bumptech.glide.load.model.GenericLoaderFactory;
|
||||
import com.bumptech.glide.load.Key;
|
||||
import com.bumptech.glide.load.Options;
|
||||
import com.bumptech.glide.load.model.ModelLoader;
|
||||
import com.bumptech.glide.load.model.ModelLoaderFactory;
|
||||
import com.bumptech.glide.load.model.stream.StreamModelLoader;
|
||||
import com.bumptech.glide.load.model.MultiModelLoaderFactory;
|
||||
|
||||
import org.thoughtcrime.securesms.database.Address;
|
||||
|
||||
import java.io.InputStream;
|
||||
import java.security.MessageDigest;
|
||||
|
||||
public class AvatarPhotoUriLoader implements StreamModelLoader<AvatarPhotoUriLoader.AvatarPhotoUri> {
|
||||
public class AvatarPhotoUriLoader implements ModelLoader<AvatarPhotoUriLoader.AvatarPhotoUri, InputStream> {
|
||||
|
||||
private final Context context;
|
||||
|
||||
private AvatarPhotoUriLoader(Context context) {
|
||||
this.context = context;
|
||||
}
|
||||
|
||||
@Nullable
|
||||
@Override
|
||||
public LoadData<InputStream> buildLoadData(AvatarPhotoUri avatarPhotoUri, int width, int height, Options options) {
|
||||
return new LoadData<>(avatarPhotoUri, new AvatarPhotoUriFetcher(context, avatarPhotoUri.address));
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean handles(AvatarPhotoUri avatarPhotoUri) {
|
||||
return true;
|
||||
}
|
||||
|
||||
public static class Factory implements ModelLoaderFactory<AvatarPhotoUri, InputStream> {
|
||||
|
||||
private final Context context;
|
||||
|
||||
public Factory(Context context) {
|
||||
this.context = context.getApplicationContext();
|
||||
}
|
||||
|
||||
@Override
|
||||
public StreamModelLoader<AvatarPhotoUri> build(Context context, GenericLoaderFactory factories) {
|
||||
public ModelLoader<AvatarPhotoUri, InputStream> build(MultiModelLoaderFactory multiFactory) {
|
||||
return new AvatarPhotoUriLoader(context);
|
||||
}
|
||||
|
||||
@@ -28,21 +52,29 @@ public class AvatarPhotoUriLoader implements StreamModelLoader<AvatarPhotoUriLoa
|
||||
public void teardown() {}
|
||||
}
|
||||
|
||||
public AvatarPhotoUriLoader(Context context) {
|
||||
this.context = context;
|
||||
}
|
||||
|
||||
@Override
|
||||
public DataFetcher<InputStream> getResourceFetcher(AvatarPhotoUri model, int width, int height) {
|
||||
return new AvatarPhotoUriFetcher(context, model.address);
|
||||
}
|
||||
|
||||
public static class AvatarPhotoUri {
|
||||
public static class AvatarPhotoUri implements Key {
|
||||
public @NonNull Address address;
|
||||
|
||||
public AvatarPhotoUri(@NonNull Address address) {
|
||||
this.address = address;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void updateDiskCacheKey(MessageDigest messageDigest) {
|
||||
messageDigest.update(address.serialize().getBytes());
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object other) {
|
||||
if (other == null || !(other instanceof AvatarPhotoUri)) return false;
|
||||
|
||||
return this.address.equals(((AvatarPhotoUri)other).address);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return address.hashCode();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user