NewPipe-app-android/app/src/main/java/org/schabi/newpipe/ImageDownloader.java

47 lines
1.5 KiB
Java
Raw Normal View History

2018-02-22 13:25:56 +01:00
package org.schabi.newpipe;
import android.annotation.SuppressLint;
2018-02-22 13:25:56 +01:00
import android.content.Context;
import android.content.SharedPreferences;
import android.content.res.Resources;
import android.preference.PreferenceManager;
2018-02-22 13:25:56 +01:00
import com.nostra13.universalimageloader.core.download.BaseImageDownloader;
import org.schabi.newpipe.extractor.NewPipe;
import java.io.IOException;
import java.io.InputStream;
public class ImageDownloader extends BaseImageDownloader {
private final Resources resources;
private final SharedPreferences preferences;
private final String downloadThumbnailKey;
2018-02-22 13:25:56 +01:00
public ImageDownloader(Context context) {
super(context);
this.resources = context.getResources();
this.preferences = PreferenceManager.getDefaultSharedPreferences(context);
this.downloadThumbnailKey = context.getString(R.string.download_thumbnail_key);
2018-02-22 13:25:56 +01:00
}
private boolean isDownloadingThumbnail() {
return preferences.getBoolean(downloadThumbnailKey, true);
2018-02-22 13:25:56 +01:00
}
@SuppressLint("ResourceType")
@Override
public InputStream getStream(String imageUri, Object extra) throws IOException {
if (isDownloadingThumbnail()) {
return super.getStream(imageUri, extra);
} else {
return resources.openRawResource(R.drawable.dummy_thumbnail_dark);
}
2018-02-22 13:25:56 +01:00
}
protected InputStream getStreamFromNetwork(String imageUri, Object extra) throws IOException {
final Downloader downloader = (Downloader) NewPipe.getDownloader();
return downloader.stream(imageUri);
}
2018-02-22 13:25:56 +01:00
}