Added ability to delete media files

This commit is contained in:
daniel oeh 2012-06-14 15:24:11 +02:00
parent ea5768f50c
commit b5296e9f4d
2 changed files with 30 additions and 1 deletions

View File

@ -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

View File

@ -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()));
}
}