Commit 4161cd02 authored by Edward Wang's avatar Edward Wang
Browse files

HistoryFragment: add a context menu

parent 5c55c81c
<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android" >
<item
android:id="@+id/history_view_play"
android:title="@string/play" />
<item
android:id="@+id/history_view_delete"
android:title="@string/delete" />
</menu>
......@@ -20,15 +20,21 @@
*****************************************************************************/
package org.videolan.vlc.gui;
import org.videolan.libvlc.LibVLC;
import org.videolan.vlc.AudioServiceController;
import org.videolan.vlc.R;
import org.videolan.vlc.gui.audio.AudioPlayerActivity;
import android.content.Intent;
import android.os.Bundle;
import android.util.Log;
import android.view.ContextMenu;
import android.view.ContextMenu.ContextMenuInfo;
import android.view.LayoutInflater;
import android.view.MenuInflater;
import android.view.MenuItem;
import android.view.View;
import android.view.ViewGroup;
import android.widget.AdapterView.AdapterContextMenuInfo;
import android.widget.ListView;
import com.actionbarsherlock.app.SherlockListFragment;
......@@ -54,19 +60,51 @@ public class HistoryFragment extends SherlockListFragment {
{
View v = inflater.inflate(R.layout.history_list, container, false);
setListAdapter(mHistoryAdapter);
final ListView listView = (ListView)v.findViewById(android.R.id.list);
registerForContextMenu(listView);
return v;
}
@Override
public void onCreateContextMenu(ContextMenu menu, View v, ContextMenuInfo menuInfo) {
MenuInflater menuInflater = getActivity().getMenuInflater();
menuInflater.inflate(R.menu.history_view, menu);
}
@Override
public void onListItemClick(ListView l, View v, int p, long id) {
playListIndex(p);
}
private void playListIndex(int position) {
AudioServiceController audioController = AudioServiceController.getInstance();
audioController.load(mHistoryAdapter.getAllURIs(), p, true, true);
audioController.load(mHistoryAdapter.getAllURIs(), position, true, true);
Intent intent = new Intent(getActivity(), AudioPlayerActivity.class);
intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
startActivity(intent);
}
@Override
public boolean onContextItemSelected(MenuItem item) {
if(!getUserVisibleHint()) return super.onContextItemSelected(item);
AdapterContextMenuInfo info = (AdapterContextMenuInfo) item.getMenuInfo();
if(info == null) // info can be null
return super.onContextItemSelected(item);
int id = item.getItemId();
if(id == R.id.history_view_play) {
playListIndex(info.position);
return true;
} else if(id == R.id.history_view_delete) {
LibVLC.getExistingInstance().removeIndex(info.position);
mHistoryAdapter.notifyDataSetChanged();
return true;
}
return super.onContextItemSelected(item);
}
public void refresh() {
Log.d(TAG, "Refreshing view!");
if( mHistoryAdapter != null )
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment