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.
|
||||
*/
|
||||
public class PlayListAdapter extends ArrayAdapter<Song> {
|
||||
public class PlayingQueueAdapter extends ArrayAdapter<Song> {
|
||||
private Context context;
|
||||
private App app;
|
||||
|
||||
public PlayListAdapter(Context context, List<Song> playList) {
|
||||
public PlayingQueueAdapter(Context context, List<Song> playList) {
|
||||
super(context, R.layout.item_playlist, playList);
|
||||
this.context = context;
|
||||
app = (App) context.getApplicationContext();
|
||||
|
|
@ -227,6 +227,19 @@ public class MusicPlayerRemote implements OnMusicRemoteEventListener {
|
|||
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
|
||||
public void onMusicRemoteEvent(MusicRemoteEvent event) {
|
||||
notifyOnMusicRemoteEventListeners(event.getAction());
|
||||
|
|
|
|||
|
|
@ -5,7 +5,7 @@ import android.content.Context;
|
|||
import com.afollestad.materialdialogs.MaterialDialog;
|
||||
import com.kabouzeid.materialmusic.App;
|
||||
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.mobeta.android.dslv.DragSortListView;
|
||||
|
||||
|
|
@ -34,15 +34,13 @@ public class PlayingQueueDialogHelper {
|
|||
})
|
||||
.build();
|
||||
final DragSortListView dragSortListView = (DragSortListView) dialog.getCustomView().findViewById(R.id.dragSortListView);
|
||||
final PlayListAdapter playListAdapter = new PlayListAdapter(context, app.getMusicPlayerRemote().getPlayingQueue());
|
||||
dragSortListView.setAdapter(playListAdapter);
|
||||
final PlayingQueueAdapter playingQueueAdapter = new PlayingQueueAdapter(context, app.getMusicPlayerRemote().getPlayingQueue());
|
||||
dragSortListView.setAdapter(playingQueueAdapter);
|
||||
dragSortListView.setDropListener(new DragSortListView.DropListener() {
|
||||
@Override
|
||||
public void drop(int from, int to) {
|
||||
Song songToMove = app.getMusicPlayerRemote().getPlayingQueue().get(from);
|
||||
app.getMusicPlayerRemote().getPlayingQueue().remove(from);
|
||||
app.getMusicPlayerRemote().getPlayingQueue().add(to, songToMove);
|
||||
playListAdapter.notifyDataSetChanged();
|
||||
app.getMusicPlayerRemote().moveSong(from, to);
|
||||
playingQueueAdapter.notifyDataSetChanged();
|
||||
}
|
||||
});
|
||||
return dialog;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue