summaryrefslogtreecommitdiff
path: root/src/de
diff options
context:
space:
mode:
Diffstat (limited to 'src/de')
-rw-r--r--src/de/podfetcher/PodcastApp.java12
-rw-r--r--src/de/podfetcher/activity/FeedInfoActivity.java2
-rw-r--r--src/de/podfetcher/activity/PodfetcherActivity.java3
-rw-r--r--src/de/podfetcher/adapter/FeedlistAdapter.java5
-rw-r--r--src/de/podfetcher/asynctask/FeedImageLoader.java22
-rw-r--r--src/de/podfetcher/feed/FeedManager.java2
-rw-r--r--src/de/podfetcher/fragment/FeedlistFragment.java3
-rw-r--r--src/de/podfetcher/service/DownloadService.java11
8 files changed, 49 insertions, 11 deletions
diff --git a/src/de/podfetcher/PodcastApp.java b/src/de/podfetcher/PodcastApp.java
index 9683f7516..e4c2f0971 100644
--- a/src/de/podfetcher/PodcastApp.java
+++ b/src/de/podfetcher/PodcastApp.java
@@ -1,8 +1,9 @@
package de.podfetcher;
-import de.podfetcher.activity.PodfetcherActivity;
-import de.podfetcher.feed.FeedManager;
import android.app.Application;
+import android.util.Log;
+import de.podfetcher.asynctask.FeedImageLoader;
+import de.podfetcher.feed.FeedManager;
public class PodcastApp extends Application {
private static final String TAG = "PodcastApp";
@@ -23,6 +24,13 @@ public class PodcastApp extends Application {
FeedManager manager = FeedManager.getInstance();
manager.loadDBData(getApplicationContext());
}
+
+ @Override
+ public void onLowMemory() {
+ super.onLowMemory();
+ Log.w(TAG, "Received onLowOnMemory warning. Cleaning image cache...");
+ FeedImageLoader.getInstance().wipeImageCache();
+ }
diff --git a/src/de/podfetcher/activity/FeedInfoActivity.java b/src/de/podfetcher/activity/FeedInfoActivity.java
index 1d82ee27d..3dcc9ec1a 100644
--- a/src/de/podfetcher/activity/FeedInfoActivity.java
+++ b/src/de/podfetcher/activity/FeedInfoActivity.java
@@ -58,6 +58,8 @@ public class FeedInfoActivity extends SherlockActivity {
}
+
+
@Override
public boolean onCreateOptionsMenu(Menu menu) {
return true;
diff --git a/src/de/podfetcher/activity/PodfetcherActivity.java b/src/de/podfetcher/activity/PodfetcherActivity.java
index 03df51772..4a7bad7e3 100644
--- a/src/de/podfetcher/activity/PodfetcherActivity.java
+++ b/src/de/podfetcher/activity/PodfetcherActivity.java
@@ -9,6 +9,7 @@ import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentPagerAdapter;
+import android.support.v4.app.FragmentStatePagerAdapter;
import android.support.v4.app.FragmentTransaction;
import android.support.v4.view.ViewPager;
import android.util.Log;
@@ -135,7 +136,7 @@ public class PodfetcherActivity extends SherlockFragmentActivity {
return true;
}
- public static class MainPagerAdapter extends FragmentPagerAdapter {
+ public static class MainPagerAdapter extends FragmentStatePagerAdapter {
private static final int NUM_ITEMS = 3;
private static final int POS_FEEDLIST = 0;
diff --git a/src/de/podfetcher/adapter/FeedlistAdapter.java b/src/de/podfetcher/adapter/FeedlistAdapter.java
index a9cc7d576..5123b36af 100644
--- a/src/de/podfetcher/adapter/FeedlistAdapter.java
+++ b/src/de/podfetcher/adapter/FeedlistAdapter.java
@@ -62,6 +62,11 @@ public class FeedlistAdapter extends ArrayAdapter<Feed> {
convertView.setTag(holder);
} else {
holder = (Holder) convertView.getTag();
+ // Recycle images which are no longer in the cache
+ if (!FeedImageLoader.getInstance().isInCache(feed.getImage())) {
+ Log.d(TAG, "Deleting reference to uncached bitmap");
+ holder.image.setImageBitmap(null);
+ }
}
if (position == selectedItemIndex) {
diff --git a/src/de/podfetcher/asynctask/FeedImageLoader.java b/src/de/podfetcher/asynctask/FeedImageLoader.java
index 9ffd2b9c9..8fcc5bdc6 100644
--- a/src/de/podfetcher/asynctask/FeedImageLoader.java
+++ b/src/de/podfetcher/asynctask/FeedImageLoader.java
@@ -1,8 +1,11 @@
package de.podfetcher.asynctask;
+import de.podfetcher.PodcastApp;
import de.podfetcher.R;
import de.podfetcher.feed.FeedImage;
import android.annotation.SuppressLint;
+import android.app.ActivityManager;
+import android.content.Context;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.os.AsyncTask;
@@ -12,17 +15,24 @@ import android.widget.ImageView;
/** Caches and loads FeedImage bitmaps in the background */
public class FeedImageLoader {
+ private static final String TAG = "FeedImageLoader";
private static FeedImageLoader singleton;
/**
* Stores references to loaded bitmaps. Bitmaps can be accessed by the id of
* the FeedImage the bitmap belongs to.
*/
+
+ final int memClass = ((ActivityManager) PodcastApp.getInstance()
+ .getSystemService(Context.ACTIVITY_SERVICE)).getMemoryClass();
+
+ // Use 1/8th of the available memory for this memory cache.
+ final int cacheSize = 1024 * 1024 * memClass / 8;
private LruCache<Long, Bitmap> imageCache;
- private static final int CACHE_SIZE = 4 * 1024 * 1024;
private FeedImageLoader() {
- imageCache = new LruCache<Long, Bitmap>(CACHE_SIZE) {
+ Log.d(TAG, "Creating cache with size " + cacheSize);
+ imageCache = new LruCache<Long, Bitmap>(cacheSize) {
@SuppressLint("NewApi")
@Override
@@ -63,6 +73,14 @@ public class FeedImageLoader {
imageCache.put(id, bitmap);
}
+ public void wipeImageCache() {
+ imageCache.evictAll();
+ }
+
+ public boolean isInCache(FeedImage image) {
+ return imageCache.get(image.getId()) != null;
+ }
+
public Bitmap getBitmapFromCache(long id) {
return imageCache.get(id);
}
diff --git a/src/de/podfetcher/feed/FeedManager.java b/src/de/podfetcher/feed/FeedManager.java
index 493c01af6..b39cfe25a 100644
--- a/src/de/podfetcher/feed/FeedManager.java
+++ b/src/de/podfetcher/feed/FeedManager.java
@@ -179,10 +179,10 @@ public class FeedManager {
public long addDownloadStatus(Context context, DownloadStatus status) {
PodDBAdapter adapter = new PodDBAdapter(context);
downloadLog.add(status);
+ adapter.open();
if (downloadLog.size() > DOWNLOAD_LOG_SIZE) {
adapter.removeDownloadStatus(downloadLog.remove(0));
}
- adapter.open();
long result = adapter.setDownloadStatus(status);
adapter.close();
return result;
diff --git a/src/de/podfetcher/fragment/FeedlistFragment.java b/src/de/podfetcher/fragment/FeedlistFragment.java
index 1003aa068..763c89ac7 100644
--- a/src/de/podfetcher/fragment/FeedlistFragment.java
+++ b/src/de/podfetcher/fragment/FeedlistFragment.java
@@ -52,6 +52,8 @@ public class FeedlistFragment extends SherlockListFragment implements
pActivity = null;
}
+
+
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
@@ -175,4 +177,5 @@ public class FeedlistFragment extends SherlockListFragment implements
selectedFeed = null;
fla.setSelectedItemIndex(FeedlistAdapter.SELECTION_NONE);
}
+
}
diff --git a/src/de/podfetcher/service/DownloadService.java b/src/de/podfetcher/service/DownloadService.java
index 8d36df888..282c7781f 100644
--- a/src/de/podfetcher/service/DownloadService.java
+++ b/src/de/podfetcher/service/DownloadService.java
@@ -297,16 +297,17 @@ public class DownloadService extends Service {
try {
feed = handler.parseFeed(feed);
Log.d(TAG, feed.getTitle() + " parsed");
- // Download Feed Image if provided
- if (feed.getImage() != null) {
+
+ feed.setDownloadId(0);
+ // Save information of feed in DB
+ savedFeed = manager.updateFeed(service, feed);
+ // Download Feed Image if provided and not downloaded
+ if (savedFeed.getImage().isDownloaded() == false) {
Log.d(TAG, "Feed has image; Downloading....");
imageId = requester.downloadImage(service, feed.getImage());
hasImage = true;
}
- feed.setDownloadId(0);
- // Save information of feed in DB
- savedFeed = manager.updateFeed(service, feed);
} catch (SAXException e) {
successful = false;
e.printStackTrace();