Search in sources :

Example 1 with MPDArtist

use of org.gateshipone.malp.mpdservice.mpdprotocol.mpdobjects.MPDArtist in project malp by gateship-one.

the class ArtworkManager method bulkLoadImages.

/**
 * Entrance point to start downloading all images for the complete database of the current
 * default MPD server.
 *
 * @param progressCallback Used callback interface to be notified about the download progress.
 */
public void bulkLoadImages(BulkLoadingProgressCallback progressCallback) {
    if (progressCallback == null) {
        return;
    }
    mBulkProgressCallback = progressCallback;
    mArtistList.clear();
    mAlbumList.clear();
    mBulkLoadAlbumsReady = false;
    mBulkLoadArtistsReady = false;
    Log.v(TAG, "Start bulk loading");
    if (HTTPAlbumImageProvider.getInstance(mContext).getActive()) {
        Log.v(TAG, "Try to get all tracks from MPD");
        MPDQueryHandler.getAllTracks(new MPDResponseFileList() {

            @Override
            public void handleTracks(List<MPDFileEntry> fileList, int windowstart, int windowend) {
                Log.v(TAG, "Received track count: " + fileList.size());
                new ParseMPDTrackListTask().execute(fileList);
            }
        });
    } else {
        if (!mAlbumProvider.equals(mContext.getString((R.string.pref_artwork_provider_none_key)))) {
            MPDQueryHandler.getAlbums(new MPDResponseAlbumList() {

                @Override
                public void handleAlbums(List<MPDAlbum> albumList) {
                    new ParseMPDAlbumListTask().execute(albumList);
                }
            });
        }
    }
    if (!mArtistProvider.equals(mContext.getString((R.string.pref_artwork_provider_none_key)))) {
        MPDQueryHandler.getArtists(new MPDResponseArtistList() {

            @Override
            public void handleArtists(List<MPDArtist> artistList) {
                new ParseMPDArtistListTask().execute(artistList);
            }
        });
    }
}
Also used : MPDFileEntry(org.gateshipone.malp.mpdservice.mpdprotocol.mpdobjects.MPDFileEntry) MPDResponseFileList(org.gateshipone.malp.mpdservice.handlers.responsehandler.MPDResponseFileList) MPDResponseAlbumList(org.gateshipone.malp.mpdservice.handlers.responsehandler.MPDResponseAlbumList) MPDArtist(org.gateshipone.malp.mpdservice.mpdprotocol.mpdobjects.MPDArtist) MPDAlbum(org.gateshipone.malp.mpdservice.mpdprotocol.mpdobjects.MPDAlbum) MPDResponseArtistList(org.gateshipone.malp.mpdservice.handlers.responsehandler.MPDResponseArtistList)

Example 2 with MPDArtist

use of org.gateshipone.malp.mpdservice.mpdprotocol.mpdobjects.MPDArtist in project malp by gateship-one.

the class FanartTVManager method getTrackArtistMBID.

/**
 * Wrapper to get an artist out of an {@link MPDTrack}.
 * @param track Track to get artist information for
 * @param listener Response listener
 * @param errorListener Error listener
 */
@Override
public void getTrackArtistMBID(final MPDTrack track, final Response.Listener<String> listener, final FanartFetchError errorListener) {
    // Create a dummy artist
    final MPDArtist artist;
    if (!track.getTrackAlbumArtist().isEmpty()) {
        artist = new MPDArtist(track.getTrackAlbumArtist());
    } else {
        artist = new MPDArtist(track.getTrackArtist());
    }
    if (!track.getTrackAlbumArtistMBID().isEmpty()) {
        artist.addMBID(track.getTrackAlbumArtistMBID());
    }
    getArtists(Uri.encode(artist.getArtistName()), response -> {
        JSONArray artists = null;
        try {
            artists = response.getJSONArray("artists");
            if (!artists.isNull(0)) {
                JSONObject artistObj = artists.getJSONObject(0);
                final String artistMBID = artistObj.getString("id");
                artist.addMBID(artistMBID);
                listener.onResponse(artistMBID);
            }
        } catch (JSONException e) {
            errorListener.fanartFetchError(track);
        }
    }, error -> errorListener.fanartFetchError(track));
}
Also used : JSONObject(org.json.JSONObject) JSONArray(org.json.JSONArray) JSONException(org.json.JSONException) MPDArtist(org.gateshipone.malp.mpdservice.mpdprotocol.mpdobjects.MPDArtist)

Example 3 with MPDArtist

use of org.gateshipone.malp.mpdservice.mpdprotocol.mpdobjects.MPDArtist in project malp by gateship-one.

the class ArtistsFragment method onItemClick.

@Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
    mLastPosition = position;
    MPDArtist artist = (MPDArtist) mArtistAdapter.getItem(position);
    Bitmap bitmap = null;
    // Check if correct view type, to be safe
    if (view instanceof AbsImageListViewItem) {
        bitmap = ((AbsImageListViewItem) view).getBitmap();
    }
    mSelectedCallback.onArtistSelected(artist, bitmap);
}
Also used : Bitmap(android.graphics.Bitmap) AbsImageListViewItem(org.gateshipone.malp.application.listviewitems.AbsImageListViewItem) MPDArtist(org.gateshipone.malp.mpdservice.mpdprotocol.mpdobjects.MPDArtist)

Example 4 with MPDArtist

use of org.gateshipone.malp.mpdservice.mpdprotocol.mpdobjects.MPDArtist in project malp by gateship-one.

the class ArtistsFragment method playArtist.

private void playArtist(int index) {
    MPDArtist artist = (MPDArtist) mArtistAdapter.getItem(index);
    MPDQueryHandler.playArtist(artist.getArtistName(), mAlbumSortOrder);
}
Also used : MPDArtist(org.gateshipone.malp.mpdservice.mpdprotocol.mpdobjects.MPDArtist)

Example 5 with MPDArtist

use of org.gateshipone.malp.mpdservice.mpdprotocol.mpdobjects.MPDArtist in project malp by gateship-one.

the class MPDQueryHandler method handleMessage.

/**
 * This is the main entry point of messages.
 * Here all possible messages types need to be handled with the MPDConnection.
 * Have a look into the baseclass MPDGenericHandler for more information about the handling.
 *
 * @param msg Message to process.
 */
