migrate queue to DSLV

This commit is contained in:
Adrian Ulrich 2014-10-17 11:41:17 +02:00
parent 51c24054ab
commit da6878da5e
4 changed files with 26 additions and 41 deletions

View File

@ -1,10 +1,17 @@
<?xml version="1.0" encoding="utf-8"?>
<ch.blinkenlights.android.vanilla.DragListView
<com.mobeta.android.dslv.DragSortListView
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:dslv="http://schemas.android.com/apk/res-auto"
android:id="@+id/list"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:divider="@color/divider_color"
android:dividerHeight="1dip"
android:listSelector="@drawable/selectable_item_bg"
android:scrollbarStyle="outsideInset" />
android:scrollbarStyle="outsideInset"
dslv:drag_enabled="true"
dslv:drag_start_mode="onMove"
dslv:drag_handle_id="@+id/playmark"
dslv:remove_enabled="true"
dslv:remove_mode="flingRemove"
/>

View File

@ -6,7 +6,7 @@
android:orientation="horizontal">
<View
android:id="@+id/playmark"
android:layout_width="4dip"
android:layout_width="20dip"
android:layout_height="fill_parent"
android:background="@android:color/holo_blue_dark" />
<TextView

View File

@ -27,12 +27,10 @@ import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.AdapterView.OnItemLongClickListener;
import android.widget.ListView;
import com.mobeta.android.dslv.DragSortListView;
public class ShowQueueActivity
extends Activity
implements ShowQueueAdapter.OnItemMovedListener
{
private DragListView mListView;
public class ShowQueueActivity extends Activity {
private DragSortListView mListView;
private ShowQueueAdapter listAdapter;
private PlaybackService mService;
@ -44,11 +42,11 @@ public class ShowQueueActivity
setContentView(R.layout.showqueue_listview);
mService = PlaybackService.get(this);
mListView = (DragListView) findViewById(R.id.list);
mListView = (DragSortListView) findViewById(R.id.list);
listAdapter = new ShowQueueAdapter(this, R.layout.showqueue_row);
mListView.setAdapter(listAdapter);
mListView.setFastScrollAlwaysVisible(true);
mListView.setEditable(true);
mListView.setDropListener(onDrop);
PlaybackService.addActivity(this);
@ -94,13 +92,19 @@ public class ShowQueueActivity
}
/**
* Fired from adapter list if user moved an item
* Fired from adapter listview if user moved an item
* @param from the item index that was dragged
* @param to the index where the item was dropped
*/
public void onItemMoved(int from, int to) {
mService.moveSong(from, to);
}
private DragSortListView.DropListener onDrop =
new DragSortListView.DropListener() {
@Override
public void drop(int from, int to) {
if (from != to) {
mService.moveSong(from, to);
}
}
};
/**
* Triggers a refresh of the queueview

View File

@ -34,28 +34,19 @@ import android.text.SpannableStringBuilder;
public class ShowQueueAdapter
extends ArrayAdapter<Song>
implements DragListView.DragAdapter {
{
int mResource;
int mHighlightRow;
Context mContext;
OnItemMovedListener mCallback;
public ShowQueueAdapter(Context context, int resource) {
super(context, resource);
mResource = resource;
mContext = context;
mCallback = (OnItemMovedListener) context;
mHighlightRow = -1;
}
/**
* Called if user moved a queue item
*/
public interface OnItemMovedListener {
public void onItemMoved(int from, int to);
}
/**
* Tells the adapter to highlight a specific row id
* Set this to -1 to disable the feature
@ -86,21 +77,4 @@ public class ShowQueueAdapter
return row;
}
@Override
public void remove(int position) {
// not implemented
}
/**
* Moves a songs position in the queue
*
* @param from the index of the song to be moved
* @param to the new index position of the song
*/
@Override
public void move(int from, int to) {
mCallback.onItemMoved(from, to);
}
}