Implemented queue and unread items menu

This commit is contained in:
daniel oeh 2013-01-27 19:37:49 +01:00
parent be9018e843
commit a227e0ebfd
3 changed files with 101 additions and 16 deletions

View File

@ -17,5 +17,21 @@
android:textColor="@color/bright_blue"
android:textSize="@dimen/text_size_large"
android:textStyle="bold" />
<ImageButton
android:id="@+id/butAction"
android:layout_width="48dp"
android:layout_height="match_parent"
android:layout_alignParentBottom="true"
android:layout_alignParentRight="true"
android:background="?attr/borderless_button"
android:clickable="false"
android:focusable="false"
android:focusableInTouchMode="false"
android:paddingLeft="16dp"
android:paddingRight="16dp"
android:paddingTop="16dp"
android:scaleType="fitEnd"
android:src="?attr/spinner_button" />
</RelativeLayout>

View File

@ -23,7 +23,7 @@ import de.danoeh.antennapod.util.EpisodeFilter;
*/
public class ExternalEpisodesListAdapter extends BaseExpandableListAdapter {
private static final String TAG = "ExternalEpisodesListAdapter";
public static final int GROUP_POS_QUEUE = 0;
public static final int GROUP_POS_UNREAD = 1;
@ -32,16 +32,19 @@ public class ExternalEpisodesListAdapter extends BaseExpandableListAdapter {
private List<FeedItem> unreadItems;
private List<FeedItem> queueItems;
ActionButtonCallback callback;
private ActionButtonCallback feedItemActionCallback;
private OnGroupActionClicked groupActionCallback;
public ExternalEpisodesListAdapter(Context context,
List<FeedItem> unreadItems, List<FeedItem> queueItems,
ActionButtonCallback callback) {
ActionButtonCallback callback,
OnGroupActionClicked groupActionCallback) {
super();
this.context = context;
this.unreadItems = unreadItems;
this.queueItems = queueItems;
this.callback = callback;
this.feedItemActionCallback = callback;
this.groupActionCallback = groupActionCallback;
}
@Override
@ -110,7 +113,7 @@ public class ExternalEpisodesListAdapter extends BaseExpandableListAdapter {
@Override
public void onClick(View v) {
callback.onActionButtonPressed(item);
feedItemActionCallback.onActionButtonPressed(item);
}
});
@ -155,13 +158,15 @@ public class ExternalEpisodesListAdapter extends BaseExpandableListAdapter {
}
@Override
public View getGroupView(int groupPosition, boolean isExpanded,
public View getGroupView(final int groupPosition, boolean isExpanded,
View convertView, ViewGroup parent) {
LayoutInflater inflater = (LayoutInflater) context
.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
convertView = inflater.inflate(R.layout.feeditemlist_header, null);
TextView headerTitle = (TextView) convertView
.findViewById(R.id.txtvHeaderTitle);
ImageButton actionButton = (ImageButton) convertView
.findViewById(R.id.butAction);
String headerString = null;
if (groupPosition == 0) {
headerString = context.getString(R.string.queue_label);
@ -175,7 +180,14 @@ public class ExternalEpisodesListAdapter extends BaseExpandableListAdapter {
}
}
headerTitle.setText(headerString);
actionButton.setFocusable(false);
actionButton.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
groupActionCallback.onClick(getGroupId(groupPosition));
}
});
return convertView;
}
@ -199,4 +211,8 @@ public class ExternalEpisodesListAdapter extends BaseExpandableListAdapter {
return true;
}
public interface OnGroupActionClicked {
public void onClick(long groupId);
}
}

View File

