diff options
Diffstat (limited to 'src/github/daneren2005')
7 files changed, 67 insertions, 23 deletions
diff --git a/src/github/daneren2005/dsub/fragments/NowPlayingFragment.java b/src/github/daneren2005/dsub/fragments/NowPlayingFragment.java index 90cc746c..868cdef1 100644 --- a/src/github/daneren2005/dsub/fragments/NowPlayingFragment.java +++ b/src/github/daneren2005/dsub/fragments/NowPlayingFragment.java @@ -71,6 +71,7 @@ import github.daneren2005.dsub.view.UpdateView; import github.daneren2005.dsub.util.Util;
import github.daneren2005.dsub.view.VisualizerView;
+import static github.daneren2005.dsub.domain.MusicDirectory.Entry;
import static github.daneren2005.dsub.domain.PlayerState.*;
import github.daneren2005.dsub.util.*;
import github.daneren2005.dsub.view.AutoRepeatButton;
@@ -113,6 +114,8 @@ public class NowPlayingFragment extends SubsonicFragment implements OnGestureLis private View toggleListButton;
private ImageButton starButton;
private ImageButton bookmarkButton;
+ private ImageButton rateBadButton;
+ private ImageButton rateGoodButton;
private View mainLayout;
private ScheduledExecutorService executorService;
private DownloadFile currentPlaying;
@@ -185,6 +188,8 @@ public class NowPlayingFragment extends SubsonicFragment implements OnGestureLis equalizerButton = (Button)rootView.findViewById(R.id.download_equalizer);
visualizerButton = (Button)rootView.findViewById(R.id.download_visualizer);
bookmarkButton = (ImageButton) rootView.findViewById(R.id.download_bookmark);
+ rateBadButton = (ImageButton) rootView.findViewById(R.id.download_rating_bad);
+ rateGoodButton = (ImageButton) rootView.findViewById(R.id.download_rating_good);
LinearLayout visualizerViewLayout = (LinearLayout)rootView.findViewById(R.id.download_visualizer_view_layout);
toggleListButton =rootView.findViewById(R.id.download_toggle_list);
@@ -195,7 +200,7 @@ public class NowPlayingFragment extends SubsonicFragment implements OnGestureLis public void onClick(View v) {
DownloadFile currentDownload = getDownloadService().getCurrentPlaying();
if (currentDownload != null) {
- MusicDirectory.Entry currentSong = currentDownload.getSong();
+ Entry currentSong = currentDownload.getSong();
toggleStarred(currentSong);
starButton.setImageResource(currentSong.isStarred() ? android.R.drawable.btn_star_big_on : android.R.drawable.btn_star_big_off);
}
@@ -402,6 +407,21 @@ public class NowPlayingFragment extends SubsonicFragment implements OnGestureLis }
});
+ rateBadButton.setOnClickListener(new View.OnClickListener() {
+ @Override
+ public void onClick(View view) {
+ Entry entry = getDownloadService().getCurrentPlaying().getSong();
+ setRating(entry, 1);
+ }
+ });
+ rateGoodButton.setOnClickListener(new View.OnClickListener() {
+ @Override
+ public void onClick(View view) {
+ Entry entry = getDownloadService().getCurrentPlaying().getSong();
+ setRating(entry, 5);
+ }
+ });
+
toggleListButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
@@ -595,7 +615,7 @@ public class NowPlayingFragment extends SubsonicFragment implements OnGestureLis private boolean menuItemSelected(int menuItemId, final DownloadFile song) {
switch (menuItemId) {
case R.id.menu_show_album: case R.id.menu_show_artist:
- MusicDirectory.Entry entry = song.getSong();
+ Entry entry = song.getSong();
Intent intent = new Intent(context, SubsonicFragmentActivity.class);
intent.putExtra(Constants.INTENT_EXTRA_VIEW_ALBUM, true);
@@ -672,7 +692,7 @@ public class NowPlayingFragment extends SubsonicFragment implements OnGestureLis }.execute();
return true;
case R.id.menu_delete:
- List<MusicDirectory.Entry> songs = new ArrayList<MusicDirectory.Entry>(1);
+ List<Entry> songs = new ArrayList<Entry>(1);
songs.add(song.getSong());
getDownloadService().delete(songs);
return true;
@@ -729,7 +749,7 @@ public class NowPlayingFragment extends SubsonicFragment implements OnGestureLis }.execute();
return true;
case R.id.menu_save_playlist:
- List<MusicDirectory.Entry> entries = new LinkedList<MusicDirectory.Entry>();
+ List<Entry> entries = new LinkedList<Entry>();
for (DownloadFile downloadFile : getDownloadService().getSongs()) {
entries.add(downloadFile.getSong());
}
@@ -747,7 +767,7 @@ public class NowPlayingFragment extends SubsonicFragment implements OnGestureLis }
return true;
case R.id.menu_add_playlist:
- songs = new ArrayList<MusicDirectory.Entry>(1);
+ songs = new ArrayList<Entry>(1);
songs.add(song.getSong());
addToPlaylist(songs);
return true;
@@ -755,7 +775,7 @@ public class NowPlayingFragment extends SubsonicFragment implements OnGestureLis displaySongInfo(song.getSong());
return true;
case R.id.menu_share:
- songs = new ArrayList<MusicDirectory.Entry>(1);
+ songs = new ArrayList<Entry>(1);
songs.add(song.getSong());
createShare(songs);
default:
@@ -1130,7 +1150,7 @@ public class NowPlayingFragment extends SubsonicFragment implements OnGestureLis @Override
protected void done(Void result) {
if (currentPlaying != null) {
- MusicDirectory.Entry song = currentPlaying.getSong();
+ Entry song = currentPlaying.getSong();
songTitleTextView.setText(song.getTitle());
getImageLoader().loadImage(albumArtImageView, song, true, true);
starButton.setImageResource(song.isStarred() ? android.R.drawable.btn_star_big_on : android.R.drawable.btn_star_big_off);
@@ -1317,13 +1337,13 @@ public class NowPlayingFragment extends SubsonicFragment implements OnGestureLis new SilentBackgroundTask<Void>(context) {
@Override
protected Void doInBackground() throws Throwable {
- MusicDirectory.Entry currentSong = currentDownload.getSong();
+ Entry currentSong = currentDownload.getSong();
MusicService musicService = MusicServiceFactory.getMusicService(context);
int position = getDownloadService().getPlayerPosition();
musicService.createBookmark(currentSong.getId(), Util.getParentFromEntry(context, currentSong), position, comment, context, null);
currentSong.setBookmark(new Bookmark(position));
- MusicDirectory.Entry find = UpdateView.findEntry(currentSong);
+ Entry find = UpdateView.findEntry(currentSong);
if(find != null && find != currentSong) {
find.setBookmark(new Bookmark(position));
}
diff --git a/src/github/daneren2005/dsub/fragments/SubsonicFragment.java b/src/github/daneren2005/dsub/fragments/SubsonicFragment.java index 9e5d936b..92709bde 100644 --- a/src/github/daneren2005/dsub/fragments/SubsonicFragment.java +++ b/src/github/daneren2005/dsub/fragments/SubsonicFragment.java @@ -1494,4 +1494,29 @@ public class SubsonicFragment extends Fragment implements SwipeRefreshLayout.OnR }
});
}
+
+ protected void setRating(final Entry entry, final int rating) {
+ new SilentBackgroundTask<Void>(context) {
+ @Override
+ protected Void doInBackground() throws Throwable {
+ MusicService musicService = MusicServiceFactory.getMusicService(context);
+ musicService.setRating(entry, rating, context, null);
+
+ entry.setRating(rating);
+ return null;
+ }
+
+ @Override
+ protected void error(Throwable error) {
+ String msg;
+ if (error instanceof OfflineException || error instanceof ServerTooOldException) {
+ msg = getErrorMessage(error);
+ } else {
+ msg = context.getResources().getString(R.string.rating_set_rating_failed, entry.getTitle()) + " " + getErrorMessage(error);
+ }
+
+ Util.toast(context, msg, false);
+ }
+ }.execute();
+ }
}
diff --git a/src/github/daneren2005/dsub/service/CachedMusicService.java b/src/github/daneren2005/dsub/service/CachedMusicService.java index 3801da67..f68adb7b 100644 --- a/src/github/daneren2005/dsub/service/CachedMusicService.java +++ b/src/github/daneren2005/dsub/service/CachedMusicService.java @@ -792,10 +792,10 @@ public class CachedMusicService implements MusicService { } @Override - public void setRating(final String id, String parent, final int rating, Context context, ProgressListener progressListener) throws Exception { - musicService.setRating(id, parent, rating, context, progressListener); + public void setRating(final Entry entry, final int rating, Context context, ProgressListener progressListener) throws Exception { + musicService.setRating(entry, rating, context, progressListener); - new GenericSongUpdater(context, parent, id) { + new GenericSongUpdater(context, entry) { @Override public void updateResult(Entry result) { result.setRating(rating); @@ -1231,22 +1231,20 @@ public class CachedMusicService implements MusicService { } private abstract class GenericSongUpdater { Context context; - String id; - String parent; + Entry entry; - public GenericSongUpdater(Context context, String id, String parent) { + public GenericSongUpdater(Context context, Entry entry) { this.context = context; - this.id = id; - this.parent = parent; + this.entry = entry; } public boolean checkResult(Entry check) { - return id.equals(check.getId()); + return entry.getId().equals(check.getId()); } public abstract void updateResult(Entry result); public void execute() { - new MusicDirectoryUpdater(context, "directory", parent) { + new MusicDirectoryUpdater(context, "directory", entry.getParent()) { @Override public boolean checkResult(Entry check) { return GenericSongUpdater.this.checkResult(check); diff --git a/src/github/daneren2005/dsub/service/MusicService.java b/src/github/daneren2005/dsub/service/MusicService.java index 28b8bbfe..466ad477 100644 --- a/src/github/daneren2005/dsub/service/MusicService.java +++ b/src/github/daneren2005/dsub/service/MusicService.java @@ -152,7 +152,7 @@ public interface MusicService { void deletePodcastEpisode(String id, String parent, ProgressListener progressListener, Context context) throws Exception; - void setRating(String id, String parent, int rating, Context context, ProgressListener progressListener) throws Exception; + void setRating(MusicDirectory.Entry entry, int rating, Context context, ProgressListener progressListener) throws Exception; MusicDirectory getBookmarks(boolean refresh, Context context, ProgressListener progressListener) throws Exception; diff --git a/src/github/daneren2005/dsub/service/OfflineMusicService.java b/src/github/daneren2005/dsub/service/OfflineMusicService.java index 6ac21c35..e20a2b41 100644 --- a/src/github/daneren2005/dsub/service/OfflineMusicService.java +++ b/src/github/daneren2005/dsub/service/OfflineMusicService.java @@ -737,7 +737,7 @@ public class OfflineMusicService implements MusicService { } @Override - public void setRating(String id, String parent, int rating, Context context, ProgressListener progressListener) throws Exception { + public void setRating(MusicDirectory.Entry entry, int rating, Context context, ProgressListener progressListener) throws Exception { throw new OfflineException(ERRORMSG); } diff --git a/src/github/daneren2005/dsub/service/RESTMusicService.java b/src/github/daneren2005/dsub/service/RESTMusicService.java index 4ec487a0..991ad5ee 100644 --- a/src/github/daneren2005/dsub/service/RESTMusicService.java +++ b/src/github/daneren2005/dsub/service/RESTMusicService.java @@ -1126,10 +1126,10 @@ public class RESTMusicService implements MusicService { } @Override - public void setRating(String id, String parent, int rating, Context context, ProgressListener progressListener) throws Exception { + public void setRating(MusicDirectory.Entry entry, int rating, Context context, ProgressListener progressListener) throws Exception { checkServerVersion(context, "1.6", "Setting ratings not supported."); - Reader reader = getReader(context, progressListener, "setRating", null, Arrays.asList("id", "rating"), Arrays.<Object>asList(id, rating)); + Reader reader = getReader(context, progressListener, "setRating", null, Arrays.asList("id", "rating"), Arrays.<Object>asList(entry.getId(), rating)); try { new ErrorParser(context, getInstance(context)).parse(reader); } finally { diff --git a/src/github/daneren2005/dsub/service/parser/MusicDirectoryEntryParser.java b/src/github/daneren2005/dsub/service/parser/MusicDirectoryEntryParser.java index 683f6857..9ca2c4e6 100644 --- a/src/github/daneren2005/dsub/service/parser/MusicDirectoryEntryParser.java +++ b/src/github/daneren2005/dsub/service/parser/MusicDirectoryEntryParser.java @@ -73,6 +73,7 @@ public class MusicDirectoryEntryParser extends AbstractParser { } else if("audiobook".equals(type)) { entry.setType(MusicDirectory.Entry.TYPE_AUDIO_BOOK); } + entry.setRating(getInteger("userRating")); } else if(!"".equals(artist)) { entry.setPath(artist + "/" + entry.getTitle()); } |