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");
|
CreatePlaylistDialog.create(songs).show(getActivity().getSupportFragmentManager(), "ADD_TO_PLAYLIST");
|
||||||
} else {
|
} else {
|
||||||
materialDialog.dismiss();
|
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) {
|
if (playlistId != -1 && getActivity() != null) {
|
||||||
//noinspection unchecked
|
//noinspection unchecked
|
||||||
ArrayList<Song> songs = (ArrayList<Song>) getArguments().getSerializable("songs");
|
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.ViewAnimationUtils;
|
||||||
import android.view.ViewGroup;
|
import android.view.ViewGroup;
|
||||||
import android.view.animation.DecelerateInterpolator;
|
import android.view.animation.DecelerateInterpolator;
|
||||||
|
import android.view.animation.OvershootInterpolator;
|
||||||
import android.widget.ImageButton;
|
import android.widget.ImageButton;
|
||||||
import android.widget.ImageView;
|
import android.widget.ImageView;
|
||||||
import android.widget.LinearLayout;
|
import android.widget.LinearLayout;
|
||||||
|
|
@ -97,6 +98,8 @@ public class MusicControllerActivity extends AbsFabActivity {
|
||||||
SquareIfPlaceImageView albumArt;
|
SquareIfPlaceImageView albumArt;
|
||||||
@InjectView(R.id.toolbar)
|
@InjectView(R.id.toolbar)
|
||||||
Toolbar toolbar;
|
Toolbar toolbar;
|
||||||
|
@InjectView(R.id.favorite_icon)
|
||||||
|
ImageView favoriteIcon;
|
||||||
|
|
||||||
TextView songCurrentProgress;
|
TextView songCurrentProgress;
|
||||||
TextView songTotalTime;
|
TextView songTotalTime;
|
||||||
|
|
@ -542,6 +545,56 @@ public class MusicControllerActivity extends AbsFabActivity {
|
||||||
updateShuffleState();
|
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
|
@Override
|
||||||
public void onPlayingMetaChanged() {
|
public void onPlayingMetaChanged() {
|
||||||
super.onPlayingMetaChanged();
|
super.onPlayingMetaChanged();
|
||||||
|
|
@ -576,6 +629,9 @@ public class MusicControllerActivity extends AbsFabActivity {
|
||||||
switch (id) {
|
switch (id) {
|
||||||
case R.id.action_toggle_favorite:
|
case R.id.action_toggle_favorite:
|
||||||
MusicUtil.toggleFavorite(this, song);
|
MusicUtil.toggleFavorite(this, song);
|
||||||
|
if (MusicUtil.isFavorite(this, song)) {
|
||||||
|
animateSetFavorite();
|
||||||
|
}
|
||||||
invalidateOptionsMenu();
|
invalidateOptionsMenu();
|
||||||
return true;
|
return true;
|
||||||
case R.id.action_share:
|
case R.id.action_share:
|
||||||
|
|
|
||||||
|
|
@ -209,7 +209,7 @@ public class MusicUtil {
|
||||||
if (isFavorite(context, song)) {
|
if (isFavorite(context, song)) {
|
||||||
PlaylistsUtil.removeFromPlaylist(context, song, getFavoritesPlaylist(context).id);
|
PlaylistsUtil.removeFromPlaylist(context, song, getFavoritesPlaylist(context).id);
|
||||||
} else {
|
} 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));
|
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<>();
|
List<Song> helperList = new ArrayList<>();
|
||||||
helperList.add(song);
|
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 int size = songs.size();
|
||||||
final ContentResolver resolver = context.getContentResolver();
|
final ContentResolver resolver = context.getContentResolver();
|
||||||
final String[] projection = new String[]{
|
final String[] projection = new String[]{
|
||||||
|
|
@ -117,8 +117,10 @@ public class PlaylistsUtil {
|
||||||
for (int offSet = 0; offSet < size; offSet += 1000)
|
for (int offSet = 0; offSet < size; offSet += 1000)
|
||||||
numinserted += resolver.bulkInsert(uri, makeInsertItems(songs, offSet, 1000, base));
|
numinserted += resolver.bulkInsert(uri, makeInsertItems(songs, offSet, 1000, base));
|
||||||
|
|
||||||
Toast.makeText(context, context.getResources().getString(
|
if (showToastOnFinish) {
|
||||||
R.string.inserted_x_songs_into_playlist, numinserted), Toast.LENGTH_SHORT).show();
|
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));
|
App.bus.post(new DataBaseChangedEvent(DataBaseChangedEvent.PLAYLISTS_CHANGED));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
BIN
app/src/main/res/drawable-xxxhdpi/ic_favorite_red_a400_96dp.png
Normal file
BIN
app/src/main/res/drawable-xxxhdpi/ic_favorite_red_a400_96dp.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 7.8 KiB |
|
|
@ -208,6 +208,14 @@
|
||||||
android:transitionName="@string/transition_album_cover"
|
android:transitionName="@string/transition_album_cover"
|
||||||
tools:ignore="ContentDescription,UnusedAttribute" />
|
tools:ignore="ContentDescription,UnusedAttribute" />
|
||||||
|
|
||||||
|
<ImageView
|
||||||
|
android:id="@+id/favorite_icon"
|
||||||
|
android:visibility="invisible"
|
||||||
|
android:layout_gravity="center"
|
||||||
|
android:src="@drawable/ic_favorite_red_a400_96dp"
|
||||||
|
android:layout_width="wrap_content"
|
||||||
|
android:layout_height="wrap_content" />
|
||||||
|
|
||||||
<RelativeLayout
|
<RelativeLayout
|
||||||
android:id="@+id/default_progress_container"
|
android:id="@+id/default_progress_container"
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue