mirror of
https://github.com/moparisthebest/k-9
synced 2025-01-31 07:10:14 -05:00
Flag "Sent" messages as Seen Issue 91
"Instant" Empty trash
This commit is contained in:
parent
b4ea7f34a4
commit
e1da49109f
@ -87,6 +87,8 @@ public class MessagingController implements Runnable {
|
|||||||
|
|
||||||
private static final String PENDING_COMMAND_TRASH =
|
private static final String PENDING_COMMAND_TRASH =
|
||||||
"com.android.email.MessagingController.trash";
|
"com.android.email.MessagingController.trash";
|
||||||
|
private static final String PENDING_COMMAND_EMPTY_TRASH =
|
||||||
|
"com.android.email.MessagingController.emptyTrash";
|
||||||
private static final String PENDING_COMMAND_SET_FLAG =
|
private static final String PENDING_COMMAND_SET_FLAG =
|
||||||
"com.android.email.MessagingController.setFlag";
|
"com.android.email.MessagingController.setFlag";
|
||||||
private static final String PENDING_COMMAND_APPEND =
|
private static final String PENDING_COMMAND_APPEND =
|
||||||
@ -176,6 +178,7 @@ public class MessagingController implements Runnable {
|
|||||||
public void run() {
|
public void run() {
|
||||||
Process.setThreadPriority(Process.THREAD_PRIORITY_BACKGROUND);
|
Process.setThreadPriority(Process.THREAD_PRIORITY_BACKGROUND);
|
||||||
while (true) {
|
while (true) {
|
||||||
|
String commandDescription = null;
|
||||||
try {
|
try {
|
||||||
Command command = mCommands.poll();
|
Command command = mCommands.poll();
|
||||||
if (command == null)
|
if (command == null)
|
||||||
@ -189,19 +192,21 @@ public class MessagingController implements Runnable {
|
|||||||
|
|
||||||
if (command != null)
|
if (command != null)
|
||||||
{
|
{
|
||||||
if (command.listener == null || mListeners.contains(command.listener)) {
|
commandDescription = command.description;
|
||||||
mBusy = true;
|
Log.d(Email.LOG_TAG, "Running background command '" + command.description + "'");
|
||||||
command.runnable.run();
|
mBusy = true;
|
||||||
for (MessagingListener l : mListeners) {
|
command.runnable.run();
|
||||||
l.controllerCommandCompleted(mCommands.size() > 0);
|
Log.d(Email.LOG_TAG, "Background command '" + command.description + "' completed");
|
||||||
}
|
for (MessagingListener l : getListeners()) {
|
||||||
}
|
l.controllerCommandCompleted(mCommands.size() > 0);
|
||||||
}
|
}
|
||||||
|
if (command.listener != null && !mListeners.contains(command.listener)) {
|
||||||
|
command.listener.controllerCommandCompleted(mCommands.size() > 0);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
catch (Exception e) {
|
catch (Exception e) {
|
||||||
if (Config.LOGV) {
|
Log.e(Email.LOG_TAG, "Error running command '" + commandDescription + "'", e);
|
||||||
Log.v(Email.LOG_TAG, "Error running command", e);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
mBusy = false;
|
mBusy = false;
|
||||||
}
|
}
|
||||||
@ -1058,6 +1063,7 @@ s * critical data as fast as possible, and then we'll fill in the de
|
|||||||
{
|
{
|
||||||
for (PendingCommand command : commands) {
|
for (PendingCommand command : commands) {
|
||||||
processingCommand = command;
|
processingCommand = command;
|
||||||
|
Log.d(Email.LOG_TAG, "Processing pending command '" + command + "'");
|
||||||
/*
|
/*
|
||||||
* We specifically do not catch any exceptions here. If a command fails it is
|
* We specifically do not catch any exceptions here. If a command fails it is
|
||||||
* most likely due to a server or IO error and it must be retried before any
|
* most likely due to a server or IO error and it must be retried before any
|
||||||
@ -1075,14 +1081,19 @@ s * critical data as fast as possible, and then we'll fill in the de
|
|||||||
else if (PENDING_COMMAND_TRASH.equals(command.command)) {
|
else if (PENDING_COMMAND_TRASH.equals(command.command)) {
|
||||||
processPendingTrash(command, account);
|
processPendingTrash(command, account);
|
||||||
}
|
}
|
||||||
|
else if (PENDING_COMMAND_EMPTY_TRASH.equals(command.command)) {
|
||||||
|
processPendingEmptyTrash(command, account);
|
||||||
|
}
|
||||||
localStore.removePendingCommand(command);
|
localStore.removePendingCommand(command);
|
||||||
|
Log.d(Email.LOG_TAG, "Done processing pending command '" + command + "'");
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
catch (MessagingException me)
|
catch (MessagingException me)
|
||||||
{
|
{
|
||||||
addErrorMessage(account, me);
|
addErrorMessage(account, me);
|
||||||
|
|
||||||
Log.e(Email.LOG_TAG, "Could not process command " + processingCommand, me);
|
Log.e(Email.LOG_TAG, "Could not process command '" + processingCommand + "'", me);
|
||||||
throw me;
|
throw me;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -1458,7 +1469,9 @@ s * critical data as fast as possible, and then we'll fill in the de
|
|||||||
final String folder,
|
final String folder,
|
||||||
final String uid,
|
final String uid,
|
||||||
final Flag flag,
|
final Flag flag,
|
||||||
boolean newState) {
|
final boolean newState) {
|
||||||
|
// TODO: put this into the background, but right now that causes odd behavior
|
||||||
|
// because the FolderMessageList doesn't have its own cache of the flag states
|
||||||
try {
|
try {
|
||||||
Store localStore = Store.getInstance(account.getLocalStoreUri(), mApplication);
|
Store localStore = Store.getInstance(account.getLocalStoreUri(), mApplication);
|
||||||
Folder localFolder = localStore.getFolder(folder);
|
Folder localFolder = localStore.getFolder(folder);
|
||||||
@ -1515,6 +1528,11 @@ s * critical data as fast as possible, and then we'll fill in the de
|
|||||||
|
|
||||||
Message message = localFolder.getMessage(uid);
|
Message message = localFolder.getMessage(uid);
|
||||||
|
|
||||||
|
// This is a view message request, so mark it read
|
||||||
|
if (!message.isSet(Flag.SEEN)) {
|
||||||
|
markMessageRead(account, folder, uid, true);
|
||||||
|
}
|
||||||
|
|
||||||
if (message.isSet(Flag.X_DOWNLOADED_FULL)) {
|
if (message.isSet(Flag.X_DOWNLOADED_FULL)) {
|
||||||
/*
|
/*
|
||||||
* If the message has been synchronized since we were called we'll
|
* If the message has been synchronized since we were called we'll
|
||||||
@ -1555,10 +1573,6 @@ s * critical data as fast as possible, and then we'll fill in the de
|
|||||||
message = localFolder.getMessage(uid);
|
message = localFolder.getMessage(uid);
|
||||||
localFolder.fetch(new Message[] { message }, fp, null);
|
localFolder.fetch(new Message[] { message }, fp, null);
|
||||||
|
|
||||||
// This is a view message request, so mark it read
|
|
||||||
if (!message.isSet(Flag.SEEN)) {
|
|
||||||
markMessageRead(account, folder, uid, true);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Mark that this message is now fully synched
|
// Mark that this message is now fully synched
|
||||||
message.setFlag(Flag.X_DOWNLOADED_FULL, true);
|
message.setFlag(Flag.X_DOWNLOADED_FULL, true);
|
||||||
@ -1595,6 +1609,10 @@ s * critical data as fast as possible, and then we'll fill in the de
|
|||||||
|
|
||||||
Message message = localFolder.getMessage(uid);
|
Message message = localFolder.getMessage(uid);
|
||||||
|
|
||||||
|
if (!message.isSet(Flag.SEEN)) {
|
||||||
|
markMessageRead(account, folder, uid, true);
|
||||||
|
}
|
||||||
|
|
||||||
for (MessagingListener l : getListeners()) {
|
for (MessagingListener l : getListeners()) {
|
||||||
l.loadMessageForViewHeadersAvailable(account, folder, uid, message);
|
l.loadMessageForViewHeadersAvailable(account, folder, uid, message);
|
||||||
}
|
}
|
||||||
@ -1605,10 +1623,6 @@ s * critical data as fast as possible, and then we'll fill in the de
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!message.isSet(Flag.SEEN)) {
|
|
||||||
markMessageRead(account, folder, uid, true);
|
|
||||||
}
|
|
||||||
|
|
||||||
FetchProfile fp = new FetchProfile();
|
FetchProfile fp = new FetchProfile();
|
||||||
fp.add(FetchProfile.Item.ENVELOPE);
|
fp.add(FetchProfile.Item.ENVELOPE);
|
||||||
fp.add(FetchProfile.Item.BODY);
|
fp.add(FetchProfile.Item.BODY);
|
||||||
@ -1821,6 +1835,7 @@ s * critical data as fast as possible, and then we'll fill in the de
|
|||||||
message.setFlag(Flag.X_SEND_IN_PROGRESS, true);
|
message.setFlag(Flag.X_SEND_IN_PROGRESS, true);
|
||||||
transport.sendMessage(message);
|
transport.sendMessage(message);
|
||||||
message.setFlag(Flag.X_SEND_IN_PROGRESS, false);
|
message.setFlag(Flag.X_SEND_IN_PROGRESS, false);
|
||||||
|
message.setFlag(Flag.SEEN, true);
|
||||||
localFolder.copyMessages(
|
localFolder.copyMessages(
|
||||||
new Message[] { message },
|
new Message[] { message },
|
||||||
localSentFolder);
|
localSentFolder);
|
||||||
@ -1985,6 +2000,18 @@ s * critical data as fast as possible, and then we'll fill in the de
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void processPendingEmptyTrash(PendingCommand command, Account account) throws MessagingException {
|
||||||
|
Store remoteStore = Store.getInstance(account.getStoreUri(), mApplication);
|
||||||
|
|
||||||
|
Folder remoteFolder = remoteStore.getFolder(account.getTrashFolderName());
|
||||||
|
if (remoteFolder.exists())
|
||||||
|
{
|
||||||
|
remoteFolder.open(OpenMode.READ_WRITE);
|
||||||
|
remoteFolder.setFlags(new Flag [] { Flag.DELETED }, true);
|
||||||
|
remoteFolder.close(true);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public void emptyTrash(final Account account, MessagingListener listener) {
|
public void emptyTrash(final Account account, MessagingListener listener) {
|
||||||
put("emptyTrash", listener, new Runnable() {
|
put("emptyTrash", listener, new Runnable() {
|
||||||
public void run() {
|
public void run() {
|
||||||
@ -1995,25 +2022,19 @@ s * critical data as fast as possible, and then we'll fill in the de
|
|||||||
localFolder.setFlags(new Flag[] { Flag.DELETED }, true);
|
localFolder.setFlags(new Flag[] { Flag.DELETED }, true);
|
||||||
localFolder.close(true);
|
localFolder.close(true);
|
||||||
|
|
||||||
Store remoteStore = Store.getInstance(account.getStoreUri(), mApplication);
|
|
||||||
|
|
||||||
Folder remoteFolder = remoteStore.getFolder(account.getTrashFolderName());
|
|
||||||
if (remoteFolder.exists())
|
|
||||||
{
|
|
||||||
remoteFolder.open(OpenMode.READ_WRITE);
|
|
||||||
remoteFolder.setFlags(new Flag [] { Flag.DELETED }, true);
|
|
||||||
remoteFolder.close(true);
|
|
||||||
}
|
|
||||||
|
|
||||||
for (MessagingListener l : getListeners()) {
|
for (MessagingListener l : getListeners()) {
|
||||||
l.emptyTrashCompleted(account);
|
l.emptyTrashCompleted(account);
|
||||||
}
|
}
|
||||||
|
List<String> args = new ArrayList<String>();
|
||||||
|
PendingCommand command = new PendingCommand();
|
||||||
|
command.command = PENDING_COMMAND_EMPTY_TRASH;
|
||||||
|
command.arguments = args.toArray(new String[0]);
|
||||||
|
queuePendingCommand(account, command);
|
||||||
|
processPendingCommands(account);
|
||||||
}
|
}
|
||||||
catch (Exception e) {
|
catch (Exception e) {
|
||||||
// TODO
|
Log.e(Email.LOG_TAG, "emptyTrash failed", e);
|
||||||
if (Config.LOGV) {
|
|
||||||
Log.v(Email.LOG_TAG, "emptyTrash");
|
|
||||||
}
|
|
||||||
addErrorMessage(account, e);
|
addErrorMessage(account, e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -821,9 +821,22 @@ public class FolderMessageList extends ExpandableListActivity
|
|||||||
//onRefresh(false);
|
//onRefresh(false);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void onEmptyTrash(Account account)
|
private void onEmptyTrash(final Account account)
|
||||||
{
|
{
|
||||||
MessagingController.getInstance(getApplication()).emptyTrash(account, null);
|
mAdapter.removeAllMessages(account.getTrashFolderName());
|
||||||
|
mHandler.dataChanged();
|
||||||
|
|
||||||
|
MessagingListener listener = new MessagingListener()
|
||||||
|
{
|
||||||
|
@Override
|
||||||
|
public void controllerCommandCompleted(boolean moreToDo)
|
||||||
|
{
|
||||||
|
Log.v(Email.LOG_TAG, "Empty Trash background task completed");
|
||||||
|
mAdapter.removeAllDeletedUids(account.getTrashFolderName());
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
MessagingController.getInstance(getApplication()).emptyTrash(account, listener);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -1417,6 +1430,29 @@ public class FolderMessageList extends ExpandableListActivity
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void removeAllDeletedUids(String folder)
|
||||||
|
{
|
||||||
|
FolderInfoHolder f = getFolder(folder);
|
||||||
|
if (f != null)
|
||||||
|
{
|
||||||
|
f.deletedUids.clear();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public void removeAllMessages(String folder)
|
||||||
|
{
|
||||||
|
FolderInfoHolder f = getFolder(folder);
|
||||||
|
if (f == null)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
for (MessageInfoHolder m : f.messages)
|
||||||
|
{
|
||||||
|
removeMessage(folder, m.uid);
|
||||||
|
}
|
||||||
|
f.unreadMessageCount = 0;
|
||||||
|
}
|
||||||
|
|
||||||
public void removeMessage(String folder, String messageUid)
|
public void removeMessage(String folder, String messageUid)
|
||||||
{
|
{
|
||||||
FolderInfoHolder f = getFolder(folder);
|
FolderInfoHolder f = getFolder(folder);
|
||||||
@ -1754,7 +1790,7 @@ public class FolderMessageList extends ExpandableListActivity
|
|||||||
|
|
||||||
if (message.flagged)
|
if (message.flagged)
|
||||||
{
|
{
|
||||||
holder.subject.setTextColor(0xffff4444);
|
holder.subject.setTextColor(Email.FLAGGED_COLOR);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
Loading…
Reference in New Issue
Block a user