Search in sources :

Example 6 with MPDAlbum

use of org.gateshipone.malp.mpdservice.mpdprotocol.mpdobjects.MPDAlbum 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)

Example 7 with MPDAlbum

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

the class AlbumsFragment method playAlbum.

/**
 * Plays the album selected by the user
 * @param index Index of the selected album
 */
private void playAlbum(int index) {
    MPDAlbum album = (MPDAlbum) mAlbumsAdapter.getItem(index);
    // support group commands and therefore do not provide artist tags for albums)
    if (mArtist != null && !mArtist.getArtistName().isEmpty() && album.getArtistName().isEmpty()) {
        album.setArtistName(mArtist.getArtistName());
        album.setArtistSortName(mArtist.getArtistName());
    }
    MPDQueryHandler.playArtistAlbum(album.getName(), album.getArtistName(), album.getMBID());
}
Also used : MPDAlbum(org.gateshipone.malp.mpdservice.mpdprotocol.mpdobjects.MPDAlbum)

Example 8 with MPDAlbum

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

the class AlbumsFragment method onItemClick.

@Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
    mLastPosition = position;
    MPDAlbum album = (MPDAlbum) mAlbumsAdapter.getItem(position);
    Bitmap bitmap = null;
    // Check if correct view type, to be safe
    if (view instanceof AbsImageListViewItem) {
        bitmap = ((AbsImageListViewItem) view).getBitmap();
    }
    // support group commands and therefore do not provide artist tags for albums)
    if (mArtist != null && !mArtist.getArtistName().isEmpty() && album.getArtistName().isEmpty()) {
        album.setArtistName(mArtist.getArtistName());
        album.setArtistSortName(mArtist.getArtistName());
    }
    // Check if the album already has an artist set. If not use the artist of the fragment
    mAlbumSelectCallback.onAlbumSelected(album, bitmap);
}
Also used : Bitmap(android.graphics.Bitmap) AbsImageListViewItem(org.gateshipone.malp.application.listviewitems.AbsImageListViewItem) MPDAlbum(org.gateshipone.malp.mpdservice.mpdprotocol.mpdobjects.MPDAlbum)

Example 9 with MPDAlbum

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

the class MainActivity method onContextItemSelected.

