Skip to content

Commit

Permalink
Unpin songs when turning off playlist sync
Browse files Browse the repository at this point in the history
  • Loading branch information
daneren2005 committed Dec 25, 2013
1 parent fa7631c commit 3f2a53d
Showing 1 changed file with 24 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,14 @@
import android.widget.EditText;
import android.widget.ListView;
import github.daneren2005.dsub.R;
import github.daneren2005.dsub.domain.MusicDirectory;
import github.daneren2005.dsub.domain.Playlist;
import github.daneren2005.dsub.service.DownloadFile;
import github.daneren2005.dsub.service.MusicService;
import github.daneren2005.dsub.service.MusicServiceFactory;
import github.daneren2005.dsub.service.OfflineException;
import github.daneren2005.dsub.service.ServerTooOldException;
import github.daneren2005.dsub.util.FileUtil;
import github.daneren2005.dsub.util.ProgressListener;
import github.daneren2005.dsub.util.SyncUtil;
import github.daneren2005.dsub.util.BackgroundTask;
Expand Down Expand Up @@ -261,7 +264,27 @@ private void syncPlaylist(Playlist playlist) {
downloadPlaylist(playlist.getId(), playlist.getName(), true, true, false, false, true);
}

private void stopSyncPlaylist(Playlist playlist) {
private void stopSyncPlaylist(final Playlist playlist) {
SyncUtil.removeSyncedPlaylist(context, playlist.getId());

new LoadingTask<Void>(context, false) {
@Override
protected Void doInBackground() throws Throwable {
// Unpin all of the songs in playlist
MusicService musicService = MusicServiceFactory.getMusicService(context);
MusicDirectory root = musicService.getPlaylist(true, playlist.getId(), playlist.getName(), context, this);
for(MusicDirectory.Entry entry: root.getChildren()) {
DownloadFile file = new DownloadFile(context, entry, false);
file.unpin();
}

return null;
}

@Override
protected void done(Void result) {

}
}.execute();
}
}

0 comments on commit 3f2a53d

Please sign in to comment.