ConversationUpdater.java revision 0f88a8a8e1df87445864a74fcd331a72853c88e6
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.AlertDialog; 21import android.content.ContentValues; 22import android.net.Uri; 23 24import com.android.mail.browse.ConfirmDialogFragment; 25import com.android.mail.browse.ConversationCursor; 26import com.android.mail.browse.ConversationMessage; 27import com.android.mail.providers.Conversation; 28import com.android.mail.providers.ConversationInfo; 29import com.android.mail.providers.Folder; 30import com.android.mail.providers.UIProvider; 31 32import java.util.Collection; 33import java.util.Set; 34 35/** 36 * Classes that can update conversations implement this interface. 37 */ 38public interface ConversationUpdater extends ConversationListCallbacks { 39 /** 40 * Modify the given conversation by changing the column provided here to contain the value 41 * provided. Column names are listed in {@link UIProvider.ConversationColumns}, for example 42 * {@link UIProvider.ConversationColumns#FOLDER_LIST} 43 * @param target 44 * @param columnName 45 * @param value 46 */ 47 void updateConversation(Collection <Conversation> target, String columnName, String value); 48 49 /** 50 * Modify the given conversation by changing the column provided here to contain the value 51 * provided. Column names are listed in {@link UIProvider.ConversationColumns}, for example 52 * {@link UIProvider.ConversationColumns#READ} 53 * @param target 54 * @param columnName 55 * @param value 56 */ 57 void updateConversation(Collection <Conversation> target, String columnName, int value); 58 59 /** 60 * Modify the given conversation by changing the column provided here to contain the value 61 * provided. Column names are listed in {@link UIProvider.ConversationColumns}, for example 62 * {@link UIProvider.ConversationColumns#HAS_ATTACHMENTS} 63 * @param target 64 * @param columnName 65 * @param value 66 */ 67 void updateConversation(Collection <Conversation> target, String columnName, boolean value); 68 69 /** 70 * Modify the given conversation by changing the columns provided here to 71 * contain the values provided. Column names are listed in 72 * {@link UIProvider.ConversationColumns}, for example 73 * {@link UIProvider.ConversationColumns#HAS_ATTACHMENTS} 74 * @param target 75 * @param values 76 */ 77 void updateConversation(Collection <Conversation> target, ContentValues values); 78 79 /** 80 * Requests the removal of the current conversation with the specified destructive action. 81 * @param actionId the unique id for the action responsible for this delete: R.id.archive, ... 82 * @param target the conversations to act upon. 83 * @param action to perform after the UI has been updated to remove the conversations 84 * @param isBatch true if this is a batch action, false otherwise. 85 * @param allowDialog <code>true</code> to allow dialogs to be displayed 86 */ 87 void delete( 88 int actionId, final Collection<Conversation> target, final DestructiveAction action, 89 boolean isBatch, boolean allowDialog); 90 91 /** 92 * Mark a number of conversations as read or unread. 93 * @param targets the conversations to act upon 94 * @param read true if the conversations are marked read, false if they are marked unread. 95 * @param viewed whether the conversations are marked viewed as well. This indicates that the 96 * conversations are shown on the UI. 97 */ 98 void markConversationsRead(Collection<Conversation> targets, boolean read, boolean viewed); 99 100 /** 101 * Mark a single conversation unread, either entirely or for just a subset of the messages in a 102 * conversation and the view <b>returns to Conversation List</b> mode. 103 * 104 * @param conv conversation to mark unread 105 * @param unreadMessageUris URIs for the subset of the conversation's messages to mark unread, 106 * or null/empty set to mark the entire conversation unread. 107 * @param originalConversationInfo the original unread state of the {@link ConversationInfo} 108 * that {@link ConversationCursor} will temporarily use until the commit is complete. 109 */ 110 void markConversationMessagesUnread(Conversation conv, Set<Uri> unreadMessageUris, 111 byte[] originalConversationInfo); 112 113 /** 114 * Star a single message within a conversation. This method requires a 115 * {@link ConversationMessage} to propagate the change to the owning {@link Conversation}. 116 * 117 */ 118 void starMessage(ConversationMessage msg, boolean starred); 119 120 /** 121 * Get a destructive action for selected conversations. The action corresponds to Menu item 122 * identifiers, for example R.id.unread, or R.id.delete. 123 * @param action 124 * @return 125 */ 126 public DestructiveAction getBatchAction(int action); 127 128 /** 129 * Get a destructive action for selected conversations. The action corresponds to Menu item 130 * identifiers, for example R.id.unread, or R.id.delete. 131 * @param action 132 * @return 133 */ 134 public DestructiveAction getDeferredBatchAction(int action); 135 136 /** 137 * Get destructive folder change for selected conversations. 138 * The caller must explicitly call performAction. 139 * @param action 140 * @return 141 */ 142 public DestructiveAction getDeferredRemoveFolder(Collection<Conversation> target, 143 Folder toRemove, boolean isDestructive, boolean isBatch, 144 boolean showUndo); 145 146 /** 147 * Assign the target conversations to the given folders, and remove them from all other folders 148 * that they might be assigned to. 149 * @param folders the folders to assign the conversations to. 150 * @param target the conversations to act upon. 151 * @param batch whether this is a batch operation 152 * @param showUndo whether to show the undo bar 153 * @param isMoveTo <code>true</code> if this is a move operation, <code>false</code> if it is 154 * some other type of folder change operation 155 */ 156 public void assignFolder(Collection<FolderOperation> folders, Collection<Conversation> target, 157 boolean batch, boolean showUndo, boolean isMoveTo); 158 159 /** 160 * Refreshes the conversation list, if one exists. 161 */ 162 void refreshConversationList(); 163 164 /** 165 * Show the next conversation after a destructive action. The next 166 * conversation is determined by list state and user preferences. 167 * @param conversations Conversations that were removed as part of the 168 * destructive action. 169 */ 170 void showNextConversation(Collection<Conversation> conversations); 171 172 /** 173 * Make an action listener for a confirmation dialog, and the currently selected set of 174 * conversations. The action is specified as an integer which marks the menu resource: 175 * R.id.delete, R.id.discard_drafts, etc. 176 * @param action the resource ID of the menu action: R.id.delete, for example 177 * @param fromSelectedSet true if the listener acts on the selected set, false if the listener 178 * acts on the current conversation. 179 */ 180 public void makeDialogListener(final int action, boolean fromSelectedSet); 181 182 /** 183 * If set, get the listener associated with the existing {@link ConfirmDialogFragment}. This 184 * listener needs to be set centrally, because the dialog fragment can get torn down, along with 185 * the current activity, and the listener has to be created afresh. 186 * @return the current listener for the positive action in the current confirmation dialog, if 187 * any. Returns null if no confirmation dialog is currently shown. 188 */ 189 public AlertDialog.OnClickListener getListener(); 190} 191