Search in sources :

Example 21 with MessageReference

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

the class WearNotifications method addArchiveAction.

private void addArchiveAction(WearableExtender wearableExtender, NotificationHolder holder) {
    int icon = R.drawable.ic_action_archive_dark;
    String title = context.getString(R.string.notification_action_archive);
    MessageReference messageReference = holder.content.messageReference;
    int notificationId = holder.notificationId;
    PendingIntent action = actionCreator.createArchiveMessagePendingIntent(messageReference, notificationId);
    NotificationCompat.Action archiveAction = new NotificationCompat.Action.Builder(icon, title, action).build();
    wearableExtender.addAction(archiveAction);
}
Also used : NotificationCompat(android.support.v4.app.NotificationCompat) PendingIntent(android.app.PendingIntent) MessageReference(com.fsck.k9.activity.MessageReference)

Example 22 with MessageReference

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

the class WearNotifications method addDeleteAction.

private void addDeleteAction(WearableExtender wearableExtender, NotificationHolder holder) {
    int icon = R.drawable.ic_action_delete_dark;
    String title = context.getString(R.string.notification_action_delete);
    MessageReference messageReference = holder.content.messageReference;
    int notificationId = holder.notificationId;
    PendingIntent action = actionCreator.createDeleteMessagePendingIntent(messageReference, notificationId);
    NotificationCompat.Action deleteAction = new NotificationCompat.Action.Builder(icon, title, action).build();
    wearableExtender.addAction(deleteAction);
}
Also used : NotificationCompat(android.support.v4.app.NotificationCompat) PendingIntent(android.app.PendingIntent) MessageReference(com.fsck.k9.activity.MessageReference)

Example 23 with MessageReference

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

the class NotificationActionService method cancelNotifications.

private void cancelNotifications(Intent intent, Account account, MessagingController controller) {
    if (intent.hasExtra(EXTRA_MESSAGE_REFERENCE)) {
        String messageReferenceString = intent.getStringExtra(EXTRA_MESSAGE_REFERENCE);
        MessageReference messageReference = MessageReference.parse(messageReferenceString);
        if (messageReference != null) {
            controller.cancelNotificationForMessage(account, messageReference);
        } else {
            Timber.w("Invalid message reference: %s", messageReferenceString);
        }
    } else if (intent.hasExtra(EXTRA_MESSAGE_REFERENCES)) {
        List<String> messageReferenceStrings = intent.getStringArrayListExtra(EXTRA_MESSAGE_REFERENCES);
        List<MessageReference> messageReferences = toMessageReferenceList(messageReferenceStrings);
        for (MessageReference messageReference : messageReferences) {
            controller.cancelNotificationForMessage(account, messageReference);
        }
    } else {
        controller.cancelNotificationsForAccount(account);
    }
}
Also used : ArrayList(java.util.ArrayList) MessageReferenceHelper.toMessageReferenceStringList(com.fsck.k9.activity.MessageReferenceHelper.toMessageReferenceStringList) MessageReferenceHelper.toMessageReferenceList(com.fsck.k9.activity.MessageReferenceHelper.toMessageReferenceList) List(java.util.List) MessageReference(com.fsck.k9.activity.MessageReference)

Example 24 with MessageReference

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

the class WearNotifications method addMarkAsSpamAction.

private void addMarkAsSpamAction(WearableExtender wearableExtender, NotificationHolder holder) {
    int icon = R.drawable.ic_action_spam_dark;
    String title = context.getString(R.string.notification_action_spam);
    MessageReference messageReference = holder.content.messageReference;
    int notificationId = holder.notificationId;
    PendingIntent action = actionCreator.createMarkMessageAsSpamPendingIntent(messageReference, notificationId);
    NotificationCompat.Action spamAction = new NotificationCompat.Action.Builder(icon, title, action).build();
    wearableExtender.addAction(spamAction);
}
Also used : NotificationCompat(android.support.v4.app.NotificationCompat) PendingIntent(android.app.PendingIntent) MessageReference(com.fsck.k9.activity.MessageReference)

Example 25 with MessageReference

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

the class MessageList method decodeExtras.

