Fixed playing queue rearranging
This commit is contained in:
parent
ecbf5fc292
commit
159123f51f
3 changed files with 20 additions and 9 deletions
|
|
@ -17,11 +17,11 @@ import java.util.List;
|
||||||
/**
|
/**
|
||||||
* Created by karim on 24.01.15.
|
* Created by karim on 24.01.15.
|
||||||
*/
|
*/
|
||||||
public class PlayListAdapter extends ArrayAdapter<Song> {
|
public class PlayingQueueAdapter extends ArrayAdapter<Song> {
|
||||||
private Context context;
|
private Context context;
|
||||||
private App app;
|
private App app;
|
||||||
|
|
||||||
public PlayListAdapter(Context context, List<Song> playList) {
|
public PlayingQueueAdapter(Context context, List<Song> playList) {
|
||||||
super(context, R.layout.item_playlist, playList);
|
super(context, R.layout.item_playlist, playList);
|
||||||
this.context = context;
|
this.context = context;
|
||||||
app = (App) context.getApplicationContext();
|
app = (App) context.getApplicationContext();
|
||||||
|
|
@ -227,6 +227,19 @@ public class MusicPlayerRemote implements OnMusicRemoteEventListener {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void moveSong(int from, int to){
|
||||||
|
final int currentPosition = getPosition();
|
||||||
|
Song songToMove = getPlayingQueue().remove(from);
|
||||||
|
getPlayingQueue().add(to, songToMove);
|
||||||
|
if(from > currentPosition && to <= currentPosition){
|
||||||
|
setPosition(getPosition() + 1);
|
||||||
|
} else if(from < currentPosition && to >= currentPosition){
|
||||||
|
setPosition(getPosition() - 1);
|
||||||
|
} else if(from == currentPosition){
|
||||||
|
setPosition(to);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onMusicRemoteEvent(MusicRemoteEvent event) {
|
public void onMusicRemoteEvent(MusicRemoteEvent event) {
|
||||||
notifyOnMusicRemoteEventListeners(event.getAction());
|
notifyOnMusicRemoteEventListeners(event.getAction());
|
||||||
|
|
|
||||||
|
|
@ -5,7 +5,7 @@ import android.content.Context;
|
||||||
import com.afollestad.materialdialogs.MaterialDialog;
|
import com.afollestad.materialdialogs.MaterialDialog;
|
||||||
import com.kabouzeid.materialmusic.App;
|
import com.kabouzeid.materialmusic.App;
|
||||||
import com.kabouzeid.materialmusic.R;
|
import com.kabouzeid.materialmusic.R;
|
||||||
import com.kabouzeid.materialmusic.adapter.PlayListAdapter;
|
import com.kabouzeid.materialmusic.adapter.PlayingQueueAdapter;
|
||||||
import com.kabouzeid.materialmusic.model.Song;
|
import com.kabouzeid.materialmusic.model.Song;
|
||||||
import com.mobeta.android.dslv.DragSortListView;
|
import com.mobeta.android.dslv.DragSortListView;
|
||||||
|
|
||||||
|
|
@ -34,15 +34,13 @@ public class PlayingQueueDialogHelper {
|
||||||
})
|
})
|
||||||
.build();
|
.build();
|
||||||
final DragSortListView dragSortListView = (DragSortListView) dialog.getCustomView().findViewById(R.id.dragSortListView);
|
final DragSortListView dragSortListView = (DragSortListView) dialog.getCustomView().findViewById(R.id.dragSortListView);
|
||||||
final PlayListAdapter playListAdapter = new PlayListAdapter(context, app.getMusicPlayerRemote().getPlayingQueue());
|
final PlayingQueueAdapter playingQueueAdapter = new PlayingQueueAdapter(context, app.getMusicPlayerRemote().getPlayingQueue());
|
||||||
dragSortListView.setAdapter(playListAdapter);
|
dragSortListView.setAdapter(playingQueueAdapter);
|
||||||
dragSortListView.setDropListener(new DragSortListView.DropListener() {
|
dragSortListView.setDropListener(new DragSortListView.DropListener() {
|
||||||
@Override
|
@Override
|
||||||
public void drop(int from, int to) {
|
public void drop(int from, int to) {
|
||||||
Song songToMove = app.getMusicPlayerRemote().getPlayingQueue().get(from);
|
app.getMusicPlayerRemote().moveSong(from, to);
|
||||||
app.getMusicPlayerRemote().getPlayingQueue().remove(from);
|
playingQueueAdapter.notifyDataSetChanged();
|
||||||
app.getMusicPlayerRemote().getPlayingQueue().add(to, songToMove);
|
|
||||||
playListAdapter.notifyDataSetChanged();
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
return dialog;
|
return dialog;
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue