1 /*
2  * Copyright (C) 2012 Google Inc.
3  * Licensed to The Android Open Source Project.
4  *
5  * Licensed under the Apache License, Version 2.0 (the "License");
6  * you may not use this file except in compliance with the License.
7  * You may obtain a copy of the License at
8  *
9  *      http://www.apache.org/licenses/LICENSE-2.0
10  *
11  * Unless required by applicable law or agreed to in writing, software
12  * distributed under the License is distributed on an "AS IS" BASIS,
13  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14  * See the License for the specific language governing permissions and
15  * limitations under the License.
16  */
17 
18 package com.android.mail.ui;
19 
20 import android.database.DataSetObservable;
21 import android.database.DataSetObserver;
22 import android.widget.ListView;
23 
24 import com.android.mail.providers.Account;
25 import com.android.mail.providers.AccountObserver;
26 import com.android.mail.providers.Folder;
27 import com.android.mail.providers.FolderWatcher;
28 import com.android.mail.utils.VeiledAddressMatcher;
29 
30 /**
31  * This class consolidates account-specific actions taken by a mail activity.
32  */
33 public interface AccountController {
34     /**
35      * Registers to receive changes to the current account, and obtain the current account.
36      */
registerAccountObserver(DataSetObserver observer)37     void registerAccountObserver(DataSetObserver observer);
38 
39     /**
40      * Removes a listener from receiving current account changes.
41      */
unregisterAccountObserver(DataSetObserver observer)42     void unregisterAccountObserver(DataSetObserver observer);
43 
44     /**
45      * Returns the current account in use by the controller. Instead of calling this method,
46      * consider registering for account changes using
47      * {@link AccountObserver#initialize(AccountController)}, which not only provides the current
48      * account, but also updates to the account, in case of settings changes.
49      */
getAccount()50     Account getAccount();
51 
52 
53     /**
54      * Registers to receive changes to the list of accounts, and obtain the current list.
55      */
registerAllAccountObserver(DataSetObserver observer)56     void registerAllAccountObserver(DataSetObserver observer);
57 
58     /**
59      * Removes a listener from receiving account list changes.
60      */
unregisterAllAccountObserver(DataSetObserver observer)61     void unregisterAllAccountObserver(DataSetObserver observer);
62 
63     /** Returns a list of all accounts currently known. */
getAllAccounts()64     Account[] getAllAccounts();
65 
66     /**
67      * Returns an object that can check veiled addresses.
68      * @return
69      */
getVeiledAddressMatcher()70     VeiledAddressMatcher getVeiledAddressMatcher();
71 
72     /**
73      * Handles selecting the currently active account from within
74      * the {@link FolderListFragment}.
75      */
switchToDefaultInboxOrChangeAccount(Account account)76     void switchToDefaultInboxOrChangeAccount(Account account);
77 
78     /**
79      * Registers to receive changes upon drawer closing when a changeAccount is called.
80      */
registerFolderOrAccountChangedObserver(final DataSetObserver observer)81     void registerFolderOrAccountChangedObserver(final DataSetObserver observer);
82 
83     /**
84      * Removes a listener from receiving current account changes.
85      */
unregisterFolderOrAccountChangedObserver(final DataSetObserver observer)86     void unregisterFolderOrAccountChangedObserver(final DataSetObserver observer);
87 
88     /**
89      * When the {@link FolderListFragment} has a new account ready for changing to,
90      * close the drawer and then wait for {@link DataSetObservable#notifyChanged()}.
91      * @param hasNewFolderOrAccount true if we need to load conversations for a different folder
92      *            or account, false otherwise.
93      */
closeDrawer(boolean hasNewFolderOrAccount, Account nextAccount, Folder nextFolder)94     void closeDrawer(boolean hasNewFolderOrAccount, Account nextAccount, Folder nextFolder);
95 
96     /**
97      * Set the folderWatcher
98      */
setFolderWatcher(FolderWatcher watcher)99     void setFolderWatcher(FolderWatcher watcher);
100 
101     /**
102      * @return <code>true</code> if the drawer pull action is enabled, <code>false</code> otherwise
103      */
isDrawerPullEnabled()104     boolean isDrawerPullEnabled();
105 
106     /**
107      * @return the choice mode to use in the {@link ListView} in the default folder list (subclasses
108      * of {@link FolderListFragment} may override this
109      */
getFolderListViewChoiceMode()110     int getFolderListViewChoiceMode();
111 }
112