diff options
author | Tom Hennen <TomHennen@users.noreply.github.com> | 2015-03-03 17:14:52 -0500 |
---|---|---|
committer | Tom Hennen <TomHennen@users.noreply.github.com> | 2015-03-03 17:14:52 -0500 |
commit | 27c8a32f0f8e8b3cc871c586e463a4a24e377b8f (patch) | |
tree | 1ef0598b969daee191e740c08d24b13b399321f6 /app/src/main/java/de | |
parent | 2f85c21c248a8d9749989041495ca82bdeeed106 (diff) | |
parent | 241fc6c33453c38ba048b042c5d23650a6bd1580 (diff) | |
download | AntennaPod-27c8a32f0f8e8b3cc871c586e463a4a24e377b8f.zip |
Merge pull request #644 from mfietz/issue-551
Persist scroll position in Queue view
Diffstat (limited to 'app/src/main/java/de')
-rw-r--r-- | app/src/main/java/de/danoeh/antennapod/fragment/QueueFragment.java | 23 |
1 files changed, 22 insertions, 1 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 ca8543b4c..bc00562aa 100644 --- a/app/src/main/java/de/danoeh/antennapod/fragment/QueueFragment.java +++ b/app/src/main/java/de/danoeh/antennapod/fragment/QueueFragment.java @@ -2,8 +2,8 @@ package de.danoeh.antennapod.fragment; import android.app.Activity; import android.content.Context; +import android.content.SharedPreferences; import android.os.AsyncTask; -import android.os.Build; import android.os.Bundle; import android.os.Handler; import android.support.v4.app.Fragment; @@ -65,6 +65,10 @@ public class QueueFragment extends Fragment { private boolean viewsCreated = false; private boolean isUpdatingFeeds = false; + private static final String PREFS = "QueueFragment"; + private static final String PREF_KEY_LIST_TOP = "list_top"; + private static final String PREF_KEY_LIST_SELECTION = "list_selection"; + private AtomicReference<Activity> activity = new AtomicReference<Activity>(); private DownloadObserver downloadObserver = null; @@ -103,6 +107,18 @@ 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(); + } + + @Override public void onStop() { super.onStop(); EventDistributor.getInstance().unregister(contentUpdate); @@ -313,6 +329,11 @@ 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); + // we need to refresh the options menu because it sometimes // needs data that may have just been loaded. getActivity().supportInvalidateOptionsMenu(); |