Search in sources :

Example 11 with MessageReference

use of com.fsck.k9.activity.MessageReference in project k-9 by k9mail.

the class MessageListFragment method getCheckedMessages.

private List<MessageReference> getCheckedMessages() {
    List<MessageReference> messages = new ArrayList<>(selected.size());
    for (int position = 0, end = adapter.getCount(); position < end; position++) {
        Cursor cursor = (Cursor) adapter.getItem(position);
        long uniqueId = cursor.getLong(uniqueIdColumn);
        if (selected.contains(uniqueId)) {
            MessageReference message = getMessageAtPosition(position);
            if (message != null) {
                messages.add(message);
            }
        }
    }
    return messages;
}
Also used : ArrayList(java.util.ArrayList) MessageReference(com.fsck.k9.activity.MessageReference) Cursor(android.database.Cursor)

Example 12 with MessageReference

use of com.fsck.k9.activity.MessageReference in project k-9 by k9mail.

the class MessageListFragment method getReferenceForPosition.

private MessageReference getReferenceForPosition(int position) {
    Cursor cursor = (Cursor) adapter.getItem(position);
    String accountUuid = cursor.getString(ACCOUNT_UUID_COLUMN);
    String folderName = cursor.getString(FOLDER_NAME_COLUMN);
    String messageUid = cursor.getString(UID_COLUMN);
    return new MessageReference(accountUuid, folderName, messageUid, null);
}
Also used : Cursor(android.database.Cursor) MessageReference(com.fsck.k9.activity.MessageReference)

Example 13 with MessageReference

use of com.fsck.k9.activity.MessageReference in project k-9 by k9mail.

the class MessageListFragment method groupMessagesByAccount.

private Map<Account, List<MessageReference>> groupMessagesByAccount(final List<MessageReference> messages) {
    Map<Account, List<MessageReference>> messagesByAccount = new HashMap<>();
    for (MessageReference message : messages) {
        Account account = preferences.getAccount(message.getAccountUuid());
        List<MessageReference> msgList = messagesByAccount.get(account);
        if (msgList == null) {
            msgList = new ArrayList<>();
            messagesByAccount.put(account, msgList);
        }
        msgList.add(message);
    }
    return messagesByAccount;
}
Also used : Account(com.fsck.k9.Account) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) List(java.util.List) MessageReference(com.fsck.k9.activity.MessageReference)

Example 14 with MessageReference

use of com.fsck.k9.activity.MessageReference in project k-9 by k9mail.

the class MessagingController method refreshLocalMessageFlags.

private void refreshLocalMessageFlags(final Account account, final Folder remoteFolder, final LocalFolder localFolder, List<Message> syncFlagMessages, final AtomicInteger progress, final int todo) throws MessagingException {
    final String folder = remoteFolder.getName();
    if (remoteFolder.supportsFetchingFlags()) {
        Timber.d("SYNC: About to sync flags for %d remote messages for folder %s", syncFlagMessages.size(), folder);
        FetchProfile fp = new FetchProfile();
        fp.add(FetchProfile.Item.FLAGS);
        List<Message> undeletedMessages = new LinkedList<>();
        for (Message message : syncFlagMessages) {
            if (!message.isSet(Flag.DELETED)) {
                undeletedMessages.add(message);
            }
        }
        remoteFolder.fetch(undeletedMessages, fp, null);
        for (Message remoteMessage : syncFlagMessages) {
            LocalMessage localMessage = localFolder.getMessage(remoteMessage.getUid());
            boolean messageChanged = syncFlags(localMessage, remoteMessage);
            if (messageChanged) {
                boolean shouldBeNotifiedOf = false;
                if (localMessage.isSet(Flag.DELETED) || isMessageSuppressed(localMessage)) {
                    for (MessagingListener l : getListeners()) {
                        l.synchronizeMailboxRemovedMessage(account, folder, localMessage);
                    }
                } else {
                    if (shouldNotifyForMessage(account, localFolder, localMessage)) {
                        shouldBeNotifiedOf = true;
                    }
                }
                // we're only interested in messages that need removing
                if (!shouldBeNotifiedOf) {
                    MessageReference messageReference = localMessage.makeMessageReference();
                    notificationController.removeNewMailNotification(account, messageReference);
                }
            }
            progress.incrementAndGet();
            for (MessagingListener l : getListeners()) {
                l.synchronizeMailboxProgress(account, folder, progress.get(), todo);
            }
        }
    }
}
Also used : LocalMessage(com.fsck.k9.mailstore.LocalMessage) FetchProfile(com.fsck.k9.mail.FetchProfile) LocalMessage(com.fsck.k9.mailstore.LocalMessage) MimeMessage(com.fsck.k9.mail.internet.MimeMessage) Message(com.fsck.k9.mail.Message) MessageReference(com.fsck.k9.activity.MessageReference) LinkedList(java.util.LinkedList)

Example 15 with MessageReference

use of com.fsck.k9.activity.MessageReference in project k-9 by k9mail.

the class MessagingController method groupMessagesByAccountAndFolder.

@NonNull
private Map<String, Map<String, List<MessageReference>>> groupMessagesByAccountAndFolder(List<MessageReference> messages) {
    Map<String, Map<String, List<MessageReference>>> accountMap = new HashMap<>();
    for (MessageReference message : messages) {
        if (message == null) {
            continue;
        }
        String accountUuid = message.getAccountUuid();
        String folderName = message.getFolderName();
        Map<String, List<MessageReference>> folderMap = accountMap.get(accountUuid);
        if (folderMap == null) {
            folderMap = new HashMap<>();
            accountMap.put(accountUuid, folderMap);
        }
        List<MessageReference> messageList = folderMap.get(folderName);
        if (messageList == null) {
            messageList = new LinkedList<>();
            folderMap.put(folderName, messageList);
        }
        messageList.add(message);
    }
    return accountMap;
}
Also used : ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) List(java.util.List) LinkedList(java.util.LinkedList) MessageReference(com.fsck.k9.activity.MessageReference) Map(java.util.Map) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) HashMap(java.util.HashMap) NonNull(android.support.annotation.NonNull)

Aggregations

MessageReference (com.fsck.k9.activity.MessageReference)54 PendingIntent (android.app.PendingIntent)25 Account (com.fsck.k9.Account)18 Test (org.junit.Test)14 NotificationCompat (android.support.v4.app.NotificationCompat)9 ArrayList (java.util.ArrayList)9 Notification (android.app.Notification)8 LocalMessage (com.fsck.k9.mailstore.LocalMessage)8 List (java.util.List)7 HashMap (java.util.HashMap)5 SearchAccount (com.fsck.k9.search.SearchAccount)4 Cursor (android.database.Cursor)3 Preferences (com.fsck.k9.Preferences)3 MessagingException (com.fsck.k9.mail.MessagingException)3 LocalFolder (com.fsck.k9.mailstore.LocalFolder)3 LinkedList (java.util.LinkedList)3 Map (java.util.Map)3 Intent (android.content.Intent)2 Bundle (android.os.Bundle)2 Message (com.fsck.k9.mail.Message)2