@Override
public void handleMessage(Message msg) {
    // Call the baseclass handleMessage method here to ensure that the messages handled
    // by the baseclass are handled in subclasses as well.
    super.handleMessage(msg);
    // Type checking
    if (!(msg.obj instanceof MPDHandlerAction)) {
        /* Check if the message object is of correct type. Otherwise just abort here. */
        return;
    }
    MPDHandlerAction mpdAction = (MPDHandlerAction) msg.obj;
    // ResponseHandler used to return the requested items to the caller
    MPDResponseHandler responseHandler;
    /*
         * All messages are handled the same way:
         *  * Check which action was requested
         *  * Check if a ResponseHandler is necessary and also provided. (If not just abort here)
         *  * Request the list of data objects from the MPDConnection (and therefor from the server)
         *  * Pack the response in a Message requested from the given ResponseHandler.
         *  * Send the message to the ResponseHandler
         */
    MPDHandlerAction.NET_HANDLER_ACTION action = mpdAction.getAction();
    try {
        if (action == MPDHandlerAction.NET_HANDLER_ACTION.ACTION_GET_ALBUMS) {
            responseHandler = mpdAction.getResponseHandler();
            if (!(responseHandler instanceof MPDResponseAlbumList)) {
                return;
            }
            List<MPDAlbum> albumList = MPDInterface.mInstance.getAlbums();
            ((MPDResponseAlbumList) responseHandler).sendAlbums(albumList);
        } else if (action == MPDHandlerAction.NET_HANDLER_ACTION.ACTION_GET_ALBUMS_IN_PATH) {
            responseHandler = mpdAction.getResponseHandler();
            if (!(responseHandler instanceof MPDResponseAlbumList)) {
                return;
            }
            String path = mpdAction.getStringExtra(MPDHandlerAction.NET_HANDLER_EXTRA_STRING.EXTRA_PATH);
            List<MPDAlbum> albumList = MPDInterface.mInstance.getAlbumsInPath(path);
            ((MPDResponseAlbumList) responseHandler).sendAlbums(albumList);
        } else if (action == MPDHandlerAction.NET_HANDLER_ACTION.ACTION_PLAY_ALBUMS_IN_PATH) {
            String path = mpdAction.getStringExtra(MPDHandlerAction.NET_HANDLER_EXTRA_STRING.EXTRA_PATH);
            List<MPDAlbum> albumList = MPDInterface.mInstance.getAlbumsInPath(path);
            MPDInterface.mInstance.clearPlaylist();
            for (MPDAlbum album : albumList) {
                MPDInterface.mInstance.addAlbumTracks(album.getName(), album.getArtistName(), album.getMBID());
            }
            MPDInterface.mInstance.playSongIndex(0);
        } else if (action == MPDHandlerAction.NET_HANDLER_ACTION.ACTION_GET_ARTIST_ALBUMS) {
            String artistName = mpdAction.getStringExtra(MPDHandlerAction.NET_HANDLER_EXTRA_STRING.EXTRA_ARTIST_NAME);
            responseHandler = mpdAction.getResponseHandler();
            if (!(responseHandler instanceof MPDResponseAlbumList) || (null == artistName)) {
                return;
            }
            List<MPDAlbum> albumList = MPDInterface.mInstance.getArtistAlbums(artistName);
            ((MPDResponseAlbumList) responseHandler).sendAlbums(albumList);
        } else if (action == MPDHandlerAction.NET_HANDLER_ACTION.ACTION_GET_ARTISTSORT_ALBUMS) {
            String artistName = mpdAction.getStringExtra(MPDHandlerAction.NET_HANDLER_EXTRA_STRING.EXTRA_ARTIST_NAME);
            responseHandler = mpdAction.getResponseHandler();
            if (!(responseHandler instanceof MPDResponseAlbumList) || (null == artistName)) {
                return;
            }
            List<MPDAlbum> albumList = MPDInterface.mInstance.getArtistSortAlbums(artistName);
            ((MPDResponseAlbumList) responseHandler).sendAlbums(albumList);
        } else if (action == MPDHandlerAction.NET_HANDLER_ACTION.ACTION_GET_ARTISTS) {
            responseHandler = mpdAction.getResponseHandler();
            if (!(responseHandler instanceof MPDResponseArtistList)) {
                return;
            }
            List<MPDArtist> artistList = MPDInterface.mInstance.getArtists();
            ((MPDResponseArtistList) responseHandler).sendArtists(artistList);
        } else if (action == MPDHandlerAction.NET_HANDLER_ACTION.ACTION_GET_ARTISTSORT) {
            responseHandler = mpdAction.getResponseHandler();
            if (!(responseHandler instanceof MPDResponseArtistList)) {
                return;
            }
            List<MPDArtist> artistList = MPDInterface.mInstance.getArtistsSort();
            ((MPDResponseArtistList) responseHandler).sendArtists(artistList);
        } else if (action == MPDHandlerAction.NET_HANDLER_ACTION.ACTION_GET_ALBUMARTISTS) {
            responseHandler = mpdAction.getResponseHandler();
            if (!(responseHandler instanceof MPDResponseArtistList)) {
                return;
            }
            MPDCapabilities caps = MPDInterface.mInstance.getServerCapabilities();
            List<MPDArtist> artistList;
            // Check if server supports the right tag, otherwise use fallback list
            if (null != caps && caps.hasTagAlbumArtist()) {
                artistList = MPDInterface.mInstance.getAlbumArtists();
            } else {
                // If server does not support the albumartist tag
                artistList = MPDInterface.mInstance.getArtists();
            }
            ((MPDResponseArtistList) responseHandler).sendArtists(artistList);
        } else if (action == MPDHandlerAction.NET_HANDLER_ACTION.ACTION_GET_ALBUMARTISTSORT) {
            responseHandler = mpdAction.getResponseHandler();
            if (!(responseHandler instanceof MPDResponseArtistList)) {
                return;
            }
            MPDCapabilities caps = MPDInterface.mInstance.getServerCapabilities();
            List<MPDArtist> artistList;
            // Check if server supports the right tag, otherwise use fallback list
            if (null != caps && caps.hasTagAlbumArtist()) {
                artistList = MPDInterface.mInstance.getAlbumArtistsSort();
            } else {
                // If server does not support the albumartist tag
                artistList = MPDInterface.mInstance.getArtistsSort();
            }
            ((MPDResponseArtistList) responseHandler).sendArtists(artistList);
        } else if (action == MPDHandlerAction.NET_HANDLER_ACTION.ACTION_GET_ALBUM_TRACKS) {
            String albumName = mpdAction.getStringExtra(MPDHandlerAction.NET_HANDLER_EXTRA_STRING.EXTRA_ALBUM_NAME);
            String albumMBID = mpdAction.getStringExtra(MPDHandlerAction.NET_HANDLER_EXTRA_STRING.EXTRA_ALBUM_MBID);
            responseHandler = mpdAction.getResponseHandler();
            if (!(responseHandler instanceof MPDResponseFileList) || (null == albumName)) {
                return;
            }
            List<MPDFileEntry> trackList = MPDInterface.mInstance.getAlbumTracks(albumName, albumMBID);
            ((MPDResponseFileList) responseHandler).sendFileList(trackList);
        } else if (action == MPDHandlerAction.NET_HANDLER_ACTION.ACTION_GET_TRACKS) {
            responseHandler = mpdAction.getResponseHandler();
            if (!(responseHandler instanceof MPDResponseFileList)) {
                return;
            }
            List<MPDFileEntry> trackList = MPDInterface.mInstance.getAllTracks();
            ((MPDResponseFileList) responseHandler).sendFileList(trackList);
        } else if (action == MPDHandlerAction.NET_HANDLER_ACTION.ACTION_GET_ARTIST_ALBUM_TRACKS) {
            String artistName = mpdAction.getStringExtra(MPDHandlerAction.NET_HANDLER_EXTRA_STRING.EXTRA_ARTIST_NAME);
            String albumName = mpdAction.getStringExtra(MPDHandlerAction.NET_HANDLER_EXTRA_STRING.EXTRA_ALBUM_NAME);
            String albumMBID = mpdAction.getStringExtra(MPDHandlerAction.NET_HANDLER_EXTRA_STRING.EXTRA_ALBUM_MBID);
            responseHandler = mpdAction.getResponseHandler();
            if (!(responseHandler instanceof MPDResponseFileList) || (null == albumName) || (null == artistName)) {
                return;
            }
            List<MPDFileEntry> trackList = MPDInterface.mInstance.getArtistAlbumTracks(albumName, artistName, albumMBID);
            ((MPDResponseFileList) responseHandler).sendFileList(trackList);
        } else if (action == MPDHandlerAction.NET_HANDLER_ACTION.ACTION_GET_ARTIST_SORT_ALBUM_TRACKS) {
            String artistName = mpdAction.getStringExtra(MPDHandlerAction.NET_HANDLER_EXTRA_STRING.EXTRA_ARTIST_NAME);
            String albumName = mpdAction.getStringExtra(MPDHandlerAction.NET_HANDLER_EXTRA_STRING.EXTRA_ALBUM_NAME);
            String albumMBID = mpdAction.getStringExtra(MPDHandlerAction.NET_HANDLER_EXTRA_STRING.EXTRA_ALBUM_MBID);
            responseHandler = mpdAction.getResponseHandler();
            if (!(responseHandler instanceof MPDResponseFileList) || (null == albumName) || (null == artistName)) {
                return;
            }
            List<MPDFileEntry> trackList = MPDInterface.mInstance.getArtistSortAlbumTracks(albumName, artistName, albumMBID);
            ((MPDResponseFileList) responseHandler).sendFileList(trackList);
        } else if (action == MPDHandlerAction.NET_HANDLER_ACTION.ACTION_GET_CURRENT_PLAYLIST) {
            responseHandler = mpdAction.getResponseHandler();
            if (!(responseHandler instanceof MPDResponseFileList)) {
                return;
            }
            List<MPDFileEntry> trackList = MPDInterface.mInstance.getCurrentPlaylist();
            ((MPDResponseFileList) responseHandler).sendFileList(trackList);
        } else if (action == MPDHandlerAction.NET_HANDLER_ACTION.ACTION_GET_CURRENT_PLAYLIST_WINDOW) {
            int start = mpdAction.getIntExtra(MPDHandlerAction.NET_HANDLER_EXTRA_INT.EXTRA_WINDOW_START);
            int end = mpdAction.getIntExtra(MPDHandlerAction.NET_HANDLER_EXTRA_INT.EXTRA_WINDOW_END);
            responseHandler = mpdAction.getResponseHandler();
            if (!(responseHandler instanceof MPDResponseFileList)) {
                return;
            }
            List<MPDFileEntry> trackList = MPDInterface.mInstance.getCurrentPlaylistWindow(start, end);
            ((MPDResponseFileList) responseHandler).sendFileList(trackList, start, end);
        } else if (action == MPDHandlerAction.NET_HANDLER_ACTION.ACTION_GET_SAVED_PLAYLIST) {
            String playlistName = mpdAction.getStringExtra(MPDHandlerAction.NET_HANDLER_EXTRA_STRING.EXTRA_PLAYLIST_NAME);
            responseHandler = mpdAction.getResponseHandler();
            if (!(responseHandler instanceof MPDResponseFileList)) {
                return;
            }
            List<MPDFileEntry> trackList = MPDInterface.mInstance.getSavedPlaylist(playlistName);
            ((MPDResponseFileList) responseHandler).sendFileList(trackList);
        } else if (action == MPDHandlerAction.NET_HANDLER_ACTION.ACTION_GET_SAVED_PLAYLISTS) {
            responseHandler = mpdAction.getResponseHandler();
            if (!(responseHandler instanceof MPDResponseFileList)) {
                return;
            }
            List<MPDFileEntry> playlistList = MPDInterface.mInstance.getPlaylists();
            ((MPDResponseFileList) responseHandler).sendFileList(playlistList);
        } else if (action == MPDHandlerAction.NET_HANDLER_ACTION.ACTION_SAVE_PLAYLIST) {
            String playlistName = mpdAction.getStringExtra(MPDHandlerAction.NET_HANDLER_EXTRA_STRING.EXTRA_PLAYLIST_NAME);
            MPDInterface.mInstance.savePlaylist(playlistName);
        } else if (action == MPDHandlerAction.NET_HANDLER_ACTION.ACTION_ADD_SONG_TO_PLAYLIST) {
            String playlistName = mpdAction.getStringExtra(MPDHandlerAction.NET_HANDLER_EXTRA_STRING.EXTRA_PLAYLIST_NAME);
            String path = mpdAction.getStringExtra(MPDHandlerAction.NET_HANDLER_EXTRA_STRING.EXTRA_PATH);
            MPDInterface.mInstance.addSongToPlaylist(playlistName, path);
        } else if (action == MPDHandlerAction.NET_HANDLER_ACTION.ACTION_REMOVE_SONG_FROM_PLAYLIST) {
            String playlistName = mpdAction.getStringExtra(MPDHandlerAction.NET_HANDLER_EXTRA_STRING.EXTRA_PLAYLIST_NAME);
            int position = mpdAction.getIntExtra(MPDHandlerAction.NET_HANDLER_EXTRA_INT.EXTRA_SONG_INDEX);
            MPDInterface.mInstance.removeSongFromPlaylist(playlistName, position);
        } else if (action == MPDHandlerAction.NET_HANDLER_ACTION.ACTION_REMOVE_PLAYLIST) {
            String playlistName = mpdAction.getStringExtra(MPDHandlerAction.NET_HANDLER_EXTRA_STRING.EXTRA_PLAYLIST_NAME);
            MPDInterface.mInstance.removePlaylist(playlistName);
        } else if (action == MPDHandlerAction.NET_HANDLER_ACTION.ACTION_LOAD_PLAYLIST) {
            String playlistName = mpdAction.getStringExtra(MPDHandlerAction.NET_HANDLER_EXTRA_STRING.EXTRA_PLAYLIST_NAME);
            MPDInterface.mInstance.loadPlaylist(playlistName);
        } else if (action == MPDHandlerAction.NET_HANDLER_ACTION.ACTION_PLAY_PLAYLIST) {
            String playlistName = mpdAction.getStringExtra(MPDHandlerAction.NET_HANDLER_EXTRA_STRING.EXTRA_PLAYLIST_NAME);
            MPDInterface.mInstance.clearPlaylist();
            MPDInterface.mInstance.loadPlaylist(playlistName);
            MPDInterface.mInstance.playSongIndex(0);
        } else if (action == MPDHandlerAction.NET_HANDLER_ACTION.ACTION_ADD_ARTIST_ALBUM) {
            String albumname = mpdAction.getStringExtra(MPDHandlerAction.NET_HANDLER_EXTRA_STRING.EXTRA_ALBUM_NAME);
            String artistname = mpdAction.getStringExtra(MPDHandlerAction.NET_HANDLER_EXTRA_STRING.EXTRA_ARTIST_NAME);
            String albumMBID = mpdAction.getStringExtra(MPDHandlerAction.NET_HANDLER_EXTRA_STRING.EXTRA_ALBUM_MBID);
            MPDInterface.mInstance.addAlbumTracks(albumname, artistname, albumMBID);
        } else if (action == MPDHandlerAction.NET_HANDLER_ACTION.ACTION_ADD_ARTIST_SORT_ALBUM) {
            String albumname = mpdAction.getStringExtra(MPDHandlerAction.NET_HANDLER_EXTRA_STRING.EXTRA_ALBUM_NAME);
            String artistname = mpdAction.getStringExtra(MPDHandlerAction.NET_HANDLER_EXTRA_STRING.EXTRA_ARTIST_NAME);
            String albumMBID = mpdAction.getStringExtra(MPDHandlerAction.NET_HANDLER_EXTRA_STRING.EXTRA_ALBUM_MBID);
            MPDInterface.mInstance.addArtistSortAlbumTracks(albumname, artistname, albumMBID);
        } else if (action == MPDHandlerAction.NET_HANDLER_ACTION.ACTION_PLAY_ARTIST_ALBUM) {
            String albumname = mpdAction.getStringExtra(MPDHandlerAction.NET_HANDLER_EXTRA_STRING.EXTRA_ALBUM_NAME);
            String artistname = mpdAction.getStringExtra(MPDHandlerAction.NET_HANDLER_EXTRA_STRING.EXTRA_ARTIST_NAME);
            String albumMBID = mpdAction.getStringExtra(MPDHandlerAction.NET_HANDLER_EXTRA_STRING.EXTRA_ALBUM_MBID);
            MPDInterface.mInstance.clearPlaylist();
            MPDInterface.mInstance.addAlbumTracks(albumname, artistname, albumMBID);
            MPDInterface.mInstance.playSongIndex(0);
        } else if (action == MPDHandlerAction.NET_HANDLER_ACTION.ACTION_PLAY_ARTIST_SORT_ALBUM) {
            String albumname = mpdAction.getStringExtra(MPDHandlerAction.NET_HANDLER_EXTRA_STRING.EXTRA_ALBUM_NAME);
            String artistname = mpdAction.getStringExtra(MPDHandlerAction.NET_HANDLER_EXTRA_STRING.EXTRA_ARTIST_NAME);
            String albumMBID = mpdAction.getStringExtra(MPDHandlerAction.NET_HANDLER_EXTRA_STRING.EXTRA_ALBUM_MBID);
            MPDInterface.mInstance.clearPlaylist();
            MPDInterface.mInstance.addArtistSortAlbumTracks(albumname, artistname, albumMBID);
            MPDInterface.mInstance.playSongIndex(0);
        } else if (action == MPDHandlerAction.NET_HANDLER_ACTION.ACTION_ADD_ARTIST) {
            String artistname = mpdAction.getStringExtra(MPDHandlerAction.NET_HANDLER_EXTRA_STRING.EXTRA_ARTIST_NAME);
            MPDAlbum.MPD_ALBUM_SORT_ORDER sortOrder = MPDAlbum.MPD_ALBUM_SORT_ORDER.values()[mpdAction.getIntExtra(MPDHandlerAction.NET_HANDLER_EXTRA_INT.EXTRA_SORT_ORDER)];
            MPDInterface.mInstance.addArtist(artistname, sortOrder);
        } else if (action == MPDHandlerAction.NET_HANDLER_ACTION.ACTION_PLAY_ARTIST) {
            String artistname = mpdAction.getStringExtra(MPDHandlerAction.NET_HANDLER_EXTRA_STRING.EXTRA_ARTIST_NAME);
            MPDAlbum.MPD_ALBUM_SORT_ORDER sortOrder = MPDAlbum.MPD_ALBUM_SORT_ORDER.values()[mpdAction.getIntExtra(MPDHandlerAction.NET_HANDLER_EXTRA_INT.EXTRA_SORT_ORDER)];
            MPDInterface.mInstance.clearPlaylist();
            MPDInterface.mInstance.addArtist(artistname, sortOrder);
            MPDInterface.mInstance.playSongIndex(0);
        } else if (action == MPDHandlerAction.NET_HANDLER_ACTION.ACTION_PLAY_ARTIST_SORT) {
            String artistname = mpdAction.getStringExtra(MPDHandlerAction.NET_HANDLER_EXTRA_STRING.EXTRA_ARTIST_NAME);
            MPDAlbum.MPD_ALBUM_SORT_ORDER sortOrder = MPDAlbum.MPD_ALBUM_SORT_ORDER.values()[mpdAction.getIntExtra(MPDHandlerAction.NET_HANDLER_EXTRA_INT.EXTRA_SORT_ORDER)];
            MPDInterface.mInstance.clearPlaylist();
            MPDInterface.mInstance.addArtistSort(artistname, sortOrder);
            MPDInterface.mInstance.playSongIndex(0);
        } else if (action == MPDHandlerAction.NET_HANDLER_ACTION.ACTION_ADD_PATH) {
            String url = mpdAction.getStringExtra(MPDHandlerAction.NET_HANDLER_EXTRA_STRING.EXTRA_SONG_URL);
            MPDInterface.mInstance.addSong(url);
        } else if (action == MPDHandlerAction.NET_HANDLER_ACTION.ACTION_PLAY_SONG_NEXT) {
            String url = mpdAction.getStringExtra(MPDHandlerAction.NET_HANDLER_EXTRA_STRING.EXTRA_SONG_URL);
            MPDCurrentStatus status = MPDInterface.mInstance.getCurrentServerStatus();
            MPDInterface.mInstance.addSongatIndex(url, status.getCurrentSongIndex() + 1);
        } else if (action == MPDHandlerAction.NET_HANDLER_ACTION.ACTION_PLAY_SONG) {
            String url = mpdAction.getStringExtra(MPDHandlerAction.NET_HANDLER_EXTRA_STRING.EXTRA_SONG_URL);
            MPDCapabilities caps = MPDInterface.mInstance.getServerCapabilities();
            /*
                 * Check if song is already enqueued in the current playlist. If it is get the position
                 * and just jump to the song position.
                 *
                 * Otherwise add it to the last playlist position and jump there.
                 */
            List<MPDFileEntry> playlistFindTracks = null;
            if (caps != null && caps.hasPlaylistFind()) {
                playlistFindTracks = MPDInterface.mInstance.getPlaylistFindTrack(url);
            }
            if (playlistFindTracks != null && playlistFindTracks.size() > 0) {
                // Song already found in the playlist. Jump there.
                MPDInterface.mInstance.playSongIndex(((MPDTrack) playlistFindTracks.get(0)).getSongPosition());
            } else {
                // Not part of the current playlist. Add it at the end of the playlist and play it from there.
                MPDInterface.mInstance.addSong(url);
                MPDCurrentStatus status = MPDInterface.mInstance.getCurrentServerStatus();
                MPDInterface.mInstance.playSongIndex(status.getPlaylistLength() - 1);
            }
        } else if (action == MPDHandlerAction.NET_HANDLER_ACTION.ACTION_CLEAR_CURRENT_PLAYLIST) {
            MPDInterface.mInstance.clearPlaylist();
        } else if (action == MPDHandlerAction.NET_HANDLER_ACTION.ACTION_SHUFFLE_CURRENT_PLAYLIST) {
            MPDInterface.mInstance.shufflePlaylist();
        } else if (action == MPDHandlerAction.NET_HANDLER_ACTION.ACTION_MOVE_SONG_AFTER_CURRENT) {
            MPDCurrentStatus status = MPDInterface.mInstance.getCurrentServerStatus();
            int index = mpdAction.getIntExtra(MPDHandlerAction.NET_HANDLER_EXTRA_INT.EXTRA_SONG_INDEX);
            if (index < status.getCurrentSongIndex()) {
                MPDInterface.mInstance.moveSongFromTo(index, status.getCurrentSongIndex());
            } else if (index > status.getCurrentSongIndex()) {
                MPDInterface.mInstance.moveSongFromTo(index, status.getCurrentSongIndex() + 1);
            }
        } else if (action == MPDHandlerAction.NET_HANDLER_ACTION.ACTION_REMOVE_SONG_FROM_CURRENT_PLAYLIST) {
            int index = mpdAction.getIntExtra(MPDHandlerAction.NET_HANDLER_EXTRA_INT.EXTRA_SONG_INDEX);
            MPDInterface.mInstance.removeIndex(index);
        } else if (action == MPDHandlerAction.NET_HANDLER_ACTION.ACTION_REMOVE_RANGE_FROM_CURRENT_PLAYLIST) {
            int start = mpdAction.getIntExtra(MPDHandlerAction.NET_HANDLER_EXTRA_INT.EXTRA_WINDOW_START);
            int end = mpdAction.getIntExtra(MPDHandlerAction.NET_HANDLER_EXTRA_INT.EXTRA_WINDOW_END);
            MPDInterface.mInstance.removeRange(start, end);
        } else if (action == MPDHandlerAction.NET_HANDLER_ACTION.ACTION_GET_FILES) {
            String path = mpdAction.getStringExtra(MPDHandlerAction.NET_HANDLER_EXTRA_STRING.EXTRA_PATH);
            responseHandler = mpdAction.getResponseHandler();
            if (!(responseHandler instanceof MPDResponseFileList)) {
                return;
            }
            List<MPDFileEntry> fileList = MPDInterface.mInstance.getFiles(path);
            ((MPDResponseFileList) responseHandler).sendFileList(fileList);
        } else if (action == MPDHandlerAction.NET_HANDLER_ACTION.ACTION_PLAY_DIRECTORY) {
            String path = mpdAction.getStringExtra(MPDHandlerAction.NET_HANDLER_EXTRA_STRING.EXTRA_PATH);
            MPDInterface.mInstance.clearPlaylist();
            MPDInterface.mInstance.addSong(path);
            MPDInterface.mInstance.playSongIndex(0);
        } else if (action == MPDHandlerAction.NET_HANDLER_ACTION.ACTION_GET_OUTPUTS) {
            responseHandler = mpdAction.getResponseHandler();
            List<MPDOutput> outputList = MPDInterface.mInstance.getOutputs();
            ((MPDResponseOutputList) responseHandler).sendOutputs(outputList);
        } else if (action == MPDHandlerAction.NET_HANDLER_ACTION.ACTION_GET_SERVER_STATISTICS) {
            responseHandler = mpdAction.getResponseHandler();
            MPDStatistics stats;
            stats = MPDInterface.mInstance.getServerStatistics();
            ((MPDResponseServerStatistics) responseHandler).sendServerStatistics(stats);
        } else if (action == MPDHandlerAction.NET_HANDLER_ACTION.ACTION_UPDATE_DATABASE) {
            String updatePath = mpdAction.getStringExtra(MPDHandlerAction.NET_HANDLER_EXTRA_STRING.EXTRA_PATH);
            MPDInterface.mInstance.updateDatabase(updatePath);
        } else if (action == MPDHandlerAction.NET_HANDLER_ACTION.ACTION_SEARCH_FILES) {
            String term = mpdAction.getStringExtra(MPDHandlerAction.NET_HANDLER_EXTRA_STRING.EXTRA_SEARCH_TERM);
            MPDCommands.MPD_SEARCH_TYPE type = MPDCommands.MPD_SEARCH_TYPE.values()[mpdAction.getIntExtra(MPDHandlerAction.NET_HANDLER_EXTRA_INT.EXTRA_SEARCH_TYPE)];
            responseHandler = mpdAction.getResponseHandler();
            if (!(responseHandler instanceof MPDResponseFileList)) {
                return;
            }
            List<MPDFileEntry> fileList = MPDInterface.mInstance.getSearchedFiles(term, type);
            ((MPDResponseFileList) responseHandler).sendFileList(fileList);
        } else if (action == MPDHandlerAction.NET_HANDLER_ACTION.ACTION_ADD_SEARCH_FILES) {
            String term = mpdAction.getStringExtra(MPDHandlerAction.NET_HANDLER_EXTRA_STRING.EXTRA_SEARCH_TERM);
            MPDCommands.MPD_SEARCH_TYPE type = MPDCommands.MPD_SEARCH_TYPE.values()[mpdAction.getIntExtra(MPDHandlerAction.NET_HANDLER_EXTRA_INT.EXTRA_SEARCH_TYPE)];
            MPDCapabilities caps = MPDInterface.mInstance.getServerCapabilities();
            // Check if server has the add search result capability
            if (null != caps && caps.hasSearchAdd()) {
                MPDInterface.mInstance.addSearchedFiles(term, type);
            } else {
                // Fetch search results and add them
                List<MPDFileEntry> searchResults = MPDInterface.mInstance.getSearchedFiles(term, type);
                MPDInterface.mInstance.addTrackList(searchResults);
            }
        } else if (action == MPDHandlerAction.NET_HANDLER_ACTION.ACTION_PLAY_SEARCH_FILES) {
            String term = mpdAction.getStringExtra(MPDHandlerAction.NET_HANDLER_EXTRA_STRING.EXTRA_SEARCH_TERM);
            MPDCommands.MPD_SEARCH_TYPE type = MPDCommands.MPD_SEARCH_TYPE.values()[mpdAction.getIntExtra(MPDHandlerAction.NET_HANDLER_EXTRA_INT.EXTRA_SEARCH_TYPE)];
            MPDInterface.mInstance.clearPlaylist();
            // Check if server has the add search result capability
            if (MPDInterface.mInstance.getServerCapabilities().hasSearchAdd()) {
                MPDInterface.mInstance.addSearchedFiles(term, type);
            } else {
                // Fetch search results and add them
                List<MPDFileEntry> searchResults = MPDInterface.mInstance.getSearchedFiles(term, type);
                MPDInterface.mInstance.addTrackList(searchResults);
            }
            MPDInterface.mInstance.playSongIndex(0);
        }
    } catch (MPDException e) {
        handleMPDError(e);
    }
}
Also used : MPDResponseFileList(org.gateshipone.malp.mpdservice.handlers.responsehandler.MPDResponseFileList) MPDResponseAlbumList(org.gateshipone.malp.mpdservice.handlers.responsehandler.MPDResponseAlbumList) MPDAlbum(org.gateshipone.malp.mpdservice.mpdprotocol.mpdobjects.MPDAlbum) MPDResponseArtistList(org.gateshipone.malp.mpdservice.handlers.responsehandler.MPDResponseArtistList) MPDResponseFileList(org.gateshipone.malp.mpdservice.handlers.responsehandler.MPDResponseFileList) List(java.util.List) MPDResponseAlbumList(org.gateshipone.malp.mpdservice.handlers.responsehandler.MPDResponseAlbumList) MPDResponseOutputList(org.gateshipone.malp.mpdservice.handlers.responsehandler.MPDResponseOutputList) MPDStatistics(org.gateshipone.malp.mpdservice.mpdprotocol.mpdobjects.MPDStatistics) MPDFileEntry(org.gateshipone.malp.mpdservice.mpdprotocol.mpdobjects.MPDFileEntry) MPDCurrentStatus(org.gateshipone.malp.mpdservice.mpdprotocol.mpdobjects.MPDCurrentStatus) MPDException(org.gateshipone.malp.mpdservice.mpdprotocol.MPDException) MPDResponseHandler(org.gateshipone.malp.mpdservice.handlers.responsehandler.MPDResponseHandler) MPDArtist(org.gateshipone.malp.mpdservice.mpdprotocol.mpdobjects.MPDArtist) MPDCapabilities(org.gateshipone.malp.mpdservice.mpdprotocol.MPDCapabilities) MPDCommands(org.gateshipone.malp.mpdservice.mpdprotocol.MPDCommands) MPDOutput(org.gateshipone.malp.mpdservice.mpdprotocol.mpdobjects.MPDOutput) MPDResponseArtistList(org.gateshipone.malp.mpdservice.handlers.responsehandler.MPDResponseArtistList) MPDResponseOutputList(org.gateshipone.malp.mpdservice.handlers.responsehandler.MPDResponseOutputList)

