Further refactoring to MessageList and FolderList to (hopefully) address

force-closes and inconsistent data on activity reuse. Also, removing
broken/unused code to preserve activity state across invocations.
across invocations.
This commit is contained in:
Jesse Vincent 2010-01-30 03:26:45 +00:00
parent cc8400cb53
commit c38384e134
2 changed files with 60 additions and 122 deletions

View file

@ -60,7 +60,7 @@ public class FolderList extends K9ListActivity
private FolderListHandler mHandler = new FolderListHandler();
private int mUnreadMessageCount = 0;
private int mUnreadMessageCount;
class FolderListHandler extends Handler
{
@ -244,18 +244,19 @@ public class FolderList extends K9ListActivity
@Override
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
onNewIntent(getIntent());
}
public void onNewIntent (Intent intent) {
public void onNewIntent(Intent intent)
{
String savedFolderName = null;
String initialFolder;
mUnreadMessageCount = 0;
mAccount = (Account)intent.getSerializableExtra(EXTRA_ACCOUNT);
initialFolder = intent.getStringExtra(EXTRA_INITIAL_FOLDER);
initialFolder = intent.getStringExtra(EXTRA_INITIAL_FOLDER);
if (
initialFolder != null
&& !K9.FOLDER_NONE.equals(initialFolder))
@ -270,11 +271,6 @@ public class FolderList extends K9ListActivity
}
}
/* There are two times when we might need to initialize the activity view
* onCreate
* OR
* onResume if the initial onCreate opened a folder directly
*/
private void initializeActivityView()
{
requestWindowFeature(Window.FEATURE_INDETERMINATE_PROGRESS);
@ -292,11 +288,7 @@ public class FolderList extends K9ListActivity
}
});
registerForContextMenu(mListView);
/*
* We manually save and restore the list's state because our adapter is
* slow.
*/
mListView.setSaveEnabled(true);
mInflater = getLayoutInflater();
@ -353,16 +345,6 @@ public class FolderList extends K9ListActivity
}
@Override
public void onSaveInstanceState(Bundle outState)
{
super.onSaveInstanceState(outState);
if (mSelectedContextFolder != null)
{
outState.putString(STATE_CURRENT_FOLDER, mSelectedContextFolder.name);
}
}
@Override public boolean onKeyDown(int keyCode, KeyEvent event)
{

View file

@ -70,7 +70,7 @@ public class MessageList
private static final String STATE_KEY_LIST = "com.fsck.k9.activity.messagelist_state";
private static final String STATE_CURRENT_FOLDER = "com.fsck.k9.activity.messagelist_folder";
private static final String STATE_QUERY = "com.fsck.k9.activity.query";
private static final String STATE_KEY_SELECTION = "com.fsck.k9.activity.messagelist_selection";
private static final String STATE_CURRENT_ITEM = "com.fsck.k9.activity.messagelist_selection";
private static final String STATE_KEY_SELECTED_COUNT = "com.fsck.k9.activity.messagelist_selected_count";
@ -330,83 +330,26 @@ public class MessageList
// Debug.startMethodTracing("k9");
super.onCreate(savedInstanceState);
requestWindowFeature(Window.FEATURE_INDETERMINATE_PROGRESS);
requestWindowFeature(Window.FEATURE_PROGRESS);
setContentView(R.layout.message_list);
mListView = (ListView) findViewById(R.id.message_list);
mListView.setScrollBarStyle(View.SCROLLBARS_OUTSIDE_INSET);
mListView.setLongClickable(true);
mListView.setFastScrollEnabled(true);
mListView.setScrollingCacheEnabled(true);
mListView.setOnItemClickListener(this);
registerForContextMenu(mListView);
/*
* We manually save and restore the list's state because our adapter is
* slow.
*/
mListView.setSaveEnabled(false);
mInflater = getLayoutInflater();
mBatchButtonArea = findViewById(R.id.batch_button_area);
mBatchReadButton = (Button) findViewById(R.id.batch_read_button);
mBatchReadButton.setOnClickListener(this);
mBatchDeleteButton = (Button) findViewById(R.id.batch_delete_button);
mBatchDeleteButton.setOnClickListener(this);
mBatchFlagButton = (Button) findViewById(R.id.batch_flag_button);
mBatchFlagButton.setOnClickListener(this);
mBatchDoneButton = (Button) findViewById(R.id.batch_done_button);
mBatchDoneButton.setOnClickListener(this);
// Gesture detection
gestureDetector = new GestureDetector(new MyGestureDetector());
gestureListener = new View.OnTouchListener()
{
public boolean onTouch(View v, MotionEvent event)
{
if (gestureDetector.onTouchEvent(event))
{
return true;
}
return false;
}
};
mListView.setOnTouchListener(gestureListener);
if (savedInstanceState != null)
{
mFolderName = savedInstanceState.getString(STATE_CURRENT_FOLDER);
mQueryString = savedInstanceState.getString(STATE_QUERY);
mSelectedCount = savedInstanceState.getInt(STATE_KEY_SELECTED_COUNT);
onRestoreListState(savedInstanceState);
}
initializeLayout();
onNewIntent(getIntent());
}
public void onNewIntent(Intent intent) {
public void onNewIntent(Intent intent)
{
mAccount = (Account)intent.getSerializableExtra(EXTRA_ACCOUNT);
mFolderName = intent.getStringExtra(EXTRA_FOLDER);
mQueryString = intent.getStringExtra(EXTRA_QUERY);
// Take the initial folder into account only if we are *not* restoring the
// activity already
mFolderName = intent.getStringExtra(EXTRA_FOLDER);
mQueryString = intent.getStringExtra(EXTRA_QUERY);
if (mFolderName == null && mQueryString == null)
{
mFolderName = mAccount.getAutoExpandFolderName();
}
if (mFolderName == null && mQueryString == null)
{
mFolderName = mAccount.getAutoExpandFolderName();
}
mAdapter = new MessageListAdapter();
final Object previousData = getLastNonConfigurationInstance();
if (previousData != null)
@ -421,32 +364,11 @@ public class MessageList
}
mController = MessagingController.getInstance(getApplication());
mListView.setAdapter(mAdapter);
}
private void onRestoreListState(Bundle savedInstanceState)
{
mFolderName = savedInstanceState.getString(STATE_CURRENT_FOLDER);
mQueryString = savedInstanceState.getString(STATE_QUERY);
int selectedChild = savedInstanceState.getInt(STATE_KEY_SELECTION, -1);
if (selectedChild != 0)
{
mListView.setSelection(selectedChild);
}
if (mFolderName != null)
{
mCurrentFolder = mAdapter.getFolder(mFolderName, mAccount);
}
mListView.onRestoreInstanceState(savedInstanceState.getParcelable(STATE_KEY_LIST));
}
@Override
public void onPause()
{
@ -455,6 +377,7 @@ public class MessageList
mController.removeListener(mAdapter.mListener);
}
/**
* On resume we refresh
* messages for the folder that is currently open. This guarantees that things
@ -497,17 +420,50 @@ public class MessageList
}
@Override
public void onSaveInstanceState(Bundle outState)
private void initializeLayout ()
{
super.onSaveInstanceState(outState);
outState.putParcelable(STATE_KEY_LIST, mListView.onSaveInstanceState());
outState.putInt(STATE_KEY_SELECTION, mListView .getSelectedItemPosition());
outState.putString(STATE_CURRENT_FOLDER, mFolderName);
outState.putString(STATE_QUERY, mQueryString);
outState.putInt(STATE_KEY_SELECTED_COUNT, mSelectedCount);
}
requestWindowFeature(Window.FEATURE_INDETERMINATE_PROGRESS);
requestWindowFeature(Window.FEATURE_PROGRESS);
setContentView(R.layout.message_list);
mListView = (ListView) findViewById(R.id.message_list);
mListView.setScrollBarStyle(View.SCROLLBARS_OUTSIDE_INSET);
mListView.setLongClickable(true);
mListView.setFastScrollEnabled(true);
mListView.setScrollingCacheEnabled(true);
mListView.setOnItemClickListener(this);
registerForContextMenu(mListView);
mBatchButtonArea = findViewById(R.id.batch_button_area);
mBatchReadButton = (Button) findViewById(R.id.batch_read_button);
mBatchReadButton.setOnClickListener(this);
mBatchDeleteButton = (Button) findViewById(R.id.batch_delete_button);
mBatchDeleteButton.setOnClickListener(this);
mBatchFlagButton = (Button) findViewById(R.id.batch_flag_button);
mBatchFlagButton.setOnClickListener(this);
mBatchDoneButton = (Button) findViewById(R.id.batch_done_button);
mBatchDoneButton.setOnClickListener(this);
// Gesture detection
gestureDetector = new GestureDetector(new MyGestureDetector());
gestureListener = new View.OnTouchListener()
{
public boolean onTouch(View v, MotionEvent event)
{
if (gestureDetector.onTouchEvent(event))
{
return true;
}
return false;
}
};
mListView.setOnTouchListener(gestureListener);
}
@Override public Object onRetainNonConfigurationInstance()
{