From 7cc611b50daa6b4ac7c09fe34ef29901faafaf37 Mon Sep 17 00:00:00 2001 From: Sam Bosley Date: Thu, 12 Jan 2012 16:58:04 -0800 Subject: [PATCH] Fixed bug where list selection would be lost after rotation (again) --- .../activity/AstridWrapperActivity.java | 3 +-- .../activity/TaskListWrapperActivity.java | 23 +++++++++++++++++-- 2 files changed, 22 insertions(+), 4 deletions(-) diff --git a/astrid/src/com/todoroo/astrid/activity/AstridWrapperActivity.java b/astrid/src/com/todoroo/astrid/activity/AstridWrapperActivity.java index 900d911ba..1d1319d7d 100644 --- a/astrid/src/com/todoroo/astrid/activity/AstridWrapperActivity.java +++ b/astrid/src/com/todoroo/astrid/activity/AstridWrapperActivity.java @@ -86,8 +86,7 @@ public class AstridWrapperActivity extends FragmentActivity */ public boolean onFilterItemClicked(FilterListItem item) { if (this instanceof TaskListWrapperActivity) { - int selectedPosition = ((TaskListWrapperActivity) this).getFilterItemPosition(item); - getSupportActionBar().setSelectedNavigationItem(selectedPosition); + ((TaskListWrapperActivity) this).setSelectedItem(item); } if (!mMultipleFragments || (item instanceof SearchFilter)) { if(item instanceof Filter) { diff --git a/astrid/src/com/todoroo/astrid/activity/TaskListWrapperActivity.java b/astrid/src/com/todoroo/astrid/activity/TaskListWrapperActivity.java index a177d9f75..b95a0edc0 100644 --- a/astrid/src/com/todoroo/astrid/activity/TaskListWrapperActivity.java +++ b/astrid/src/com/todoroo/astrid/activity/TaskListWrapperActivity.java @@ -13,6 +13,9 @@ import com.todoroo.astrid.service.ThemeService; public class TaskListWrapperActivity extends AstridWrapperActivity { + public static final String TOKEN_SELECTED_FILTER = "selectedFilter"; + private int selectionToSet; + private ArrayAdapter listDropdownAdapter; /** * @see android.app.Activity#onCreate(Bundle) @@ -30,6 +33,11 @@ public class TaskListWrapperActivity extends AstridWrapperActivity { ActionBar actionBar = getSupportActionBar(); actionBar.setNavigationMode(ActionBar.NAVIGATION_MODE_LIST); actionBar.setDisplayOptions(0, ActionBar.DISPLAY_SHOW_TITLE); + + if (savedInstanceState != null) { + selectionToSet = savedInstanceState.getInt(TOKEN_SELECTED_FILTER); + } + } /* (non-Javadoc) @@ -57,10 +65,21 @@ public class TaskListWrapperActivity extends AstridWrapperActivity { return true; } }); + if (selectionToSet != -1 && selectionToSet < listDropdownAdapter.getCount()) { + selectionToSet = -1; + getSupportActionBar().setSelectedNavigationItem(selectionToSet); + } + } + + @Override + protected void onSaveInstanceState(Bundle icicle) { + icicle.putInt(TOKEN_SELECTED_FILTER, getSupportActionBar().getSelectedNavigationIndex()); + super.onSaveInstanceState(icicle); } - public int getFilterItemPosition(FilterListItem item) { - return listDropdownAdapter.getPosition(item); + public void setSelectedItem(FilterListItem item) { + int position = listDropdownAdapter.getPosition(item); + getSupportActionBar().setSelectedNavigationItem(position); } @Override