change DSLV usage

This commit is contained in:
Adrian Ulrich 2015-08-10 20:54:19 +02:00
parent 1be79d7ca9
commit 0f1c7a6da9
3 changed files with 44 additions and 49 deletions

View File

@ -46,6 +46,7 @@ public class PlaylistActivity extends Activity
implements View.OnClickListener
, AbsListView.OnItemClickListener
, DialogInterface.OnClickListener
, DragSortListView.DropListener
{
/**
* The SongTimeline play mode corresponding to each
@ -102,7 +103,7 @@ public class PlaylistActivity extends Activity
DragSortListView view = (DragSortListView)findViewById(R.id.list);
view.setOnItemClickListener(this);
view.setOnCreateContextMenuListener(this);
view.setDropListener(onDrop);
view.setDropListener(this);
mListView = view;
View header = LayoutInflater.from(this).inflate(R.layout.playlist_buttons, null);
@ -287,12 +288,9 @@ public class PlaylistActivity extends Activity
* @param from the item index that was dragged
* @param to the index where the item was dropped
*/
private DragSortListView.DropListener onDrop =
new DragSortListView.DropListener() {
@Override
public void drop(int from, int to) {
mAdapter.moveItem(from, to);
}
};
@Override
public void drop(int from, int to) {
mAdapter.moveItem(from, to);
}
}

View File

@ -33,8 +33,10 @@ import android.widget.ListView;
import com.mobeta.android.dslv.DragSortListView;
public class ShowQueueActivity extends PlaybackActivity
implements DialogInterface.OnDismissListener
{
implements DialogInterface.OnDismissListener,
DragSortListView.DropListener,
DragSortListView.RemoveListener
{
private DragSortListView mListView;
private ShowQueueAdapter listAdapter;
private PlaybackService mService;
@ -51,8 +53,8 @@ public class ShowQueueActivity extends PlaybackActivity
mListView = (DragSortListView) findViewById(R.id.list);
listAdapter = new ShowQueueAdapter(this, R.layout.draggable_row, mHandler.getLooper());
mListView.setAdapter(listAdapter);
mListView.setDropListener(onDrop);
mListView.setRemoveListener(onRemove);
mListView.setDropListener(this);
mListView.setRemoveListener(this);
mListView.setOnItemClickListener(new OnItemClickListener() {
@Override
@ -121,27 +123,21 @@ public class ShowQueueActivity extends PlaybackActivity
* @param from the item index that was dragged
* @param to the index where the item was dropped
*/
private DragSortListView.DropListener onDrop =
new DragSortListView.DropListener() {
@Override
public void drop(int from, int to) {
if (from != to) {
mService.moveSongPosition(from, to);
}
}
};
@Override
public void drop(int from, int to) {
if (from != to) {
mService.moveSongPosition(from, to);
}
}
/**
* Fired from adapter listview after user removed a song
* @param which index to remove from queue
*/
private DragSortListView.RemoveListener onRemove =
new DragSortListView.RemoveListener() {
@Override
public void remove(int which) {
mService.removeSongPosition(which);
}
};
@Override
public void remove(int which) {
mService.removeSongPosition(which);
}
/**
* Saves the current queue as a playlist

View File

@ -34,7 +34,11 @@ import com.mobeta.android.dslv.DragSortListView;
/**
* The preferences activity in which one can change application preferences.
*/
public class TabOrderActivity extends Activity implements View.OnClickListener, OnItemClickListener {
public class TabOrderActivity extends Activity
implements View.OnClickListener,
OnItemClickListener,
DragSortListView.DropListener
{
private TabOrderAdapter mAdapter;
private DragSortListView mList;
@ -54,7 +58,7 @@ public class TabOrderActivity extends Activity implements View.OnClickListener,
DragSortListView list = (DragSortListView)findViewById(R.id.list);
list.setAdapter(mAdapter);
list.setOnItemClickListener(this);
list.setDropListener(onDrop);
list.setDropListener(this);
mList = list;
load();
@ -161,28 +165,25 @@ public class TabOrderActivity extends Activity implements View.OnClickListener,
* @param from the item index that was dragged
* @param to the index where the item was dropped
*/
private DragSortListView.DropListener onDrop =
new DragSortListView.DropListener() {
@Override
public void drop(int from, int to) {
if (from == to)
return;
@Override
public void drop(int from, int to) {
if (from == to)
return;
int[] ids = mAdapter.getTabIds();
int tempId = ids[from];
int[] ids = mAdapter.getTabIds();
int tempId = ids[from];
if (from > to) {
System.arraycopy(ids, to, ids, to + 1, from - to);
} else {
System.arraycopy(ids, from + 1, ids, from, to - from);
}
if (from > to) {
System.arraycopy(ids, to, ids, to + 1, from - to);
} else {
System.arraycopy(ids, from + 1, ids, from, to - from);
}
ids[to] = tempId;
save();
mAdapter.notifyDataSetChanged();
// no need to update the copy in mAdapter: We worked on a reference
}
};
ids[to] = tempId;
save();
mAdapter.notifyDataSetChanged();
// no need to update the copy in mAdapter: We worked on a reference
}
}