MessageCompose: when loading message, wait for save to finish.

Bug 2465675

Change-Id: I3290c676bbe63db8441a8f6d320d798abc2fcde5
This commit is contained in:
Mihai Preda 2010-03-05 12:13:15 +01:00
parent b00a660c0a
commit c556b6bfe5
1 changed files with 24 additions and 0 deletions

View File

@ -107,6 +107,13 @@ public class MessageCompose extends Activity implements OnClickListener, OnFocus
OpenableColumns.SIZE
};
// Is set while the draft is saved by a background thread.
// Is static in order to be shared between the two activity instances
// on orientation change.
private static boolean sSaveInProgress = false;
// lock and condition for sSaveInProgress
private static final Object sSaveInProgressCondition = new Object();
private Account mAccount;
// mDraft has mId > 0 after the first draft save.
@ -558,6 +565,15 @@ public class MessageCompose extends Activity implements OnClickListener, OnFocus
private class LoadMessageTask extends AsyncTask<Long, Void, Object[]> {
@Override
protected Object[] doInBackground(Long... messageIds) {
synchronized (sSaveInProgressCondition) {
while (sSaveInProgress) {
try {
sSaveInProgressCondition.wait();
} catch (InterruptedException e) {
// ignore & retry loop
}
}
}
Message message = Message.restoreMessageWithId(MessageCompose.this, messageIds[0]);
if (message == null) {
return new Object[] {null, null};
@ -827,6 +843,10 @@ public class MessageCompose extends Activity implements OnClickListener, OnFocus
}
updateMessage(mDraft, mAccount, attachments.length > 0);
synchronized (sSaveInProgressCondition) {
sSaveInProgress = true;
}
mSaveMessageTask = new AsyncTask<Void, Void, Void>() {
@Override
protected Void doInBackground(Void... params) {
@ -866,6 +886,10 @@ public class MessageCompose extends Activity implements OnClickListener, OnFocus
@Override
protected void onPostExecute(Void dummy) {
synchronized (sSaveInProgressCondition) {
sSaveInProgress = false;
sSaveInProgressCondition.notify();
}
if (isCancelled()) {
return;
}