diff options
author | Scott Jackson <daneren2005@gmail.com> | 2015-07-14 18:00:34 -0700 |
---|---|---|
committer | Scott Jackson <daneren2005@gmail.com> | 2015-07-18 10:23:34 -0700 |
commit | 775e66c3006ff90df86da3b87b08436b441b79e4 (patch) | |
tree | 46f3f373de05245137541249cac60e82f5d99639 /app/src/main/java/github/daneren2005 | |
parent | 67ed55d9c0b4e92ef962d39ef9f20326c11beaa1 (diff) | |
download | dsub-775e66c3006ff90df86da3b87b08436b441b79e4.tar.gz dsub-775e66c3006ff90df86da3b87b08436b441b79e4.tar.bz2 dsub-775e66c3006ff90df86da3b87b08436b441b79e4.zip |
Update to use tinted drawables
Diffstat (limited to 'app/src/main/java/github/daneren2005')
6 files changed, 62 insertions, 40 deletions
diff --git a/app/src/main/java/github/daneren2005/dsub/fragments/NowPlayingFragment.java b/app/src/main/java/github/daneren2005/dsub/fragments/NowPlayingFragment.java index 9fa377da..bec43a22 100644 --- a/app/src/main/java/github/daneren2005/dsub/fragments/NowPlayingFragment.java +++ b/app/src/main/java/github/daneren2005/dsub/fragments/NowPlayingFragment.java @@ -235,7 +235,11 @@ public class NowPlayingFragment extends SubsonicFragment implements OnGestureLis toggleStarred(currentSong, new OnStarChange() { @Override void starChange(boolean starred) { - starButton.setImageResource(currentSong.isStarred() ? android.R.drawable.btn_star_big_on : android.R.drawable.btn_star_big_off); + if(currentSong.isStarred()) { + starButton.setImageDrawable(DrawableTint.getTintedDrawable(context, R.drawable.ic_toggle_star)); + } else { + starButton.setImageResource(R.drawable.ic_toggle_star_outline_dark); + } } }); } @@ -398,7 +402,7 @@ public class NowPlayingFragment extends SubsonicFragment implements OnGestureLis if(context.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)); + rateBadButton.setImageResource(DrawableTint.getDrawableRes(context, R.attr.rating_bad)); } } else { // Immediately skip to the next song @@ -406,13 +410,13 @@ public class NowPlayingFragment extends SubsonicFragment implements OnGestureLis // Otherwise set rating to 1 setRating(entry, 1); - rateBadButton.setImageResource(R.drawable.ic_action_rating_bad_selected); + rateBadButton.setImageDrawable(DrawableTint.getTintedDrawable(context, R.drawable.ic_action_rating_bad_selected)); // Make sure good rating is blank if (context.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.setImageResource(DrawableTint.getDrawableRes(context, R.attr.rating_good)); } } } @@ -438,18 +442,18 @@ public class NowPlayingFragment extends SubsonicFragment implements OnGestureLis if (context.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.setImageResource(DrawableTint.getDrawableRes(context, R.attr.rating_good)); } } else { // Otherwise set rating to maximum setRating(entry, 5); - rateGoodButton.setImageResource(R.drawable.ic_action_rating_good_selected); + rateGoodButton.setImageDrawable(DrawableTint.getTintedDrawable(context, R.drawable.ic_action_rating_good_selected)); // Make sure bad rating is blank if (context.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)); + rateBadButton.setImageResource(DrawableTint.getDrawableRes(context, R.attr.rating_bad)); } } } @@ -1102,7 +1106,7 @@ public class NowPlayingFragment extends SubsonicFragment implements OnGestureLis final int position = downloadService.getPlayerPosition(); final Bookmark oldBookmark = currentSong.getBookmark(); currentSong.setBookmark(new Bookmark(position)); - bookmarkButton.setImageResource(R.drawable.ic_menu_bookmark_selected); + bookmarkButton.setImageDrawable(DrawableTint.getTintedDrawable(context, R.drawable.ic_menu_bookmark_selected)); new SilentBackgroundTask<Void>(context) { @Override @@ -1137,7 +1141,7 @@ public class NowPlayingFragment extends SubsonicFragment implements OnGestureLis if(context.getResources().getConfiguration().orientation == Configuration.ORIENTATION_PORTRAIT) { bookmark = R.drawable.ic_menu_bookmark_dark; } else { - bookmark = Util.getAttribute(context, R.attr.bookmark); + bookmark = DrawableTint.getDrawableRes(context, R.attr.bookmark); } bookmarkButton.setImageResource(bookmark); } @@ -1252,40 +1256,50 @@ public class NowPlayingFragment extends SubsonicFragment implements OnGestureLis 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); - setSubtitle(context.getResources().getString(R.string.download_playing_out_of, Math.max(0, currentPlayingIndex + 1), currentPlayingSize)); + if(song.isStarred()) { + starButton.setImageDrawable(DrawableTint.getTintedDrawable(context, R.drawable.ic_toggle_star)); + } else { + starButton.setImageResource(R.drawable.ic_toggle_star_outline_dark); + } + 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(context.getResources().getConfiguration().orientation == Configuration.ORIENTATION_PORTRAIT) { - badRating = R.drawable.ic_action_rating_bad_dark; + rateBadButton.setImageDrawable(DrawableTint.getTintedDrawable(context, R.drawable.ic_action_rating_bad_selected)); } else { - badRating = Util.getAttribute(context, R.attr.rating_bad); + if(context.getResources().getConfiguration().orientation == Configuration.ORIENTATION_PORTRAIT) { + badRating = R.drawable.ic_action_rating_bad_dark; + } else { + badRating = DrawableTint.getDrawableRes(context, R.attr.rating_bad); + } + rateBadButton.setImageResource(badRating); } - rateBadButton.setImageResource(badRating); if(song.getRating() == 5) { - goodRating = R.drawable.ic_action_rating_good_selected; - } else if(context.getResources().getConfiguration().orientation == Configuration.ORIENTATION_PORTRAIT) { - goodRating = R.drawable.ic_action_rating_good_dark; + rateGoodButton.setImageDrawable(DrawableTint.getTintedDrawable(context, R.drawable.ic_action_rating_good_selected)); } else { - goodRating = Util.getAttribute(context, R.attr.rating_good); + if(context.getResources().getConfiguration().orientation == Configuration.ORIENTATION_PORTRAIT) { + goodRating = R.drawable.ic_action_rating_good_dark; + } else { + goodRating = DrawableTint.getDrawableRes(context, R.attr.rating_good); + } + rateGoodButton.setImageResource(goodRating); } - rateGoodButton.setImageResource(goodRating); if(song.getBookmark() != null) { - bookmark = R.drawable.ic_menu_bookmark_selected; - } else if(context.getResources().getConfiguration().orientation == Configuration.ORIENTATION_PORTRAIT) { - bookmark = R.drawable.ic_menu_bookmark_dark; + bookmarkButton.setImageDrawable(DrawableTint.getTintedDrawable(context, R.drawable.ic_menu_bookmark_selected)); } else { - bookmark = Util.getAttribute(context, R.attr.bookmark); + if(context.getResources().getConfiguration().orientation == Configuration.ORIENTATION_PORTRAIT) { + bookmark = R.drawable.ic_menu_bookmark_dark; + } else { + bookmark = DrawableTint.getDrawableRes(context, R.attr.bookmark); + } + bookmarkButton.setImageResource(bookmark); } - bookmarkButton.setImageResource(bookmark); } else { songTitleTextView.setText(null); getImageLoader().loadImage(albumArtImageView, null, true, false); - starButton.setImageResource(android.R.drawable.btn_star_big_off); + starButton.setImageResource(R.drawable.ic_toggle_star_outline_dark); setSubtitle(null); } } diff --git a/app/src/main/java/github/daneren2005/dsub/fragments/SelectDirectoryFragment.java b/app/src/main/java/github/daneren2005/dsub/fragments/SelectDirectoryFragment.java index ed6afd46..370d1e51 100644 --- a/app/src/main/java/github/daneren2005/dsub/fragments/SelectDirectoryFragment.java +++ b/app/src/main/java/github/daneren2005/dsub/fragments/SelectDirectoryFragment.java @@ -40,6 +40,7 @@ import github.daneren2005.dsub.domain.MusicDirectory; import github.daneren2005.dsub.domain.ServerInfo; import github.daneren2005.dsub.domain.Share; import github.daneren2005.dsub.service.DownloadService; +import github.daneren2005.dsub.util.DrawableTint; import github.daneren2005.dsub.util.ImageLoader; import java.io.Serializable; @@ -1435,14 +1436,23 @@ public class SelectDirectoryFragment extends SubsonicFragment implements Section final ImageButton starButton = (ImageButton) header.findViewById(R.id.select_album_star); if(directory != null && Util.getPreferences(context).getBoolean(Constants.PREFERENCES_KEY_MENU_STAR, true) && artistInfo == null) { - starButton.setImageResource(directory.isStarred() ? android.R.drawable.btn_star_big_on : android.R.drawable.btn_star_big_off); + if(directory.isStarred()) { + starButton.setImageDrawable(DrawableTint.getTintedDrawable(context, R.drawable.ic_toggle_star)); + } else { + starButton.setImageResource(DrawableTint.getDrawableRes(context, R.attr.star_outline)); + } starButton.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { toggleStarred(directory, new OnStarChange() { @Override void starChange(boolean starred) { - starButton.setImageResource(directory.isStarred() ? android.R.drawable.btn_star_big_on : android.R.drawable.btn_star_big_off); + if(directory.isStarred()) { + starButton.setImageResource(DrawableTint.getDrawableRes(context, R.attr.star_outline)); + starButton.setImageDrawable(DrawableTint.getTintedDrawable(context, R.drawable.ic_toggle_star)); + } else { + starButton.setImageResource(DrawableTint.getDrawableRes(context, R.attr.star_outline)); + } } }); } diff --git a/app/src/main/java/github/daneren2005/dsub/util/DrawableTint.java b/app/src/main/java/github/daneren2005/dsub/util/DrawableTint.java index d3c4ebb4..f6b5d315 100644 --- a/app/src/main/java/github/daneren2005/dsub/util/DrawableTint.java +++ b/app/src/main/java/github/daneren2005/dsub/util/DrawableTint.java @@ -34,6 +34,9 @@ public class DrawableTint { private static final Map<Integer, Integer> attrMap = new HashMap<>(); private static final WeakHashMap<Integer, Drawable> tintedDrawables = new WeakHashMap<>(); + public static Drawable getTintedDrawable(Context context, @DrawableRes int drawableRes) { + return getTintedDrawable(context, drawableRes, R.attr.colorAccent); + } public static Drawable getTintedDrawable(Context context, @DrawableRes int drawableRes, @AttrRes int colorAttr) { if(tintedDrawables.containsKey(drawableRes)) { return tintedDrawables.get(drawableRes); diff --git a/app/src/main/java/github/daneren2005/dsub/util/Util.java b/app/src/main/java/github/daneren2005/dsub/util/Util.java index a3728d29..ce26bf1e 100644 --- a/app/src/main/java/github/daneren2005/dsub/util/Util.java +++ b/app/src/main/java/github/daneren2005/dsub/util/Util.java @@ -1177,15 +1177,6 @@ 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. diff --git a/app/src/main/java/github/daneren2005/dsub/view/SongView.java b/app/src/main/java/github/daneren2005/dsub/view/SongView.java index 41cba046..dcde0f92 100644 --- a/app/src/main/java/github/daneren2005/dsub/view/SongView.java +++ b/app/src/main/java/github/daneren2005/dsub/view/SongView.java @@ -200,7 +200,7 @@ public class SongView extends UpdateView2<MusicDirectory.Entry, Boolean> { if(item.isStarred()) { if(!starred) { if(starButton.getDrawable() == null) { - starButton.setImageDrawable(DrawableTint.getTintedDrawable(context, R.drawable.ic_toggle_star, R.attr.colorPrimary)); + starButton.setImageDrawable(DrawableTint.getTintedDrawable(context, R.drawable.ic_toggle_star)); } starButton.setVisibility(View.VISIBLE); starred = true; @@ -257,6 +257,10 @@ public class SongView extends UpdateView2<MusicDirectory.Entry, Boolean> { if(isBookmarked) { if(!bookmarked) { + if(bookmarkButton.getDrawable() == null) { + bookmarkButton.setImageDrawable(DrawableTint.getTintedDrawable(context, R.drawable.ic_menu_bookmark_selected)); + } + bookmarkButton.setVisibility(View.VISIBLE); bookmarked = true; } diff --git a/app/src/main/java/github/daneren2005/dsub/view/UpdateView.java b/app/src/main/java/github/daneren2005/dsub/view/UpdateView.java index 37290240..e639eaa8 100644 --- a/app/src/main/java/github/daneren2005/dsub/view/UpdateView.java +++ b/app/src/main/java/github/daneren2005/dsub/view/UpdateView.java @@ -241,7 +241,7 @@ public abstract class UpdateView<T> extends LinearLayout { if(isStarred) { if(!starred) { if(starButton.getDrawable() == null) { - starButton.setImageDrawable(DrawableTint.getTintedDrawable(context, R.drawable.ic_toggle_star, R.attr.colorPrimary)); + starButton.setImageDrawable(DrawableTint.getTintedDrawable(context, R.drawable.ic_toggle_star)); } starButton.setVisibility(View.VISIBLE); starred = true; |