simplify glide requests
This commit is contained in:
parent
59fa7728a1
commit
b6e633762d
5 changed files with 0 additions and 124 deletions
|
|
@ -78,9 +78,6 @@
|
|||
<meta-data
|
||||
android:name="com.lge.support.SPLIT_WINDOW"
|
||||
android:value="true" />
|
||||
<meta-data
|
||||
android:name="com.kabouzeid.gramophone.glide.CustomGlideModule"
|
||||
android:value="GlideModule" />
|
||||
<meta-data
|
||||
android:name="com.bumptech.glide.integration.okhttp3.OkHttpGlideModule"
|
||||
android:value="GlideModule" />
|
||||
|
|
|
|||
|
|
@ -1,22 +0,0 @@
|
|||
package com.kabouzeid.gramophone.glide;
|
||||
|
||||
import android.content.Context;
|
||||
|
||||
import java.io.InputStream;
|
||||
|
||||
import com.bumptech.glide.Glide;
|
||||
import com.bumptech.glide.GlideBuilder;
|
||||
import com.bumptech.glide.module.GlideModule;
|
||||
import com.kabouzeid.gramophone.glide.audiocover.AudioFileCover;
|
||||
import com.kabouzeid.gramophone.glide.audiocover.AudioFileCoverLoader;
|
||||
|
||||
public class CustomGlideModule implements GlideModule {
|
||||
@Override
|
||||
public void applyOptions(Context context, GlideBuilder builder) {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void registerComponents(Context context, Glide glide) {
|
||||
glide.register(AudioFileCover.class, InputStream.class, new AudioFileCoverLoader.Factory());
|
||||
}
|
||||
}
|
||||
|
|
@ -1,18 +0,0 @@
|
|||
package com.kabouzeid.gramophone.glide.audiocover;
|
||||
|
||||
import com.kabouzeid.gramophone.App;
|
||||
|
||||
import org.jellyfin.apiclient.model.dto.ImageOptions;
|
||||
import org.jellyfin.apiclient.model.entities.ImageType;
|
||||
|
||||
public class AudioFileCover {
|
||||
public String location;
|
||||
|
||||
public AudioFileCover(String item) {
|
||||
ImageOptions options = new ImageOptions();
|
||||
options.setImageType(ImageType.Primary);
|
||||
options.setMaxHeight(800);
|
||||
|
||||
this.location = App.getApiClient().GetImageUrl(item, options);
|
||||
}
|
||||
}
|
||||
|
|
@ -1,51 +0,0 @@
|
|||
package com.kabouzeid.gramophone.glide.audiocover;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
|
||||
import com.bumptech.glide.Priority;
|
||||
import com.bumptech.glide.load.data.DataFetcher;
|
||||
import com.bumptech.glide.load.data.HttpUrlFetcher;
|
||||
import com.bumptech.glide.load.model.GlideUrl;
|
||||
|
||||
public class AudioFileCoverFetcher implements DataFetcher<InputStream> {
|
||||
private final AudioFileCover model;
|
||||
|
||||
private InputStream stream;
|
||||
|
||||
public AudioFileCoverFetcher(AudioFileCover model) {
|
||||
this.model = model;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getId() {
|
||||
// make sure we never return null here
|
||||
return String.valueOf(model.location);
|
||||
}
|
||||
|
||||
@Override
|
||||
public InputStream loadData(final Priority priority) throws Exception {
|
||||
final GlideUrl url = new GlideUrl(String.valueOf(model.location));
|
||||
final HttpUrlFetcher retriever = new HttpUrlFetcher(url);
|
||||
|
||||
stream = retriever.loadData(Priority.NORMAL);
|
||||
return stream;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void cleanup() {
|
||||
// already cleaned up in loadData
|
||||
if (stream != null) {
|
||||
try {
|
||||
stream.close();
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void cancel() {
|
||||
// cannot cancel
|
||||
}
|
||||
}
|
||||
|
|
@ -1,30 +0,0 @@
|
|||
package com.kabouzeid.gramophone.glide.audiocover;
|
||||
|
||||
import android.content.Context;
|
||||
|
||||
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 java.io.InputStream;
|
||||
|
||||
public class AudioFileCoverLoader implements StreamModelLoader<AudioFileCover> {
|
||||
|
||||
@Override
|
||||
public DataFetcher<InputStream> getResourceFetcher(AudioFileCover model, int width, int height) {
|
||||
return new AudioFileCoverFetcher(model);
|
||||
}
|
||||
|
||||
public static class Factory implements ModelLoaderFactory<AudioFileCover, InputStream> {
|
||||
@Override
|
||||
public ModelLoader<AudioFileCover, InputStream> build(Context context, GenericLoaderFactory factories) {
|
||||
return new AudioFileCoverLoader();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void teardown() {
|
||||
}
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue