From d3feca9c173b999d663dd861bb369e7ce9b6b564 Mon Sep 17 00:00:00 2001 From: linus_lee Date: Tue, 4 Nov 2014 17:52:36 -0800 Subject: 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 --- src/com/cyngn/eleven/ui/fragments/PlaylistDetailFragment.java | 8 ++++++-- src/com/cyngn/eleven/ui/fragments/QueueFragment.java | 5 +++++ 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/src/com/cyngn/eleven/ui/fragments/PlaylistDetailFragment.java b/src/com/cyngn/eleven/ui/fragments/PlaylistDetailFragment.java index 8e13067..b1e7a04 100644 --- a/src/com/cyngn/eleven/ui/fragments/PlaylistDetailFragment.java +++ b/src/com/cyngn/eleven/ui/fragments/PlaylistDetailFragment.java @@ -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 diff --git a/src/com/cyngn/eleven/ui/fragments/QueueFragment.java b/src/com/cyngn/eleven/ui/fragments/QueueFragment.java index d47dd88..87c5f6c 100644 --- a/src/com/cyngn/eleven/ui/fragments/QueueFragment.java +++ b/src/com/cyngn/eleven/ui/fragments/QueueFragment.java @@ -358,6 +358,9 @@ public class QueueFragment extends Fragment implements LoaderCallbacks> loader, final List 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