From b5296e9f4da88536c92442e31be8ba22343c4e31 Mon Sep 17 00:00:00 2001 From: daniel oeh Date: Thu, 14 Jun 2012 15:24:11 +0200 Subject: [PATCH] Added ability to delete media files --- .../podfetcher/activity/ItemviewActivity.java | 11 ++++++++++ src/de/podfetcher/feed/FeedManager.java | 20 ++++++++++++++++++- 2 files changed, 30 insertions(+), 1 deletion(-) diff --git a/src/de/podfetcher/activity/ItemviewActivity.java b/src/de/podfetcher/activity/ItemviewActivity.java index 8eea7ca79..36c2e6b32 100644 --- a/src/de/podfetcher/activity/ItemviewActivity.java +++ b/src/de/podfetcher/activity/ItemviewActivity.java @@ -74,6 +74,17 @@ public class ItemviewActivity extends SherlockActivity { v.getContext().startActivity(playerIntent); } }); + + butRemove.setOnClickListener(new View.OnClickListener() { + + @Override + public void onClick(View v) { + if (manager.deleteFeedMedia(v.getContext(), item.getMedia())) { + setNotDownloadedState(); + } + + } + }); } @Override diff --git a/src/de/podfetcher/feed/FeedManager.java b/src/de/podfetcher/feed/FeedManager.java index 5dd578b64..d087a7222 100644 --- a/src/de/podfetcher/feed/FeedManager.java +++ b/src/de/podfetcher/feed/FeedManager.java @@ -1,5 +1,6 @@ package de.podfetcher.feed; +import java.io.File; import java.util.ArrayList; import java.util.Date; @@ -36,10 +37,27 @@ public class FeedManager { return singleton; } + /** Remove media item that has been downloaded. */ + public boolean deleteFeedMedia(Context context, FeedMedia media) { + boolean result = false; + if (media.isDownloaded()) { + File mediaFile = new File(media.file_url); + if (mediaFile.exists()) { + result = mediaFile.delete(); + } + media.setDownloaded(false); + media.setFile_url(""); + setFeedMedia(context, media); + } + Log.d(TAG, "Deleting File. Result: " + result); + return result; + } + public void refreshAllFeeds(Context context) { Log.d(TAG, "Refreshing all feeds."); for (Feed feed : feeds) { - requester.downloadFeed(context, new Feed(feed.getDownload_url(), new Date())); + requester.downloadFeed(context, new Feed(feed.getDownload_url(), + new Date())); } }