@Override
public boolean onContextItemSelected(MenuItem item) {
    AdapterView.AdapterContextMenuInfo info = (AdapterView.AdapterContextMenuInfo) item.getMenuInfo();
    if (info == null) {
        return super.onContextItemSelected(item);
    }
    CurrentPlaylistView currentPlaylistView = findViewById(R.id.now_playing_playlist);
    if (currentPlaylistView != null && mNowPlayingDragStatus == DRAG_STATUS.DRAGGED_UP) {
        MPDTrack track = (MPDTrack) currentPlaylistView.getItem(info.position);
        switch(item.getItemId()) {
            case R.id.action_song_play_next:
                MPDQueryHandler.playIndexAsNext(info.position);
                return true;
            case R.id.action_add_to_saved_playlist:
                // open dialog in order to save the current playlist as a playlist in the mediastore
                ChoosePlaylistDialog choosePlaylistDialog = new ChoosePlaylistDialog();
                Bundle args = new Bundle();
                args.putBoolean(ChoosePlaylistDialog.EXTRA_SHOW_NEW_ENTRY, true);
                choosePlaylistDialog.setCallback(new AddPathToPlaylist(track, this));
                choosePlaylistDialog.setArguments(args);
                choosePlaylistDialog.show(getSupportFragmentManager(), "ChoosePlaylistDialog");
                return true;
            case R.id.action_remove_song:
                MPDQueryHandler.removeSongFromCurrentPlaylist(info.position);
                return true;
            case R.id.action_remove_album:
                currentPlaylistView.removeAlbumFrom(info.position);
                return true;
            case R.id.action_show_artist:
                if (mUseArtistSort) {
                    onArtistSelected(new MPDArtist(track.getTrackArtistSort()), null);
                } else {
                    onArtistSelected(new MPDArtist(track.getTrackArtist()), null);
                }
                return true;
            case R.id.action_show_album:
                MPDAlbum tmpAlbum = new MPDAlbum(track.getTrackAlbum());
                // Set album artist
                if (!track.getTrackAlbumArtist().isEmpty()) {
                    tmpAlbum.setArtistName(track.getTrackAlbumArtist());
                } else {
                    tmpAlbum.setArtistName(track.getTrackArtist());
                }
                // Set albumartistsort
                if (!track.getTrackAlbumArtistSort().isEmpty()) {
                    tmpAlbum.setArtistSortName(track.getTrackAlbumArtistSort());
                } else {
                    tmpAlbum.setArtistSortName(track.getTrackArtistSort());
                }
                tmpAlbum.setMBID(track.getTrackAlbumMBID());
                onAlbumSelected(tmpAlbum, null);
                return true;
            case R.id.action_show_details:
                // Open song details dialog
                SongDetailsDialog songDetailsDialog = new SongDetailsDialog();
                Bundle songArgs = new Bundle();
                songArgs.putParcelable(SongDetailsDialog.EXTRA_FILE, track);
                songDetailsDialog.setArguments(songArgs);
                songDetailsDialog.show(getSupportFragmentManager(), "SongDetails");
                return true;
        }
    }
    return false;
}
Also used : AddPathToPlaylist(org.gateshipone.malp.application.callbacks.AddPathToPlaylist) MPDTrack(org.gateshipone.malp.mpdservice.mpdprotocol.mpdobjects.MPDTrack) MPDAlbum(org.gateshipone.malp.mpdservice.mpdprotocol.mpdobjects.MPDAlbum) Bundle(android.os.Bundle) ChoosePlaylistDialog(org.gateshipone.malp.application.fragments.serverfragments.ChoosePlaylistDialog) AdapterView(android.widget.AdapterView) MPDArtist(org.gateshipone.malp.mpdservice.mpdprotocol.mpdobjects.MPDArtist) CurrentPlaylistView(org.gateshipone.malp.application.views.CurrentPlaylistView) SongDetailsDialog(org.gateshipone.malp.application.fragments.serverfragments.SongDetailsDialog)

Example 10 with MPDAlbum

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

the class ArtworkManager method fetchAlbumImage.

/**
 * Starts an asynchronous fetch for the image of the given album
 *
 * @param album Album to fetch an image for.
 */
