summaryrefslogtreecommitdiff
path: root/app/src
diff options
context:
space:
mode:
authorTom Hennen <tom.hennen@gmail.com>2015-04-05 16:52:51 -0400
committerTom Hennen <tom.hennen@gmail.com>2015-04-05 16:52:51 -0400
commit2a5c7e04548cee22258e0231325d11d8288e2b9f (patch)
treed41ce4ecb068d56b42cef99d0c6d76466c4163d0 /app/src
parent4013707f96c059c754d1074334876ca4e730198a (diff)
downloadAntennaPod-2a5c7e04548cee22258e0231325d11d8288e2b9f.zip
now persisting the scroll position for New Episodes
Diffstat (limited to 'app/src')
-rw-r--r--app/src/main/java/de/danoeh/antennapod/fragment/NewEpisodesFragment.java34
1 files changed, 33 insertions, 1 deletions
diff --git a/app/src/main/java/de/danoeh/antennapod/fragment/NewEpisodesFragment.java b/app/src/main/java/de/danoeh/antennapod/fragment/NewEpisodesFragment.java
index 5601000dc..8bc4099a9 100644
--- a/app/src/main/java/de/danoeh/antennapod/fragment/NewEpisodesFragment.java
+++ b/app/src/main/java/de/danoeh/antennapod/fragment/NewEpisodesFragment.java
@@ -64,7 +64,8 @@ public class NewEpisodesFragment extends Fragment {
private static final int RECENT_EPISODES_LIMIT = 150;
private static final String PREF_NAME = "PrefNewEpisodesFragment";
private static final String PREF_EPISODE_FILTER_BOOL = "newEpisodeFilterEnabled";
-
+ private static final String PREF_KEY_LIST_TOP = "list_top";
+ private static final String PREF_KEY_LIST_SELECTION = "list_selection";
private DragSortListView listView;
private NewEpisodesListAdapter listAdapter;
@@ -118,6 +119,12 @@ public class NewEpisodesFragment extends Fragment {
}
@Override
+ public void onPause() {
+ super.onPause();
+ saveScrollPosition();
+ }
+
+ @Override
public void onStop() {
super.onStop();
EventDistributor.getInstance().unregister(contentUpdate);
@@ -136,6 +143,30 @@ public class NewEpisodesFragment extends Fragment {
resetViewState();
}
+ private void saveScrollPosition() {
+ SharedPreferences prefs = getActivity().getSharedPreferences(PREF_NAME, 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(PREF_NAME, 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() {
listAdapter = null;
activity.set(null);
@@ -302,6 +333,7 @@ public class NewEpisodesFragment extends Fragment {
downloadObserver.onResume();
}
listAdapter.notifyDataSetChanged();
+ restoreScrollPosition();
getActivity().supportInvalidateOptionsMenu();
updateShowOnlyEpisodesListViewState();
}