Merge pull request #717 from TomHennen/persist_scroll_pos_in_new_ep_628
now persisting the scroll position for New Episodes
This commit is contained in:
commit
976f308dbd
|
@ -64,7 +64,8 @@ public class NewEpisodesFragment extends Fragment {
|
||||||
private static final int RECENT_EPISODES_LIMIT = 150;
|
private static final int RECENT_EPISODES_LIMIT = 150;
|
||||||
private static final String PREF_NAME = "PrefNewEpisodesFragment";
|
private static final String PREF_NAME = "PrefNewEpisodesFragment";
|
||||||
private static final String PREF_EPISODE_FILTER_BOOL = "newEpisodeFilterEnabled";
|
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 DragSortListView listView;
|
||||||
private NewEpisodesListAdapter listAdapter;
|
private NewEpisodesListAdapter listAdapter;
|
||||||
|
@ -117,6 +118,12 @@ public class NewEpisodesFragment extends Fragment {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onPause() {
|
||||||
|
super.onPause();
|
||||||
|
saveScrollPosition();
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onStop() {
|
public void onStop() {
|
||||||
super.onStop();
|
super.onStop();
|
||||||
|
@ -136,6 +143,30 @@ public class NewEpisodesFragment extends Fragment {
|
||||||
resetViewState();
|
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() {
|
private void resetViewState() {
|
||||||
listAdapter = null;
|
listAdapter = null;
|
||||||
activity.set(null);
|
activity.set(null);
|
||||||
|
@ -302,6 +333,7 @@ public class NewEpisodesFragment extends Fragment {
|
||||||
downloadObserver.onResume();
|
downloadObserver.onResume();
|
||||||
}
|
}
|
||||||
listAdapter.notifyDataSetChanged();
|
listAdapter.notifyDataSetChanged();
|
||||||
|
restoreScrollPosition();
|
||||||
getActivity().supportInvalidateOptionsMenu();
|
getActivity().supportInvalidateOptionsMenu();
|
||||||
updateShowOnlyEpisodesListViewState();
|
updateShowOnlyEpisodesListViewState();
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue