From 5ae23c33d575eefeaefac934b8f575a83bf2f9de Mon Sep 17 00:00:00 2001 From: Scott Jackson Date: Sun, 31 Aug 2014 10:04:46 -0700 Subject: Add rating/bookmark selected logic --- .../ic_action_rating_good_selected.png | Bin 0 -> 921 bytes .../ic_action_rating_good_selected.png | Bin 0 -> 581 bytes .../ic_action_rating_good_selected.png | Bin 0 -> 1176 bytes .../ic_action_rating_good_selected.png | Bin 0 -> 1915 bytes .../daneren2005/dsub/domain/MusicDirectory.java | 4 +- .../dsub/fragments/NowPlayingFragment.java | 47 +++++++++++++++++++++ src/github/daneren2005/dsub/util/Util.java | 10 +++++ 7 files changed, 59 insertions(+), 2 deletions(-) create mode 100644 res/drawable-hdpi/ic_action_rating_good_selected.png create mode 100644 res/drawable-mdpi/ic_action_rating_good_selected.png create mode 100644 res/drawable-xhdpi/ic_action_rating_good_selected.png create mode 100644 res/drawable-xxhdpi/ic_action_rating_good_selected.png diff --git a/res/drawable-hdpi/ic_action_rating_good_selected.png b/res/drawable-hdpi/ic_action_rating_good_selected.png new file mode 100644 index 00000000..34d53153 Binary files /dev/null and b/res/drawable-hdpi/ic_action_rating_good_selected.png differ diff --git a/res/drawable-mdpi/ic_action_rating_good_selected.png b/res/drawable-mdpi/ic_action_rating_good_selected.png new file mode 100644 index 00000000..97d279be Binary files /dev/null and b/res/drawable-mdpi/ic_action_rating_good_selected.png differ diff --git a/res/drawable-xhdpi/ic_action_rating_good_selected.png b/res/drawable-xhdpi/ic_action_rating_good_selected.png new file mode 100644 index 00000000..c6770221 Binary files /dev/null and b/res/drawable-xhdpi/ic_action_rating_good_selected.png differ diff --git a/res/drawable-xxhdpi/ic_action_rating_good_selected.png b/res/drawable-xxhdpi/ic_action_rating_good_selected.png new file mode 100644 index 00000000..bb444806 Binary files /dev/null and b/res/drawable-xxhdpi/ic_action_rating_good_selected.png differ diff --git a/src/github/daneren2005/dsub/domain/MusicDirectory.java b/src/github/daneren2005/dsub/domain/MusicDirectory.java index 1caf77cf..a738f9bf 100644 --- a/src/github/daneren2005/dsub/domain/MusicDirectory.java +++ b/src/github/daneren2005/dsub/domain/MusicDirectory.java @@ -400,8 +400,8 @@ public class MusicDirectory implements Serializable { this.starred = starred; } - public Integer getRating() { - return rating; + public int getRating() { + return rating == null ? 0 : rating; } public void setRating(Integer rating) { this.rating = rating; diff --git a/src/github/daneren2005/dsub/fragments/NowPlayingFragment.java b/src/github/daneren2005/dsub/fragments/NowPlayingFragment.java index 868cdef1..b24fa7f2 100644 --- a/src/github/daneren2005/dsub/fragments/NowPlayingFragment.java +++ b/src/github/daneren2005/dsub/fragments/NowPlayingFragment.java @@ -24,6 +24,8 @@ import android.app.AlertDialog; import android.content.DialogInterface; import android.content.Intent; import android.content.SharedPreferences; +import android.content.res.Configuration; +import android.content.res.TypedArray; import android.graphics.Color; import android.os.Build; import android.os.Bundle; @@ -404,6 +406,7 @@ public class NowPlayingFragment extends SubsonicFragment implements OnGestureLis @Override public void onClick(View view) { createBookmark(); + bookmarkButton.setImageResource(R.drawable.ic_menu_bookmark_selected); } }); @@ -412,6 +415,14 @@ public class NowPlayingFragment extends SubsonicFragment implements OnGestureLis public void onClick(View view) { Entry entry = getDownloadService().getCurrentPlaying().getSong(); setRating(entry, 1); + rateBadButton.setImageResource(R.drawable.ic_action_rating_bad_selected); + + // Make sure good rating is blank + if(getResources().getConfiguration().orientation == Configuration.ORIENTATION_PORTRAIT) { + rateGoodButton.setImageResource(R.drawable.ic_action_rating_good_dark); + } else { + rateGoodButton.setImageResource(Util.getAttribute(context, R.attr.rating_good)); + } } }); rateGoodButton.setOnClickListener(new View.OnClickListener() { @@ -419,6 +430,14 @@ public class NowPlayingFragment extends SubsonicFragment implements OnGestureLis public void onClick(View view) { Entry entry = getDownloadService().getCurrentPlaying().getSong(); setRating(entry, 5); + rateGoodButton.setImageResource(R.drawable.ic_action_rating_good_selected); + + // Make sure bad rating is blank + if(getResources().getConfiguration().orientation == Configuration.ORIENTATION_PORTRAIT) { + rateBadButton.setImageResource(R.drawable.ic_action_rating_bad_dark); + } else { + rateBadButton.setImageResource(Util.getAttribute(context, R.attr.rating_bad)); + } } }); @@ -1155,6 +1174,34 @@ public class NowPlayingFragment extends SubsonicFragment implements OnGestureLis getImageLoader().loadImage(albumArtImageView, song, true, true); starButton.setImageResource(song.isStarred() ? android.R.drawable.btn_star_big_on : android.R.drawable.btn_star_big_off); setSubtitle(context.getResources().getString(R.string.download_playing_out_of, currentPlayingIndex, currentPlayingSize)); + + int badRating, goodRating, bookmark; + if(song.getRating() == 1) { + badRating = R.drawable.ic_action_rating_bad_selected; + } else if(getResources().getConfiguration().orientation == Configuration.ORIENTATION_PORTRAIT) { + badRating = R.drawable.ic_action_rating_bad_dark; + } else { + badRating = Util.getAttribute(context, R.attr.rating_bad); + } + rateBadButton.setImageResource(badRating); + + if(song.getRating() == 5) { + goodRating = R.drawable.ic_action_rating_good_selected; + } else if(getResources().getConfiguration().orientation == Configuration.ORIENTATION_PORTRAIT) { + goodRating = R.drawable.ic_action_rating_good_dark; + } else { + goodRating = Util.getAttribute(context, R.attr.rating_good); + } + rateGoodButton.setImageResource(goodRating); + + if(song.getBookmark() != null) { + bookmark = R.drawable.ic_menu_bookmark_selected; + } else if(getResources().getConfiguration().orientation == Configuration.ORIENTATION_PORTRAIT) { + bookmark = R.drawable.ic_menu_bookmark_dark; + } else { + bookmark = Util.getAttribute(context, R.attr.bookmark); + } + bookmarkButton.setImageResource(bookmark); } else { songTitleTextView.setText(null); getImageLoader().loadImage(albumArtImageView, null, true, false); diff --git a/src/github/daneren2005/dsub/util/Util.java b/src/github/daneren2005/dsub/util/Util.java index c1d026d4..24458eb3 100644 --- a/src/github/daneren2005/dsub/util/Util.java +++ b/src/github/daneren2005/dsub/util/Util.java @@ -30,6 +30,7 @@ import android.content.Intent; import android.content.SharedPreferences; import android.content.res.Configuration; import android.content.res.Resources; +import android.content.res.TypedArray; import android.graphics.Bitmap; import android.graphics.BitmapFactory; import android.graphics.drawable.BitmapDrawable; @@ -1089,6 +1090,15 @@ public final class Util { } } + public static int getAttribute(Context context, int attr) { + int res; + int[] attrs = new int[] {attr}; + TypedArray typedArray = context.obtainStyledAttributes(attrs); + res = typedArray.getResourceId(0, 0); + typedArray.recycle(); + return res; + } + public static void registerMediaButtonEventReceiver(Context context) { // Only do it if enabled in the settings. -- cgit v1.2.3