Search in sources :

Example 36 with MessageReference

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

the class MessageListFragment method openMessageAtPosition.

private void openMessageAtPosition(int position) {
    // Scroll message into view if necessary
    int listViewPosition = adapterToListViewPosition(position);
    if (listViewPosition != AdapterView.INVALID_POSITION && (listViewPosition < listView.getFirstVisiblePosition() || listViewPosition > listView.getLastVisiblePosition())) {
        listView.setSelection(listViewPosition);
    }
    MessageReference ref = getReferenceForPosition(position);
    // For some reason the listView.setSelection() above won't do anything when we call
    // onOpenMessage() (and consequently adapter.notifyDataSetChanged()) right away. So we
    // defer the call using MessageListHandler.
    handler.openMessage(ref);
}
Also used : MessageReference(com.fsck.k9.activity.MessageReference)

Example 37 with MessageReference

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

the class MessageListFragment method checkCopyOrMovePossible.

/**
     * Display a Toast message if any message isn't synchronized
     *
     * @param messages
     *         The messages to copy or move. Never {@code null}.
     * @param operation
     *         The type of operation to perform. Never {@code null}.
     *
     * @return {@code true}, if operation is possible.
     */
private boolean checkCopyOrMovePossible(final List<MessageReference> messages, final FolderOperation operation) {
    if (messages.isEmpty()) {
        return false;
    }
    boolean first = true;
    for (MessageReference message : messages) {
        if (first) {
            first = false;
            Account account = preferences.getAccount(message.getAccountUuid());
            if ((operation == FolderOperation.MOVE && !messagingController.isMoveCapable(account)) || (operation == FolderOperation.COPY && !messagingController.isCopyCapable(account))) {
                return false;
            }
        }
        // message check
        if ((operation == FolderOperation.MOVE && !messagingController.isMoveCapable(message)) || (operation == FolderOperation.COPY && !messagingController.isCopyCapable(message))) {
            final Toast toast = Toast.makeText(getActivity(), R.string.move_copy_cannot_copy_unsynced_message, Toast.LENGTH_LONG);
            toast.show();
            return false;
        }
    }
    return true;
}
Also used : Account(com.fsck.k9.Account) Toast(android.widget.Toast) MessageReference(com.fsck.k9.activity.MessageReference)

Example 38 with MessageReference

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

the class MessageListFragment method getMessageAtPosition.

private MessageReference getMessageAtPosition(int adapterPosition) {
    if (adapterPosition == AdapterView.INVALID_POSITION) {
        return null;
    }
    Cursor cursor = (Cursor) adapter.getItem(adapterPosition);
    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 39 with MessageReference

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

the class MessageListFragment method onSpamConfirmed.

private void onSpamConfirmed(List<MessageReference> messages) {
    Map<Account, List<MessageReference>> messagesByAccount = groupMessagesByAccount(messages);
    for (Entry<Account, List<MessageReference>> entry : messagesByAccount.entrySet()) {
        Account account = entry.getKey();
        String spamFolder = account.getSpamFolderName();
        if (!K9.FOLDER_NONE.equals(spamFolder)) {
            move(entry.getValue(), spamFolder);
        }
    }
}
Also used : Account(com.fsck.k9.Account) ArrayList(java.util.ArrayList) List(java.util.List)

Example 40 with MessageReference

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

the class MessageListFragment method copyOrMove.

/**
     * The underlying implementation for {@link #copy(List, String)} and
     * {@link #move(List, String)}. This method was added mainly because those 2
     * methods share common behavior.
     *
     * @param messages
     *         The list of messages to copy or move. Never {@code null}.
     * @param destination
     *         The name of the destination folder. Never {@code null} or {@link K9#FOLDER_NONE}.
     * @param operation
     *         Specifies what operation to perform. Never {@code null}.
     */
private void copyOrMove(List<MessageReference> messages, final String destination, final FolderOperation operation) {
    Map<String, List<MessageReference>> folderMap = new HashMap<>();
    for (MessageReference message : messages) {
        if ((operation == FolderOperation.MOVE && !messagingController.isMoveCapable(message)) || (operation == FolderOperation.COPY && !messagingController.isCopyCapable(message))) {
            Toast.makeText(getActivity(), R.string.move_copy_cannot_copy_unsynced_message, Toast.LENGTH_LONG).show();
            // message isn't synchronized
            return;
        }
        String folderName = message.getFolderName();
        if (folderName.equals(destination)) {
            // Skip messages already in the destination folder
            continue;
        }
        List<MessageReference> outMessages = folderMap.get(folderName);
        if (outMessages == null) {
            outMessages = new ArrayList<>();
            folderMap.put(folderName, outMessages);
        }
        outMessages.add(message);
    }
    for (Map.Entry<String, List<MessageReference>> entry : folderMap.entrySet()) {
        String folderName = entry.getKey();
        List<MessageReference> outMessages = entry.getValue();
        Account account = preferences.getAccount(outMessages.get(0).getAccountUuid());
        if (operation == FolderOperation.MOVE) {
            if (showingThreadedList) {
                messagingController.moveMessagesInThread(account, folderName, outMessages, destination);
            } else {
                messagingController.moveMessages(account, folderName, outMessages, destination);
            }
        } else {
            if (showingThreadedList) {
                messagingController.copyMessagesInThread(account, folderName, outMessages, destination);
            } else {
                messagingController.copyMessages(account, folderName, outMessages, destination);
            }
        }
    }
}
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) Map(java.util.Map) EnumMap(java.util.EnumMap) HashMap(java.util.HashMap)

Aggregations

MessageReference (com.fsck.k9.activity.MessageReference)49 PendingIntent (android.app.PendingIntent)25 Account (com.fsck.k9.Account)22 Test (org.junit.Test)14 LocalMessage (com.fsck.k9.mailstore.LocalMessage)13 MessageReference (com.fsck.k9.controller.MessageReference)12 NotificationCompat (android.support.v4.app.NotificationCompat)9 ArrayList (java.util.ArrayList)9 Notification (android.app.Notification)8 List (java.util.List)7 MessagingException (com.fsck.k9.mail.MessagingException)6 LocalFolder (com.fsck.k9.mailstore.LocalFolder)5 SearchAccount (com.fsck.k9.search.SearchAccount)5 HashMap (java.util.HashMap)5 Cursor (android.database.Cursor)3 Message (com.fsck.k9.mail.Message)3 LinkedList (java.util.LinkedList)3 Map (java.util.Map)3 Intent (android.content.Intent)2 Uri (android.net.Uri)2