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/fragment/FeedlistFragment.java | |
parent | 245f272a3510ccc816aeedd8b215d5491e08c67a (diff) | |
download | AntennaPod-e2ddfd292b7655e1dd6cf9becefde8b17bb8bd17.zip |
Feeds can now be deleted
Diffstat (limited to 'src/de/podfetcher/fragment/FeedlistFragment.java')
-rw-r--r-- | src/de/podfetcher/fragment/FeedlistFragment.java | 81 |
1 files changed, 76 insertions, 5 deletions
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; + + } + }; } |