Aggregations

MPDArtist (org.gateshipone.malp.mpdservice.mpdprotocol.mpdobjects.MPDArtist)15 MPDAlbum (org.gateshipone.malp.mpdservice.mpdprotocol.mpdobjects.MPDAlbum)5 Bitmap (android.graphics.Bitmap)3 HashMap (java.util.HashMap)3 MPDTrack (org.gateshipone.malp.mpdservice.mpdprotocol.mpdobjects.MPDTrack)3 SharedPreferences (android.content.SharedPreferences)2 Bundle (android.os.Bundle)2 AbsListView (android.widget.AbsListView)2 AdapterView (android.widget.AdapterView)2 GridView (android.widget.GridView)2 ArrayList (java.util.ArrayList)2 List (java.util.List)2 MPDResponseAlbumList (org.gateshipone.malp.mpdservice.handlers.responsehandler.MPDResponseAlbumList)2 MPDResponseArtistList (org.gateshipone.malp.mpdservice.handlers.responsehandler.MPDResponseArtistList)2 MPDResponseFileList (org.gateshipone.malp.mpdservice.handlers.responsehandler.MPDResponseFileList)2 MPDFileEntry (org.gateshipone.malp.mpdservice.mpdprotocol.mpdobjects.MPDFileEntry)2 BroadcastReceiver (android.content.BroadcastReceiver)1 Context (android.content.Context)1 Intent (android.content.Intent)1 IntentFilter (android.content.IntentFilter)1