Search in sources :

Example 6 with MPDFileEntry

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

the class FilesFragment method onCreateContextMenu.

/**
 * Create the context menu.
 */
@Override
public void onCreateContextMenu(ContextMenu menu, View v, ContextMenu.ContextMenuInfo menuInfo) {
    super.onCreateContextMenu(menu, v, menuInfo);
    MenuInflater inflater = getActivity().getMenuInflater();
    int position = ((AdapterView.AdapterContextMenuInfo) menuInfo).position;
    MPDFileEntry file = (MPDFileEntry) mAdapter.getItem(position);
    if (file instanceof MPDTrack) {
        inflater.inflate(R.menu.context_menu_track, menu);
    } else if (file instanceof MPDDirectory) {
        inflater.inflate(R.menu.context_menu_directory, menu);
    } else if (file instanceof MPDPlaylist) {
        inflater.inflate(R.menu.context_menu_playlist, menu);
    }
}
Also used : MPDFileEntry(org.gateshipone.malp.mpdservice.mpdprotocol.mpdobjects.MPDFileEntry) MPDTrack(org.gateshipone.malp.mpdservice.mpdprotocol.mpdobjects.MPDTrack) MenuInflater(android.view.MenuInflater) MPDDirectory(org.gateshipone.malp.mpdservice.mpdprotocol.mpdobjects.MPDDirectory) MPDPlaylist(org.gateshipone.malp.mpdservice.mpdprotocol.mpdobjects.MPDPlaylist)

Example 7 with MPDFileEntry

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

the class FileAdapter method getItemViewType.

/**
 * Returns the type (section track or normal track) of the item at the given position.
 * If preceding {@link MPDFileEntry} is not a {@link MPDTrack} it will generate a secion entry.
 * Else it will check if the preceding {@link MPDTrack} is another album.
 *
 * @param position Position of the item in question
 * @return the int value of the enum {@link CurrentPlaylistAdapter.VIEW_TYPES}
 */
@Override
public int getItemViewType(int position) {
    // Get MPDTrack at the given index used for this item.
    MPDFileEntry file = (MPDFileEntry) getItem(position);
    if (file instanceof MPDTrack) {
        boolean newAlbum = false;
        MPDTrack track = (MPDTrack) file;
        MPDFileEntry previousFile;
        if (position > 0) {
            previousFile = (MPDFileEntry) getItem(position - 1);
            if (previousFile != null) {
                if (previousFile instanceof MPDTrack) {
                    MPDTrack previousTrack = (MPDTrack) previousFile;
                    newAlbum = !previousTrack.getTrackAlbum().equals(track.getTrackAlbum());
                }
            }
        } else {
            return VIEW_TYPES.TYPE_SECTION_FILE_ITEM.ordinal();
        }
        return newAlbum ? VIEW_TYPES.TYPE_SECTION_FILE_ITEM.ordinal() : VIEW_TYPES.TYPE_FILE_ITEM.ordinal();
    } else {
        return VIEW_TYPES.TYPE_FILE_ITEM.ordinal();
    }
}
Also used : MPDFileEntry(org.gateshipone.malp.mpdservice.mpdprotocol.mpdobjects.MPDFileEntry) MPDTrack(org.gateshipone.malp.mpdservice.mpdprotocol.mpdobjects.MPDTrack)

Example 8 with MPDFileEntry

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

the class MPDResponseFileList method handleMessage.

/**
 * Handle function for the track list. This only calls the abstract method
 * which needs to get implemented by the user of this class.
 * @param msg Message object containing a list of MPDTrack items.
 */
@Override
public void handleMessage(Message msg) {
    super.handleMessage(msg);
    Bundle args = msg.getData();
    int windowStart = msg.getData().getInt(EXTRA_WINDOW_START);
    int windowEnd = msg.getData().getInt(EXTRA_WINDOW_END);
    /* Call album response handler */
    List<MPDFileEntry> trackList = (List<MPDFileEntry>) msg.obj;
    handleTracks(trackList, windowStart, windowEnd);
}
Also used : MPDFileEntry(org.gateshipone.malp.mpdservice.mpdprotocol.mpdobjects.MPDFileEntry) Bundle(android.os.Bundle) List(java.util.List)

Example 9 with MPDFileEntry

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

the class MPDInterface method addTrackList.

/*
     ***********************
     *    Queue commands   *
     ***********************
     */
/**
 * This method adds songs in a bulk command list. Should be reasonably in performance this way.
 *
 * @param tracks List of MPDFileEntry objects to add to the current playlist.
 */
public synchronized void addTrackList(List<MPDFileEntry> tracks) throws MPDException {
    if (null == tracks) {
        return;
    }
    mConnection.startCommandList();
    for (MPDFileEntry track : tracks) {
        if (track instanceof MPDTrack) {
            mConnection.sendMPDRAWCommand(MPDCommands.MPD_COMMAND_ADD_FILE(track.getPath()));
        }
    }
    mConnection.endCommandList();
}
Also used : MPDFileEntry(org.gateshipone.malp.mpdservice.mpdprotocol.mpdobjects.MPDFileEntry) MPDTrack(org.gateshipone.malp.mpdservice.mpdprotocol.mpdobjects.MPDTrack)

Example 10 with MPDFileEntry

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

the class MPDResponseParser method parseMPDTracks.

/**
 * Parses the response of mpd on requests that return track items. This is also used
 * for MPD file, directory and playlist responses. This allows the GUI to develop
 * one adapter for all three types. Also MPD mixes them when requesting directory listings.
 * <p/>
 * It will return a list of MPDFileEntry objects which is a parent class for (MPDTrack, MPDPlaylist,
 * MPDDirectory) you can use instanceof to check which type you got.
 *
 * @return List of MPDFileEntry objects
 * @throws MPDException if an error from MPD was received during reading
 */
