From 0caca67f44dd0297f5486f160ce6ccff2ff43c35 Mon Sep 17 00:00:00 2001 From: Bradlee Speice Date: Wed, 23 Jul 2014 23:35:12 -0400 Subject: [PATCH] DownloadActivity remembers your category on rotate --- .../activity/downloader/DownloadActivity.java | 18 ++++++++++++++++-- .../activity/navigation/NavDrawerFragment.java | 4 ++++ 2 files changed, 20 insertions(+), 2 deletions(-) diff --git a/app/src/main/java/org/bspeice/minimalbible/activity/downloader/DownloadActivity.java b/app/src/main/java/org/bspeice/minimalbible/activity/downloader/DownloadActivity.java index 933db9a..4e645b7 100644 --- a/app/src/main/java/org/bspeice/minimalbible/activity/downloader/DownloadActivity.java +++ b/app/src/main/java/org/bspeice/minimalbible/activity/downloader/DownloadActivity.java @@ -28,6 +28,8 @@ public class DownloadActivity extends BaseActivity implements Injector { private final String TAG = "DownloadActivity"; + private final String TAG_CURRENT_CATEGORY = "CurrentCategory"; + @Inject @Named("ValidCategories") List validCategories; @@ -41,6 +43,7 @@ public class DownloadActivity extends BaseActivity implements * {@link #restoreActionBar()}. */ private CharSequence mTitle; + private ObjectGraph daObjectGraph; /** @@ -82,7 +85,13 @@ public class DownloadActivity extends BaseActivity implements // Set up the drawer. mNavigationDrawerFragment.setUp(R.id.navigation_drawer, (DrawerLayout) findViewById(R.id.drawer_layout)); - mNavigationDrawerFragment.selectItem(0); + + // And select our first item + int itemToSelect = 0; + if (savedInstanceState != null) { + itemToSelect = savedInstanceState.getInt(TAG_CURRENT_CATEGORY); + } + mNavigationDrawerFragment.selectItem(itemToSelect); } @Override @@ -132,5 +141,10 @@ public class DownloadActivity extends BaseActivity implements return super.onOptionsItemSelected(item); } - + @Override + protected void onSaveInstanceState(Bundle outState) { + super.onSaveInstanceState(outState); + outState.putInt(TAG_CURRENT_CATEGORY, + mNavigationDrawerFragment.getCurrentPosition()); + } } diff --git a/app/src/main/java/org/bspeice/minimalbible/activity/navigation/NavDrawerFragment.java b/app/src/main/java/org/bspeice/minimalbible/activity/navigation/NavDrawerFragment.java index 9b33ce4..b2cf122 100644 --- a/app/src/main/java/org/bspeice/minimalbible/activity/navigation/NavDrawerFragment.java +++ b/app/src/main/java/org/bspeice/minimalbible/activity/navigation/NavDrawerFragment.java @@ -45,4 +45,8 @@ public class NavDrawerFragment extends AbstractNavDrawerFragment { mCallbacks.onNavigationDrawerItemSelected(position); } } + + public int getCurrentPosition() { + return mCurrentSelectedPosition; + } }