From 83090581889ea62e39a79b7c0ca53b15f65a91d4 Mon Sep 17 00:00:00 2001 From: Martin Fietz Date: Mon, 2 Mar 2015 16:36:18 +0100 Subject: Persist scroll position in Queue view --- .../danoeh/antennapod/fragment/QueueFragment.java | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) (limited to 'app') 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 913b544a5..ebfe03382 100644 --- a/app/src/main/java/de/danoeh/antennapod/fragment/QueueFragment.java +++ b/app/src/main/java/de/danoeh/antennapod/fragment/QueueFragment.java @@ -3,6 +3,7 @@ package de.danoeh.antennapod.fragment; import android.app.Activity; import android.content.Context; import android.content.DialogInterface; +import android.content.SharedPreferences; import android.os.AsyncTask; import android.os.Bundle; import android.os.Handler; @@ -66,6 +67,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 = new AtomicReference(); private DownloadObserver downloadObserver = null; @@ -103,6 +108,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(); @@ -329,6 +346,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(); -- cgit v1.2.3