2018-02-22 13:25:56 +01:00
|
|
|
package org.schabi.newpipe;
|
|
|
|
|
|
|
|
import android.content.Context;
|
2018-03-14 04:25:22 +01:00
|
|
|
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;
|
|
|
|
|
2018-03-14 04:25:22 +01:00
|
|
|
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 {
|
2018-03-14 04:25:22 +01:00
|
|
|
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);
|
2018-03-14 04:25:22 +01:00
|
|
|
this.preferences = PreferenceManager.getDefaultSharedPreferences(context);
|
|
|
|
this.downloadThumbnailKey = context.getString(R.string.download_thumbnail_key);
|
2018-02-22 13:25:56 +01:00
|
|
|
}
|
|
|
|
|
2018-03-14 04:25:22 +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 {
|
2018-03-14 04:25:22 +01:00
|
|
|
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
|
|
|
}
|
|
|
|
}
|