AccountController.java revision 77ee0ceaefaa9be699a20bfbe162f4c0ef83c6e1
17c401b7896910c00e6234e8774aab0be45740d32Vikram Aggarwal/*
27c401b7896910c00e6234e8774aab0be45740d32Vikram Aggarwal * Copyright (C) 2012 Google Inc.
37c401b7896910c00e6234e8774aab0be45740d32Vikram Aggarwal * Licensed to The Android Open Source Project.
47c401b7896910c00e6234e8774aab0be45740d32Vikram Aggarwal *
57c401b7896910c00e6234e8774aab0be45740d32Vikram Aggarwal * Licensed under the Apache License, Version 2.0 (the "License");
67c401b7896910c00e6234e8774aab0be45740d32Vikram Aggarwal * you may not use this file except in compliance with the License.
77c401b7896910c00e6234e8774aab0be45740d32Vikram Aggarwal * You may obtain a copy of the License at
87c401b7896910c00e6234e8774aab0be45740d32Vikram Aggarwal *
97c401b7896910c00e6234e8774aab0be45740d32Vikram Aggarwal *      http://www.apache.org/licenses/LICENSE-2.0
107c401b7896910c00e6234e8774aab0be45740d32Vikram Aggarwal *
117c401b7896910c00e6234e8774aab0be45740d32Vikram Aggarwal * Unless required by applicable law or agreed to in writing, software
127c401b7896910c00e6234e8774aab0be45740d32Vikram Aggarwal * distributed under the License is distributed on an "AS IS" BASIS,
137c401b7896910c00e6234e8774aab0be45740d32Vikram Aggarwal * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
147c401b7896910c00e6234e8774aab0be45740d32Vikram Aggarwal * See the License for the specific language governing permissions and
157c401b7896910c00e6234e8774aab0be45740d32Vikram Aggarwal * limitations under the License.
167c401b7896910c00e6234e8774aab0be45740d32Vikram Aggarwal */
177c401b7896910c00e6234e8774aab0be45740d32Vikram Aggarwal
187c401b7896910c00e6234e8774aab0be45740d32Vikram Aggarwalpackage com.android.mail.ui;
197c401b7896910c00e6234e8774aab0be45740d32Vikram Aggarwal
200f73d905c5e935a5280f8eb647cc924c2854b7deRohan Shahimport android.database.DataSetObservable;
217c401b7896910c00e6234e8774aab0be45740d32Vikram Aggarwalimport android.database.DataSetObserver;
227c401b7896910c00e6234e8774aab0be45740d32Vikram Aggarwal
237c401b7896910c00e6234e8774aab0be45740d32Vikram Aggarwalimport com.android.mail.providers.Account;
247c401b7896910c00e6234e8774aab0be45740d32Vikram Aggarwalimport com.android.mail.providers.AccountObserver;
2577ee0ceaefaa9be699a20bfbe162f4c0ef83c6e1Vikram Aggarwalimport com.android.mail.providers.FolderWatcher;
2669a6cdff8afde77ec9bcd75a5651ee212344019eVikram Aggarwalimport com.android.mail.utils.VeiledAddressMatcher;
277c401b7896910c00e6234e8774aab0be45740d32Vikram Aggarwal
287c401b7896910c00e6234e8774aab0be45740d32Vikram Aggarwal/**
297c401b7896910c00e6234e8774aab0be45740d32Vikram Aggarwal * This class consolidates account-specific actions taken by a mail activity.
307c401b7896910c00e6234e8774aab0be45740d32Vikram Aggarwal */
317c401b7896910c00e6234e8774aab0be45740d32Vikram Aggarwalpublic interface AccountController {
327c401b7896910c00e6234e8774aab0be45740d32Vikram Aggarwal    /**
337c401b7896910c00e6234e8774aab0be45740d32Vikram Aggarwal     * Registers to receive changes to the current account, and obtain the current account.
347c401b7896910c00e6234e8774aab0be45740d32Vikram Aggarwal     */
357c401b7896910c00e6234e8774aab0be45740d32Vikram Aggarwal    void registerAccountObserver(DataSetObserver observer);
367c401b7896910c00e6234e8774aab0be45740d32Vikram Aggarwal
377c401b7896910c00e6234e8774aab0be45740d32Vikram Aggarwal    /**
387c401b7896910c00e6234e8774aab0be45740d32Vikram Aggarwal     * Removes a listener from receiving current account changes.
397c401b7896910c00e6234e8774aab0be45740d32Vikram Aggarwal     */
407c401b7896910c00e6234e8774aab0be45740d32Vikram Aggarwal    void unregisterAccountObserver(DataSetObserver observer);
417c401b7896910c00e6234e8774aab0be45740d32Vikram Aggarwal
427c401b7896910c00e6234e8774aab0be45740d32Vikram Aggarwal    /**
437c401b7896910c00e6234e8774aab0be45740d32Vikram Aggarwal     * Returns the current account in use by the controller. Instead of calling this method,
447c401b7896910c00e6234e8774aab0be45740d32Vikram Aggarwal     * consider registering for account changes using
457c401b7896910c00e6234e8774aab0be45740d32Vikram Aggarwal     * {@link AccountObserver#initialize(AccountController)}, which not only provides the current
467c401b7896910c00e6234e8774aab0be45740d32Vikram Aggarwal     * account, but also updates to the account, in case of settings changes.
477c401b7896910c00e6234e8774aab0be45740d32Vikram Aggarwal     */
487c401b7896910c00e6234e8774aab0be45740d32Vikram Aggarwal    Account getAccount();
4969a6cdff8afde77ec9bcd75a5651ee212344019eVikram Aggarwal
5007dbaa6989ea5c63ecf79b5ce7ec3a6a18a1ff35Vikram Aggarwal
5107dbaa6989ea5c63ecf79b5ce7ec3a6a18a1ff35Vikram Aggarwal    /**
5207dbaa6989ea5c63ecf79b5ce7ec3a6a18a1ff35Vikram Aggarwal     * Registers to receive changes to the list of accounts, and obtain the current list.
5307dbaa6989ea5c63ecf79b5ce7ec3a6a18a1ff35Vikram Aggarwal     */
5407dbaa6989ea5c63ecf79b5ce7ec3a6a18a1ff35Vikram Aggarwal    void registerAllAccountObserver(DataSetObserver observer);
5507dbaa6989ea5c63ecf79b5ce7ec3a6a18a1ff35Vikram Aggarwal
5607dbaa6989ea5c63ecf79b5ce7ec3a6a18a1ff35Vikram Aggarwal    /**
5707dbaa6989ea5c63ecf79b5ce7ec3a6a18a1ff35Vikram Aggarwal     * Removes a listener from receiving account list changes.
5807dbaa6989ea5c63ecf79b5ce7ec3a6a18a1ff35Vikram Aggarwal     */
5907dbaa6989ea5c63ecf79b5ce7ec3a6a18a1ff35Vikram Aggarwal    void unregisterAllAccountObserver(DataSetObserver observer);
6007dbaa6989ea5c63ecf79b5ce7ec3a6a18a1ff35Vikram Aggarwal
6107dbaa6989ea5c63ecf79b5ce7ec3a6a18a1ff35Vikram Aggarwal    /** Returns a list of all accounts currently known. */
6207dbaa6989ea5c63ecf79b5ce7ec3a6a18a1ff35Vikram Aggarwal    Account[] getAllAccounts();
6307dbaa6989ea5c63ecf79b5ce7ec3a6a18a1ff35Vikram Aggarwal
6469a6cdff8afde77ec9bcd75a5651ee212344019eVikram Aggarwal    /**
6569a6cdff8afde77ec9bcd75a5651ee212344019eVikram Aggarwal     * Returns an object that can check veiled addresses.
6669a6cdff8afde77ec9bcd75a5651ee212344019eVikram Aggarwal     * @return
6769a6cdff8afde77ec9bcd75a5651ee212344019eVikram Aggarwal     */
6869a6cdff8afde77ec9bcd75a5651ee212344019eVikram Aggarwal    VeiledAddressMatcher getVeiledAddressMatcher();
6907dbaa6989ea5c63ecf79b5ce7ec3a6a18a1ff35Vikram Aggarwal
7007dbaa6989ea5c63ecf79b5ce7ec3a6a18a1ff35Vikram Aggarwal    /**
7107dbaa6989ea5c63ecf79b5ce7ec3a6a18a1ff35Vikram Aggarwal     * Handles selecting an account from within the {@link FolderListFragment}.
7207dbaa6989ea5c63ecf79b5ce7ec3a6a18a1ff35Vikram Aggarwal     *
7307dbaa6989ea5c63ecf79b5ce7ec3a6a18a1ff35Vikram Aggarwal     * @param account the account to change to.
7407dbaa6989ea5c63ecf79b5ce7ec3a6a18a1ff35Vikram Aggarwal     */
755fd8afd5c1b40580c069a5a97039ca0601208216Vikram Aggarwal    void changeAccount(Account account);
7607dbaa6989ea5c63ecf79b5ce7ec3a6a18a1ff35Vikram Aggarwal
774cbb0da3cd701ee0c06237ded965648d68c663c8Andrew Sapperstein    /**
784cbb0da3cd701ee0c06237ded965648d68c663c8Andrew Sapperstein     * Handles selecting the currently active account from within
794cbb0da3cd701ee0c06237ded965648d68c663c8Andrew Sapperstein     * the {@link FolderListFragment}.
804cbb0da3cd701ee0c06237ded965648d68c663c8Andrew Sapperstein     */
814cbb0da3cd701ee0c06237ded965648d68c663c8Andrew Sapperstein    void switchToDefaultInboxOrChangeAccount(Account account);
820f73d905c5e935a5280f8eb647cc924c2854b7deRohan Shah
830f73d905c5e935a5280f8eb647cc924c2854b7deRohan Shah    /**
840f73d905c5e935a5280f8eb647cc924c2854b7deRohan Shah     * Registers to receive changes upon drawer closing when a changeAccount is called.
850f73d905c5e935a5280f8eb647cc924c2854b7deRohan Shah     */
860f73d905c5e935a5280f8eb647cc924c2854b7deRohan Shah    void registerDrawerClosedObserver(final DataSetObserver observer);
870f73d905c5e935a5280f8eb647cc924c2854b7deRohan Shah
880f73d905c5e935a5280f8eb647cc924c2854b7deRohan Shah    /**
890f73d905c5e935a5280f8eb647cc924c2854b7deRohan Shah     * Removes a listener from receiving current account changes.
900f73d905c5e935a5280f8eb647cc924c2854b7deRohan Shah     */
910f73d905c5e935a5280f8eb647cc924c2854b7deRohan Shah    void unregisterDrawerClosedObserver(final DataSetObserver observer);
920f73d905c5e935a5280f8eb647cc924c2854b7deRohan Shah
930f73d905c5e935a5280f8eb647cc924c2854b7deRohan Shah    /**
940f73d905c5e935a5280f8eb647cc924c2854b7deRohan Shah     * When the {@link FolderListFragment} has a new account ready for changing to,
950f73d905c5e935a5280f8eb647cc924c2854b7deRohan Shah     * close the drawer and then wait for {@link DataSetObservable#notifyChanged()}.
968bcb7c5c37ffd5a1a0c5f4efbcab084830d5e033Rohan Shah     * @param hasNewFolderOrAccount true if we need to load conversations for a different folder
978bcb7c5c37ffd5a1a0c5f4efbcab084830d5e033Rohan Shah     *            or account, false otherwise.
980f73d905c5e935a5280f8eb647cc924c2854b7deRohan Shah     */
998bcb7c5c37ffd5a1a0c5f4efbcab084830d5e033Rohan Shah    void closeDrawer(boolean hasNewFolderOrAccount);
10077ee0ceaefaa9be699a20bfbe162f4c0ef83c6e1Vikram Aggarwal
10177ee0ceaefaa9be699a20bfbe162f4c0ef83c6e1Vikram Aggarwal    /**
10277ee0ceaefaa9be699a20bfbe162f4c0ef83c6e1Vikram Aggarwal     * Set the folderWatcher
10377ee0ceaefaa9be699a20bfbe162f4c0ef83c6e1Vikram Aggarwal     */
10477ee0ceaefaa9be699a20bfbe162f4c0ef83c6e1Vikram Aggarwal    void setFolderWatcher(FolderWatcher watcher);
1057c401b7896910c00e6234e8774aab0be45740d32Vikram Aggarwal}
106