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

41 lines
1.3 KiB
Java
Raw Normal View History

2018-02-22 13:25:56 +01:00
package org.schabi.newpipe;
import android.content.Context;
import android.content.SharedPreferences;
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.ByteArrayInputStream;
2018-02-22 13:25:56 +01:00
import java.io.IOException;
import java.io.InputStream;
public class ImageDownloader extends BaseImageDownloader {
private static final ByteArrayInputStream DUMMY_INPUT_STREAM =
new ByteArrayInputStream(new byte[]{});
private final SharedPreferences preferences;
private final String downloadThumbnailKey;
2018-02-22 13:25:56 +01:00
public ImageDownloader(Context context) {
super(context);
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
}
protected InputStream getStreamFromNetwork(String imageUri, Object extra) throws IOException {
if (isDownloadingThumbnail()) {
final Downloader downloader = (Downloader) NewPipe.getDownloader();
return downloader.stream(imageUri);
} else {
return DUMMY_INPUT_STREAM;
}
2018-02-22 13:25:56 +01:00
}
}