diff options
author | daniel oeh <daniel.oeh@gmail.com> | 2014-05-12 18:12:15 +0200 |
---|---|---|
committer | daniel oeh <daniel.oeh@gmail.com> | 2014-05-12 18:12:15 +0200 |
commit | c78081fbd9c1cc7b504101bcdefa993db5a0e40e (patch) | |
tree | ece4d2ed20663b32f52e71830d85281640f4eaf0 /src/de/danoeh/antennapod/fragment | |
parent | 6444d5433ab5a1be55a267828a02ed99aed281cb (diff) | |
download | AntennaPod-c78081fbd9c1cc7b504101bcdefa993db5a0e40e.zip |
Reimplemented move to top/bottom feature in queue fragment
- move to top(bottom) is now disabled for the item at the first(last) item instead of removed. closes #380
Diffstat (limited to 'src/de/danoeh/antennapod/fragment')
-rw-r--r-- | src/de/danoeh/antennapod/fragment/QueueFragment.java | 43 |
1 files changed, 42 insertions, 1 deletions
diff --git a/src/de/danoeh/antennapod/fragment/QueueFragment.java b/src/de/danoeh/antennapod/fragment/QueueFragment.java index 2756a468f..ef191631e 100644 --- a/src/de/danoeh/antennapod/fragment/QueueFragment.java +++ b/src/de/danoeh/antennapod/fragment/QueueFragment.java @@ -7,7 +7,6 @@ import android.os.Bundle; import android.os.Handler; import android.os.Parcelable; import android.support.v4.app.Fragment; -import android.support.v4.view.MenuItemCompat; import android.support.v7.widget.SearchView; import android.util.Log; import android.view.*; @@ -109,6 +108,7 @@ public class QueueFragment extends Fragment { } private void resetViewState() { + unregisterForContextMenu(listView); listAdapter = null; undoBarController = null; activity.set(null); @@ -148,6 +148,45 @@ public class QueueFragment extends Fragment { } @Override + public void onCreateContextMenu(ContextMenu menu, View v, ContextMenu.ContextMenuInfo menuInfo) { + super.onCreateContextMenu(menu, v, menuInfo); + AdapterView.AdapterContextMenuInfo adapterInfo = (AdapterView.AdapterContextMenuInfo) menuInfo; + FeedItem item = itemAccess.getItem(adapterInfo.position); + + MenuInflater inflater = getActivity().getMenuInflater(); + inflater.inflate(R.menu.queue_context, menu); + + if (item != null) { + menu.setHeaderTitle(item.getTitle()); + } + + menu.findItem(R.id.move_to_top_item).setEnabled(!queue.isEmpty() && queue.get(0) != item); + menu.findItem(R.id.move_to_bottom_item).setEnabled(!queue.isEmpty() && queue.get(queue.size() - 1) != item); + } + + @Override + public boolean onContextItemSelected(MenuItem item) { + AdapterView.AdapterContextMenuInfo menuInfo = (AdapterView.AdapterContextMenuInfo) item.getMenuInfo(); + FeedItem selectedItem = itemAccess.getItem(menuInfo.position); + + if (selectedItem == null) { + Log.i(TAG, "Selected item at position " + menuInfo.position + " was null, ignoring selection"); + return super.onContextItemSelected(item); + } + + switch (item.getItemId()) { + case R.id.move_to_top_item: + DBWriter.moveQueueItemToTop(getActivity(), selectedItem.getId(), true); + return true; + case R.id.move_to_bottom_item: + DBWriter.moveQueueItemToBottom(getActivity(), selectedItem.getId(), true); + return true; + default: + return super.onContextItemSelected(item); + } + } + + @Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { super.onCreateView(inflater, container, savedInstanceState); ((MainActivity) getActivity()).getSupportActionBar().setTitle(R.string.queue_label); @@ -212,6 +251,8 @@ public class QueueFragment extends Fragment { } }); + registerForContextMenu(listView); + if (!itemsLoaded) { progLoading.setVisibility(View.VISIBLE); txtvEmpty.setVisibility(View.GONE); |