mirror of
https://github.com/moparisthebest/k-9
synced 2024-11-27 19:52:17 -05:00
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:
parent
cc8400cb53
commit
c38384e134
@ -60,7 +60,7 @@ public class FolderList extends K9ListActivity
|
|||||||
|
|
||||||
private FolderListHandler mHandler = new FolderListHandler();
|
private FolderListHandler mHandler = new FolderListHandler();
|
||||||
|
|
||||||
private int mUnreadMessageCount = 0;
|
private int mUnreadMessageCount;
|
||||||
|
|
||||||
class FolderListHandler extends Handler
|
class FolderListHandler extends Handler
|
||||||
{
|
{
|
||||||
@ -244,15 +244,16 @@ public class FolderList extends K9ListActivity
|
|||||||
@Override
|
@Override
|
||||||
public void onCreate(Bundle savedInstanceState)
|
public void onCreate(Bundle savedInstanceState)
|
||||||
{
|
{
|
||||||
|
|
||||||
|
|
||||||
super.onCreate(savedInstanceState);
|
super.onCreate(savedInstanceState);
|
||||||
onNewIntent(getIntent());
|
onNewIntent(getIntent());
|
||||||
}
|
}
|
||||||
|
|
||||||
public void onNewIntent (Intent intent) {
|
public void onNewIntent(Intent intent)
|
||||||
|
{
|
||||||
String savedFolderName = null;
|
String savedFolderName = null;
|
||||||
String initialFolder;
|
String initialFolder;
|
||||||
|
|
||||||
|
mUnreadMessageCount = 0;
|
||||||
mAccount = (Account)intent.getSerializableExtra(EXTRA_ACCOUNT);
|
mAccount = (Account)intent.getSerializableExtra(EXTRA_ACCOUNT);
|
||||||
|
|
||||||
initialFolder = intent.getStringExtra(EXTRA_INITIAL_FOLDER);
|
initialFolder = intent.getStringExtra(EXTRA_INITIAL_FOLDER);
|
||||||
@ -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()
|
private void initializeActivityView()
|
||||||
{
|
{
|
||||||
requestWindowFeature(Window.FEATURE_INDETERMINATE_PROGRESS);
|
requestWindowFeature(Window.FEATURE_INDETERMINATE_PROGRESS);
|
||||||
@ -293,10 +289,6 @@ public class FolderList extends K9ListActivity
|
|||||||
});
|
});
|
||||||
registerForContextMenu(mListView);
|
registerForContextMenu(mListView);
|
||||||
|
|
||||||
/*
|
|
||||||
* We manually save and restore the list's state because our adapter is
|
|
||||||
* slow.
|
|
||||||
*/
|
|
||||||
mListView.setSaveEnabled(true);
|
mListView.setSaveEnabled(true);
|
||||||
|
|
||||||
mInflater = getLayoutInflater();
|
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)
|
@Override public boolean onKeyDown(int keyCode, KeyEvent event)
|
||||||
{
|
{
|
||||||
|
@ -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_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_CURRENT_FOLDER = "com.fsck.k9.activity.messagelist_folder";
|
||||||
private static final String STATE_QUERY = "com.fsck.k9.activity.query";
|
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";
|
private static final String STATE_KEY_SELECTED_COUNT = "com.fsck.k9.activity.messagelist_selected_count";
|
||||||
|
|
||||||
|
|
||||||
@ -330,75 +330,19 @@ public class MessageList
|
|||||||
// Debug.startMethodTracing("k9");
|
// Debug.startMethodTracing("k9");
|
||||||
super.onCreate(savedInstanceState);
|
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();
|
mInflater = getLayoutInflater();
|
||||||
|
initializeLayout();
|
||||||
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);
|
|
||||||
}
|
|
||||||
onNewIntent(getIntent());
|
onNewIntent(getIntent());
|
||||||
}
|
}
|
||||||
|
|
||||||
public void onNewIntent(Intent intent) {
|
public void onNewIntent(Intent intent)
|
||||||
|
{
|
||||||
mAccount = (Account)intent.getSerializableExtra(EXTRA_ACCOUNT);
|
mAccount = (Account)intent.getSerializableExtra(EXTRA_ACCOUNT);
|
||||||
|
|
||||||
// Take the initial folder into account only if we are *not* restoring the
|
|
||||||
// activity already
|
|
||||||
|
|
||||||
mFolderName = intent.getStringExtra(EXTRA_FOLDER);
|
mFolderName = intent.getStringExtra(EXTRA_FOLDER);
|
||||||
mQueryString = intent.getStringExtra(EXTRA_QUERY);
|
mQueryString = intent.getStringExtra(EXTRA_QUERY);
|
||||||
|
|
||||||
|
// Take the initial folder into account only if we are *not* restoring the
|
||||||
|
// activity already
|
||||||
|
|
||||||
if (mFolderName == null && mQueryString == null)
|
if (mFolderName == null && mQueryString == null)
|
||||||
{
|
{
|
||||||
@ -406,7 +350,6 @@ public class MessageList
|
|||||||
}
|
}
|
||||||
|
|
||||||
mAdapter = new MessageListAdapter();
|
mAdapter = new MessageListAdapter();
|
||||||
|
|
||||||
final Object previousData = getLastNonConfigurationInstance();
|
final Object previousData = getLastNonConfigurationInstance();
|
||||||
|
|
||||||
if (previousData != null)
|
if (previousData != null)
|
||||||
@ -421,32 +364,11 @@ public class MessageList
|
|||||||
}
|
}
|
||||||
|
|
||||||
mController = MessagingController.getInstance(getApplication());
|
mController = MessagingController.getInstance(getApplication());
|
||||||
|
|
||||||
mListView.setAdapter(mAdapter);
|
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
|
@Override
|
||||||
public void onPause()
|
public void onPause()
|
||||||
{
|
{
|
||||||
@ -455,6 +377,7 @@ public class MessageList
|
|||||||
mController.removeListener(mAdapter.mListener);
|
mController.removeListener(mAdapter.mListener);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* On resume we refresh
|
* On resume we refresh
|
||||||
* messages for the folder that is currently open. This guarantees that things
|
* messages for the folder that is currently open. This guarantees that things
|
||||||
@ -497,17 +420,50 @@ public class MessageList
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
private void initializeLayout ()
|
||||||
public void onSaveInstanceState(Bundle outState)
|
|
||||||
{
|
{
|
||||||
super.onSaveInstanceState(outState);
|
requestWindowFeature(Window.FEATURE_INDETERMINATE_PROGRESS);
|
||||||
outState.putParcelable(STATE_KEY_LIST, mListView.onSaveInstanceState());
|
requestWindowFeature(Window.FEATURE_PROGRESS);
|
||||||
outState.putInt(STATE_KEY_SELECTION, mListView .getSelectedItemPosition());
|
setContentView(R.layout.message_list);
|
||||||
outState.putString(STATE_CURRENT_FOLDER, mFolderName);
|
|
||||||
outState.putString(STATE_QUERY, mQueryString);
|
|
||||||
outState.putInt(STATE_KEY_SELECTED_COUNT, mSelectedCount);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
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()
|
@Override public Object onRetainNonConfigurationInstance()
|
||||||
{
|
{
|
||||||
|
Loading…
Reference in New Issue
Block a user