diff options
author | daniel oeh <daniel.oeh@gmail.com> | 2012-06-19 21:02:36 +0200 |
---|---|---|
committer | daniel oeh <daniel.oeh@gmail.com> | 2012-06-19 21:02:36 +0200 |
commit | e2ddfd292b7655e1dd6cf9becefde8b17bb8bd17 (patch) | |
tree | bec04aa91e977092bc079166ab4c48e91a68916a /src/de/podfetcher | |
parent | 245f272a3510ccc816aeedd8b215d5491e08c67a (diff) | |
download | AntennaPod-e2ddfd292b7655e1dd6cf9becefde8b17bb8bd17.zip |
Feeds can now be deleted
Diffstat (limited to 'src/de/podfetcher')
-rw-r--r-- | src/de/podfetcher/feed/FeedManager.java | 26 | ||||
-rw-r--r-- | src/de/podfetcher/fragment/FeedlistFragment.java | 81 | ||||
-rw-r--r-- | src/de/podfetcher/storage/PodDBAdapter.java | 35 |
3 files changed, 137 insertions, 5 deletions
diff --git a/src/de/podfetcher/feed/FeedManager.java b/src/de/podfetcher/feed/FeedManager.java index 4c77c2059..8fcd57119 100644 --- a/src/de/podfetcher/feed/FeedManager.java +++ b/src/de/podfetcher/feed/FeedManager.java @@ -84,6 +84,32 @@ public class FeedManager { Log.d(TAG, "Deleting File. Result: " + result); return result; } + + /** Remove a feed with all its items and media files and its image. */ + public boolean deleteFeed(Context context, Feed feed) { + PodDBAdapter adapter = new PodDBAdapter(context); + + // delete image file + if (feed.getImage() != null) { + if (feed.getImage().isDownloaded() && feed.getImage().getFile_url() == null) { + File imageFile = new File(feed.getImage().getFile_url()); + imageFile.delete(); + } + } + // delete stored media files and mark them as read + for (FeedItem item : feed.getItems()) { + if (!item.isRead()) { + unreadItems.remove(item); + } + if (item.getMedia() != null && item.getMedia().isDownloaded()) { + File mediaFile = new File(item.getMedia().getFile_url()); + mediaFile.delete(); + } + } + adapter.removeFeed(feed); + return feeds.remove(feed); + + } /** * Sets the 'read'-attribute of a FeedItem. Should be used by all Classes diff --git a/src/de/podfetcher/fragment/FeedlistFragment.java b/src/de/podfetcher/fragment/FeedlistFragment.java index 73e86c881..e76bfbe60 100644 --- a/src/de/podfetcher/fragment/FeedlistFragment.java +++ b/src/de/podfetcher/fragment/FeedlistFragment.java @@ -15,23 +15,27 @@ import android.content.Intent; import android.content.IntentFilter; import android.content.BroadcastReceiver; import android.content.Context; +import android.widget.AdapterView; +import android.widget.AdapterView.OnItemLongClickListener; import android.widget.ListView; import com.actionbarsherlock.app.SherlockListFragment; import com.actionbarsherlock.app.SherlockFragmentActivity; +import com.actionbarsherlock.view.ActionMode; import com.actionbarsherlock.view.Menu; import com.actionbarsherlock.view.MenuInflater; import com.actionbarsherlock.view.MenuItem; import android.util.Log; - public class FeedlistFragment extends SherlockListFragment { private static final String TAG = "FeedlistFragment"; public static final String EXTRA_SELECTED_FEED = "extra.de.podfetcher.activity.selected_feed"; - + private FeedManager manager; private FeedlistAdapter fla; private SherlockFragmentActivity pActivity; + private Feed selectedFeed; + private ActionMode mActionMode; @Override public void onAttach(Activity activity) { @@ -44,20 +48,52 @@ public class FeedlistFragment extends SherlockListFragment { super.onDetach(); pActivity = null; } + @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); - Log.d(TAG, "Creating"); + Log.d(TAG, "Creating"); manager = FeedManager.getInstance(); fla = new FeedlistAdapter(pActivity, 0, manager.getFeeds()); setListAdapter(fla); + } + + + @Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { super.onCreateView(inflater, container, savedInstanceState); return inflater.inflate(R.layout.feedlist, container, false); + + } + + @Override + public void onViewCreated(View view, Bundle savedInstanceState) { + super.onViewCreated(view, savedInstanceState); + getListView().setOnItemLongClickListener(new OnItemLongClickListener() { + + @Override + public boolean onItemLongClick(AdapterView<?> parent, View view, + int position, long id) { + Feed selection = fla.getItem(position); + Log.d(TAG, "Selected Feed with title " + selection.getTitle()); + if (selection != null) { + if (mActionMode != null) { + mActionMode.finish(); + } + selectedFeed = selection; + mActionMode = getSherlockActivity().startActionMode( + mActionModeCallback); + + + } + return true; + } + + }); } @Override @@ -67,7 +103,7 @@ public class FeedlistFragment extends SherlockListFragment { filter.addAction(DownloadService.ACTION_FEED_SYNC_COMPLETED); pActivity.registerReceiver(contentUpdate, filter); - fla.notifyDataSetChanged(); + fla.notifyDataSetChanged(); } @Override @@ -79,7 +115,7 @@ public class FeedlistFragment extends SherlockListFragment { private BroadcastReceiver contentUpdate = new BroadcastReceiver() { @Override public void onReceive(Context context, Intent intent) { - Log.d(TAG, "Received contentUpdate Intent."); + Log.d(TAG, "Received contentUpdate Intent."); fla.notifyDataSetChanged(); } }; @@ -92,4 +128,39 @@ public class FeedlistFragment extends SherlockListFragment { pActivity.startActivity(showFeed); } + + private ActionMode.Callback mActionModeCallback = new ActionMode.Callback() { + + @Override + public boolean onCreateActionMode(ActionMode mode, Menu menu) { + MenuInflater inflater = mode.getMenuInflater(); + inflater.inflate(R.menu.feedlist, menu); + mode.setTitle(selectedFeed.getTitle()); + return true; + } + + @Override + public boolean onPrepareActionMode(ActionMode mode, Menu menu) { + return false; + } + + @Override + public boolean onActionItemClicked(ActionMode mode, MenuItem item) { + switch (item.getItemId()) { + case R.id.remove_item: + manager.deleteFeed(getSherlockActivity(), selectedFeed); + fla.notifyDataSetChanged(); + break; + } + mode.finish(); + return true; + } + + @Override + public void onDestroyActionMode(ActionMode mode) { + mActionMode = null; + selectedFeed = null; + + } + }; } diff --git a/src/de/podfetcher/storage/PodDBAdapter.java b/src/de/podfetcher/storage/PodDBAdapter.java index 6d05b61eb..1a357c786 100644 --- a/src/de/podfetcher/storage/PodDBAdapter.java +++ b/src/de/podfetcher/storage/PodDBAdapter.java @@ -293,6 +293,41 @@ public class PodDBAdapter { close(); return status.getId(); } + + public void removeFeedMedia(FeedMedia media) { + open(); + db.delete(TABLE_NAME_FEED_MEDIA, KEY_ID + "=?", new String[] {String.valueOf(media.getId())}); + close(); + } + + public void removeFeedImage(FeedImage image) { + open(); + db.delete(TABLE_NAME_FEED_IMAGES, KEY_ID + "=?", new String[] {String.valueOf(image.getId())}); + close(); + } + + /** Remove a FeedItem and its FeedMedia entry. */ + public void removeFeedItem(FeedItem item) { + if (item.getMedia() != null) { + removeFeedMedia(item.getMedia()); + } + open(); + db.delete(TABLE_NAME_FEED_ITEMS, KEY_ID + "=?", new String[] {String.valueOf(item.getId())}); + close(); + } + + /** Remove a feed with all its FeedItems and Media entries. */ + public void removeFeed(Feed feed) { + if (feed.getImage() != null) { + removeFeedImage(feed.getImage()); + } + for (FeedItem item : feed.getItems()) { + removeFeedItem(item); + } + open(); + db.delete(TABLE_NAME_FEEDS, KEY_ID + "=?", new String[] {String.valueOf(feed.getId())}); + close(); + } public void removeDownloadStatus(DownloadStatus remove) { open(); |