@ -16,6 +16,7 @@ import android.widget.ExpandableListView;
import android.widget.ExpandableListView.OnChildClickListener;
import com.actionbarsherlock.app.SherlockFragment;
import com.actionbarsherlock.view.Menu;
import de.danoeh.antennapod.AppConfig;
import de.danoeh.antennapod.R;
@ -37,11 +38,12 @@ public class EpisodesFragment extends SherlockFragment {
private ExternalEpisodesListAdapter adapter;
protected FeedItem selectedItem = null;
protected long selectedGroupId = -1;
protected boolean contextMenuClosed = true;
@Override
public void onPause() {
super.onPause();
public void onDestroy() {
super.onDestroy();
try {
getActivity().unregisterReceiver(contentUpdate);
} catch (IllegalArgumentException e) {
@ -73,8 +75,18 @@ public class EpisodesFragment extends SherlockFragment {
@Override
public void onActionButtonPressed(FeedItem item) {
resetContextMenuSelection();
selectedItem = item;
contextMenuClosed = true;
listView.showContextMenu();
}
};
protected ExternalEpisodesListAdapter.OnGroupActionClicked groupActionCallback = new ExternalEpisodesListAdapter.OnGroupActionClicked() {
@Override
public void onClick(long groupId) {
resetContextMenuSelection();
selectedGroupId = groupId;
listView.showContextMenu();
}
};
@ -84,7 +96,8 @@ public class EpisodesFragment extends SherlockFragment {
super.onViewCreated(view, savedInstanceState);
FeedManager manager = FeedManager.getInstance();
adapter = new ExternalEpisodesListAdapter(getActivity(),
manager.getUnreadItems(), manager.getQueue(), adapterCallback);
manager.getUnreadItems(), manager.getQueue(), adapterCallback,
groupActionCallback);
listView.setAdapter(adapter);
listView.expandGroup(ExternalEpisodesListAdapter.GROUP_POS_QUEUE);
listView.expandGroup(ExternalEpisodesListAdapter.GROUP_POS_UNREAD);
@ -126,7 +139,7 @@ public class EpisodesFragment extends SherlockFragment {
ContextMenuInfo menuInfo) {
super.onCreateContextMenu(menu, v, menuInfo);
if (!contextMenuClosed) { // true if context menu was cancelled before
selectedItem = null;
resetContextMenuSelection();
}
contextMenuClosed = false;
listView.setOnItemLongClickListener(null);
@ -143,13 +156,23 @@ public class EpisodesFragment extends SherlockFragment {
}
}, selectedItem, false);
} else if (selectedGroupId == ExternalEpisodesListAdapter.GROUP_POS_QUEUE) {
menu.add(Menu.NONE, R.id.clear_queue_item, Menu.NONE, getActivity()
.getString(R.string.clear_queue_label));
menu.add(Menu.NONE, R.id.download_all_item, Menu.NONE,
getActivity().getString(R.string.download_all));
} else if (selectedGroupId == ExternalEpisodesListAdapter.GROUP_POS_UNREAD) {
menu.add(Menu.NONE, R.id.mark_all_read_item, Menu.NONE,
getActivity().getString(R.string.mark_all_read_label));
menu.add(Menu.NONE, R.id.enqueue_all_item, Menu.NONE, getActivity()
.getString(R.string.enqueue_all_new));
}
}
@Override
public boolean onContextItemSelected(android.view.MenuItem item) {
boolean handled = false;
FeedManager manager = FeedManager.getInstance();
if (selectedItem != null) {
try {
handled = FeedItemMenuHandler.onMenuItemClicked(
@ -159,13 +182,43 @@ public class EpisodesFragment extends SherlockFragment {
DownloadRequestErrorDialogCreator.newRequestErrorDialog(
getActivity(), e.getMessage());
}
if (handled) {
adapter.notifyDataSetChanged();
} else if (selectedGroupId == ExternalEpisodesListAdapter.GROUP_POS_QUEUE) {
handled = true;
switch (item.getItemId()) {
case R.id.clear_queue_item:
manager.clearQueue(getActivity());
break;
case R.id.download_all_item:
manager.downloadAllItemsInQueue(getActivity());
break;
default:
handled = false;
}
} else if (selectedGroupId == ExternalEpisodesListAdapter.GROUP_POS_UNREAD) {
handled = true;
switch (item.getItemId()) {
case R.id.mark_all_read_item:
manager.markAllItemsRead(getActivity());
break;
case R.id.enqueue_all_item:
manager.enqueueAllNewItems(getActivity());
break;
default:
handled = false;
}
}
selectedItem = null;
contextMenuClosed = true;
if (handled) {
adapter.notifyDataSetChanged();
}
resetContextMenuSelection();
return handled;
}
private void resetContextMenuSelection() {
selectedItem = null;
selectedGroupId = -1;
contextMenuClosed = true;
}
}