static ArrayList<MPDFileEntry> parseMPDTracks(final MPDConnection connection) throws MPDException {
    ArrayList<MPDFileEntry> trackList = new ArrayList<>();
    if (!connection.isConnected()) {
        return trackList;
    }
    /* Temporary file entry (added to list later) */
    MPDFileEntry tempFileEntry = null;
    /* Response line from MPD */
    String response = connection.readLine();
    while (response != null && !response.startsWith("OK")) {
        /* This if block will just check all the different response possible by MPDs file/dir/playlist response */
        if (response.startsWith(MPDResponses.MPD_RESPONSE_FILE)) {
            if (null != tempFileEntry) {
                trackList.add(tempFileEntry);
            }
            tempFileEntry = new MPDTrack(response.substring(MPDResponses.MPD_RESPONSE_FILE.length()));
        } else if (response.startsWith(MPDResponses.MPD_RESPONSE_PLAYLIST)) {
            if (null != tempFileEntry) {
                trackList.add(tempFileEntry);
            }
            tempFileEntry = new MPDPlaylist(response.substring(MPDResponses.MPD_RESPONSE_PLAYLIST.length()));
        } else if (response.startsWith(MPDResponses.MPD_RESPONSE_DIRECTORY)) {
            if (null != tempFileEntry) {
                trackList.add(tempFileEntry);
            }
            tempFileEntry = new MPDDirectory(response.substring(MPDResponses.MPD_RESPONSE_DIRECTORY.length()));
        }
        // Currently parsing a file (check its properties)
        if (tempFileEntry instanceof MPDTrack) {
            if (response.startsWith(MPDResponses.MPD_RESPONSE_TRACK_TITLE)) {
                ((MPDTrack) tempFileEntry).setTrackTitle(response.substring(MPDResponses.MPD_RESPONSE_TRACK_TITLE.length()));
            } else if (response.startsWith(MPDResponses.MPD_RESPONSE_ARTIST_NAME)) {
                ((MPDTrack) tempFileEntry).setTrackArtist(response.substring(MPDResponses.MPD_RESPONSE_ARTIST_NAME.length()));
            } else if (response.startsWith(MPDResponses.MPD_RESPONSE_ARTIST_SORT_NAME)) {
                ((MPDTrack) tempFileEntry).setTrackArtistSort(response.substring(MPDResponses.MPD_RESPONSE_ARTIST_SORT_NAME.length()));
            } else if (response.startsWith(MPDResponses.MPD_RESPONSE_TRACK_NAME)) {
                ((MPDTrack) tempFileEntry).setTrackName(response.substring(MPDResponses.MPD_RESPONSE_TRACK_NAME.length()));
            } else if (response.startsWith(MPDResponses.MPD_RESPONSE_ALBUMARTIST_NAME)) {
                ((MPDTrack) tempFileEntry).setTrackAlbumArtist(response.substring(MPDResponses.MPD_RESPONSE_ALBUMARTIST_NAME.length()));
            } else if (response.startsWith(MPDResponses.MPD_RESPONSE_ALBUMARTIST_SORT_NAME)) {
                ((MPDTrack) tempFileEntry).setTrackAlbumArtistSort(response.substring(MPDResponses.MPD_RESPONSE_ALBUMARTIST_SORT_NAME.length()));
            } else if (response.startsWith(MPDResponses.MPD_RESPONSE_ALBUM_NAME)) {
                ((MPDTrack) tempFileEntry).setTrackAlbum(response.substring(MPDResponses.MPD_RESPONSE_ALBUM_NAME.length()));
            } else if (response.startsWith(MPDResponses.MPD_RESPONSE_DATE)) {
                ((MPDTrack) tempFileEntry).setDate(response.substring(MPDResponses.MPD_RESPONSE_DATE.length()));
            } else if (response.startsWith(MPDResponses.MPD_RESPONSE_ALBUM_MBID)) {
                ((MPDTrack) tempFileEntry).setTrackAlbumMBID(response.substring(MPDResponses.MPD_RESPONSE_ALBUM_MBID.length()));
            } else if (response.startsWith(MPDResponses.MPD_RESPONSE_ARTIST_MBID)) {
                ((MPDTrack) tempFileEntry).setTrackArtistMBID(response.substring(MPDResponses.MPD_RESPONSE_ARTIST_MBID.length()));
            } else if (response.startsWith(MPDResponses.MPD_RESPONSE_ALBUM_ARTIST_MBID)) {
                ((MPDTrack) tempFileEntry).setTrackAlbumArtistMBID(response.substring(MPDResponses.MPD_RESPONSE_ALBUM_ARTIST_MBID.length()));
            } else if (response.startsWith(MPDResponses.MPD_RESPONSE_TRACK_MBID)) {
                ((MPDTrack) tempFileEntry).setTrackMBID(response.substring(MPDResponses.MPD_RESPONSE_TRACK_MBID.length()));
            } else if (response.startsWith(MPDResponses.MPD_RESPONSE_TRACK_TIME)) {
                try {
                    ((MPDTrack) tempFileEntry).setLength(Integer.valueOf(response.substring(MPDResponses.MPD_RESPONSE_TRACK_TIME.length())));
                } catch (NumberFormatException ignored) {
                }
            } else if (response.startsWith(MPDResponses.MPD_RESPONSE_SONG_ID)) {
                try {
                    ((MPDTrack) tempFileEntry).setSongID(Integer.valueOf(response.substring(MPDResponses.MPD_RESPONSE_SONG_ID.length())));
                } catch (NumberFormatException ignored) {
                }
            } else if (response.startsWith(MPDResponses.MPD_RESPONSE_SONG_POS)) {
                try {
                    ((MPDTrack) tempFileEntry).setSongPosition(Integer.valueOf(response.substring(MPDResponses.MPD_RESPONSE_SONG_POS.length())));
                } catch (NumberFormatException ignored) {
                }
            } else if (response.startsWith(MPDResponses.MPD_RESPONSE_DISC_NUMBER)) {
                /*
                * Check if MPD returned a discnumber like: "1" or "1/3" and set disc count accordingly.
                */
                String discNumber = response.substring(MPDResponses.MPD_RESPONSE_DISC_NUMBER.length());
                discNumber = discNumber.replaceAll(" ", "");
                String[] discNumberSep = discNumber.split("/");
                if (discNumberSep.length > 0) {
                    try {
                        ((MPDTrack) tempFileEntry).setDiscNumber(Integer.valueOf(discNumberSep[0]));
                    } catch (NumberFormatException ignored) {
                    }
                    if (discNumberSep.length > 1) {
                        try {
                            ((MPDTrack) tempFileEntry).psetAlbumDiscCount(Integer.valueOf(discNumberSep[1]));
                        } catch (NumberFormatException ignored) {
                        }
                    }
                } else {
                    try {
                        ((MPDTrack) tempFileEntry).setDiscNumber(Integer.valueOf(discNumber));
                    } catch (NumberFormatException ignored) {
                    }
                }
            } else if (response.startsWith(MPDResponses.MPD_RESPONSE_TRACK_NUMBER)) {
                /*
                 * Check if MPD returned a tracknumber like: "12" or "12/42" and set albumtrack count accordingly.
                 */
                String trackNumber = response.substring(MPDResponses.MPD_RESPONSE_TRACK_NUMBER.length());
                trackNumber = trackNumber.replaceAll(" ", "");
                String[] trackNumbersSep = trackNumber.split("/");
                if (trackNumbersSep.length > 0) {
                    try {
                        ((MPDTrack) tempFileEntry).setTrackNumber(Integer.valueOf(trackNumbersSep[0]));
                    } catch (NumberFormatException ignored) {
                    }
                    if (trackNumbersSep.length > 1) {
                        try {
                            ((MPDTrack) tempFileEntry).setAlbumTrackCount(Integer.valueOf(trackNumbersSep[1]));
                        } catch (NumberFormatException ignored) {
                        }
                    }
                } else {
                    try {
                        ((MPDTrack) tempFileEntry).setTrackNumber(Integer.valueOf(trackNumber));
                    } catch (NumberFormatException ignored) {
                    }
                }
            } else if (response.startsWith(MPDResponses.MPD_RESPONSE_LAST_MODIFIED)) {
                tempFileEntry.setLastModified(response.substring(MPDResponses.MPD_RESPONSE_LAST_MODIFIED.length()));
            }
        } else if (tempFileEntry != null) {
            // Other case tempFileEntry is a playlist or a directory (properties of generic files)
            if (response.startsWith(MPDResponses.MPD_RESPONSE_LAST_MODIFIED)) {
                tempFileEntry.setLastModified(response.substring(MPDResponses.MPD_RESPONSE_LAST_MODIFIED.length()));
            }
        }
        // Move to the next line.
        response = connection.readLine();
    }
    /* Add last remaining track to list. */
    if (null != tempFileEntry) {
        trackList.add(tempFileEntry);
    }
    return trackList;
}
Also used : MPDFileEntry(org.gateshipone.malp.mpdservice.mpdprotocol.mpdobjects.MPDFileEntry) MPDTrack(org.gateshipone.malp.mpdservice.mpdprotocol.mpdobjects.MPDTrack) MPDDirectory(org.gateshipone.malp.mpdservice.mpdprotocol.mpdobjects.MPDDirectory) ArrayList(java.util.ArrayList) MPDPlaylist(org.gateshipone.malp.mpdservice.mpdprotocol.mpdobjects.MPDPlaylist)

