Skip to content

Commit

Permalink
Merge branch 'release/1.07_RC4'
Browse files Browse the repository at this point in the history
  • Loading branch information
abarisain committed Nov 30, 2014
2 parents 182bf4a + 3e205d5 commit c3913da
Show file tree
Hide file tree
Showing 15 changed files with 180 additions and 67 deletions.
3 changes: 2 additions & 1 deletion .idea/gradle.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 3 additions & 3 deletions JMPDComm/backends/java/JMPDCommJava.iml
Original file line number Diff line number Diff line change
Expand Up @@ -18,18 +18,18 @@
<exclude-output />
<content url="file://$MODULE_DIR$">
<sourceFolder url="file://$MODULE_DIR$/src/main/java" isTestSource="false" />
<sourceFolder url="file://$MODULE_DIR$/src/test/resources" isTestSource="true" />
<sourceFolder url="file://$MODULE_DIR$/src/test/java" isTestSource="true" />
<sourceFolder url="file://$MODULE_DIR$/src/test/resources" type="java-test-resource" />
<excludeFolder url="file://$MODULE_DIR$/.gradle" />
<excludeFolder url="file://$MODULE_DIR$/build" />
</content>
<content url="file://$MODULE_DIR$/../../src/main/java">
<sourceFolder url="file://$MODULE_DIR$/../../src/main/java" isTestSource="false" />
</content>
<content url="file://$MODULE_DIR$/../../src/main/resources">
<sourceFolder url="file://$MODULE_DIR$/../../src/main/resources" type="java-resource" />
<sourceFolder url="file://$MODULE_DIR$/../../src/main/resources" isTestSource="false" />
</content>
<orderEntry type="inheritedJdk" />
<orderEntry type="jdk" jdkName="1.7" jdkType="JavaSDK" />
<orderEntry type="sourceFolder" forTests="false" />
</component>
</module>
Expand Down
143 changes: 111 additions & 32 deletions JMPDComm/src/main/java/org/a0z/mpd/MPD.java
Original file line number Diff line number Diff line change
Expand Up @@ -113,44 +113,36 @@ public MPD(final String server, final int port, final String password)
connect(server, port, password);
}