public void fetchAlbumImage(final MPDAlbum album) {
    ConnectivityManager cm = (ConnectivityManager) mContext.getSystemService(Context.CONNECTIVITY_SERVICE);
    NetworkInfo networkInfo = cm.getActiveNetworkInfo();
    if (networkInfo == null) {
        return;
    }
    boolean isWifi = networkInfo.getType() == ConnectivityManager.TYPE_WIFI || networkInfo.getType() == ConnectivityManager.TYPE_ETHERNET;
    if (mWifiOnly && !isWifi) {
        return;
    }
    if (mAlbumProvider.equals(mContext.getString(R.string.pref_artwork_provider_musicbrainz_key))) {
        MusicBrainzManager.getInstance(mContext).fetchAlbumImage(album, response -> new InsertAlbumImageTask().execute(response), this);
    } else if (mAlbumProvider.equals(mContext.getString(R.string.pref_artwork_provider_lastfm_key))) {
        LastFMManager.getInstance(mContext).fetchAlbumImage(album, response -> new InsertAlbumImageTask().execute(response), this);
    }
}
Also used : LastFMManager(org.gateshipone.malp.application.artworkdatabase.network.artprovider.LastFMManager) Context(android.content.Context) MPDResponseArtistList(org.gateshipone.malp.mpdservice.handlers.responsehandler.MPDResponseArtistList) MPDResponseFileList(org.gateshipone.malp.mpdservice.handlers.responsehandler.MPDResponseFileList) ByteArrayOutputStream(java.io.ByteArrayOutputStream) R(org.gateshipone.malp.R) FanartTVManager(org.gateshipone.malp.application.artworkdatabase.network.artprovider.FanartTVManager) Intent(android.content.Intent) BitmapFactory(android.graphics.BitmapFactory) HashMap(java.util.HashMap) MPDArtist(org.gateshipone.malp.mpdservice.mpdprotocol.mpdobjects.MPDArtist) AlbumImageResponse(org.gateshipone.malp.application.artworkdatabase.network.responses.AlbumImageResponse) ArrayList(java.util.ArrayList) ArtistFetchError(org.gateshipone.malp.application.artworkdatabase.network.responses.ArtistFetchError) JSONException(org.json.JSONException) HTTPAlbumImageProvider(org.gateshipone.malp.application.artworkdatabase.network.artprovider.HTTPAlbumImageProvider) BitmapUtils(org.gateshipone.malp.application.utils.BitmapUtils) MusicBrainzManager(org.gateshipone.malp.application.artworkdatabase.network.artprovider.MusicBrainzManager) MPDQueryHandler(org.gateshipone.malp.mpdservice.handlers.serverhandler.MPDQueryHandler) PreferenceManager(android.preference.PreferenceManager) NetworkResponse(com.android.volley.NetworkResponse) AlbumFetchError(org.gateshipone.malp.application.artworkdatabase.network.responses.AlbumFetchError) Log(android.util.Log) ConnectivityManager(android.net.ConnectivityManager) TrackAlbumImageResponse(org.gateshipone.malp.application.artworkdatabase.network.responses.TrackAlbumImageResponse) MPDAlbum(org.gateshipone.malp.mpdservice.mpdprotocol.mpdobjects.MPDAlbum) AsyncTask(android.os.AsyncTask) MALPRequestQueue(org.gateshipone.malp.application.artworkdatabase.network.MALPRequestQueue) IntentFilter(android.content.IntentFilter) NetworkInfo(android.net.NetworkInfo) MPDFileEntry(org.gateshipone.malp.mpdservice.mpdprotocol.mpdobjects.MPDFileEntry) TrackAlbumFetchError(org.gateshipone.malp.application.artworkdatabase.network.responses.TrackAlbumFetchError) VolleyError(com.android.volley.VolleyError) BroadcastReceiver(android.content.BroadcastReceiver) FormatHelper(org.gateshipone.malp.application.utils.FormatHelper) List(java.util.List) SharedPreferences(android.content.SharedPreferences) MPDResponseAlbumList(org.gateshipone.malp.mpdservice.handlers.responsehandler.MPDResponseAlbumList) Bitmap(android.graphics.Bitmap) MPDTrack(org.gateshipone.malp.mpdservice.mpdprotocol.mpdobjects.MPDTrack) ArtistImageResponse(org.gateshipone.malp.application.artworkdatabase.network.responses.ArtistImageResponse) NetworkInfo(android.net.NetworkInfo) ConnectivityManager(android.net.ConnectivityManager)

Aggregations

MPDAlbum (org.gateshipone.malp.mpdservice.mpdprotocol.mpdobjects.MPDAlbum)15 MPDArtist (org.gateshipone.malp.mpdservice.mpdprotocol.mpdobjects.MPDArtist)5 MPDTrack (org.gateshipone.malp.mpdservice.mpdprotocol.mpdobjects.MPDTrack)5 Bitmap (android.graphics.Bitmap)3 MPDFileEntry (org.gateshipone.malp.mpdservice.mpdprotocol.mpdobjects.MPDFileEntry)3 VolleyError (com.android.volley.VolleyError)2 ArrayList (java.util.ArrayList)2 List (java.util.List)2 TrackAlbumFetchError (org.gateshipone.malp.application.artworkdatabase.network.responses.TrackAlbumFetchError)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 BroadcastReceiver (android.content.BroadcastReceiver)1 Context (android.content.Context)1 Intent (android.content.Intent)1 IntentFilter (android.content.IntentFilter)1 SharedPreferences (android.content.SharedPreferences)1 BitmapFactory (android.graphics.BitmapFactory)1 ConnectivityManager (android.net.ConnectivityManager)1 NetworkInfo (android.net.NetworkInfo)1