Async check if song is favorite.
This commit is contained in:
parent
c351921855
commit
1e622e88af
1 changed files with 19 additions and 6 deletions
|
|
@ -5,6 +5,7 @@ import android.animation.AnimatorSet;
|
||||||
import android.graphics.Color;
|
import android.graphics.Color;
|
||||||
import android.graphics.PorterDuff;
|
import android.graphics.PorterDuff;
|
||||||
import android.graphics.drawable.Drawable;
|
import android.graphics.drawable.Drawable;
|
||||||
|
import android.os.AsyncTask;
|
||||||
import android.os.Build;
|
import android.os.Build;
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
import android.support.annotation.ColorInt;
|
import android.support.annotation.ColorInt;
|
||||||
|
|
@ -77,6 +78,8 @@ public class PlayerFragment extends AbsPlayerFragment implements PlayerAlbumCove
|
||||||
private RecyclerView.Adapter wrappedAdapter;
|
private RecyclerView.Adapter wrappedAdapter;
|
||||||
private RecyclerViewDragDropManager recyclerViewDragDropManager;
|
private RecyclerViewDragDropManager recyclerViewDragDropManager;
|
||||||
|
|
||||||
|
private AsyncTask updateIsFavoriteTask;
|
||||||
|
|
||||||
private Impl impl;
|
private Impl impl;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
@ -240,13 +243,23 @@ public class PlayerFragment extends AbsPlayerFragment implements PlayerAlbumCove
|
||||||
|
|
||||||
|
|
||||||
private void updateIsFavorite() {
|
private void updateIsFavorite() {
|
||||||
boolean isFavorite = MusicUtil.isFavorite(getActivity(), MusicPlayerRemote.getCurrentSong());
|
if (updateIsFavoriteTask != null) updateIsFavoriteTask.cancel(false);
|
||||||
int res = isFavorite ? R.drawable.ic_favorite_white_24dp : R.drawable.ic_favorite_border_white_24dp;
|
updateIsFavoriteTask = new AsyncTask<Song, Void, Boolean>() {
|
||||||
|
@Override
|
||||||
|
protected Boolean doInBackground(Song... params) {
|
||||||
|
return MusicUtil.isFavorite(getActivity(), params[0]);
|
||||||
|
}
|
||||||
|
|
||||||
Drawable favoriteIcon = TintHelper.createTintedDrawable(ContextCompat.getDrawable(getActivity(), res), ToolbarContentTintHelper.toolbarContentColor(getActivity(), Color.TRANSPARENT));
|
@Override
|
||||||
toolbar.getMenu().findItem(R.id.action_toggle_favorite)
|
protected void onPostExecute(Boolean isFavorite) {
|
||||||
.setIcon(favoriteIcon)
|
int res = isFavorite ? R.drawable.ic_favorite_white_24dp : R.drawable.ic_favorite_border_white_24dp;
|
||||||
.setTitle(isFavorite ? getString(R.string.action_remove_from_favorites) : getString(R.string.action_add_to_favorites));
|
int color = ToolbarContentTintHelper.toolbarContentColor(getActivity(), Color.TRANSPARENT);
|
||||||
|
Drawable drawable = TintHelper.createTintedDrawable(ContextCompat.getDrawable(getActivity(), res), color);
|
||||||
|
toolbar.getMenu().findItem(R.id.action_toggle_favorite)
|
||||||
|
.setIcon(drawable)
|
||||||
|
.setTitle(isFavorite ? getString(R.string.action_remove_from_favorites) : getString(R.string.action_add_to_favorites));
|
||||||
|
}
|
||||||
|
}.execute(MusicPlayerRemote.getCurrentSong());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue