Skip to content

Commit

Permalink
#27: Party mode interface (WIP)
Browse files Browse the repository at this point in the history
  • Loading branch information
jendib committed Feb 21, 2015
1 parent f0873e5 commit 9b5e008
Show file tree
Hide file tree
Showing 10 changed files with 163 additions and 25 deletions.
20 changes: 10 additions & 10 deletions music-android/app/app.iml
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@
<option name="SELECTED_TEST_ARTIFACT" value="_android_test_" />
<option name="ASSEMBLE_TASK_NAME" value="assembleDebug" />
<option name="COMPILE_JAVA_TASK_NAME" value="compileDebugSources" />
<option name="ASSEMBLE_TEST_TASK_NAME" value="assembleDebugTest" />
<option name="ASSEMBLE_TEST_TASK_NAME" value="assembleDebugAndroidTest" />
<option name="SOURCE_GEN_TASK_NAME" value="generateDebugSources" />
<option name="TEST_SOURCE_GEN_TASK_NAME" value="generateDebugTestSources" />
<option name="TEST_SOURCE_GEN_TASK_NAME" value="generateDebugAndroidTestSources" />
<option name="ALLOW_USER_CONFIGURATION" value="false" />
<option name="MANIFEST_FILE_RELATIVE_PATH" value="/src/main/AndroidManifest.xml" />
<option name="RES_FOLDER_RELATIVE_PATH" value="/src/main/res" />
Expand All @@ -25,7 +25,7 @@
</component>
<component name="NewModuleRootManager" inherit-compiler-output="false">
<output url="file://$MODULE_DIR$/build/intermediates/classes/debug" />
<output-test url="file://$MODULE_DIR$/build/intermediates/classes/test/debug" />
<output-test url="file://$MODULE_DIR$/build/intermediates/classes/androidTest/debug" />
<exclude-output />
<content url="file://$MODULE_DIR$">
<sourceFolder url="file://$MODULE_DIR$/build/generated/source/r/debug" isTestSource="false" generated="true" />
Expand All @@ -34,12 +34,12 @@
<sourceFolder url="file://$MODULE_DIR$/build/generated/source/rs/debug" isTestSource="false" generated="true" />
<sourceFolder url="file://$MODULE_DIR$/build/generated/res/rs/debug" type="java-resource" />
<sourceFolder url="file://$MODULE_DIR$/build/generated/res/generated/debug" type="java-resource" />
<sourceFolder url="file://$MODULE_DIR$/build/generated/source/r/test/debug" isTestSource="true" generated="true" />
<sourceFolder url="file://$MODULE_DIR$/build/generated/source/aidl/test/debug" isTestSource="true" generated="true" />
<sourceFolder url="file://$MODULE_DIR$/build/generated/source/buildConfig/test/debug" isTestSource="true" generated="true" />
<sourceFolder url="file://$MODULE_DIR$/build/generated/source/rs/test/debug" isTestSource="true" generated="true" />
<sourceFolder url="file://$MODULE_DIR$/build/generated/res/rs/test/debug" type="java-test-resource" />
<sourceFolder url="file://$MODULE_DIR$/build/generated/res/generated/test/debug" type="java-test-resource" />
<sourceFolder url="file://$MODULE_DIR$/build/generated/source/r/androidTest/debug" isTestSource="true" generated="true" />
<sourceFolder url="file://$MODULE_DIR$/build/generated/source/aidl/androidTest/debug" isTestSource="true" generated="true" />
<sourceFolder url="file://$MODULE_DIR$/build/generated/source/buildConfig/androidTest/debug" isTestSource="true" generated="true" />
<sourceFolder url="file://$MODULE_DIR$/build/generated/source/rs/androidTest/debug" isTestSource="true" generated="true" />
<sourceFolder url="file://$MODULE_DIR$/build/generated/res/rs/androidTest/debug" type="java-test-resource" />
<sourceFolder url="file://$MODULE_DIR$/build/generated/res/generated/androidTest/debug" type="java-test-resource" />
<sourceFolder url="file://$MODULE_DIR$/src/debug/res" type="java-resource" />
<sourceFolder url="file://$MODULE_DIR$/src/debug/resources" type="java-resource" />
<sourceFolder url="file://$MODULE_DIR$/src/debug/assets" type="java-resource" />
Expand Down Expand Up @@ -102,8 +102,8 @@
<orderEntry type="jdk" jdkName="Android API 21 Platform" jdkType="Android SDK" />
<orderEntry type="sourceFolder" forTests="false" />
<orderEntry type="library" exported="" name="android-async-http-1.4.4" level="project" />
<orderEntry type="library" exported="" name="eventbus-2.2.0" level="project" />
<orderEntry type="library" exported="" name="support-annotations-21.0.0" level="project" />
<orderEntry type="library" exported="" name="eventbus-2.2.0" level="project" />
<orderEntry type="library" exported="" name="support-v4-21.0.0" level="project" />
<orderEntry type="library" exported="" name="android-query.0.26.7" level="project" />
<orderEntry type="library" exported="" name="drag-sort-listview-0.6.1-SNAPSHOT-AAR" level="project" />
Expand Down
2 changes: 1 addition & 1 deletion music-android/app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ buildscript {
mavenCentral()
}
dependencies {
classpath 'com.android.tools.build:gradle:1.0.1'
classpath 'com.android.tools.build:gradle:1.1.0'
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -246,6 +246,8 @@ private QueryParam getQueryParam(TrackCriteria criteria) {
sb.append(" order by pt.PLT_ORDER_N asc");
} else if (criteria.getLike() != null || criteria.getArtistId() != null) {
sb.append(" order by alb.ALB_NAME_C, t.TRK_ORDER_N, t.TRK_TITLE_C asc");
} else if (criteria.getRandom() != null && criteria.getRandom()) {
sb.append(" order by rand()");
} else {
sb.append(" order by t.TRK_ORDER_N, t.TRK_TITLE_C asc");
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,11 @@ public class TrackCriteria {
*/
private String artistName;

/**
* Random order.
*/
private Boolean random;

/**
* Getter of albumId.
*
Expand Down Expand Up @@ -203,4 +208,23 @@ public TrackCriteria setArtistId(String artistId) {
this.artistId = artistId;
return this;
}

/**
* Getter of random.
*
* @return the random
*/
public Boolean getRandom() {
return random;
}

/**
* Setter of random.
*
* @param random random
*/
public TrackCriteria setRandom(Boolean random) {
this.random = random;
return this;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@
import com.sismics.music.core.dao.dbi.dto.TrackDto;
import com.sismics.music.core.model.dbi.Playlist;
import com.sismics.music.core.model.dbi.Track;
import com.sismics.music.core.util.dbi.PaginatedList;
import com.sismics.music.core.util.dbi.PaginatedLists;
import com.sismics.music.rest.util.JsonUtil;
import com.sismics.rest.exception.ClientException;
import com.sismics.rest.exception.ForbiddenClientException;
Expand All @@ -41,6 +43,7 @@ public class PlaylistResource extends BaseResource {
*
* @param id Track ID
* @param order Insert at this order in the playlist
* @param clear If true, clear the playlist
* @return Response
*/
@PUT
Expand Down Expand Up @@ -90,6 +93,7 @@ public Response insertTrack(
* Inserts tracks in the playlist.
*
* @param idList List of track ID
* @param clear If true, clear the playlist
* @return Response
*/
@PUT
Expand Down Expand Up @@ -136,6 +140,53 @@ public Response insertTracks(
.entity(buildPlaylistJson(playlist))
.build();
}

/**
* Start or continue party mode.
* Adds some good tracks.
*
* @param clear If true, clear the playlist
* @return Response
*/
@POST
@Path("party")
public Response party(@FormParam("clear") Boolean clear) {
if (!authenticate()) {
throw new ForbiddenClientException();
}

// Get the playlist
PlaylistDao playlistDao = new PlaylistDao();
Playlist playlist = playlistDao.getActiveByUserId(principal.getId());
if (playlist == null) {
throw new ServerException("UnknownError", MessageFormat.format("Playlist not found for user {0}", principal.getId()));
}
PlaylistTrackDao playlistTrackDao = new PlaylistTrackDao();

if (clear != null && clear) {
// Delete all tracks in the playlist
playlistTrackDao.deleteByPlaylistId(playlist.getId());
}

// Get the track order
int order = playlistTrackDao.getPlaylistTrackNextOrder(playlist.getId());

// TODO Add prefered tracks
// Add random tracks
TrackDao trackDao = new TrackDao();
PaginatedList<TrackDto> paginatedList = PaginatedLists.create();
trackDao.findByCriteria(new TrackCriteria().setRandom(true), paginatedList);

for (TrackDto trackDto : paginatedList.getResultList()) {
// Insert the track into the playlist
playlistTrackDao.insertPlaylistTrack(playlist.getId(), trackDto.getId(), order++);
}

// Output the playlist
return Response.ok()
.entity(buildPlaylistJson(playlist))
.build();
}

/**
* Move the track to another position in the playlist.
Expand Down
3 changes: 2 additions & 1 deletion music-web/src/main/webapp/src/app/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,8 @@ angular.module('music',
abstract: true,
views: {
'page': {
templateUrl: 'partial/main.html'
templateUrl: 'partial/main.html',
controller: 'Main'
}
}
})
Expand Down
11 changes: 11 additions & 0 deletions music-web/src/main/webapp/src/app/controller/Main.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
'use strict';

/**
* Main controller.
*/
angular.module('music').controller('Main', function($state, $scope, Playlist) {
$scope.startPartyMode = function() {
Playlist.party(true, true);
$state.transitionTo('main.playing');
};
});
67 changes: 54 additions & 13 deletions music-web/src/main/webapp/src/app/service/Playlist.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ angular.module('music').factory('Playlist', function($rootScope, Restangular, to
var repeat = true;
var shuffle = false;
var visualization = true;
var partyMode = false;

// Read Local Storage settings
if (!_.isUndefined(localStorage.playlistRepeat)) {
Expand Down Expand Up @@ -51,11 +52,12 @@ angular.module('music').factory('Playlist', function($rootScope, Restangular, to
$rootScope.$broadcast('audio.stop');
currentTrack = null;
tracks = [];
service.setPartyMode(false);
},

/**
* Play a track from the current playlist.
* @param _currentTrack
* @param _currentTrack Track to play
*/
play: function(_currentTrack) {
if (_.size(tracks) > _currentTrack) {
Expand All @@ -66,8 +68,8 @@ angular.module('music').factory('Playlist', function($rootScope, Restangular, to

/**
* Move a track in the playlist.
* @param order
* @param neworder
* @param order Old order
* @param neworder New order
*/
moveTrack: function(order, neworder) {
if (currentTrack != null) {
Expand Down Expand Up @@ -100,7 +102,7 @@ angular.module('music').factory('Playlist', function($rootScope, Restangular, to

/**
* Open a track without playing it.
* @param _currentTrack
* @param _currentTrack Track to open
*/
open: function(_currentTrack) {
if (_.size(tracks) > _currentTrack) {
Expand Down Expand Up @@ -143,11 +145,13 @@ angular.module('music').factory('Playlist', function($rootScope, Restangular, to

/**
* Add a track to the playlist.
* @param track
* @param clear
* @param track Track to add
* @param clear Clear the playlist
* @param play If true, immediately play the first track once added
*/
add: function(track, clear, play) {
service.setPartyMode(false);

Restangular.one('playlist').put({
id: track.id,
clear: clear,
Expand All @@ -165,11 +169,13 @@ angular.module('music').factory('Playlist', function($rootScope, Restangular, to

/**
* Add a list of tracks to the playlist.
* @param trackIdList
* @param clear
* @param trackIdList List of track IDs
* @param clear Clear the playlist
* @param play If true, immediately play the first track once added
*/
addAll: function(trackIdList, clear, play) {
service.setPartyMode(false);

Restangular.one('playlist/multiple').put({
ids: trackIdList,
clear: clear
Expand All @@ -186,9 +192,28 @@ angular.module('music').factory('Playlist', function($rootScope, Restangular, to
});
},

/**
* Start or continue party mode.
* @param clear Clear the playlist
* @param play If true, immediately play the first track once added
*/
party: function(clear, play) {
Restangular.one('playlist').post('party', {
clear: clear
}).then(function(data) {
service.setTracks(data.tracks);
service.setPartyMode(_.size(tracks) > 0);

if (play && _.size(tracks) > 0) {
service.play(0);
toaster.pop('success', 'Party mode', 'Let\'s get the party started!');
}
});
},

/**
* Remove a given track from the playlist.
* @param order
* @param order Order to remove
*/
remove: function(order) {
if (currentTrack != null) {
Expand All @@ -213,6 +238,7 @@ angular.module('music').factory('Playlist', function($rootScope, Restangular, to
clear: function() {
// Stop the audio
currentTrack = null;
service.setPartyMode(false);
$rootScope.$broadcast('audio.stop');

return Restangular.one('playlist').remove().then(function() {
Expand Down Expand Up @@ -283,11 +309,26 @@ angular.module('music').factory('Playlist', function($rootScope, Restangular, to
currentOrder: function() { return currentTrack; },
getTracks: function() { return angular.copy(tracks); },
isRepeat: function() { return repeat; },
toggleRepeat: function() { repeat = !repeat; localStorage.playlistRepeat = repeat; },
isShuffle: function() { return shuffle; },
toggleShuffle: function() { shuffle = !shuffle; localStorage.playlistShuffle = shuffle; },
toggleRepeat: function() {
repeat = !repeat;
localStorage.playlistRepeat = repeat;
},
isShuffle: function() {return shuffle; },
toggleShuffle: function() {
shuffle = !shuffle;
localStorage.playlistShuffle = shuffle;
},
isVisualization: function() { return visualization; },
toggleVisualization: function() { visualization = !visualization; localStorage.playlistVisualization = visualization; }
toggleVisualization: function() {
visualization = !visualization;
localStorage.playlistVisualization = visualization;
},
setPartyMode: function(_partyMode) {
partyMode = _partyMode;
if (partyMode != _partyMode) {
$rootScope.$broadcast('playlist.party', partyMode);
}
}
};

return service;
Expand Down
1 change: 1 addition & 0 deletions music-web/src/main/webapp/src/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@
<script src="app/controller/Login.js" type="text/javascript"></script>
<script src="app/controller/Navigation.js" type="text/javascript"></script>
<script src="app/controller/AudioPlayer.js" type="text/javascript"></script>
<script src="app/controller/Main.js" type="text/javascript"></script>
<script src="app/controller/MainDefault.js" type="text/javascript"></script>
<script src="app/controller/Playing.js" type="text/javascript"></script>
<script src="app/controller/Lyrics.js" type="text/javascript"></script>
Expand Down
7 changes: 7 additions & 0 deletions music-web/src/main/webapp/src/partial/main.html
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,13 @@
</div>
</div>

<div class="panel">
<button class="btn btn-primary btn-block" title="Start listening to your prefered music endlessly" ng-click="startPartyMode()">
<span class="glyphicon glyphicon-glass"></span>
Get the party started!
</button>
</div>

<div class="panel panel-default">
<div class="list-group">
<a class="list-group-item" ng-class="{ active: $uiRoute }" ui-route="/playing" href="#/playing">
Expand Down

0 comments on commit 9b5e008

Please sign in to comment.