Skip to content

Commit

Permalink
fix #103: retain menu drawer scroll position after switching activities
Browse files Browse the repository at this point in the history
  • Loading branch information
maxme committed Dec 17, 2014
1 parent 5a72a14 commit a844a15
Showing 1 changed file with 22 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
package org.wordpress.android.util;

import android.content.Context;
import android.content.SharedPreferences;
import android.content.SharedPreferences.Editor;
import android.preference.PreferenceManager;
import android.view.View;
import android.widget.ListView;

Expand Down Expand Up @@ -33,4 +37,22 @@ public void restoreScrollOffset() {
mListView.setItemChecked(mSelectedPosition, true);
}
}

public void saveToPreferences(Context context, String uniqueId) {
saveScrollOffset();
SharedPreferences settings = PreferenceManager.getDefaultSharedPreferences(context);
Editor editor = settings.edit();
editor.putInt("scroll-position-manager-index-" + uniqueId, mListViewScrollStateIndex);
editor.putInt("scroll-position-manager-offset-" + uniqueId, mListViewScrollStateOffset);
editor.putInt("scroll-position-manager-selected-position-" + uniqueId, mSelectedPosition);
editor.apply();
}

public void restoreFromPreferences(Context context, String uniqueId) {
SharedPreferences settings = PreferenceManager.getDefaultSharedPreferences(context);
mListViewScrollStateIndex = settings.getInt("scroll-position-manager-index-" + uniqueId, 0);
mListViewScrollStateOffset = settings.getInt("scroll-position-manager-offset-" + uniqueId, 0);
mSelectedPosition = settings.getInt("scroll-position-manager-selected-position-" + uniqueId, 0);
restoreScrollOffset();
}
}

0 comments on commit a844a15

Please sign in to comment.