diff options
author | Tom Hennen <TomHennen@users.noreply.github.com> | 2015-03-08 19:16:12 -0400 |
---|---|---|
committer | Tom Hennen <TomHennen@users.noreply.github.com> | 2015-03-08 19:16:12 -0400 |
commit | 66f1040f0c3561916f5d61095f4de3915ca0ab2d (patch) | |
tree | eaf7257d5aacd49043d924885a9d3d469462cc60 | |
parent | 006f793faea5bd055dd7bbcc2d1f0ef219b28aae (diff) | |
parent | d3e1fcdcba3a5f9dabbceb30686101ae74251e6e (diff) | |
download | AntennaPod-66f1040f0c3561916f5d61095f4de3915ca0ab2d.zip |
Merge pull request #661 from mfietz/fix/queue-false-scroll-position-restore
Fix for false restore where swipe to dismiss scrolls to the top of the list
-rw-r--r-- | app/src/main/java/de/danoeh/antennapod/fragment/QueueFragment.java | 37 |
1 files changed, 26 insertions, 11 deletions
diff --git a/app/src/main/java/de/danoeh/antennapod/fragment/QueueFragment.java b/app/src/main/java/de/danoeh/antennapod/fragment/QueueFragment.java index 3e60f1af0..da33c6ea3 100644 --- a/app/src/main/java/de/danoeh/antennapod/fragment/QueueFragment.java +++ b/app/src/main/java/de/danoeh/antennapod/fragment/QueueFragment.java @@ -116,13 +116,7 @@ public class QueueFragment extends Fragment { @Override public void onPause() { super.onPause(); - SharedPreferences prefs = getActivity().getSharedPreferences(PREFS, Context.MODE_PRIVATE); - SharedPreferences.Editor editor = prefs.edit(); - View v = listView.getChildAt(0); - int top = (v == null) ? 0 : (v.getTop() - listView.getPaddingTop()); - editor.putInt(PREF_KEY_LIST_SELECTION, listView.getFirstVisiblePosition()); - editor.putInt(PREF_KEY_LIST_TOP, top); - editor.commit(); + saveScrollPosition(); } @Override @@ -138,6 +132,30 @@ public class QueueFragment extends Fragment { this.activity.set((MainActivity) activity); } + private void saveScrollPosition() { + SharedPreferences prefs = getActivity().getSharedPreferences(PREFS, Context.MODE_PRIVATE); + SharedPreferences.Editor editor = prefs.edit(); + View v = listView.getChildAt(0); + int top = (v == null) ? 0 : (v.getTop() - listView.getPaddingTop()); + editor.putInt(PREF_KEY_LIST_SELECTION, listView.getFirstVisiblePosition()); + editor.putInt(PREF_KEY_LIST_TOP, top); + editor.commit(); + } + + private void restoreScrollPosition() { + SharedPreferences prefs = getActivity().getSharedPreferences(PREFS, Context.MODE_PRIVATE); + int listSelection = prefs.getInt(PREF_KEY_LIST_SELECTION, 0); + int top = prefs.getInt(PREF_KEY_LIST_TOP, 0); + if(listSelection > 0 || top > 0) { + listView.setSelectionFromTop(listSelection, top); + // restore once, then forget + SharedPreferences.Editor editor = prefs.edit(); + editor.putInt(PREF_KEY_LIST_SELECTION, 0); + editor.putInt(PREF_KEY_LIST_TOP, 0); + editor.commit(); + } + } + private void resetViewState() { unregisterForContextMenu(listView); listAdapter = null; @@ -374,10 +392,7 @@ public class QueueFragment extends Fragment { } listAdapter.notifyDataSetChanged(); - SharedPreferences prefs = getActivity().getSharedPreferences(PREFS, Context.MODE_PRIVATE); - int listSelection = prefs.getInt(PREF_KEY_LIST_SELECTION, 0); - int top = prefs.getInt(PREF_KEY_LIST_TOP, 0); - listView.setSelectionFromTop(listSelection, top); + restoreScrollPosition(); // we need to refresh the options menu because it sometimes // needs data that may have just been loaded. |