Search in sources :

Example 1 with MPDDirectory

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

the class FileAdapter method getView.

/**
 * Create the actual listview items if no reusable object is provided.
 *
 * @param position    Index of the item to create.
 * @param convertView If != null this view can be reused to optimize performance.
 * @param parent      Parent of the view
 * @return
 */
@Override
public View getView(int position, View convertView, ViewGroup parent) {
    // Get MPDTrack at the given index used for this item.
    MPDFileEntry file = (MPDFileEntry) getItem(position);
    if (file instanceof MPDTrack) {
        MPDTrack track = (MPDTrack) file;
        // Normal file entry
        if (!mShowSectionItems || (VIEW_TYPES.values()[getItemViewType(position)] == VIEW_TYPES.TYPE_FILE_ITEM)) {
            if (convertView == null) {
                convertView = new FileListItem(mContext, mShowIcons);
            }
            ((FileListItem) convertView).setTrack(track, mUseTags, mContext);
            if (!mShowTrackNumbers) {
                ((FileListItem) convertView).setTrackNumber(String.valueOf(position + 1));
            }
            return convertView;
        } else {
            // Section items
            if (convertView == null) {
                // If not create a new Listitem
                convertView = new FileListItem(mContext, track.getTrackAlbum(), mShowIcons, this);
            }
            FileListItem tracksListViewItem = (FileListItem) convertView;
            tracksListViewItem.setSectionHeader(track.getTrackAlbum());
            tracksListViewItem.setTrack(track, mUseTags, mContext);
            if (!mShowTrackNumbers) {
                tracksListViewItem.setTrackNumber(String.valueOf(position + 1));
            }
            // This will prepare the view for fetching the image from the internet if not already saved in local database.
            // Dummy MPDAlbum
            MPDAlbum tmpAlbum = new MPDAlbum(track.getTrackAlbum());
            tmpAlbum.setMBID(track.getTrackAlbumMBID());
            ((FileListItem) convertView).prepareArtworkFetching(ArtworkManager.getInstance(mContext.getApplicationContext()), tmpAlbum);
            // starts the loading.
            if (mScrollSpeed == 0) {
                ((FileListItem) convertView).startCoverImageTask();
            }
            return convertView;
        }
    } else if (file instanceof MPDDirectory) {
        if (convertView == null) {
            convertView = new FileListItem(mContext, mShowIcons);
        }
        ((FileListItem) convertView).setDirectory((MPDDirectory) file, mContext);
        return convertView;
    } else if (file instanceof MPDPlaylist) {
        if (convertView == null) {
            convertView = new FileListItem(mContext, mShowIcons);
        }
        ((FileListItem) convertView).setPlaylist((MPDPlaylist) file, mContext);
        return convertView;
    }
    return new FileListItem(mContext, mShowIcons);
}
Also used : MPDFileEntry(org.gateshipone.malp.mpdservice.mpdprotocol.mpdobjects.MPDFileEntry) MPDTrack(org.gateshipone.malp.mpdservice.mpdprotocol.mpdobjects.MPDTrack) MPDAlbum(org.gateshipone.malp.mpdservice.mpdprotocol.mpdobjects.MPDAlbum) MPDDirectory(org.gateshipone.malp.mpdservice.mpdprotocol.mpdobjects.MPDDirectory) MPDPlaylist(org.gateshipone.malp.mpdservice.mpdprotocol.mpdobjects.MPDPlaylist) FileListItem(org.gateshipone.malp.application.listviewitems.FileListItem)

Example 2 with MPDDirectory

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

the class FilesFragment method onItemClick.

@Override
public void onItemClick(AdapterView<?> adapterView, View view, int position, long l) {
    mLastPosition = position;
    MPDFileEntry file = (MPDFileEntry) mAdapter.getItem(position);
    if (file instanceof MPDDirectory) {
        mCallback.openPath(file.getPath());
    } else if (file instanceof MPDPlaylist) {
        mPlaylistCallback.openPlaylist(file.getPath());
    } else if (file instanceof MPDTrack) {
        switch(mClickAction) {
            case ACTION_SHOW_DETAILS:
                {
                    // Open song details dialog
                    SongDetailsDialog songDetailsDialog = new SongDetailsDialog();
                    Bundle args = new Bundle();
                    args.putParcelable(SongDetailsDialog.EXTRA_FILE, (MPDTrack) mAdapter.getItem(position));
                    songDetailsDialog.setArguments(args);
                    songDetailsDialog.show(((AppCompatActivity) getContext()).getSupportFragmentManager(), "SongDetails");
                    return;
                }
            case ACTION_ADD_SONG:
                {
                    MPDTrack track = (MPDTrack) mAdapter.getItem(position);
                    MPDQueryHandler.addPath(track.getPath());
                    return;
                }
            case ACTION_PLAY_SONG:
                {
                    MPDTrack track = (MPDTrack) mAdapter.getItem(position);
                    MPDQueryHandler.playSong(track.getPath());
                    return;
                }
            case ACTION_PLAY_SONG_NEXT:
                {
                    MPDTrack track = (MPDTrack) mAdapter.getItem(position);
                    MPDQueryHandler.playSongNext(track.getPath());
                    return;
                }
        }
    }
}
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) Bundle(android.os.Bundle) MPDPlaylist(org.gateshipone.malp.mpdservice.mpdprotocol.mpdobjects.MPDPlaylist) AppCompatActivity(android.support.v7.app.AppCompatActivity)

Example 3 with MPDDirectory

use of org.gateshipone.malp.mpdservice.mpdprotocol.mpdobjects.MPDDirectory 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 4 with MPDDirectory

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

MPDDirectory (org.gateshipone.malp.mpdservice.mpdprotocol.mpdobjects.MPDDirectory)4 MPDFileEntry (org.gateshipone.malp.mpdservice.mpdprotocol.mpdobjects.MPDFileEntry)4 MPDPlaylist (org.gateshipone.malp.mpdservice.mpdprotocol.mpdobjects.MPDPlaylist)4 MPDTrack (org.gateshipone.malp.mpdservice.mpdprotocol.mpdobjects.MPDTrack)4 Bundle (android.os.Bundle)1 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 MPDAlbum (org.gateshipone.malp.mpdservice.mpdprotocol.mpdobjects.MPDAlbum)1