package fr.tvbarthel.simplesoundcloud.library.player;

import fr.tvbarthel.simplesoundcloud.library.models.SoundCloudPlaylist;
import fr.tvbarthel.simplesoundcloud.library.models.SoundCloudTrack;

/**
 * Used to manage the player playlist.
 */
public final class SimpleSoundCloudPlayerPlaylist {

    /**
     * Singleton pattern.
     */
    private static SimpleSoundCloudPlayerPlaylist sInstance;

    /**
     * Current playlist.
     */
    private SoundCloudPlaylist mSoundCloudPlaylist;

    /**
     * Index of the current track.
     */
    private int mCurrentTrackIndex;

    /**
     * Singleton.
     */
    private SimpleSoundCloudPlayerPlaylist() {
        mSoundCloudPlaylist = new SoundCloudPlaylist();
    }

    /**
     * Retrieve the instance of the playlist manager.
     *
     * @return instance.
     */
    public static SimpleSoundCloudPlayerPlaylist getInstance() {
        if (sInstance == null) {
            sInstance = new SimpleSoundCloudPlayerPlaylist();
        }
        return sInstance;
    }

    /**
     * Retrieve the current playlist.
     *
     * @return current playlist.
     */
    public SoundCloudPlaylist getPlaylist() {
        return mSoundCloudPlaylist;
    }

    /**
     * Add a track at the end of the playlist.
     *
     * @param track track to be added.
     */
    public void add(SoundCloudTrack track) {
        add(mSoundCloudPlaylist.getTracks().size(), track);
    }

    /**
     * Add a track to the given position.
     *
     * @param position position of the track to insert
     * @param track    track to insert.
     */
    public void add(int position, SoundCloudTrack track) {
        mSoundCloudPlaylist.addTrack(position, track);
    }

    /**
     * Remove a track from the SoundCloud player playlist.
     * <p/>
     * If the track is currently played, it will be stopped before being removed.
     *
     * @param playlistIndex index of the track to be removed.
     */
    public void remove(int playlistIndex) {

    }

    /**
     * Retrieve the next track.
     *
     * @return next track to be played.
     */
    public SoundCloudTrack next() {
        return new SoundCloudTrack();
    }

    /**
     * Retrieve the previous track.
     *
     * @return previous track to be played.
     */
    public SoundCloudTrack previous() {
        return new SoundCloudTrack();
    }
}

@@ -48,16 +48,45 @@
 layer;%0A%0A
+import java.util.ArrayList;%0A%0A
 import f
@@ -738,24 +738,57 @@
 Playlist();%0A
+        mCurrentTrackIndex = -1;%0A
     %7D%0A%0A    /
@@ -1262,32 +1262,372 @@
 laylist;%0A    %7D%0A%0A
+    /**%0A     * Return the current track.%0A     *%0A     * @return current track or null if none has been added to the player playlist.%0A     */%0A    public SoundCloudTrack getCurrentTrack() %7B%0A        if (mCurrentTrackIndex %3E -1) %7B%0A            return mSoundCloudPlaylist.getTracks().get(mCurrentTrackIndex);%0A        %7D%0A        return null;%0A    %7D%0A%0A
     /**%0A     * A
@@ -2042,32 +2042,118 @@
 dTrack track) %7B%0A
+        if (mCurrentTrackIndex == -1) %7B%0A            mCurrentTrackIndex = 0;%0A        %7D%0A
         mSoundCl
@@ -2380,24 +2380,21 @@
  @param 
-playlist
+track
 Index in
@@ -2435,416 +2435,1052 @@
    *
-/%0A    public void remove(int playlistIndex) %7B%0A%0A    %7D%0A%0A    /**%0A     * Retrieve the next track.%0A     *%0A     * @return next track to be played.%0A     */%0A    public SoundCloudTrack next() %7B%0A        return new SoundCloudTrack();%0A    %7D%0A%0A    /**%0A     * Retrieve the previous track.%0A     *%0A     * @return previous track to be played.%0A     */%0A    public SoundCloudTrack previous() %7B%0A        return new SoundCloudTrack(
+ @return track removed or null if given index can't be found.%0A     */%0A    public SoundCloudTrack remove(int trackIndex) %7B%0A%0A        ArrayList%3CSoundCloudTrack%3E tracks = mSoundCloudPlaylist.getTracks();%0A%0A        // check if track is in the playlist%0A        if (trackIndex %3E= 0 && trackIndex %3C tracks.size()) %7B%0A            return tracks.remove(trackIndex);%0A        %7D%0A%0A        return null;%0A    %7D%0A%0A    /**%0A     * Retrieve the next track.%0A     *%0A     * @return next track to be played.%0A     */%0A    public SoundCloudTrack next() %7B%0A        mCurrentTrackIndex = (mCurrentTrackIndex + 1) %25 mSoundCloudPlaylist.getTracks().size();%0A        return mSoundCloudPlaylist.getTracks().get(mCurrentTrackIndex);%0A    %7D%0A%0A    /**%0A     * Retrieve the previous track.%0A     *%0A     * @return previous track to be played.%0A     */%0A    public SoundCloudTrack previous() %7B%0A        int tracks = mSoundCloudPlaylist.getTracks().size();%0A        mCurrentTrackIndex = (tracks + mCurrentTrackIndex - 1) %25 tracks;%0A        return mSoundCloudPlaylist.getTracks().get(mCurrentTrackIndex
 );%0A 

implement player playlist behavior