private boolean decodeExtras(Intent intent) {
    String action = intent.getAction();
    if (Intent.ACTION_VIEW.equals(action) && intent.getData() != null) {
        Uri uri = intent.getData();
        List<String> segmentList = uri.getPathSegments();
        String accountId = segmentList.get(0);
        Collection<Account> accounts = Preferences.getPreferences(this).getAvailableAccounts();
        for (Account account : accounts) {
            if (String.valueOf(account.getAccountNumber()).equals(accountId)) {
                String folderName = segmentList.get(1);
                String messageUid = segmentList.get(2);
                mMessageReference = new MessageReference(account.getUuid(), folderName, messageUid, null);
                break;
            }
        }
    } else if (ACTION_SHORTCUT.equals(action)) {
        // Handle shortcut intents
        String specialFolder = intent.getStringExtra(EXTRA_SPECIAL_FOLDER);
        if (SearchAccount.UNIFIED_INBOX.equals(specialFolder)) {
            mSearch = SearchAccount.createUnifiedInboxAccount(this).getRelatedSearch();
        } else if (SearchAccount.ALL_MESSAGES.equals(specialFolder)) {
            mSearch = SearchAccount.createAllMessagesAccount(this).getRelatedSearch();
        }
    } else if (intent.getStringExtra(SearchManager.QUERY) != null) {
        // check if this intent comes from the system search ( remote )
        if (Intent.ACTION_SEARCH.equals(intent.getAction())) {
            //Query was received from Search Dialog
            String query = intent.getStringExtra(SearchManager.QUERY).trim();
            mSearch = new LocalSearch(getString(R.string.search_results));
            mSearch.setManualSearch(true);
            mNoThreading = true;
            mSearch.or(new SearchCondition(SearchField.SENDER, Attribute.CONTAINS, query));
            mSearch.or(new SearchCondition(SearchField.SUBJECT, Attribute.CONTAINS, query));
            mSearch.or(new SearchCondition(SearchField.MESSAGE_CONTENTS, Attribute.CONTAINS, query));
            Bundle appData = intent.getBundleExtra(SearchManager.APP_DATA);
            if (appData != null) {
                mSearch.addAccountUuid(appData.getString(EXTRA_SEARCH_ACCOUNT));
                // searches started from a folder list activity will provide an account, but no folder
                if (appData.getString(EXTRA_SEARCH_FOLDER) != null) {
                    mSearch.addAllowedFolder(appData.getString(EXTRA_SEARCH_FOLDER));
                }
            } else {
                mSearch.addAccountUuid(LocalSearch.ALL_ACCOUNTS);
            }
        }
    } else if (intent.hasExtra(EXTRA_SEARCH_OLD)) {
        mSearch = intent.getParcelableExtra(EXTRA_SEARCH_OLD);
        mNoThreading = intent.getBooleanExtra(EXTRA_NO_THREADING, false);
    } else {
        // regular LocalSearch object was passed
        mSearch = intent.hasExtra(EXTRA_SEARCH) ? ParcelableUtil.unmarshall(intent.getByteArrayExtra(EXTRA_SEARCH), LocalSearch.CREATOR) : null;
        mNoThreading = intent.getBooleanExtra(EXTRA_NO_THREADING, false);
    }
    if (mMessageReference == null) {
        String messageReferenceString = intent.getStringExtra(EXTRA_MESSAGE_REFERENCE);
        mMessageReference = MessageReference.parse(messageReferenceString);
    }
    if (mMessageReference != null) {
        mSearch = new LocalSearch();
        mSearch.addAccountUuid(mMessageReference.getAccountUuid());
        mSearch.addAllowedFolder(mMessageReference.getFolderName());
    }
    if (mSearch == null) {
        // We've most likely been started by an old unread widget
        String accountUuid = intent.getStringExtra("account");
        String folderName = intent.getStringExtra("folder");
        mSearch = new LocalSearch(folderName);
        mSearch.addAccountUuid((accountUuid == null) ? "invalid" : accountUuid);
        if (folderName != null) {
            mSearch.addAllowedFolder(folderName);
        }
    }
    Preferences prefs = Preferences.getPreferences(getApplicationContext());
    String[] accountUuids = mSearch.getAccountUuids();
    if (mSearch.searchAllAccounts()) {
        List<Account> accounts = prefs.getAccounts();
        mSingleAccountMode = (accounts.size() == 1);
        if (mSingleAccountMode) {
            mAccount = accounts.get(0);
        }
    } else {
        mSingleAccountMode = (accountUuids.length == 1);
        if (mSingleAccountMode) {
            mAccount = prefs.getAccount(accountUuids[0]);
        }
    }
    mSingleFolderMode = mSingleAccountMode && (mSearch.getFolderNames().size() == 1);
    if (mSingleAccountMode && (mAccount == null || !mAccount.isAvailable(this))) {
        Timber.i("not opening MessageList of unavailable account");
        onAccountUnavailable();
        return false;
    }
    if (mSingleFolderMode) {
        mFolderName = mSearch.getFolderNames().get(0);
    }
    // now we know if we are in single account mode and need a subtitle
    mActionBarSubTitle.setVisibility((!mSingleFolderMode) ? View.GONE : View.VISIBLE);
    return true;
}
Also used : SearchAccount(com.fsck.k9.search.SearchAccount) Account(com.fsck.k9.Account) SearchCondition(com.fsck.k9.search.SearchSpecification.SearchCondition) LocalSearch(com.fsck.k9.search.LocalSearch) Bundle(android.os.Bundle) Preferences(com.fsck.k9.Preferences) Uri(android.net.Uri)

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