mirror of
https://github.com/moparisthebest/k-9
synced 2024-12-26 01:28:50 -05:00
Nasty hack to retain threads in MessageListFragment when polling
This commit is contained in:
parent
63b6b497a0
commit
16d2326033
@ -24,6 +24,7 @@ public class MessageInfoHolder {
|
|||||||
public boolean selected;
|
public boolean selected;
|
||||||
public String account;
|
public String account;
|
||||||
public String uri;
|
public String uri;
|
||||||
|
public int threadCount;
|
||||||
|
|
||||||
// Empty constructor for comparison
|
// Empty constructor for comparison
|
||||||
public MessageInfoHolder() {
|
public MessageInfoHolder() {
|
||||||
|
@ -687,7 +687,7 @@ public class MessageListFragment extends SherlockFragment implements OnItemClick
|
|||||||
final MessageInfoHolder message = (MessageInfoHolder) parent.getItemAtPosition(position);
|
final MessageInfoHolder message = (MessageInfoHolder) parent.getItemAtPosition(position);
|
||||||
if (mSelectedCount > 0) {
|
if (mSelectedCount > 0) {
|
||||||
toggleMessageSelect(message);
|
toggleMessageSelect(message);
|
||||||
} else if (((LocalMessage) message.message).getThreadCount() > 1) {
|
} else if (message.threadCount > 1) {
|
||||||
Folder folder = message.message.getFolder();
|
Folder folder = message.message.getFolder();
|
||||||
long rootId = ((LocalMessage) message.message).getRootId();
|
long rootId = ((LocalMessage) message.message).getRootId();
|
||||||
mFragmentListener.showThread(folder.getAccount(), folder.getName(), rootId);
|
mFragmentListener.showThread(folder.getAccount(), folder.getName(), rootId);
|
||||||
@ -1767,7 +1767,36 @@ public class MessageListFragment extends SherlockFragment implements OnItemClick
|
|||||||
FolderInfoHolder folderInfoHolder = new FolderInfoHolder(
|
FolderInfoHolder folderInfoHolder = new FolderInfoHolder(
|
||||||
getActivity(), messageFolder, messageAccount);
|
getActivity(), messageFolder, messageAccount);
|
||||||
messageHelper.populate(m, message, folderInfoHolder, messageAccount);
|
messageHelper.populate(m, message, folderInfoHolder, messageAccount);
|
||||||
messagesToAdd.add(m);
|
|
||||||
|
if (verifyAgainstSearch) {
|
||||||
|
LocalMessage localMessage = (LocalMessage) message;
|
||||||
|
|
||||||
|
if (mThreadId != -1) {
|
||||||
|
if (localMessage.getRootId() == mThreadId ||
|
||||||
|
localMessage.getId() == mThreadId) {
|
||||||
|
messagesToAdd.add(m);
|
||||||
|
}
|
||||||
|
} else if (mThreadViewEnabled) {
|
||||||
|
long threadId = localMessage.getRootId();
|
||||||
|
if (threadId == -1) {
|
||||||
|
threadId = localMessage.getId();
|
||||||
|
}
|
||||||
|
|
||||||
|
MessageInfoHolder threadPlaceHolder = getThread(threadId);
|
||||||
|
if (threadPlaceHolder == null) {
|
||||||
|
messagesToAdd.add(m);
|
||||||
|
} else if (m.compareDate.after(threadPlaceHolder.compareDate)) {
|
||||||
|
messagesToRemove.add(threadPlaceHolder);
|
||||||
|
messagesToAdd.add(m);
|
||||||
|
} else {
|
||||||
|
threadPlaceHolder.threadCount = m.threadCount;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
messagesToAdd.add(m);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
messagesToAdd.add(m);
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
if (mQueryString != null) {
|
if (mQueryString != null) {
|
||||||
if (verifyAgainstSearch) {
|
if (verifyAgainstSearch) {
|
||||||
@ -1876,6 +1905,17 @@ public class MessageListFragment extends SherlockFragment implements OnItemClick
|
|||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private MessageInfoHolder getThread(long threadId) {
|
||||||
|
for (MessageInfoHolder holder : mMessages) {
|
||||||
|
LocalMessage localMessage = (LocalMessage) holder.message;
|
||||||
|
if (localMessage.getId() == threadId || localMessage.getRootId() == threadId) {
|
||||||
|
return holder;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
public FolderInfoHolder getFolder(String folder, Account account) {
|
public FolderInfoHolder getFolder(String folder, Account account) {
|
||||||
LocalFolder local_folder = null;
|
LocalFolder local_folder = null;
|
||||||
try {
|
try {
|
||||||
@ -2056,7 +2096,7 @@ public class MessageListFragment extends SherlockFragment implements OnItemClick
|
|||||||
subject = message.message.getSubject();
|
subject = message.message.getSubject();
|
||||||
}
|
}
|
||||||
|
|
||||||
int threadCount = ((LocalMessage) message.message).getThreadCount();
|
int threadCount = message.threadCount;
|
||||||
if (threadCount > 1) {
|
if (threadCount > 1) {
|
||||||
holder.threadCount.setText(Integer.toString(threadCount));
|
holder.threadCount.setText(Integer.toString(threadCount));
|
||||||
holder.threadCount.setVisibility(View.VISIBLE);
|
holder.threadCount.setVisibility(View.VISIBLE);
|
||||||
|
@ -17,6 +17,7 @@ import com.fsck.k9.mail.Flag;
|
|||||||
import com.fsck.k9.mail.Message;
|
import com.fsck.k9.mail.Message;
|
||||||
import com.fsck.k9.mail.MessagingException;
|
import com.fsck.k9.mail.MessagingException;
|
||||||
import com.fsck.k9.mail.Message.RecipientType;
|
import com.fsck.k9.mail.Message.RecipientType;
|
||||||
|
import com.fsck.k9.mail.store.LocalStore.LocalMessage;
|
||||||
import com.fsck.k9.helper.DateFormatter;
|
import com.fsck.k9.helper.DateFormatter;
|
||||||
|
|
||||||
public class MessageHelper {
|
public class MessageHelper {
|
||||||
@ -86,6 +87,8 @@ public class MessageHelper {
|
|||||||
target.account = account.getUuid();
|
target.account = account.getUuid();
|
||||||
target.uri = "email://messages/" + account.getAccountNumber() + "/" + message.getFolder().getName() + "/" + message.getUid();
|
target.uri = "email://messages/" + account.getAccountNumber() + "/" + message.getFolder().getName() + "/" + message.getUid();
|
||||||
|
|
||||||
|
target.threadCount = ((LocalMessage) message).getThreadCount();
|
||||||
|
|
||||||
} catch (MessagingException me) {
|
} catch (MessagingException me) {
|
||||||
Log.w(K9.LOG_TAG, "Unable to load message info", me);
|
Log.w(K9.LOG_TAG, "Unable to load message info", me);
|
||||||
}
|
}
|
||||||
|
@ -93,6 +93,10 @@ public class LocalStore extends Store implements Serializable {
|
|||||||
"subject, sender_list, date, uid, flags, id, to_list, cc_list, "
|
"subject, sender_list, date, uid, flags, id, to_list, cc_list, "
|
||||||
+ "bcc_list, reply_to_list, attachment_count, internal_date, message_id, folder_id, preview, thread_root, thread_parent, empty ";
|
+ "bcc_list, reply_to_list, attachment_count, internal_date, message_id, folder_id, preview, thread_root, thread_parent, empty ";
|
||||||
|
|
||||||
|
static private String GET_MESSAGES_COLS_PREFIX =
|
||||||
|
"m.subject, m.sender_list, m.date, m.uid, m.flags, m.id, m.to_list, m.cc_list, " +
|
||||||
|
"m.bcc_list, m.reply_to_list, m.attachment_count, m.internal_date, m.message_id, " +
|
||||||
|
"m.folder_id, m.preview, m.thread_root, m.thread_parent, m.empty ";
|
||||||
|
|
||||||
static private String GET_FOLDER_COLS = "id, name, unread_count, visible_limit, last_updated, status, push_state, last_pushed, flagged_count, integrate, top_group, poll_class, push_class, display_class";
|
static private String GET_FOLDER_COLS = "id, name, unread_count, visible_limit, last_updated, status, push_state, last_pushed, flagged_count, integrate, top_group, poll_class, push_class, display_class";
|
||||||
|
|
||||||
@ -1891,13 +1895,23 @@ public class LocalStore extends Store implements Serializable {
|
|||||||
|
|
||||||
try {
|
try {
|
||||||
cursor = db.rawQuery(
|
cursor = db.rawQuery(
|
||||||
"SELECT "
|
"SELECT " +
|
||||||
+ GET_MESSAGES_COLS
|
GET_MESSAGES_COLS_PREFIX + ", COUNT(c.id) " +
|
||||||
+ "FROM messages WHERE uid = ? AND folder_id = ?",
|
"FROM messages m LEFT JOIN messages c " +
|
||||||
|
"ON (" +
|
||||||
|
"(" +
|
||||||
|
"m.thread_root IN (c.thread_root, c.id)" +
|
||||||
|
" OR " +
|
||||||
|
"(m.thread_root IS NULL AND m.id IN (c.thread_root, c.id))" +
|
||||||
|
") AND c.empty != 1) " +
|
||||||
|
"WHERE m.uid = ? AND m.folder_id = ?",
|
||||||
new String[] {
|
new String[] {
|
||||||
message.getUid(), Long.toString(mFolderId)
|
message.getUid(), Long.toString(mFolderId)
|
||||||
});
|
});
|
||||||
if (!cursor.moveToNext()) {
|
|
||||||
|
// Note: Because of the COUNT(c.id) we will always get one result
|
||||||
|
// row even if nothing was found. So we check if 'id' is NULL
|
||||||
|
if (!cursor.moveToNext() || cursor.isNull(0)) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
message.populateFromGetMessageCursor(cursor);
|
message.populateFromGetMessageCursor(cursor);
|
||||||
|
Loading…
Reference in New Issue
Block a user