Aggregations

MPDFileEntry (org.gateshipone.malp.mpdservice.mpdprotocol.mpdobjects.MPDFileEntry)10 MPDTrack (org.gateshipone.malp.mpdservice.mpdprotocol.mpdobjects.MPDTrack)7 MPDDirectory (org.gateshipone.malp.mpdservice.mpdprotocol.mpdobjects.MPDDirectory)4 MPDPlaylist (org.gateshipone.malp.mpdservice.mpdprotocol.mpdobjects.MPDPlaylist)4 MPDAlbum (org.gateshipone.malp.mpdservice.mpdprotocol.mpdobjects.MPDAlbum)3 Bundle (android.os.Bundle)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 MPDArtist (org.gateshipone.malp.mpdservice.mpdprotocol.mpdobjects.MPDArtist)2 AppCompatActivity (android.support.v7.app.AppCompatActivity)1 MenuInflater (android.view.MenuInflater)1 ArrayList (java.util.ArrayList)1 FileListItem (org.gateshipone.malp.application.listviewitems.FileListItem)1 MPDResponseHandler (org.gateshipone.malp.mpdservice.handlers.responsehandler.MPDResponseHandler)1 MPDResponseOutputList (org.gateshipone.malp.mpdservice.handlers.responsehandler.MPDResponseOutputList)1 MPDCapabilities (org.gateshipone.malp.mpdservice.mpdprotocol.MPDCapabilities)1 MPDCommands (org.gateshipone.malp.mpdservice.mpdprotocol.MPDCommands)1 MPDException (org.gateshipone.malp.mpdservice.mpdprotocol.MPDException)1