Fixed a coloring bug
This commit is contained in:
parent
74705b8e22
commit
c5b5460e01
2 changed files with 32 additions and 10 deletions
|
|
@ -36,6 +36,9 @@ public class AlbumCoverPagerAdapter extends CustomFragmentStatePagerAdapter {
|
|||
|
||||
private ArrayList<Song> dataSet;
|
||||
|
||||
private AlbumCoverFragment.ColorReceiver currentColorReceiver;
|
||||
private int currentColorReceiverPosition = -1;
|
||||
|
||||
public AlbumCoverPagerAdapter(FragmentManager fm, ArrayList<Song> dataSet) {
|
||||
super(fm);
|
||||
this.dataSet = dataSet;
|
||||
|
|
@ -51,6 +54,30 @@ public class AlbumCoverPagerAdapter extends CustomFragmentStatePagerAdapter {
|
|||
return dataSet.size();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object instantiateItem(ViewGroup container, int position) {
|
||||
Object o = super.instantiateItem(container, position);
|
||||
if (currentColorReceiver != null && currentColorReceiverPosition == position) {
|
||||
receiveColor(currentColorReceiver, currentColorReceiverPosition);
|
||||
}
|
||||
return o;
|
||||
}
|
||||
|
||||
/**
|
||||
* Only the latest passed {@link AlbumCoverFragment.ColorReceiver} is guaranteed to receive a response
|
||||
*/
|
||||
public void receiveColor(AlbumCoverFragment.ColorReceiver colorReceiver, int position) {
|
||||
AlbumCoverFragment fragment = (AlbumCoverFragment) getFragment(position);
|
||||
if (fragment != null) {
|
||||
currentColorReceiver = null;
|
||||
currentColorReceiverPosition = -1;
|
||||
fragment.receiveColor(colorReceiver, position);
|
||||
} else {
|
||||
currentColorReceiver = colorReceiver;
|
||||
currentColorReceiverPosition = position;
|
||||
}
|
||||
}
|
||||
|
||||
public static class AlbumCoverFragment extends Fragment implements SharedPreferences.OnSharedPreferenceChangeListener {
|
||||
private static final String SONG_ARG = "song";
|
||||
|
||||
|
|
|
|||
|
|
@ -4,7 +4,6 @@ import android.animation.Animator;
|
|||
import android.os.Bundle;
|
||||
import android.support.annotation.ColorInt;
|
||||
import android.support.v4.view.ViewPager;
|
||||
import android.util.Log;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
|
|
@ -34,7 +33,7 @@ public class PlayerAlbumCoverFragment extends AbsMusicServiceFragment implements
|
|||
ImageView favoriteIcon;
|
||||
|
||||
private OnColorChangedListener onColorChangedListener;
|
||||
private int currentRequest;
|
||||
private int currentPosition;
|
||||
|
||||
@Override
|
||||
public View onCreateView(LayoutInflater inflater, ViewGroup container,
|
||||
|
|
@ -81,11 +80,8 @@ public class PlayerAlbumCoverFragment extends AbsMusicServiceFragment implements
|
|||
|
||||
@Override
|
||||
public void onPageSelected(int position) {
|
||||
currentRequest = position;
|
||||
AlbumCoverPagerAdapter.AlbumCoverFragment albumCoverFragment = ((AlbumCoverPagerAdapter.AlbumCoverFragment) ((AlbumCoverPagerAdapter) viewPager.getAdapter()).getFragment(position));
|
||||
if (albumCoverFragment != null) {
|
||||
albumCoverFragment.receiveColor(colorReceiver, position);
|
||||
}
|
||||
currentPosition = position;
|
||||
((AlbumCoverPagerAdapter) viewPager.getAdapter()).receiveColor(colorReceiver, position);
|
||||
if (position != MusicPlayerRemote.getPosition()) {
|
||||
MusicPlayerRemote.playSongAt(position);
|
||||
}
|
||||
|
|
@ -93,9 +89,8 @@ public class PlayerAlbumCoverFragment extends AbsMusicServiceFragment implements
|
|||
|
||||
private AlbumCoverPagerAdapter.AlbumCoverFragment.ColorReceiver colorReceiver = new AlbumCoverPagerAdapter.AlbumCoverFragment.ColorReceiver() {
|
||||
@Override
|
||||
public void onColorReady(int color, int request) {
|
||||
Log.d(TAG, "currentRequest == request : " + (currentRequest == request));
|
||||
if (currentRequest == request) {
|
||||
public void onColorReady(int color, int requestCode) {
|
||||
if (currentPosition == requestCode) {
|
||||
notifyColorChange(color);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue