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
18package com.android.mail.ui;
19
20import android.app.LoaderManager.LoaderCallbacks;
21import android.database.DataSetObserver;
22import android.os.Bundle;
23import android.os.Parcelable;
24
25import com.android.mail.browse.ConversationCursor;
26import com.android.mail.providers.Conversation;
27
28/**
29 * A controller interface that is to receive user initiated events and handle them.
30 */
31public interface ConversationListCallbacks {
32    /**
33     * Show the conversation provided here. If the conversation is null, this is a request to pop
34     * <em>out</em> of conversation view mode and head back to conversation list mode, or whatever
35     * should best show in its place.
36     * @param conversation conversation to display, possibly null.
37     * @param inLoaderCallbacks whether we are in the scope of a {@link LoaderCallbacks} method
38     * (when fragment transactions are disallowed)
39     */
40    void onConversationSelected(Conversation conversation, boolean inLoaderCallbacks);
41
42    /**
43     * Possibly show the conversation provided here depending on implementation.
44     * Used mainly by two-pane landscape mode when we are navigating with the keyboard.
45     */
46    void onConversationFocused(Conversation conversation);
47
48    /**
49     * Called whenever CAB mode has been entered via long press or selecting a sender image.
50     */
51    void onCabModeEntered();
52
53    /**
54     * Called whenever CAB mode has been exited.
55     */
56    void onCabModeExited();
57
58    ConversationCursor getConversationListCursor();
59
60    Conversation getCurrentConversation();
61    void setCurrentConversation(Conversation c);
62
63    /**
64     * Returns whether the initial conversation has begun but not finished loading. If this returns
65     * true, you can register to be told when the load in progress finishes
66     * ({@link #registerConversationLoadedObserver(DataSetObserver)}).
67     * <p>
68     * This flag only applies to the first conversation in a set (e.g. when using ViewPager).
69     *
70     * @return true if the initial conversation has begun but not finished loading
71     */
72    boolean isInitialConversationLoading();
73    void registerConversationLoadedObserver(DataSetObserver observer);
74    void unregisterConversationLoadedObserver(DataSetObserver observer);
75    /**
76     * Coordinates actions that might occur in response to a conversation that has finished loading
77     * and is now user-visible.
78     */
79    void onConversationSeen();
80
81    void registerConversationListObserver(DataSetObserver observer);
82    void unregisterConversationListObserver(DataSetObserver observer);
83
84    /**
85     * Commit any destructive action leave behind items so that it is no longer
86     * possible to undo them.
87     */
88    void commitDestructiveActions(boolean animate);
89
90    /**
91     * Detect if there are any animations occurring in the conversation list.
92     */
93    boolean isAnimating();
94
95    /**
96     * Tell the controller that the conversation view has entered detached mode.
97     */
98    void setDetachedMode();
99
100    String CONVERSATION_LIST_SCROLL_POSITION_INDEX = "index";
101    String CONVERSATION_LIST_SCROLL_POSITION_OFFSET = "offset";
102
103    /**
104     * Gets the last save scroll position of the conversation list for the specified Folder.
105     *
106     * @return A {@link Bundle} containing two ints,
107     *         {@link #CONVERSATION_LIST_SCROLL_POSITION_INDEX} and
108     *         {@link #CONVERSATION_LIST_SCROLL_POSITION_OFFSET}, or <code>null</code>
109     */
110    Parcelable getConversationListScrollPosition(String folderUri);
111
112    /**
113     * Sets the last save scroll position of the conversation list for the specified Folder for
114     * restoration on returning to this list.
115     *
116     * @param savedPosition A {@link Bundle} containing two ints,
117     *            {@link #CONVERSATION_LIST_SCROLL_POSITION_INDEX} and
118     *            {@link #CONVERSATION_LIST_SCROLL_POSITION_OFFSET}
119     */
120    void setConversationListScrollPosition(String folderUri, Parcelable savedPosition);
121}
122