Added an animation when adding a song to favorites from the now playing screen.
This commit is contained in:
parent
4db8e8d302
commit
456fc40cd7
7 changed files with 74 additions and 8 deletions
|
|
@ -57,7 +57,7 @@ public class AddToPlaylistDialog extends DialogFragment {
|
|||
CreatePlaylistDialog.create(songs).show(getActivity().getSupportFragmentManager(), "ADD_TO_PLAYLIST");
|
||||
} else {
|
||||
materialDialog.dismiss();
|
||||
PlaylistsUtil.addToPlaylist(getActivity(), songs, playlists.get(i - 1).id);
|
||||
PlaylistsUtil.addToPlaylist(getActivity(), songs, playlists.get(i - 1).id, true);
|
||||
}
|
||||
}
|
||||
})
|
||||
|
|
|
|||
|
|
@ -57,7 +57,7 @@ public class CreatePlaylistDialog extends DialogFragment {
|
|||
if (playlistId != -1 && getActivity() != null) {
|
||||
//noinspection unchecked
|
||||
ArrayList<Song> songs = (ArrayList<Song>) getArguments().getSerializable("songs");
|
||||
PlaylistsUtil.addToPlaylist(getActivity(), songs, playlistId);
|
||||
PlaylistsUtil.addToPlaylist(getActivity(), songs, playlistId, true);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -25,6 +25,7 @@ import android.view.View;
|
|||
import android.view.ViewAnimationUtils;
|
||||
import android.view.ViewGroup;
|
||||
import android.view.animation.DecelerateInterpolator;
|
||||
import android.view.animation.OvershootInterpolator;
|
||||
import android.widget.ImageButton;
|
||||
import android.widget.ImageView;
|
||||
import android.widget.LinearLayout;
|
||||
|
|
@ -97,6 +98,8 @@ public class MusicControllerActivity extends AbsFabActivity {
|
|||
SquareIfPlaceImageView albumArt;
|
||||
@InjectView(R.id.toolbar)
|
||||
Toolbar toolbar;
|
||||
@InjectView(R.id.favorite_icon)
|
||||
ImageView favoriteIcon;
|
||||
|
||||
TextView songCurrentProgress;
|
||||
TextView songTotalTime;
|
||||
|
|
@ -542,6 +545,56 @@ public class MusicControllerActivity extends AbsFabActivity {
|
|||
updateShuffleState();
|
||||
}
|
||||
|
||||
private void animateSetFavorite() {
|
||||
favoriteIcon.clearAnimation();
|
||||
|
||||
favoriteIcon.setAlpha(0f);
|
||||
favoriteIcon.setScaleX(0f);
|
||||
favoriteIcon.setScaleY(0f);
|
||||
favoriteIcon.setVisibility(View.VISIBLE);
|
||||
favoriteIcon.setPivotX(favoriteIcon.getWidth() / 2);
|
||||
favoriteIcon.setPivotY(favoriteIcon.getHeight() / 2);
|
||||
|
||||
favoriteIcon.animate()
|
||||
.setDuration(600)
|
||||
.setInterpolator(new OvershootInterpolator())
|
||||
.scaleX(1f)
|
||||
.scaleY(1f)
|
||||
.alpha(1f)
|
||||
.setListener(new Animator.AnimatorListener() {
|
||||
@Override
|
||||
public void onAnimationStart(Animator animation) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onAnimationEnd(Animator animation) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onAnimationCancel(Animator animation) {
|
||||
favoriteIcon.setVisibility(View.INVISIBLE);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onAnimationRepeat(Animator animation) {
|
||||
|
||||
}
|
||||
})
|
||||
.withEndAction(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
favoriteIcon.animate()
|
||||
.setDuration(300)
|
||||
.setInterpolator(new DecelerateInterpolator())
|
||||
.alpha(0f)
|
||||
.start();
|
||||
}
|
||||
})
|
||||
.start();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onPlayingMetaChanged() {
|
||||
super.onPlayingMetaChanged();
|
||||
|
|
@ -576,6 +629,9 @@ public class MusicControllerActivity extends AbsFabActivity {
|
|||
switch (id) {
|
||||
case R.id.action_toggle_favorite:
|
||||
MusicUtil.toggleFavorite(this, song);
|
||||
if (MusicUtil.isFavorite(this, song)) {
|
||||
animateSetFavorite();
|
||||
}
|
||||
invalidateOptionsMenu();
|
||||
return true;
|
||||
case R.id.action_share:
|
||||
|
|
|
|||
|
|
@ -209,7 +209,7 @@ public class MusicUtil {
|
|||
if (isFavorite(context, song)) {
|
||||
PlaylistsUtil.removeFromPlaylist(context, song, getFavoritesPlaylist(context).id);
|
||||
} else {
|
||||
PlaylistsUtil.addToPlaylist(context, song, getOrCreateFavoritesPlaylist(context).id);
|
||||
PlaylistsUtil.addToPlaylist(context, song, getOrCreateFavoritesPlaylist(context).id, false);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -85,13 +85,13 @@ public class PlaylistsUtil {
|
|||
App.bus.post(new DataBaseChangedEvent(DataBaseChangedEvent.PLAYLISTS_CHANGED));
|
||||
}
|
||||
|
||||
public static void addToPlaylist(final Context context, final Song song, final int playlistId) {
|
||||
public static void addToPlaylist(final Context context, final Song song, final int playlistId, final boolean showToastOnFinish) {
|
||||
List<Song> helperList = new ArrayList<>();
|
||||
helperList.add(song);
|
||||
addToPlaylist(context, helperList, playlistId);
|
||||
addToPlaylist(context, helperList, playlistId, showToastOnFinish);
|
||||
}
|
||||
|
||||
public static void addToPlaylist(final Context context, final List<Song> songs, final int playlistId) {
|
||||
public static void addToPlaylist(final Context context, final List<Song> songs, final int playlistId, final boolean showToastOnFinish) {
|
||||
final int size = songs.size();
|
||||
final ContentResolver resolver = context.getContentResolver();
|
||||
final String[] projection = new String[]{
|
||||
|
|
@ -117,8 +117,10 @@ public class PlaylistsUtil {
|
|||
for (int offSet = 0; offSet < size; offSet += 1000)
|
||||
numinserted += resolver.bulkInsert(uri, makeInsertItems(songs, offSet, 1000, base));
|
||||
|
||||
Toast.makeText(context, context.getResources().getString(
|
||||
R.string.inserted_x_songs_into_playlist, numinserted), Toast.LENGTH_SHORT).show();
|
||||
if (showToastOnFinish) {
|
||||
Toast.makeText(context, context.getResources().getString(
|
||||
R.string.inserted_x_songs_into_playlist, numinserted), Toast.LENGTH_SHORT).show();
|
||||
}
|
||||
App.bus.post(new DataBaseChangedEvent(DataBaseChangedEvent.PLAYLISTS_CHANGED));
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue