Fixed a coloring bug

This commit is contained in:
Karim Abou Zeid 2015-12-23 17:00:40 +01:00
commit c5b5460e01
2 changed files with 32 additions and 10 deletions

View file

@ -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";