WIP added album cover view pager
This commit is contained in:
parent
b1b1aa093d
commit
50035ef8e6
7 changed files with 355 additions and 238 deletions
|
|
@ -0,0 +1,196 @@
|
||||||
|
package com.kabouzeid.gramophone.adapter;
|
||||||
|
|
||||||
|
import android.animation.Animator;
|
||||||
|
import android.content.SharedPreferences;
|
||||||
|
import android.graphics.Bitmap;
|
||||||
|
import android.os.Bundle;
|
||||||
|
import android.support.annotation.Nullable;
|
||||||
|
import android.support.v4.app.Fragment;
|
||||||
|
import android.support.v4.app.FragmentManager;
|
||||||
|
import android.support.v4.app.FragmentStatePagerAdapter;
|
||||||
|
import android.view.LayoutInflater;
|
||||||
|
import android.view.View;
|
||||||
|
import android.view.ViewGroup;
|
||||||
|
import android.view.animation.AccelerateInterpolator;
|
||||||
|
import android.view.animation.DecelerateInterpolator;
|
||||||
|
import android.widget.ImageView;
|
||||||
|
|
||||||
|
import com.kabouzeid.gramophone.R;
|
||||||
|
import com.kabouzeid.gramophone.misc.SimpleAnimatorListener;
|
||||||
|
import com.kabouzeid.gramophone.model.Song;
|
||||||
|
import com.kabouzeid.gramophone.util.ColorUtil;
|
||||||
|
import com.kabouzeid.gramophone.util.MusicUtil;
|
||||||
|
import com.kabouzeid.gramophone.util.PreferenceUtil;
|
||||||
|
import com.kabouzeid.gramophone.util.ViewUtil;
|
||||||
|
import com.nostra13.universalimageloader.core.DisplayImageOptions;
|
||||||
|
import com.nostra13.universalimageloader.core.ImageLoader;
|
||||||
|
import com.nostra13.universalimageloader.core.assist.FailReason;
|
||||||
|
import com.nostra13.universalimageloader.core.listener.SimpleImageLoadingListener;
|
||||||
|
import com.nostra13.universalimageloader.core.process.BitmapProcessor;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
|
||||||
|
import butterknife.Bind;
|
||||||
|
import butterknife.ButterKnife;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author Karim Abou Zeid (kabouzeid)
|
||||||
|
*/
|
||||||
|
public class AlbumCoverPagerAdapter extends FragmentStatePagerAdapter {
|
||||||
|
public static final String TAG = AlbumCoverPagerAdapter.class.getSimpleName();
|
||||||
|
|
||||||
|
private ArrayList<Song> dataSet;
|
||||||
|
|
||||||
|
public AlbumCoverPagerAdapter(FragmentManager fm, ArrayList<Song> dataSet) {
|
||||||
|
super(fm);
|
||||||
|
this.dataSet = dataSet;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Fragment getItem(final int position) {
|
||||||
|
return AlbumCoverFragment.newInstance(dataSet.get(position));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int getCount() {
|
||||||
|
return dataSet.size();
|
||||||
|
}
|
||||||
|
|
||||||
|
public static class AlbumCoverFragment extends Fragment implements SharedPreferences.OnSharedPreferenceChangeListener {
|
||||||
|
private static final String SONG_ARG = "song";
|
||||||
|
|
||||||
|
@Bind(R.id.player_image)
|
||||||
|
ImageView albumCover;
|
||||||
|
@Bind(R.id.player_favorite_icon)
|
||||||
|
ImageView favoriteIcon;
|
||||||
|
|
||||||
|
private int color;
|
||||||
|
private Song song;
|
||||||
|
|
||||||
|
public static AlbumCoverFragment newInstance(final Song song) {
|
||||||
|
AlbumCoverFragment frag = new AlbumCoverFragment();
|
||||||
|
final Bundle args = new Bundle();
|
||||||
|
args.putSerializable(SONG_ARG, song);
|
||||||
|
frag.setArguments(args);
|
||||||
|
return frag;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onCreate(final Bundle savedInstanceState) {
|
||||||
|
super.onCreate(savedInstanceState);
|
||||||
|
song = (Song) getArguments().getSerializable(SONG_ARG);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public View onCreateView(LayoutInflater inflater, ViewGroup container,
|
||||||
|
Bundle savedInstanceState) {
|
||||||
|
View view = inflater.inflate(R.layout.fragment_album_cover, container, false);
|
||||||
|
ButterKnife.bind(this, view);
|
||||||
|
return view;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onViewCreated(View view, Bundle savedInstanceState) {
|
||||||
|
super.onViewCreated(view, savedInstanceState);
|
||||||
|
forceSquareAlbumCover(PreferenceUtil.getInstance(getContext()).forceSquareAlbumCover());
|
||||||
|
PreferenceUtil.getInstance(getActivity()).registerOnSharedPreferenceChangedListener(this);
|
||||||
|
loadAlbumCover();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onDestroyView() {
|
||||||
|
super.onDestroyView();
|
||||||
|
PreferenceUtil.getInstance(getActivity()).unregisterOnSharedPreferenceChangedListener(this);
|
||||||
|
ButterKnife.unbind(this);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void loadAlbumCover() {
|
||||||
|
ImageLoader.getInstance().displayImage(
|
||||||
|
MusicUtil.getSongImageLoaderString(song),
|
||||||
|
albumCover,
|
||||||
|
new DisplayImageOptions.Builder()
|
||||||
|
.cacheInMemory(true)
|
||||||
|
.showImageOnFail(R.drawable.default_album_art)
|
||||||
|
.postProcessor(new BitmapProcessor() {
|
||||||
|
@Override
|
||||||
|
public Bitmap process(Bitmap bitmap) {
|
||||||
|
color = ColorUtil.generateColor(getActivity(), bitmap);
|
||||||
|
return bitmap;
|
||||||
|
}
|
||||||
|
})
|
||||||
|
.build(),
|
||||||
|
new SimpleImageLoadingListener() {
|
||||||
|
@Override
|
||||||
|
public void onLoadingFailed(String imageUri, View view, @Nullable FailReason failReason) {
|
||||||
|
color = ColorUtil.resolveColor(getActivity(), R.attr.default_bar_color);
|
||||||
|
notifyColorIsReady();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onLoadingComplete(String imageUri, View view, @Nullable Bitmap loadedImage) {
|
||||||
|
if (loadedImage == null) {
|
||||||
|
onLoadingFailed(imageUri, view, null);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
notifyColorIsReady();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void showHeartAnimation() {
|
||||||
|
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(ViewUtil.PHONOGRAPH_ANIM_TIME / 2)
|
||||||
|
.setInterpolator(new DecelerateInterpolator())
|
||||||
|
.scaleX(1f)
|
||||||
|
.scaleY(1f)
|
||||||
|
.alpha(1f)
|
||||||
|
.setListener(new SimpleAnimatorListener() {
|
||||||
|
@Override
|
||||||
|
public void onAnimationCancel(Animator animation) {
|
||||||
|
favoriteIcon.setVisibility(View.INVISIBLE);
|
||||||
|
}
|
||||||
|
})
|
||||||
|
.withEndAction(new Runnable() {
|
||||||
|
@Override
|
||||||
|
public void run() {
|
||||||
|
favoriteIcon.animate()
|
||||||
|
.setDuration(ViewUtil.PHONOGRAPH_ANIM_TIME / 2)
|
||||||
|
.setInterpolator(new AccelerateInterpolator())
|
||||||
|
.scaleX(0f)
|
||||||
|
.scaleY(0f)
|
||||||
|
.alpha(0f)
|
||||||
|
.start();
|
||||||
|
}
|
||||||
|
})
|
||||||
|
.start();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onSharedPreferenceChanged(SharedPreferences sharedPreferences, String key) {
|
||||||
|
switch (key) {
|
||||||
|
case PreferenceUtil.FORCE_SQUARE_ALBUM_COVER:
|
||||||
|
forceSquareAlbumCover(PreferenceUtil.getInstance(getActivity()).forceSquareAlbumCover());
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public void forceSquareAlbumCover(boolean forceSquareAlbumCover) {
|
||||||
|
albumCover.setScaleType(forceSquareAlbumCover ? ImageView.ScaleType.FIT_CENTER : ImageView.ScaleType.CENTER_CROP);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void notifyColorIsReady() {
|
||||||
|
// TODO
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
@ -0,0 +1,74 @@
|
||||||
|
package com.kabouzeid.gramophone.ui.fragments;
|
||||||
|
|
||||||
|
import android.content.Context;
|
||||||
|
import android.os.Bundle;
|
||||||
|
import android.support.v4.app.Fragment;
|
||||||
|
import android.view.View;
|
||||||
|
|
||||||
|
import com.kabouzeid.gramophone.interfaces.MusicServiceEventListener;
|
||||||
|
import com.kabouzeid.gramophone.ui.activities.base.AbsMusicServiceActivity;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author Karim Abou Zeid (kabouzeid)
|
||||||
|
*/
|
||||||
|
public class AbsMusicServiceFragment extends Fragment implements MusicServiceEventListener {
|
||||||
|
private AbsMusicServiceActivity activity;
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onAttach(Context context) {
|
||||||
|
super.onAttach(context);
|
||||||
|
try {
|
||||||
|
activity = (AbsMusicServiceActivity) context;
|
||||||
|
} catch (ClassCastException e) {
|
||||||
|
throw new RuntimeException(context.getClass().getSimpleName() + " must be an instance of " + AbsMusicServiceActivity.class.getSimpleName());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onDetach() {
|
||||||
|
super.onDetach();
|
||||||
|
activity = null;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onViewCreated(View view, Bundle savedInstanceState) {
|
||||||
|
super.onViewCreated(view, savedInstanceState);
|
||||||
|
activity.addMusicServiceEventListener(this);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onDestroyView() {
|
||||||
|
super.onDestroyView();
|
||||||
|
activity.removeMusicServiceEventListener(this);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onPlayingMetaChanged() {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onQueueChanged() {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onPlayStateChanged() {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onRepeatModeChanged() {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onShuffleModeChanged() {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onMediaStoreChanged() {
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -2,11 +2,8 @@ package com.kabouzeid.gramophone.ui.fragments.player;
|
||||||
|
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.content.Intent;
|
import android.content.Intent;
|
||||||
import android.os.Bundle;
|
|
||||||
import android.support.v4.app.Fragment;
|
|
||||||
import android.support.v7.widget.Toolbar;
|
import android.support.v7.widget.Toolbar;
|
||||||
import android.view.MenuItem;
|
import android.view.MenuItem;
|
||||||
import android.view.View;
|
|
||||||
|
|
||||||
import com.kabouzeid.gramophone.R;
|
import com.kabouzeid.gramophone.R;
|
||||||
import com.kabouzeid.gramophone.dialogs.AddToPlaylistDialog;
|
import com.kabouzeid.gramophone.dialogs.AddToPlaylistDialog;
|
||||||
|
|
@ -14,82 +11,36 @@ import com.kabouzeid.gramophone.dialogs.SleepTimerDialog;
|
||||||
import com.kabouzeid.gramophone.dialogs.SongDetailDialog;
|
import com.kabouzeid.gramophone.dialogs.SongDetailDialog;
|
||||||
import com.kabouzeid.gramophone.dialogs.SongShareDialog;
|
import com.kabouzeid.gramophone.dialogs.SongShareDialog;
|
||||||
import com.kabouzeid.gramophone.helper.MusicPlayerRemote;
|
import com.kabouzeid.gramophone.helper.MusicPlayerRemote;
|
||||||
import com.kabouzeid.gramophone.interfaces.MusicServiceEventListener;
|
|
||||||
import com.kabouzeid.gramophone.interfaces.PaletteColorHolder;
|
import com.kabouzeid.gramophone.interfaces.PaletteColorHolder;
|
||||||
import com.kabouzeid.gramophone.loader.SongLoader;
|
import com.kabouzeid.gramophone.loader.SongLoader;
|
||||||
import com.kabouzeid.gramophone.model.Song;
|
import com.kabouzeid.gramophone.model.Song;
|
||||||
import com.kabouzeid.gramophone.ui.activities.base.AbsMusicServiceActivity;
|
|
||||||
import com.kabouzeid.gramophone.ui.activities.tageditor.AbsTagEditorActivity;
|
import com.kabouzeid.gramophone.ui.activities.tageditor.AbsTagEditorActivity;
|
||||||
import com.kabouzeid.gramophone.ui.activities.tageditor.SongTagEditorActivity;
|
import com.kabouzeid.gramophone.ui.activities.tageditor.SongTagEditorActivity;
|
||||||
|
import com.kabouzeid.gramophone.ui.fragments.AbsMusicServiceFragment;
|
||||||
import com.kabouzeid.gramophone.util.MusicUtil;
|
import com.kabouzeid.gramophone.util.MusicUtil;
|
||||||
import com.kabouzeid.gramophone.util.NavigationUtil;
|
import com.kabouzeid.gramophone.util.NavigationUtil;
|
||||||
|
|
||||||
public abstract class AbsPlayerFragment extends Fragment implements MusicServiceEventListener, Toolbar.OnMenuItemClickListener, PaletteColorHolder {
|
public abstract class AbsPlayerFragment extends AbsMusicServiceFragment implements Toolbar.OnMenuItemClickListener, PaletteColorHolder {
|
||||||
public static final String TAG = AbsPlayerFragment.class.getSimpleName();
|
public static final String TAG = AbsPlayerFragment.class.getSimpleName();
|
||||||
|
|
||||||
protected AbsMusicServiceActivity activity;
|
private Callbacks callbacks;
|
||||||
protected Callbacks callbacks;
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onAttach(Context context) {
|
public void onAttach(Context context) {
|
||||||
super.onAttach(context);
|
super.onAttach(context);
|
||||||
try {
|
try {
|
||||||
activity = (AbsMusicServiceActivity) context;
|
|
||||||
callbacks = (Callbacks) context;
|
callbacks = (Callbacks) context;
|
||||||
} catch (ClassCastException e) {
|
} catch (ClassCastException e) {
|
||||||
throw new RuntimeException(context.getClass().getSimpleName() + " must be an instance of " + AbsMusicServiceActivity.class.getSimpleName() + " and implement " + Callbacks.class.getSimpleName());
|
throw new RuntimeException(context.getClass().getSimpleName() + " must implement " + Callbacks.class.getSimpleName());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onDetach() {
|
public void onDetach() {
|
||||||
super.onDetach();
|
super.onDetach();
|
||||||
activity = null;
|
|
||||||
callbacks = null;
|
callbacks = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public void onViewCreated(final View view, Bundle savedInstanceState) {
|
|
||||||
super.onViewCreated(view, savedInstanceState);
|
|
||||||
activity.addMusicServiceEventListener(this);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void onDestroyView() {
|
|
||||||
super.onDestroyView();
|
|
||||||
activity.removeMusicServiceEventListener(this);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void onPlayingMetaChanged() {
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void onQueueChanged() {
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void onPlayStateChanged() {
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void onRepeatModeChanged() {
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void onShuffleModeChanged() {
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void onMediaStoreChanged() {
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean onMenuItemClick(MenuItem item) {
|
public boolean onMenuItemClick(MenuItem item) {
|
||||||
final Song song = MusicPlayerRemote.getCurrentSong();
|
final Song song = MusicPlayerRemote.getCurrentSong();
|
||||||
|
|
@ -98,16 +49,16 @@ public abstract class AbsPlayerFragment extends Fragment implements MusicService
|
||||||
new SleepTimerDialog().show(getFragmentManager(), "SET_SLEEP_TIMER");
|
new SleepTimerDialog().show(getFragmentManager(), "SET_SLEEP_TIMER");
|
||||||
return true;
|
return true;
|
||||||
case R.id.action_toggle_favorite:
|
case R.id.action_toggle_favorite:
|
||||||
MusicUtil.toggleFavorite(activity, song);
|
MusicUtil.toggleFavorite(getActivity(), song);
|
||||||
return true;
|
return true;
|
||||||
case R.id.action_share:
|
case R.id.action_share:
|
||||||
SongShareDialog.create(song).show(getFragmentManager(), "SHARE_SONG");
|
SongShareDialog.create(song).show(getFragmentManager(), "SHARE_SONG");
|
||||||
return true;
|
return true;
|
||||||
case R.id.action_equalizer:
|
case R.id.action_equalizer:
|
||||||
NavigationUtil.openEqualizer(activity);
|
NavigationUtil.openEqualizer(getActivity());
|
||||||
return true;
|
return true;
|
||||||
case R.id.action_shuffle_all:
|
case R.id.action_shuffle_all:
|
||||||
MusicPlayerRemote.openAndShuffleQueue(SongLoader.getAllSongs(activity), true);
|
MusicPlayerRemote.openAndShuffleQueue(SongLoader.getAllSongs(getActivity()), true);
|
||||||
return true;
|
return true;
|
||||||
case R.id.action_add_to_playlist:
|
case R.id.action_add_to_playlist:
|
||||||
AddToPlaylistDialog.create(song).show(getFragmentManager(), "ADD_PLAYLIST");
|
AddToPlaylistDialog.create(song).show(getFragmentManager(), "ADD_PLAYLIST");
|
||||||
|
|
@ -115,7 +66,7 @@ public abstract class AbsPlayerFragment extends Fragment implements MusicService
|
||||||
// case R.id.action_playing_queue:
|
// case R.id.action_playing_queue:
|
||||||
// return true;
|
// return true;
|
||||||
case R.id.action_tag_editor:
|
case R.id.action_tag_editor:
|
||||||
Intent intent = new Intent(activity, SongTagEditorActivity.class);
|
Intent intent = new Intent(getActivity(), SongTagEditorActivity.class);
|
||||||
intent.putExtra(AbsTagEditorActivity.EXTRA_ID, song.id);
|
intent.putExtra(AbsTagEditorActivity.EXTRA_ID, song.id);
|
||||||
startActivity(intent);
|
startActivity(intent);
|
||||||
return true;
|
return true;
|
||||||
|
|
@ -123,10 +74,10 @@ public abstract class AbsPlayerFragment extends Fragment implements MusicService
|
||||||
SongDetailDialog.create(song).show(getFragmentManager(), "SONG_DETAIL");
|
SongDetailDialog.create(song).show(getFragmentManager(), "SONG_DETAIL");
|
||||||
return true;
|
return true;
|
||||||
case R.id.action_go_to_album:
|
case R.id.action_go_to_album:
|
||||||
NavigationUtil.goToAlbum(activity, song.albumId);
|
NavigationUtil.goToAlbum(getActivity(), song.albumId);
|
||||||
return true;
|
return true;
|
||||||
case R.id.action_go_to_artist:
|
case R.id.action_go_to_artist:
|
||||||
NavigationUtil.goToArtist(activity, song.artistId);
|
NavigationUtil.goToArtist(getActivity(), song.artistId);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
|
|
@ -138,6 +89,10 @@ public abstract class AbsPlayerFragment extends Fragment implements MusicService
|
||||||
|
|
||||||
public abstract boolean onBackPressed();
|
public abstract boolean onBackPressed();
|
||||||
|
|
||||||
|
public Callbacks getCallbacks() {
|
||||||
|
return callbacks;
|
||||||
|
}
|
||||||
|
|
||||||
public interface Callbacks {
|
public interface Callbacks {
|
||||||
void onPaletteColorChanged();
|
void onPaletteColorChanged();
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,35 +1,16 @@
|
||||||
package com.kabouzeid.gramophone.ui.fragments.player;
|
package com.kabouzeid.gramophone.ui.fragments.player;
|
||||||
|
|
||||||
import android.animation.Animator;
|
|
||||||
import android.content.Context;
|
|
||||||
import android.content.SharedPreferences;
|
|
||||||
import android.graphics.Bitmap;
|
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
import android.support.annotation.ColorInt;
|
import android.support.annotation.ColorInt;
|
||||||
import android.support.annotation.Nullable;
|
import android.support.v4.view.ViewPager;
|
||||||
import android.support.v4.app.Fragment;
|
|
||||||
import android.view.LayoutInflater;
|
import android.view.LayoutInflater;
|
||||||
import android.view.View;
|
import android.view.View;
|
||||||
import android.view.ViewGroup;
|
import android.view.ViewGroup;
|
||||||
import android.view.animation.AccelerateInterpolator;
|
|
||||||
import android.view.animation.DecelerateInterpolator;
|
|
||||||
import android.widget.ImageView;
|
|
||||||
|
|
||||||
import com.kabouzeid.gramophone.R;
|
import com.kabouzeid.gramophone.R;
|
||||||
|
import com.kabouzeid.gramophone.adapter.AlbumCoverPagerAdapter;
|
||||||
import com.kabouzeid.gramophone.helper.MusicPlayerRemote;
|
import com.kabouzeid.gramophone.helper.MusicPlayerRemote;
|
||||||
import com.kabouzeid.gramophone.interfaces.MusicServiceEventListener;
|
import com.kabouzeid.gramophone.ui.fragments.AbsMusicServiceFragment;
|
||||||
import com.kabouzeid.gramophone.misc.SimpleAnimatorListener;
|
|
||||||
import com.kabouzeid.gramophone.ui.activities.base.AbsMusicServiceActivity;
|
|
||||||
import com.kabouzeid.gramophone.util.ColorUtil;
|
|
||||||
import com.kabouzeid.gramophone.util.MusicUtil;
|
|
||||||
import com.kabouzeid.gramophone.util.PreferenceUtil;
|
|
||||||
import com.kabouzeid.gramophone.util.ViewUtil;
|
|
||||||
import com.nostra13.universalimageloader.core.DisplayImageOptions;
|
|
||||||
import com.nostra13.universalimageloader.core.ImageLoader;
|
|
||||||
import com.nostra13.universalimageloader.core.assist.FailReason;
|
|
||||||
import com.nostra13.universalimageloader.core.display.FadeInBitmapDisplayer;
|
|
||||||
import com.nostra13.universalimageloader.core.listener.SimpleImageLoadingListener;
|
|
||||||
import com.nostra13.universalimageloader.core.process.BitmapProcessor;
|
|
||||||
|
|
||||||
import butterknife.Bind;
|
import butterknife.Bind;
|
||||||
import butterknife.ButterKnife;
|
import butterknife.ButterKnife;
|
||||||
|
|
@ -37,180 +18,76 @@ import butterknife.ButterKnife;
|
||||||
/**
|
/**
|
||||||
* @author Karim Abou Zeid (kabouzeid)
|
* @author Karim Abou Zeid (kabouzeid)
|
||||||
*/
|
*/
|
||||||
public class PlayerAlbumCoverFragment extends Fragment implements MusicServiceEventListener, SharedPreferences.OnSharedPreferenceChangeListener {
|
public class PlayerAlbumCoverFragment extends AbsMusicServiceFragment implements ViewPager.OnPageChangeListener {
|
||||||
|
|
||||||
@Bind(R.id.player_image)
|
@Bind(R.id.player_album_cover_viewpager)
|
||||||
ImageView albumCover;
|
ViewPager viewPager;
|
||||||
@Bind(R.id.player_favorite_icon)
|
|
||||||
ImageView favoriteIcon;
|
|
||||||
|
|
||||||
private AbsMusicServiceActivity activity;
|
private AlbumCoverPagerAdapter pagerAdapter;
|
||||||
private OnColorChangedListener onColorChangedListener;
|
private OnColorChangedListener onColorChangedListener;
|
||||||
|
|
||||||
@Override
|
|
||||||
public void onAttach(Context context) {
|
|
||||||
super.onAttach(context);
|
|
||||||
try {
|
|
||||||
activity = (AbsMusicServiceActivity) context;
|
|
||||||
} catch (ClassCastException e) {
|
|
||||||
throw new RuntimeException(context.getClass().getSimpleName() + " must be an instance of " + AbsMusicServiceActivity.class.getSimpleName());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void onDetach() {
|
|
||||||
super.onDetach();
|
|
||||||
activity = null;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public View onCreateView(LayoutInflater inflater, ViewGroup container,
|
public View onCreateView(LayoutInflater inflater, ViewGroup container,
|
||||||
Bundle savedInstanceState) {
|
Bundle savedInstanceState) {
|
||||||
return inflater.inflate(R.layout.fragment_player_album_cover, container, false);
|
View view = inflater.inflate(R.layout.fragment_player_album_cover, container, false);
|
||||||
|
ButterKnife.bind(this, view);
|
||||||
|
return view;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onViewCreated(View view, Bundle savedInstanceState) {
|
public void onViewCreated(View view, Bundle savedInstanceState) {
|
||||||
super.onViewCreated(view, savedInstanceState);
|
super.onViewCreated(view, savedInstanceState);
|
||||||
ButterKnife.bind(this, view);
|
viewPager.setOffscreenPageLimit(2);
|
||||||
|
updatePlayingQueue();
|
||||||
forceSquareAlbumCover(PreferenceUtil.getInstance(getContext()).forceSquareAlbumCover());
|
viewPager.addOnPageChangeListener(this);
|
||||||
|
|
||||||
PreferenceUtil.getInstance(getContext()).registerOnSharedPreferenceChangedListener(this);
|
|
||||||
activity.addMusicServiceEventListener(this);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onDestroyView() {
|
public void onDestroyView() {
|
||||||
super.onDestroyView();
|
super.onDestroyView();
|
||||||
activity.removeMusicServiceEventListener(this);
|
viewPager.removeOnPageChangeListener(this);
|
||||||
PreferenceUtil.getInstance(activity).unregisterOnSharedPreferenceChangedListener(this);
|
|
||||||
ButterKnife.unbind(this);
|
ButterKnife.unbind(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onPlayingMetaChanged() {
|
public void onPlayingMetaChanged() {
|
||||||
loadAlbumCover();
|
viewPager.setCurrentItem(MusicPlayerRemote.getPosition());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onQueueChanged() {
|
public void onQueueChanged() {
|
||||||
|
updatePlayingQueue();
|
||||||
|
}
|
||||||
|
|
||||||
|
private void updatePlayingQueue() {
|
||||||
|
viewPager.setAdapter(new AlbumCoverPagerAdapter(getFragmentManager(), MusicPlayerRemote.getPlayingQueue()));
|
||||||
|
viewPager.setCurrentItem(MusicPlayerRemote.getPosition());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onPlayStateChanged() {
|
public void onPageSelected(int position) {
|
||||||
|
if (position != MusicPlayerRemote.getPosition()) {
|
||||||
}
|
MusicPlayerRemote.playSongAt(position);
|
||||||
|
|
||||||
@Override
|
|
||||||
public void onRepeatModeChanged() {
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void onShuffleModeChanged() {
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void onMediaStoreChanged() {
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void onSharedPreferenceChanged(SharedPreferences sharedPreferences, String key) {
|
|
||||||
switch (key) {
|
|
||||||
case PreferenceUtil.FORCE_SQUARE_ALBUM_COVER:
|
|
||||||
forceSquareAlbumCover(PreferenceUtil.getInstance(activity).forceSquareAlbumCover());
|
|
||||||
break;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onPageScrollStateChanged(int state) {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
private static class ColorHolder {
|
private static class ColorHolder {
|
||||||
@ColorInt
|
@ColorInt
|
||||||
public int color;
|
public int color;
|
||||||
}
|
}
|
||||||
|
|
||||||
private void loadAlbumCover() {
|
|
||||||
final ColorHolder colorHolder = new ColorHolder();
|
|
||||||
ImageLoader.getInstance().displayImage(
|
|
||||||
MusicUtil.getSongImageLoaderString(MusicPlayerRemote.getCurrentSong()),
|
|
||||||
albumCover,
|
|
||||||
new DisplayImageOptions.Builder()
|
|
||||||
.cacheInMemory(true)
|
|
||||||
.showImageOnFail(R.drawable.default_album_art)
|
|
||||||
.postProcessor(new BitmapProcessor() {
|
|
||||||
@Override
|
|
||||||
public Bitmap process(Bitmap bitmap) {
|
|
||||||
colorHolder.color = ColorUtil.generateColor(activity, bitmap);
|
|
||||||
return bitmap;
|
|
||||||
}
|
|
||||||
})
|
|
||||||
.displayer(new FadeInBitmapDisplayer(ViewUtil.PHONOGRAPH_ANIM_TIME))
|
|
||||||
.build(),
|
|
||||||
new SimpleImageLoadingListener() {
|
|
||||||
@Override
|
|
||||||
public void onLoadingFailed(String imageUri, View view, @Nullable FailReason failReason) {
|
|
||||||
FadeInBitmapDisplayer.animate(view, ViewUtil.PHONOGRAPH_ANIM_TIME);
|
|
||||||
setColor(ColorUtil.resolveColor(activity, R.attr.default_bar_color));
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void onLoadingComplete(String imageUri, View view, @Nullable Bitmap loadedImage) {
|
|
||||||
if (loadedImage == null) {
|
|
||||||
onLoadingFailed(imageUri, view, null);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
setColor(colorHolder.color);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
public void showHeartAnimation() {
|
public void showHeartAnimation() {
|
||||||
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(ViewUtil.PHONOGRAPH_ANIM_TIME / 2)
|
|
||||||
.setInterpolator(new DecelerateInterpolator())
|
|
||||||
.scaleX(1f)
|
|
||||||
.scaleY(1f)
|
|
||||||
.alpha(1f)
|
|
||||||
.setListener(new SimpleAnimatorListener() {
|
|
||||||
@Override
|
|
||||||
public void onAnimationCancel(Animator animation) {
|
|
||||||
favoriteIcon.setVisibility(View.INVISIBLE);
|
|
||||||
}
|
|
||||||
})
|
|
||||||
.withEndAction(new Runnable() {
|
|
||||||
@Override
|
|
||||||
public void run() {
|
|
||||||
favoriteIcon.animate()
|
|
||||||
.setDuration(ViewUtil.PHONOGRAPH_ANIM_TIME / 2)
|
|
||||||
.setInterpolator(new AccelerateInterpolator())
|
|
||||||
.scaleX(0f)
|
|
||||||
.scaleY(0f)
|
|
||||||
.alpha(0f)
|
|
||||||
.start();
|
|
||||||
}
|
|
||||||
})
|
|
||||||
.start();
|
|
||||||
}
|
|
||||||
|
|
||||||
public void forceSquareAlbumCover(boolean forceSquareAlbumCover) {
|
|
||||||
albumCover.setScaleType(forceSquareAlbumCover ? ImageView.ScaleType.FIT_CENTER : ImageView.ScaleType.CENTER_CROP);
|
|
||||||
}
|
|
||||||
|
|
||||||
private void setColor(int color) {
|
|
||||||
if (onColorChangedListener != null) onColorChangedListener.onColorChanged(color);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setOnColorChangedListener(OnColorChangedListener listener) {
|
public void setOnColorChangedListener(OnColorChangedListener listener) {
|
||||||
|
|
|
||||||
|
|
@ -124,7 +124,7 @@ public class PlayerFragment extends AbsPlayerFragment implements PlayerAlbumCove
|
||||||
public void onPlayingMetaChanged() {
|
public void onPlayingMetaChanged() {
|
||||||
updateIsFavorite();
|
updateIsFavorite();
|
||||||
updateCurrentSong();
|
updateCurrentSong();
|
||||||
updateQueue();
|
updateQueuePosition();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
@ -139,6 +139,13 @@ public class PlayerFragment extends AbsPlayerFragment implements PlayerAlbumCove
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void updateQueuePosition() {
|
||||||
|
playingQueueAdapter.setCurrent(MusicPlayerRemote.getPosition());
|
||||||
|
if (slidingUpPanelLayout.getPanelState() == SlidingUpPanelLayout.PanelState.COLLAPSED) {
|
||||||
|
resetToCurrentPosition();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@SuppressWarnings("ConstantConditions")
|
@SuppressWarnings("ConstantConditions")
|
||||||
private void updateCurrentSong() {
|
private void updateCurrentSong() {
|
||||||
Song song = MusicPlayerRemote.getCurrentSong();
|
Song song = MusicPlayerRemote.getCurrentSong();
|
||||||
|
|
@ -156,7 +163,7 @@ public class PlayerFragment extends AbsPlayerFragment implements PlayerAlbumCove
|
||||||
albumCoverContainer.forceSquare(false);
|
albumCoverContainer.forceSquare(false);
|
||||||
}
|
}
|
||||||
slidingUpPanelLayout.setPanelHeight(Math.max(minPanelHeight, availablePanelHeight));
|
slidingUpPanelLayout.setPanelHeight(Math.max(minPanelHeight, availablePanelHeight));
|
||||||
((AbsSlidingMusicPanelActivity) activity).setAntiDragView(slidingUpPanelLayout.findViewById(R.id.player_panel));
|
((AbsSlidingMusicPanelActivity) getActivity()).setAntiDragView(slidingUpPanelLayout.findViewById(R.id.player_panel));
|
||||||
}
|
}
|
||||||
|
|
||||||
private void setUpSubFragments() {
|
private void setUpSubFragments() {
|
||||||
|
|
@ -172,7 +179,7 @@ public class PlayerFragment extends AbsPlayerFragment implements PlayerAlbumCove
|
||||||
toolbar.setNavigationOnClickListener(new View.OnClickListener() {
|
toolbar.setNavigationOnClickListener(new View.OnClickListener() {
|
||||||
@Override
|
@Override
|
||||||
public void onClick(View v) {
|
public void onClick(View v) {
|
||||||
activity.onBackPressed();
|
getActivity().onBackPressed();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
toolbar.setOnMenuItemClickListener(this);
|
toolbar.setOnMenuItemClickListener(this);
|
||||||
|
|
@ -185,12 +192,12 @@ public class PlayerFragment extends AbsPlayerFragment implements PlayerAlbumCove
|
||||||
currentSongViewHolder.separator.setVisibility(View.VISIBLE);
|
currentSongViewHolder.separator.setVisibility(View.VISIBLE);
|
||||||
currentSongViewHolder.shortSeparator.setVisibility(View.GONE);
|
currentSongViewHolder.shortSeparator.setVisibility(View.GONE);
|
||||||
currentSongViewHolder.image.setScaleType(ImageView.ScaleType.CENTER);
|
currentSongViewHolder.image.setScaleType(ImageView.ScaleType.CENTER);
|
||||||
currentSongViewHolder.image.setImageDrawable(Util.getTintedDrawable(activity, R.drawable.ic_volume_up_white_24dp, ColorUtil.resolveColor(activity, R.attr.icon_color)));
|
currentSongViewHolder.image.setImageDrawable(Util.getTintedDrawable(getActivity(), R.drawable.ic_volume_up_white_24dp, ColorUtil.resolveColor(getActivity(), R.attr.icon_color)));
|
||||||
}
|
}
|
||||||
|
|
||||||
private void updateIsFavorite() {
|
private void updateIsFavorite() {
|
||||||
boolean isFavorite = MusicUtil.isFavorite(activity, MusicPlayerRemote.getCurrentSong());
|
boolean isFavorite = MusicUtil.isFavorite(getActivity(), MusicPlayerRemote.getCurrentSong());
|
||||||
Drawable favoriteIcon = Util.getTintedDrawable(activity, isFavorite ? R.drawable.ic_favorite_white_24dp : R.drawable.ic_favorite_outline_white_24dp, ViewUtil.getToolbarIconColor(activity, false));
|
Drawable favoriteIcon = Util.getTintedDrawable(getActivity(), isFavorite ? R.drawable.ic_favorite_white_24dp : R.drawable.ic_favorite_outline_white_24dp, ViewUtil.getToolbarIconColor(getActivity(), false));
|
||||||
toolbar.getMenu().findItem(R.id.action_toggle_favorite)
|
toolbar.getMenu().findItem(R.id.action_toggle_favorite)
|
||||||
.setIcon(favoriteIcon)
|
.setIcon(favoriteIcon)
|
||||||
.setTitle(isFavorite ? getString(R.string.action_remove_from_favorites) : getString(R.string.action_add_to_favorites));
|
.setTitle(isFavorite ? getString(R.string.action_remove_from_favorites) : getString(R.string.action_add_to_favorites));
|
||||||
|
|
@ -250,7 +257,7 @@ public class PlayerFragment extends AbsPlayerFragment implements PlayerAlbumCove
|
||||||
switch (item.getItemId()) {
|
switch (item.getItemId()) {
|
||||||
case R.id.action_toggle_favorite:
|
case R.id.action_toggle_favorite:
|
||||||
super.onMenuItemClick(item);
|
super.onMenuItemClick(item);
|
||||||
if (MusicUtil.isFavorite(activity, song)) {
|
if (MusicUtil.isFavorite(getActivity(), song)) {
|
||||||
playerAlbumCoverFragment.showHeartAnimation();
|
playerAlbumCoverFragment.showHeartAnimation();
|
||||||
}
|
}
|
||||||
updateIsFavorite();
|
updateIsFavorite();
|
||||||
|
|
@ -282,7 +289,7 @@ public class PlayerFragment extends AbsPlayerFragment implements PlayerAlbumCove
|
||||||
public void onColorChanged(int color) {
|
public void onColorChanged(int color) {
|
||||||
animateColorChange(color);
|
animateColorChange(color);
|
||||||
playbackControlsFragment.setColor(color);
|
playbackControlsFragment.setColor(color);
|
||||||
callbacks.onPaletteColorChanged();
|
getCallbacks().onPaletteColorChanged();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
|
||||||
26
app/src/main/res/layout/fragment_album_cover.xml
Normal file
26
app/src/main/res/layout/fragment_album_cover.xml
Normal file
|
|
@ -0,0 +1,26 @@
|
||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<FrameLayout android:id="@+id/player_album_art_frame"
|
||||||
|
xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
|
xmlns:tools="http://schemas.android.com/tools"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="match_parent"
|
||||||
|
android:background="@android:color/transparent">
|
||||||
|
|
||||||
|
<com.kabouzeid.gramophone.views.WidthFitSquareImageView
|
||||||
|
android:id="@+id/player_image"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="match_parent"
|
||||||
|
android:scaleType="centerCrop"
|
||||||
|
tools:ignore="ContentDescription,UnusedAttribute" />
|
||||||
|
|
||||||
|
<ImageView
|
||||||
|
android:id="@+id/player_favorite_icon"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="match_parent"
|
||||||
|
android:layout_gravity="center"
|
||||||
|
android:padding="72dp"
|
||||||
|
android:src="@drawable/ic_favorite_red_a400_96dp"
|
||||||
|
android:visibility="invisible"
|
||||||
|
tools:ignore="ContentDescription" />
|
||||||
|
|
||||||
|
</FrameLayout>
|
||||||
|
|
@ -1,28 +1,10 @@
|
||||||
<?xml version="1.0" encoding="utf-8"?>
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
<FrameLayout
|
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
xmlns:android="http://schemas.android.com/apk/res/android"
|
|
||||||
xmlns:tools="http://schemas.android.com/tools"
|
|
||||||
android:id="@+id/player_album_art_frame"
|
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="match_parent"
|
android:layout_height="match_parent">
|
||||||
android:layout_above="@id/player_footer_frame"
|
|
||||||
android:background="@android:color/black">
|
|
||||||
|
|
||||||
<com.kabouzeid.gramophone.views.WidthFitSquareImageView
|
<android.support.v4.view.ViewPager
|
||||||
android:id="@+id/player_image"
|
android:id="@+id/player_album_cover_viewpager"
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="match_parent"
|
android:layout_height="match_parent" />
|
||||||
android:scaleType="centerCrop"
|
|
||||||
tools:ignore="ContentDescription,UnusedAttribute" />
|
|
||||||
|
|
||||||
<ImageView
|
|
||||||
android:id="@+id/player_favorite_icon"
|
|
||||||
android:layout_width="match_parent"
|
|
||||||
android:layout_height="match_parent"
|
|
||||||
android:layout_gravity="center"
|
|
||||||
android:padding="72dp"
|
|
||||||
android:src="@drawable/ic_favorite_red_a400_96dp"
|
|
||||||
android:visibility="invisible"
|
|
||||||
tools:ignore="ContentDescription" />
|
|
||||||
|
|
||||||
</FrameLayout>
|
</FrameLayout>
|
||||||
Loading…
Add table
Add a link
Reference in a new issue