Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@
import org.wordpress.android.util.BlogUtils;
import org.wordpress.android.util.DeviceUtils;
import org.wordpress.android.util.DisplayUtils;
import org.wordpress.android.util.ListScrollPositionManager;
import org.wordpress.android.util.ToastUtils;
import org.wordpress.android.util.ToastUtils.Duration;
import org.wordpress.android.util.WPActivityUtils;
Expand All @@ -62,7 +63,7 @@
*/
public abstract class WPDrawerActivity extends ActionBarActivity {
public static final int NEW_BLOG_CANCELED = 10;

private static final String SCROLL_POSITION_ID = "WPDrawerActivity";
/**
* AuthenticatorRequest code used when no accounts exist, and user is prompted to add an
* account.
Expand All @@ -88,6 +89,7 @@ public abstract class WPDrawerActivity extends ActionBarActivity {
private DrawerAdapter mDrawerAdapter;
private ListView mDrawerListView;
private Spinner mBlogSpinner;
private ListScrollPositionManager mScrollPositionManager;

private static final int OPENED_FROM_DRAWER_DELAY = 250;

Expand Down Expand Up @@ -136,6 +138,7 @@ protected void onPause() {
overridePendingTransition(0, 0);
finish();
}
mScrollPositionManager.saveToPreferences(this, SCROLL_POSITION_ID);
}

@Override
Expand All @@ -147,6 +150,7 @@ protected void onResume() {
// Sync the toggle state after onRestoreInstanceState has occurred.
mDrawerToggle.syncState();
}
mScrollPositionManager.restoreFromPreferences(this, SCROLL_POSITION_ID);
}

@TargetApi(Build.VERSION_CODES.JELLY_BEAN_MR1)
Expand Down Expand Up @@ -240,7 +244,7 @@ public void onDrawerOpened(View drawerView) {
View view = getLayoutInflater().inflate(R.layout.drawer_header, mDrawerListView, false);
mDrawerListView.addHeaderView(view, null, false);
}

mScrollPositionManager = new ListScrollPositionManager(mDrawerListView, false);
View settingsRow = findViewById(R.id.settings_row);
settingsRow.setOnClickListener(new View.OnClickListener() {
@Override
Expand Down
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();
}
}