mirror of
https://github.com/moparisthebest/k-9
synced 2024-11-16 06:25:06 -05:00
Moved methods modifying the message list to MessageListAdapter
This commit is contained in:
parent
75a97a82c0
commit
bd9b6aea2d
@ -349,6 +349,9 @@ public class MessageList
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* FIXME
|
||||||
|
*/
|
||||||
class MessageListHandler extends Handler {
|
class MessageListHandler extends Handler {
|
||||||
private static final int ACTION_REMOVE_MESSAGES = 1;
|
private static final int ACTION_REMOVE_MESSAGES = 1;
|
||||||
private static final int ACTION_ADD_MESSAGES = 2;
|
private static final int ACTION_ADD_MESSAGES = 2;
|
||||||
@ -408,20 +411,20 @@ public class MessageList
|
|||||||
switch (msg.what) {
|
switch (msg.what) {
|
||||||
case ACTION_REMOVE_MESSAGES: {
|
case ACTION_REMOVE_MESSAGES: {
|
||||||
List<MessageInfoHolder> messages = (List<MessageInfoHolder>) msg.obj;
|
List<MessageInfoHolder> messages = (List<MessageInfoHolder>) msg.obj;
|
||||||
MessageList.this.removeMessages(messages);
|
mAdapter.removeMessages(messages);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case ACTION_ADD_MESSAGES: {
|
case ACTION_ADD_MESSAGES: {
|
||||||
List<MessageInfoHolder> messages = (List<MessageInfoHolder>) msg.obj;
|
List<MessageInfoHolder> messages = (List<MessageInfoHolder>) msg.obj;
|
||||||
MessageList.this.addMessages(messages);
|
mAdapter.addMessages(messages);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case ACTION_RESET_UNREAD_COUNT: {
|
case ACTION_RESET_UNREAD_COUNT: {
|
||||||
MessageList.this.resetUnreadCount();
|
mAdapter.resetUnreadCount();
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case ACTION_SORT_MESSAGES: {
|
case ACTION_SORT_MESSAGES: {
|
||||||
MessageList.this.sortMessages();
|
mAdapter.sortMessages();
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case ACTION_FOLDER_LOADING: {
|
case ACTION_FOLDER_LOADING: {
|
||||||
@ -443,79 +446,6 @@ public class MessageList
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void removeMessages(final List<MessageInfoHolder> messages) {
|
|
||||||
if (messages.isEmpty()) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
for (MessageInfoHolder message : messages) {
|
|
||||||
if (message != null && (mFolderName == null || (
|
|
||||||
message.folder != null &&
|
|
||||||
message.folder.name.equals(mFolderName)))) {
|
|
||||||
if (message.selected && mSelectedCount > 0) {
|
|
||||||
mSelectedCount--;
|
|
||||||
}
|
|
||||||
mAdapter.messages.remove(message);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
resetUnreadCount();
|
|
||||||
|
|
||||||
mAdapter.notifyDataSetChanged();
|
|
||||||
toggleBatchButtons();
|
|
||||||
}
|
|
||||||
|
|
||||||
private void addMessages(final List<MessageInfoHolder> messages) {
|
|
||||||
if (messages.isEmpty()) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
final boolean wasEmpty = mAdapter.messages.isEmpty();
|
|
||||||
|
|
||||||
for (final MessageInfoHolder message : messages) {
|
|
||||||
if (mFolderName == null || (message.folder != null && message.folder.name.equals(mFolderName))) {
|
|
||||||
int index;
|
|
||||||
synchronized (mAdapter.messages) {
|
|
||||||
index = Collections.binarySearch(mAdapter.messages, message, getComparator());
|
|
||||||
}
|
|
||||||
|
|
||||||
if (index < 0) {
|
|
||||||
index = (index * -1) - 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
mAdapter.messages.add(index, message);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (wasEmpty) {
|
|
||||||
mListView.setSelection(0);
|
|
||||||
}
|
|
||||||
resetUnreadCount();
|
|
||||||
|
|
||||||
mAdapter.notifyDataSetChanged();
|
|
||||||
}
|
|
||||||
|
|
||||||
private void resetUnreadCount() {
|
|
||||||
if (mQueryString != null) {
|
|
||||||
int unreadCount = 0;
|
|
||||||
synchronized (mAdapter.messages) {
|
|
||||||
for (MessageInfoHolder holder : mAdapter.messages) {
|
|
||||||
unreadCount += holder.read ? 0 : 1;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
mUnreadMessageCount = unreadCount;
|
|
||||||
refreshTitle();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private void sortMessages() {
|
|
||||||
final Comparator<MessageInfoHolder> chainComparator = getComparator();
|
|
||||||
|
|
||||||
synchronized (mAdapter.messages) {
|
|
||||||
Collections.sort(mAdapter.messages, chainComparator);
|
|
||||||
}
|
|
||||||
mAdapter.notifyDataSetChanged();
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @return The comparator to use to display messages in an ordered
|
* @return The comparator to use to display messages in an ordered
|
||||||
* fashion. Never <code>null</code>.
|
* fashion. Never <code>null</code>.
|
||||||
@ -1985,7 +1915,7 @@ public class MessageList
|
|||||||
if (holder == null) {
|
if (holder == null) {
|
||||||
Log.w(K9.LOG_TAG, "Got callback to remove non-existent message with UID " + message.getUid());
|
Log.w(K9.LOG_TAG, "Got callback to remove non-existent message with UID " + message.getUid());
|
||||||
} else {
|
} else {
|
||||||
removeMessages(Collections.singletonList(holder));
|
mHandler.removeMessages(Collections.singletonList(holder));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -2025,7 +1955,7 @@ public class MessageList
|
|||||||
public void listLocalMessagesRemoveMessage(Account account, String folder, Message message) {
|
public void listLocalMessagesRemoveMessage(Account account, String folder, Message message) {
|
||||||
MessageInfoHolder holder = getMessage(message);
|
MessageInfoHolder holder = getMessage(message);
|
||||||
if (holder != null) {
|
if (holder != null) {
|
||||||
removeMessages(Collections.singletonList(holder));
|
mHandler.removeMessages(Collections.singletonList(holder));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -2103,18 +2033,101 @@ public class MessageList
|
|||||||
mSelectedCount--;
|
mSelectedCount--;
|
||||||
toggleBatchButtons();
|
toggleBatchButtons();
|
||||||
}
|
}
|
||||||
mAdapter.removeMessages(Collections.singletonList(holder));
|
mHandler.removeMessages(Collections.singletonList(holder));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
* Note: Only call this from the UI thread!
|
||||||
|
*
|
||||||
* @param holders
|
* @param holders
|
||||||
* Never {@code null}.
|
* Never {@code null}.
|
||||||
*/
|
*/
|
||||||
public void removeMessages(List<MessageInfoHolder> holders) {
|
public void removeMessages(final List<MessageInfoHolder> messages) {
|
||||||
mHandler.removeMessages(holders);
|
if (messages.isEmpty()) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
for (MessageInfoHolder message : messages) {
|
||||||
|
if (message != null && (mFolderName == null || (
|
||||||
|
message.folder != null &&
|
||||||
|
message.folder.name.equals(mFolderName)))) {
|
||||||
|
if (message.selected && mSelectedCount > 0) {
|
||||||
|
mSelectedCount--;
|
||||||
|
}
|
||||||
|
mAdapter.messages.remove(message);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
resetUnreadCount();
|
||||||
|
|
||||||
|
notifyDataSetChanged();
|
||||||
|
toggleBatchButtons();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Note: Only call this from the UI thread!
|
||||||
|
*
|
||||||
|
* @param messages
|
||||||
|
*/
|
||||||
|
public void addMessages(final List<MessageInfoHolder> messages) {
|
||||||
|
if (messages.isEmpty()) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
final boolean wasEmpty = mAdapter.messages.isEmpty();
|
||||||
|
|
||||||
|
for (final MessageInfoHolder message : messages) {
|
||||||
|
if (mFolderName == null || (message.folder != null && message.folder.name.equals(mFolderName))) {
|
||||||
|
int index;
|
||||||
|
synchronized (mAdapter.messages) {
|
||||||
|
index = Collections.binarySearch(mAdapter.messages, message, getComparator());
|
||||||
|
}
|
||||||
|
|
||||||
|
if (index < 0) {
|
||||||
|
index = (index * -1) - 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
mAdapter.messages.add(index, message);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (wasEmpty) {
|
||||||
|
mListView.setSelection(0);
|
||||||
|
}
|
||||||
|
resetUnreadCount();
|
||||||
|
|
||||||
|
notifyDataSetChanged();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Note: Only call this from the UI thread!
|
||||||
|
*/
|
||||||
|
public void resetUnreadCount() {
|
||||||
|
if (mQueryString != null) {
|
||||||
|
int unreadCount = 0;
|
||||||
|
synchronized (mAdapter.messages) {
|
||||||
|
for (MessageInfoHolder holder : mAdapter.messages) {
|
||||||
|
unreadCount += holder.read ? 0 : 1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
mUnreadMessageCount = unreadCount;
|
||||||
|
refreshTitle();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Note: Only call this from the UI thread!
|
||||||
|
*/
|
||||||
|
public void sortMessages() {
|
||||||
|
final Comparator<MessageInfoHolder> chainComparator = getComparator();
|
||||||
|
|
||||||
|
synchronized (mAdapter.messages) {
|
||||||
|
Collections.sort(mAdapter.messages, chainComparator);
|
||||||
|
}
|
||||||
|
|
||||||
|
notifyDataSetChanged();
|
||||||
}
|
}
|
||||||
|
|
||||||
private void addOrUpdateMessage(Account account, String folderName, Message message, boolean verifyAgainstSearch) {
|
private void addOrUpdateMessage(Account account, String folderName, Message message, boolean verifyAgainstSearch) {
|
||||||
@ -2180,7 +2193,7 @@ public class MessageList
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (!messagesToRemove.isEmpty()) {
|
if (!messagesToRemove.isEmpty()) {
|
||||||
removeMessages(messagesToRemove);
|
mHandler.removeMessages(messagesToRemove);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!messagesToAdd.isEmpty()) {
|
if (!messagesToAdd.isEmpty()) {
|
||||||
@ -2719,7 +2732,7 @@ public class MessageList
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
mAdapter.removeMessages(removeHolderList);
|
mHandler.removeMessages(removeHolderList);
|
||||||
|
|
||||||
if (!messageList.isEmpty()) {
|
if (!messageList.isEmpty()) {
|
||||||
if (v == mBatchDeleteButton) {
|
if (v == mBatchDeleteButton) {
|
||||||
|
Loading…
Reference in New Issue
Block a user