Improved handling of invalid image file urls
This commit is contained in:
parent
2c9a5ff54e
commit
e7f7838a9c
@ -1,8 +1,12 @@
|
||||
package de.podfetcher.asynctask;
|
||||
|
||||
import java.io.File;
|
||||
|
||||
import de.podfetcher.PodcastApp;
|
||||
import de.podfetcher.R;
|
||||
import de.podfetcher.feed.FeedImage;
|
||||
import de.podfetcher.feed.FeedManager;
|
||||
import de.podfetcher.storage.DownloadRequester;
|
||||
import android.annotation.SuppressLint;
|
||||
import android.app.ActivityManager;
|
||||
import android.content.Context;
|
||||
@ -128,7 +132,11 @@ public class FeedImageLoader {
|
||||
|
||||
@Override
|
||||
protected Void doInBackground(FeedImage... params) {
|
||||
File f = null;
|
||||
if (params[0].getFile_url() != null) {
|
||||
f = new File(params[0].getFile_url());
|
||||
}
|
||||
if (params[0].getFile_url() != null && f.exists()) {
|
||||
BitmapFactory.Options options = new BitmapFactory.Options();
|
||||
options.inJustDecodeBounds = true;
|
||||
BitmapFactory.decodeFile(params[0].getFile_url(), options);
|
||||
@ -139,15 +147,29 @@ public class FeedImageLoader {
|
||||
options.inSampleSize = sampleSize;
|
||||
decodedBitmap = BitmapFactory.decodeFile(
|
||||
params[0].getFile_url(), options);
|
||||
if (decodedBitmap == null) {
|
||||
Log.i(TAG,
|
||||
"Bitmap could not be decoded in custom sample size. Trying default sample size (path was "
|
||||
+ params[0].getFile_url() + ")");
|
||||
decodedBitmap = BitmapFactory.decodeFile(params[0]
|
||||
.getFile_url());
|
||||
}
|
||||
bitmap = Bitmap.createScaledBitmap(decodedBitmap,
|
||||
PREFERRED_LENGTH, PREFERRED_LENGTH, false);
|
||||
|
||||
addBitmapToCache(params[0].getId(), bitmap);
|
||||
Log.d(TAG, "Finished loading bitmaps");
|
||||
} else {
|
||||
Log.e(TAG, "FeedImage has no file url. Using default image");
|
||||
Log.e(TAG,
|
||||
"FeedImage has no valid file url. Using default image");
|
||||
bitmap = BitmapFactory.decodeResource(target.getResources(),
|
||||
R.drawable.default_cover);
|
||||
if (params[0].getFile_url() != null
|
||||
&& !DownloadRequester.getInstance().isDownloadingFile(
|
||||
params[0])) {
|
||||
FeedManager.getInstance().notifyInvalidImageFile(
|
||||
PodcastApp.getInstance(), params[0]);
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
@ -215,6 +215,18 @@ public class FeedManager {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Notifies the feed manager that the an image file is invalid. It will try
|
||||
* to redownload it
|
||||
*/
|
||||
public void notifyInvalidImageFile(Context context, FeedImage image) {
|
||||
Log.i(TAG,
|
||||
"The feedmanager was notified about an invalid image download. It will now try to redownload the image file");
|
||||
image.setDownloaded(false);
|
||||
image.setFile_url(null);
|
||||
requester.downloadImage(context, image);
|
||||
}
|
||||
|
||||
public void refreshFeed(Context context, Feed feed) {
|
||||
requester.downloadFeed(context, new Feed(feed.getDownload_url(),
|
||||
new Date()));
|
||||
|
Loading…
x
Reference in New Issue
Block a user