private static MPDCommand getAlbumDetailsCommand(final Album album) {
private static String[] getAlbumArtistPair(final Album album) {
final Artist artist = album.getArtist();
String artistCommand = null;
String artistName = null;

if (artist != null) {
artistName = artist.getName();
final String[] artistPair;

if (artist == null) {
artistPair = new String[]{null, null};
} else {
if (album.hasAlbumArtist()) {
artistCommand = MPDCommand.MPD_TAG_ALBUM_ARTIST;
artistPair = new String[]{MPDCommand.MPD_TAG_ALBUM_ARTIST, artist.getName()};
} else {
artistCommand = MPDCommand.MPD_FIND_ARTIST;
artistPair = new String[]{MPDCommand.MPD_TAG_ARTIST, artist.getName()};
}
}

return artistPair;
}

private static MPDCommand getAlbumDetailsCommand(final Album album) {
final String[] artistPair = getAlbumArtistPair(album);

return new MPDCommand(MPDCommand.MPD_CMD_COUNT,
MPDCommand.MPD_TAG_ALBUM, album.getName(),
artistCommand, artistName);
artistPair[0], artistPair[1]);
}

private static MPDCommand getSongsCommand(final Album album) {
final String albumName = album.getName();
final Artist artist = album.getArtist();
String artistName = null;
String artistCommand = null;
final String[] artistPair = getAlbumArtistPair(album);

if (artist != null) {
artistName = artist.getName();

if (album.hasAlbumArtist()) {
artistCommand = MPDCommand.MPD_TAG_ALBUM_ARTIST;
} else {
artistCommand = MPDCommand.MPD_TAG_ARTIST;
}
}

return new MPDCommand(MPDCommand.MPD_CMD_FIND, MPDCommand.MPD_TAG_ALBUM, albumName,
artistCommand, artistName);
return new MPDCommand(MPDCommand.MPD_CMD_FIND, MPDCommand.MPD_TAG_ALBUM, album.getName(),
artistPair[0], artistPair[1]);
}

/*
Expand Down Expand Up @@ -213,8 +205,20 @@ public void add(final Album album) throws IOException, MPDException {
*/
public void add(final Album album, final boolean replace, final boolean play)
throws IOException, MPDException {
final List<Music> songs = getSongs(album);
final CommandQueue commandQueue = MPDPlaylist.addAllCommand(songs);
final CommandQueue commandQueue;

if (isCommandAvailable(MPDCommand.MPD_CMD_FIND_ADD)) {
final String[] artistPair = getAlbumArtistPair(album);

commandQueue = new CommandQueue();

commandQueue
.add(MPDCommand.MPD_CMD_FIND_ADD, MPDCommand.MPD_TAG_ALBUM, album.getName(),
artistPair[0], artistPair[1]);
} else {
final List<Music> songs = getSongs(album);
commandQueue = MPDPlaylist.addAllCommand(songs);
}

add(commandQueue, replace, play);
}
Expand All @@ -241,8 +245,17 @@ public void add(final Artist artist) throws IOException, MPDException {
*/
public void add(final Artist artist, final boolean replace, final boolean play)
throws IOException, MPDException {
final List<Music> songs = getSongs(artist);
final CommandQueue commandQueue = MPDPlaylist.addAllCommand(songs);
final CommandQueue commandQueue;

if (isCommandAvailable(MPDCommand.MPD_CMD_FIND_ADD)) {
commandQueue = new CommandQueue();

commandQueue
.add(MPDCommand.MPD_CMD_FIND_ADD, MPDCommand.MPD_TAG_ARTIST, artist.getName());
} else {
final List<Music> songs = getSongs(artist);
commandQueue = MPDPlaylist.addAllCommand(songs);
}

add(commandQueue, replace, play);
}
Expand All @@ -261,7 +274,11 @@ public void add(final FilesystemTreeEntry music, final boolean replace, final bo
throws IOException, MPDException {
final CommandQueue commandQueue = new CommandQueue();

commandQueue.add(MPDPlaylist.addCommand(music.getFullPath()));
if (music instanceof PlaylistFile) {
commandQueue.add(MPDPlaylist.loadCommand(music.getFullPath()));
} else {
commandQueue.add(MPDPlaylist.addCommand(music.getFullPath()));
}

add(commandQueue, replace, play);
}
Expand All @@ -277,6 +294,24 @@ public void add(final FilesystemTreeEntry music) throws IOException, MPDExceptio
add(music, false, false);
}

public void add(final Genre genre, final boolean replace, final boolean play)
throws IOException, MPDException {
final CommandQueue commandQueue;

if (isCommandAvailable(MPDCommand.MPD_CMD_FIND_ADD)) {
commandQueue = new CommandQueue();

commandQueue
.add(MPDCommand.MPD_CMD_FIND_ADD, MPDCommand.MPD_TAG_GENRE, genre.getName());
} else {
final Collection<Music> music = find(MPDCommand.MPD_TAG_GENRE, genre.getName());

commandQueue = MPDPlaylist.addAllCommand(music);
}

add(commandQueue, replace, play);
}

/**
* Adds songs to the queue. Optionally, clears the queue prior to the addition. Optionally,
* play the added songs afterward.
Expand Down Expand Up @@ -394,12 +429,24 @@ public void addStream(final String stream, final boolean replace, final boolean

public void addToPlaylist(final String playlistName, final Album album)
throws IOException, MPDException {
addToPlaylist(playlistName, new ArrayList<>(getSongs(album)));
if (mIdleConnection.isCommandAvailable(MPDCommand.MPD_CMD_SEARCH_ADD_PLAYLIST)) {
final String[] artistPair = getAlbumArtistPair(album);

mConnection.sendCommand(MPDCommand.MPD_CMD_SEARCH_ADD_PLAYLIST, playlistName,
MPDCommand.MPD_SEARCH_ALBUM, album.getName(), artistPair[0], artistPair[1]);
} else {
addToPlaylist(playlistName, new ArrayList<>(getSongs(album)));
}
}

public void addToPlaylist(final String playlistName, final Artist artist)
throws IOException, MPDException {
addToPlaylist(playlistName, new ArrayList<>(getSongs(artist)));
if (mIdleConnection.isCommandAvailable(MPDCommand.MPD_CMD_SEARCH_ADD_PLAYLIST)) {
mConnection.sendCommand(MPDCommand.MPD_CMD_SEARCH_ADD_PLAYLIST, playlistName,
MPDCommand.MPD_SEARCH_ARTIST, artist.getName());
} else {
addToPlaylist(playlistName, new ArrayList<>(getSongs(artist)));
}
}

public void addToPlaylist(final String playlistName, final Collection<Music> musicCollection)
Expand All @@ -421,6 +468,18 @@ public void addToPlaylist(final String playlistName, final FilesystemTreeEntry e
entry.getFullPath());
}

public void addToPlaylist(final String playlistName, final Genre genre)
throws IOException, MPDException {
if (mIdleConnection.isCommandAvailable(MPDCommand.MPD_CMD_SEARCH_ADD_PLAYLIST)) {
mConnection.sendCommand(MPDCommand.MPD_CMD_SEARCH_ADD_PLAYLIST, playlistName,
MPDCommand.MPD_SEARCH_GENRE, genre.getName());
} else {
final Collection<Music> music = find(MPDCommand.MPD_TAG_GENRE, genre.getName());

addToPlaylist(playlistName, music);
}
}

public void addToPlaylist(final String playlistName, final Music music)
throws IOException, MPDException {
final Collection<Music> songs = new ArrayList<>(1);
Expand Down Expand Up @@ -1547,6 +1606,26 @@ public void refreshDirectory(final Directory directory) throws IOException, MPDE
directory.refresh(mConnection);
}

/**
* Removes a list of tracks from a playlist file, by position.
*
* @param playlistName The playlist file to remove tracks from.
* @param positions The positions of the tracks to remove from the playlist file.
* @throws IOException Thrown upon a communication error with the server.
* @throws MPDException Thrown if an error occurs as a result of command execution.
*/
public void removeFromPlaylist(final String playlistName, final List<Integer> positions)
throws IOException, MPDException {
Collections.sort(positions, Collections.reverseOrder());
final CommandQueue commandQueue = new CommandQueue(positions.size());

for (final Integer position : positions) {
commandQueue.add(MPDCommand.MPD_CMD_PLAYLIST_DEL, playlistName, position.toString());
}

commandQueue.send(mConnection);
}

public void removeFromPlaylist(final String playlistName, final Integer pos)
throws IOException, MPDException {
mConnection.sendCommand(MPDCommand.MPD_CMD_PLAYLIST_DEL, playlistName,
Expand Down
10 changes: 6 additions & 4 deletions JMPDComm/src/main/java/org/a0z/mpd/MPDCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,9 @@ public class MPDCommand {

public static final String MPD_CMD_FIND = "find";

/** Added in MPD protocol 0.16.0 */
public static final String MPD_CMD_FIND_ADD = "findadd";

public static final String MPD_CMD_GROUP = "group";

public static final String MPD_CMD_IDLE = "idle";
Expand Down Expand Up @@ -115,6 +118,9 @@ public class MPDCommand {

public static final String MPD_CMD_SEARCH = "search";

/** Added in MPD protocol 0.17.0. */
public static final String MPD_CMD_SEARCH_ADD_PLAYLIST = "searchaddpl";

public static final String MPD_CMD_SEEK = "seek";

public static final String MPD_CMD_SEEK_ID = "seekid";
Expand All @@ -132,10 +138,6 @@ public class MPDCommand {
// deprecated commands
public static final String MPD_CMD_VOLUME = "volume";

public static final String MPD_FIND_ALBUM = "album";

public static final String MPD_FIND_ARTIST = "artist";

public static final String MPD_LIST_RESPONSE_ARTIST = "Artist";

public static final String MPD_SEARCH_ALBUM = "album";
Expand Down
17 changes: 17 additions & 0 deletions JMPDComm/src/main/java/org/a0z/mpd/MPDPlaylist.java
Original file line number Diff line number Diff line change
Expand Up @@ -390,6 +390,23 @@ public void removeById(final int... songIds) throws IOException, MPDException {
commandQueue.send(mConnection);
}

/**
* Removes entries from playlist.
*
* @param songIds Playlist songIDs to remove.
* @throws IOException Thrown upon a communication error with the server.
* @throws MPDException Thrown if an error occurs as a result of command execution.
*/
public void removeById(final Collection<Integer> songIds) throws IOException, MPDException {
final CommandQueue commandQueue = new CommandQueue(songIds.size());

for (final Integer id : songIds) {
commandQueue.add(MPD_CMD_PLAYLIST_REMOVE_ID, id.toString());
}

commandQueue.send(mConnection);
}

/**
* Removes entries from playlist.
*
Expand Down
4 changes: 2 additions & 2 deletions MPDroid/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,8 @@ android {
defaultConfig {
minSdkVersion 14
targetSdkVersion 21
versionCode 51
versionName "1.07 RC3 " + gitShortHash()
versionCode 52
versionName "1.07 RC4 " + gitShortHash()
}

lintOptions {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,11 @@ protected void add(final Item item, final boolean replace, final boolean play) {
final Directory toAdd = mCurrentDirectory.getDirectory(item.getName());
if (toAdd == null) {
mApp.oMPDAsyncHelper.oMPD.add((FilesystemTreeEntry) item, replace, play);
Tools.notifyUser(R.string.songAdded, item);
if (item instanceof PlaylistFile) {
Tools.notifyUser(R.string.playlistAdded, item);
} else {
Tools.notifyUser(R.string.songAdded, item);
}
} else {
// Valid directory
mApp.oMPDAsyncHelper.oMPD.add(toAdd, replace, play);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,7 @@ public GenresFragment() {
@Override
protected void add(final Item item, final boolean replace, final boolean play) {
try {
mApp.oMPDAsyncHelper.oMPD.getPlaylist().addAll(
mApp.oMPDAsyncHelper.oMPD.find("genre", item.getName()));
mApp.oMPDAsyncHelper.oMPD.add((Genre) item, replace, play);
Tools.notifyUser(mIrAdded, item);
} catch (final IOException | MPDException e) {
Log.e(TAG, "Failed to add all from playlist.", e);
Expand All @@ -54,8 +53,7 @@ protected void add(final Item item, final boolean replace, final boolean play) {
@Override
protected void add(final Item item, final String playlist) {
try {
mApp.oMPDAsyncHelper.oMPD.addToPlaylist(playlist,
mApp.oMPDAsyncHelper.oMPD.find("genre", item.getName()));
mApp.oMPDAsyncHelper.oMPD.addToPlaylist(playlist, (Genre) item);
Tools.notifyUser(mIrAdded, item);
} catch (final IOException | MPDException e) {
Log.e(TAG, "Failed to add all genre to playlist.", e);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,13 @@ public boolean onOptionsItemSelected(final MenuItem item) {

}

@Override
public void onResume() {
super.onResume();

updateList();
}

@Override
public void onSaveInstanceState(final Bundle outState) {
outState.putString(EXTRA_PLAYLIST_NAME, mPlaylistName);
Expand Down
Loading

0 comments on commit c3913da

Please sign in to comment.