Feeds can now be deleted
This commit is contained in:
parent
245f272a35
commit
e2ddfd292b
|
@ -0,0 +1,6 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<menu xmlns:android="http://schemas.android.com/apk/res/android" >
|
||||
<item android:id="@+id/remove_item" android:title="@string/remove_label" android:icon="@drawable/content_discard" android:visible="true"></item>
|
||||
|
||||
|
||||
</menu>
|
|
@ -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
|
||||
|
|
|
@ -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;
|
||||
|
||||
}
|
||||
};
|
||||
}
|
||||
|
|
|
@ -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();
|
||||
|
|
Loading…
Reference in New Issue