Commit d3feca9c authored by linus_lee's avatar linus_lee
Browse files

Eleven: Make the adapter changes refresh not jump to the top of the list

https://cyanogen.atlassian.net/browse/MUSIC-122
https://cyanogen.atlassian.net/browse/MUSIC-130

Change-Id: I6216a84eb13d47b1b6a68fef2b698efebf677d9f
parent 38df2d88
......@@ -150,6 +150,7 @@ public class PlaylistDetailFragment extends FadingBarFragment implements
@Override
protected void removeFromPlaylist() {
mAdapter.remove(mSong);
mAdapter.buildCache();
mAdapter.notifyDataSetChanged();
MusicUtils.removeFromPlaylist(getActivity(), mSong.mSongId, mPlaylistId);
getLoaderManager().restartLoader(LOADER, null, PlaylistDetailFragment.this);
......@@ -326,12 +327,17 @@ public class PlaylistDetailFragment extends FadingBarFragment implements
// show the header container
mHeaderContainer.setVisibility(View.VISIBLE);
// pause notifying the adapter and make changes before re-enabling it so that the list
// view doesn't reset to the top of the list
mAdapter.setNotifyOnChange(false);
// Start fresh
mAdapter.unload();
// Return the correct count
mAdapter.addAll(data);
// build the cache
mAdapter.buildCache();
// re-enable the notify by calling notify dataset changes
mAdapter.notifyDataSetChanged();
// set the number of songs
String numberOfSongs = MusicUtils.makeLabel(getActivity(), R.plurals.Nsongs,
data.size());
......@@ -358,8 +364,6 @@ public class PlaylistDetailFragment extends FadingBarFragment implements
@Override
public void restartLoader() {
// unload the adapter - this will also get the loading progress bar to show
mAdapter.unload();
lookupName(); // playlist name may have changed
if(mPlaylistName == null) {
// if name is null, we've been deleted, so close the this fragment
......
......@@ -358,6 +358,9 @@ public class QueueFragment extends Fragment implements LoaderCallbacks<List<Song
*/
@Override
public void onLoadFinished(final Loader<List<Song>> loader, final List<Song> data) {
// pause notifying the adapter and make changes before re-enabling it so that the list
// view doesn't reset to the top of the list
mAdapter.setNotifyOnChange(false);
mAdapter.unload(); // Start fresh
if (data.isEmpty()) {
......@@ -372,6 +375,8 @@ public class QueueFragment extends Fragment implements LoaderCallbacks<List<Song
// Set the currently playing audio
mAdapter.setCurrentQueuePosition(MusicUtils.getQueuePosition());
}
// re-enable the notify by calling notify dataset changes
mAdapter.notifyDataSetChanged();
}
/**
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment