⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 messagelistupdater.java

📁 The Funambol J2ME Mail Client aims to be a light, easy to use, free email client for J2ME devices.
💻 JAVA
字号:
/*
 * Copyright (C) 2006-2007 Funambol
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 *
 *
 */

package com.funambol.mailclient.ui.controller;

import com.funambol.mail.Folder;
import com.funambol.mail.MailException;
import com.funambol.mail.Message;
import com.funambol.mail.Store;
import com.funambol.mailclient.Cache;
import com.funambol.mailclient.mm.FolderInfo;
import com.funambol.mailclient.mm.MessageInfo;
import com.funambol.mailclient.mm.MessageManager;
import com.funambol.mailclient.ui.utils.UiUtils;
import com.funambol.mailclient.ui.view.FunCanvasContactList;
import com.funambol.mailclient.ui.view.FunCanvasInboxMessageList;
import com.funambol.util.Log;
import com.funambol.util.Observer;
import com.funambol.mailclient.mm.SyncEventInfo;

public class MessageListUpdater implements Observer{
    
    private boolean alerted;
    
    /** Creates a new instance of MessageListUpdater */
    public MessageListUpdater() {
    }
    
    public void update(Object o) {
        if (o!=null) {
            //  Log.debug(this, "updating messagelists  "+ o.getClass().getName());
            if (o instanceof Message) {
                handleInboxMessage((Message)o);
            } else if (o instanceof SyncEventInfo){
                handle((SyncEventInfo)o);
            }
        } else {
            //Log.debug(this, "updating messagelists <null> ");
            UIController.updateInboxMessageList(null);
        }
    }
    
    private void handleInboxMessage(Message msg) {
        Folder parent = msg.getParent();
        if (parent != null) {
            String parentName = parent.getName();
            // TODO: play sound only if the message has unread flag
            if ((Store.INBOX).equals(parentName)) {
                if (!alerted) {
                    UIController.playSound();
                    alerted=true;
                }
                FolderInfo folderInfo =
                        UIController.getFolderInfo(MessageManager.INBOX);
                FunCanvasInboxMessageList messageList =
                        UIController.getInboxMessageList();
                
                try {
                    messageList.addMessage(new MessageInfo(msg, folderInfo));
                    
                } catch (MailException ex) {
                    Log.error("handleInboxMessage: " + ex.toString());
                    ex.printStackTrace();
                }
            }
        }
    }
    
    private void handle(SyncEventInfo syncEventInfo) {
        Log.info("MessageListUpdater - syncEventInfo.infoCode: " + syncEventInfo.infoCode);
        switch (syncEventInfo.infoCode) {
            
            case SyncEventInfo.START_OPERATION:
                //DISABLE GetMail Command during sync mail
                UIController.enableSyncCommands(false);
                break;
            case SyncEventInfo.END_OPERATION:
                //ENABLE GetMail Command during sync mail
                UIController.enableSyncCommands(true);
                try {
                    Cache.saveMsgSnapShot(Cache.INBOX,
                            UIController.getInboxMessageList().getMessageInfoList());
                } catch (Exception ex) {
                    //catch all the exception and do nothing
                    ex.printStackTrace();
                    Log.error("MessageListUpdater: " + ex.toString());
                }
                 
                // reloading messages from rms.
                // we need this to be consistent with the number of received messages
                // because we sometimes remove messages from the ui to avoid oom
                MessageInfo[] messagelist = UIController.getSortedMessageInfo(
                UIController.getFolderInfo(MessageManager.INBOX));
                UIController.getInboxMessageList().setMessageInfoList(messagelist);
                break;
                
            case SyncEventInfo.CONNECTION_COMPLETED:
                UIController.updateInboxMessageList(syncEventInfo.infoMessage);
                break;
            case SyncEventInfo.MESSAGE_SENT:
            case SyncEventInfo.MESSAGE_RECEIVED:
            case SyncEventInfo.START_RECEIVE:
            case SyncEventInfo.START_SEND:
                UIController.updateInboxMessageList(syncEventInfo.infoMessage);
                break;
            case SyncEventInfo.START_MESSAGE_SESSION:
                UIController.enableSyncCommands(false);
                UIController.updateInboxMessageList(syncEventInfo.infoMessage);
                break;
            case  SyncEventInfo.END_MESSAGE_SESSION:
                UIController.updateInboxMessageList(syncEventInfo.infoMessage);
                UIController.resortInboxMessages();
                break;
            case SyncEventInfo.START_CONTACT_SESSION:
                // we need this because we can sync the contacts without syncing 
                // the mail
                UIController.enableSyncCommands(false);
                UIController.updateInboxMessageList(syncEventInfo.infoMessage);
                break;
            case SyncEventInfo.END_CONTACT_SESSION:
                //Log.debug("End contact session title: " + syncEventInfo.infoMessage);
                UIController.updateInboxMessageList(syncEventInfo.infoMessage);
                break;
            case SyncEventInfo.START_SEND_MESSAGE_SESSION:
                UIController.enableSyncCommands(false);
                UIController.updateInboxMessageList(syncEventInfo.infoMessage);
                break;
            case SyncEventInfo.END_SEND_MESSAGE_SESSION:
                UIController.updateInboxMessageList(syncEventInfo.infoMessage);
                UIController.getInboxMessageList().resetTitle();
                break;
            case SyncEventInfo.MESSAGE_DELETED:
                //if message is in inbox, we delete it.
                UIController.getInboxMessageList().deleteMessage(syncEventInfo.msgId);
                break;
            case SyncEventInfo.MESSAGE_FLAGS_UPDATED:
                //if message is in inbox, we update the flags
                UIController.getInboxMessageList().updateMessageFlags(
                        syncEventInfo.msgId, syncEventInfo.flags);
                break;
            case SyncEventInfo.RELOAD_INBOX:
                    UIController.reloadInboxMessageListMessages();
            default:
                break;
        }
    }
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -