That fuck shit the fascists are using
at master 63 lines 1.5 kB view raw
1package org.tm.archive.glide; 2 3 4import android.content.Context; 5 6import androidx.annotation.NonNull; 7 8import com.bumptech.glide.Priority; 9import com.bumptech.glide.load.DataSource; 10import com.bumptech.glide.load.data.DataFetcher; 11 12import org.tm.archive.contacts.avatars.ContactPhoto; 13 14import java.io.FileNotFoundException; 15import java.io.IOException; 16import java.io.InputStream; 17 18class ContactPhotoFetcher implements DataFetcher<InputStream> { 19 20 private final Context context; 21 private final ContactPhoto contactPhoto; 22 23 private InputStream inputStream; 24 25 ContactPhotoFetcher(@NonNull Context context, @NonNull ContactPhoto contactPhoto) { 26 this.context = context.getApplicationContext(); 27 this.contactPhoto = contactPhoto; 28 } 29 30 @Override 31 public void loadData(@NonNull Priority priority, @NonNull DataCallback<? super InputStream> callback) { 32 try { 33 inputStream = contactPhoto.openInputStream(context); 34 callback.onDataReady(inputStream); 35 } catch (FileNotFoundException e) { 36 callback.onDataReady(null); 37 } catch (IOException e) { 38 callback.onLoadFailed(e); 39 } 40 } 41 42 @Override 43 public void cleanup() { 44 try { 45 if (inputStream != null) inputStream.close(); 46 } catch (IOException e) {} 47 } 48 49 @Override 50 public void cancel() { 51 52 } 53 54 @Override 55 public @NonNull Class<InputStream> getDataClass() { 56 return InputStream.class; 57 } 58 59 @Override 60 public @NonNull DataSource getDataSource() { 61 return DataSource.LOCAL; 62 } 63}