Home | History | Annotate | Download | only in email
      1 /*
      2  * Copyright (C) 2009 The Android Open Source Project
      3  *
      4  * Licensed under the Apache License, Version 2.0 (the "License");
      5  * you may not use this file except in compliance with the License.
      6  * You may obtain a copy of the License at
      7  *
      8  *      http://www.apache.org/licenses/LICENSE-2.0
      9  *
     10  * Unless required by applicable law or agreed to in writing, software
     11  * distributed under the License is distributed on an "AS IS" BASIS,
     12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
     13  * See the License for the specific language governing permissions and
     14  * limitations under the License.
     15  */
     16 
     17 package com.android.email;
     18 
     19 import android.content.Context;
     20 
     21 import java.util.Set;
     22 import java.util.concurrent.ConcurrentHashMap;
     23 
     24 public class GroupMessagingListener extends MessagingListener {
     25     /* The synchronization of the methods in this class
     26        is not needed because we use ConcurrentHashMap.
     27 
     28        Nevertheless, let's keep the "synchronized" for a while in the case
     29        we may want to change the implementation to use something else
     30        than ConcurrentHashMap.
     31     */
     32 
     33     private ConcurrentHashMap<MessagingListener, Object> mListenersMap =
     34         new ConcurrentHashMap<MessagingListener, Object>();
     35 
     36     private Set<MessagingListener> mListeners = mListenersMap.keySet();
     37 
     38     synchronized public void addListener(MessagingListener listener) {
     39         // we use "this" as a dummy non-null value
     40         mListenersMap.put(listener, this);
     41     }
     42 
     43     synchronized public void removeListener(MessagingListener listener) {
     44         mListenersMap.remove(listener);
     45     }
     46 
     47     synchronized public boolean isActiveListener(MessagingListener listener) {
     48         return mListenersMap.containsKey(listener);
     49     }
     50 
     51     @Override
     52     synchronized public void listFoldersStarted(long accountId) {
     53         for (MessagingListener l : mListeners) {
     54             l.listFoldersStarted(accountId);
     55         }
     56     }
     57 
     58     @Override
     59     synchronized public void listFoldersFailed(long accountId, String message) {
     60         for (MessagingListener l : mListeners) {
     61             l.listFoldersFailed(accountId, message);
     62         }
     63     }
     64 
     65     @Override
     66     synchronized public void listFoldersFinished(long accountId) {
     67         for (MessagingListener l : mListeners) {
     68             l.listFoldersFinished(accountId);
     69         }
     70     }
     71 
     72     @Override
     73     synchronized public void synchronizeMailboxStarted(long accountId, long mailboxId) {
     74         for (MessagingListener l : mListeners) {
     75             l.synchronizeMailboxStarted(accountId, mailboxId);
     76         }
     77     }
     78 
     79     @Override
     80     synchronized public void synchronizeMailboxFinished(long accountId, long mailboxId,
     81             int totalMessagesInMailbox, int numNewMessages) {
     82         for (MessagingListener l : mListeners) {
     83             l.synchronizeMailboxFinished(accountId, mailboxId,
     84                     totalMessagesInMailbox, numNewMessages);
     85         }
     86     }
     87 
     88     @Override
     89     synchronized public void synchronizeMailboxFailed(long accountId, long mailboxId, Exception e) {
     90         for (MessagingListener l : mListeners) {
     91             l.synchronizeMailboxFailed(accountId, mailboxId, e);
     92         }
     93     }
     94 
     95     @Override
     96     synchronized public void loadMessageForViewStarted(long messageId) {
     97         for (MessagingListener l : mListeners) {
     98             l.loadMessageForViewStarted(messageId);
     99         }
    100     }
    101 
    102     @Override
    103     synchronized public void loadMessageForViewFinished(long messageId) {
    104         for (MessagingListener l : mListeners) {
    105             l.loadMessageForViewFinished(messageId);
    106         }
    107     }
    108 
    109     @Override
    110     synchronized public void loadMessageForViewFailed(long messageId, String message) {
    111         for (MessagingListener l : mListeners) {
    112             l.loadMessageForViewFailed(messageId, message);
    113         }
    114     }
    115 
    116     @Override
    117     synchronized public void checkMailStarted(Context context, long accountId, long tag) {
    118         for (MessagingListener l : mListeners) {
    119             l.checkMailStarted(context, accountId, tag);
    120         }
    121     }
    122 
    123     @Override
    124     synchronized public void checkMailFinished(Context context, long accountId, long folderId,
    125             long tag) {
    126         for (MessagingListener l : mListeners) {
    127             l.checkMailFinished(context, accountId, folderId, tag);
    128         }
    129     }
    130 
    131     @Override
    132     synchronized public void sendPendingMessagesStarted(long accountId, long messageId) {
    133         for (MessagingListener l : mListeners) {
    134             l.sendPendingMessagesStarted(accountId, messageId);
    135         }
    136     }
    137 
    138     @Override
    139     synchronized public void sendPendingMessagesCompleted(long accountId) {
    140         for (MessagingListener l : mListeners) {
    141             l.sendPendingMessagesCompleted(accountId);
    142         }
    143     }
    144 
    145     @Override
    146     synchronized public void sendPendingMessagesFailed(long accountId, long messageId,
    147             Exception reason) {
    148         for (MessagingListener l : mListeners) {
    149             l.sendPendingMessagesFailed(accountId, messageId, reason);
    150         }
    151     }
    152 
    153     @Override
    154     synchronized public void messageUidChanged(long accountId, long mailboxId,
    155             String oldUid, String newUid) {
    156         for (MessagingListener l : mListeners) {
    157             l.messageUidChanged(accountId, mailboxId, oldUid, newUid);
    158         }
    159     }
    160 
    161     @Override
    162     synchronized public void loadAttachmentStarted(
    163             long accountId,
    164             long messageId,
    165             long attachmentId,
    166             boolean requiresDownload) {
    167         for (MessagingListener l : mListeners) {
    168             l.loadAttachmentStarted(accountId, messageId, attachmentId, requiresDownload);
    169         }
    170     }
    171 
    172     @Override
    173     synchronized public void loadAttachmentFinished(
    174             long accountId,
    175             long messageId,
    176             long attachmentId) {
    177         for (MessagingListener l : mListeners) {
    178             l.loadAttachmentFinished(accountId, messageId, attachmentId);
    179         }
    180     }
    181 
    182     @Override
    183     synchronized public void loadAttachmentFailed(
    184             long accountId,
    185             long messageId,
    186             long attachmentId,
    187             String reason) {
    188         for (MessagingListener l : mListeners) {
    189             l.loadAttachmentFailed(accountId, messageId, attachmentId, reason);
    190         }
    191     }
    192 
    193     @Override
    194     synchronized public void controllerCommandCompleted(boolean moreCommandsToRun) {
    195         for (MessagingListener l : mListeners) {
    196             l.controllerCommandCompleted(moreCommandsToRun);
    197         }
    198     }
    199 }
    200