Improved handling of invalid image file urls
This commit is contained in:
parent
2c9a5ff54e
commit
e7f7838a9c
@ -1,8 +1,12 @@
|
|||||||
package de.podfetcher.asynctask;
|
package de.podfetcher.asynctask;
|
||||||
|
|
||||||
|
import java.io.File;
|
||||||
|
|
||||||
import de.podfetcher.PodcastApp;
|
import de.podfetcher.PodcastApp;
|
||||||
import de.podfetcher.R;
|
import de.podfetcher.R;
|
||||||
import de.podfetcher.feed.FeedImage;
|
import de.podfetcher.feed.FeedImage;
|
||||||
|
import de.podfetcher.feed.FeedManager;
|
||||||
|
import de.podfetcher.storage.DownloadRequester;
|
||||||
import android.annotation.SuppressLint;
|
import android.annotation.SuppressLint;
|
||||||
import android.app.ActivityManager;
|
import android.app.ActivityManager;
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
@ -128,26 +132,44 @@ public class FeedImageLoader {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected Void doInBackground(FeedImage... params) {
|
protected Void doInBackground(FeedImage... params) {
|
||||||
|
File f = null;
|
||||||
if (params[0].getFile_url() != 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();
|
BitmapFactory.Options options = new BitmapFactory.Options();
|
||||||
options.inJustDecodeBounds = true;
|
options.inJustDecodeBounds = true;
|
||||||
BitmapFactory.decodeFile(params[0].getFile_url(), options);
|
BitmapFactory.decodeFile(params[0].getFile_url(), options);
|
||||||
int sampleSize = calculateSampleSize(options.outWidth,
|
int sampleSize = calculateSampleSize(options.outWidth,
|
||||||
options.outHeight);
|
options.outHeight);
|
||||||
|
|
||||||
options.inJustDecodeBounds = false;
|
options.inJustDecodeBounds = false;
|
||||||
options.inSampleSize = sampleSize;
|
options.inSampleSize = sampleSize;
|
||||||
decodedBitmap = BitmapFactory.decodeFile(
|
decodedBitmap = BitmapFactory.decodeFile(
|
||||||
params[0].getFile_url(), options);
|
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,
|
bitmap = Bitmap.createScaledBitmap(decodedBitmap,
|
||||||
PREFERRED_LENGTH, PREFERRED_LENGTH, false);
|
PREFERRED_LENGTH, PREFERRED_LENGTH, false);
|
||||||
|
|
||||||
addBitmapToCache(params[0].getId(), bitmap);
|
addBitmapToCache(params[0].getId(), bitmap);
|
||||||
Log.d(TAG, "Finished loading bitmaps");
|
Log.d(TAG, "Finished loading bitmaps");
|
||||||
} else {
|
} 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(),
|
bitmap = BitmapFactory.decodeResource(target.getResources(),
|
||||||
R.drawable.default_cover);
|
R.drawable.default_cover);
|
||||||
|
if (params[0].getFile_url() != null
|
||||||
|
&& !DownloadRequester.getInstance().isDownloadingFile(
|
||||||
|
params[0])) {
|
||||||
|
FeedManager.getInstance().notifyInvalidImageFile(
|
||||||
|
PodcastApp.getInstance(), params[0]);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
@ -193,7 +193,7 @@ public class FeedManager {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Marks all items in the unread items list as read */
|
/** Marks all items in the unread items list as read */
|
||||||
public void markAllItemsRead(Context context) {
|
public void markAllItemsRead(Context context) {
|
||||||
Log.d(TAG, "marking all items as read");
|
Log.d(TAG, "marking all items as read");
|
||||||
@ -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) {
|
public void refreshFeed(Context context, Feed feed) {
|
||||||
requester.downloadFeed(context, new Feed(feed.getDownload_url(),
|
requester.downloadFeed(context, new Feed(feed.getDownload_url(),
|
||||||
new Date()));
|
new Date()));
|
||||||
@ -240,7 +252,7 @@ public class FeedManager {
|
|||||||
adapter.close();
|
adapter.close();
|
||||||
sendQueueUpdateBroadcast(context, item);
|
sendQueueUpdateBroadcast(context, item);
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Removes all items in queue */
|
/** Removes all items in queue */
|
||||||
public void clearQueue(Context context) {
|
public void clearQueue(Context context) {
|
||||||
Log.d(TAG, "Clearing queue");
|
Log.d(TAG, "Clearing queue");
|
||||||
|
Loading…
x
Reference in New Issue
Block a user