Always include currently opened message in the message list

This should fix various bugs where moving to the next/previous message
didn't work.
This commit is contained in:
cketti 2013-05-23 17:15:09 +02:00
parent 79059e30da
commit f16082eab3
2 changed files with 38 additions and 9 deletions

View file

@ -1118,15 +1118,17 @@ public class MessageList extends K9FragmentActivity implements MessageListFragme
} else {
mMessageViewContainer.removeView(mMessageViewPlaceHolder);
if (mMessageListFragment != null) {
mMessageListFragment.setActiveMessage(messageReference);
}
MessageViewFragment fragment = MessageViewFragment.newInstance(messageReference);
FragmentTransaction ft = getSupportFragmentManager().beginTransaction();
ft.replace(R.id.message_view_container, fragment);
mMessageViewFragment = fragment;
ft.commit();
if (mDisplayMode == DisplayMode.SPLIT_VIEW) {
mMessageListFragment.setActiveMessage(messageReference);
} else {
if (mDisplayMode != DisplayMode.SPLIT_VIEW) {
showMessageView();
}
}

View file

@ -1042,12 +1042,7 @@ public class MessageListFragment extends SherlockFragment implements OnItemClick
mSenderAboveSubject = K9.messageListSenderAboveSubject();
if (!mLoaderJustInitialized) {
// Refresh the message list
LoaderManager loaderManager = getLoaderManager();
for (int i = 0; i < mAccountUuids.length; i++) {
loaderManager.restartLoader(i, null, this);
mCursorValid[i] = false;
}
restartLoader();
} else {
mLoaderJustInitialized = false;
}
@ -1090,6 +1085,19 @@ public class MessageListFragment extends SherlockFragment implements OnItemClick
updateTitle();
}
private void restartLoader() {
if (mCursorValid == null) {
return;
}
// Refresh the message list
LoaderManager loaderManager = getLoaderManager();
for (int i = 0; i < mAccountUuids.length; i++) {
loaderManager.restartLoader(i, null, this);
mCursorValid[i] = false;
}
}
private void initializePullToRefresh(LayoutInflater inflater, View layout) {
mPullToRefreshView = (PullToRefreshListView) layout.findViewById(R.id.message_list);
@ -3222,7 +3230,19 @@ public class MessageListFragment extends SherlockFragment implements OnItemClick
StringBuilder query = new StringBuilder();
List<String> queryArgs = new ArrayList<String>();
if (needConditions) {
boolean selectActive = mActiveMessage != null && mActiveMessage.accountUuid.equals(accountUuid);
if (selectActive) {
query.append("(" + MessageColumns.UID + " = ? AND " + SpecialColumns.FOLDER_NAME + " = ?) OR (");
queryArgs.add(mActiveMessage.uid);
queryArgs.add(mActiveMessage.folderName);
}
SqlQueryBuilder.buildWhereClause(account, mSearch.getConditions(), query, queryArgs);
if (selectActive) {
query.append(')');
}
}
String selection = query.toString();
@ -3453,6 +3473,13 @@ public class MessageListFragment extends SherlockFragment implements OnItemClick
*/
public void setActiveMessage(MessageReference messageReference) {
mActiveMessage = messageReference;
// Reload message list with modified query that always includes the active message
if (isAdded()) {
restartLoader();
}
// Redraw list immediately
if (mAdapter != null) {
mAdapter.notifyDataSetChanged();
}