Set mailbox uiSyncStatus when IMAP and POP folders are created
b/17443087 Now for certain folder types, when they are first created, the uiSyncStatus is set to NEEDS_INITIAL_SYNC. This prevents us from displaying the empty state until after the sync has completed. Change-Id: Ib04c915f6972ecb75092dd50e90dee8647ee2f64
This commit is contained in:
parent
1d929d18fe
commit
79cb83cad1
@ -156,6 +156,16 @@ public abstract class Store {
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Some protocols allow for syncing of folder types other than inbox. The store for any such
|
||||
* protocol should override this to return what types can be synced.
|
||||
* @param type The type of mailbox
|
||||
* @return true if the given type of mailbox can be synced.
|
||||
*/
|
||||
public boolean canSyncFolderType(final int type) {
|
||||
return (type == Mailbox.TYPE_INBOX);
|
||||
}
|
||||
|
||||
public Folder getFolder(String name) throws MessagingException {
|
||||
return null;
|
||||
}
|
||||
|
@ -40,6 +40,7 @@ import com.android.emailcommon.mail.Message;
|
||||
import com.android.emailcommon.mail.MessagingException;
|
||||
import com.android.emailcommon.provider.Account;
|
||||
import com.android.emailcommon.provider.Credential;
|
||||
import com.android.emailcommon.provider.EmailContent;
|
||||
import com.android.emailcommon.provider.HostAuth;
|
||||
import com.android.emailcommon.provider.Mailbox;
|
||||
import com.android.emailcommon.service.EmailServiceProxy;
|
||||
@ -133,6 +134,26 @@ public class ImapStore extends Store {
|
||||
return mPassword;
|
||||
}
|
||||
|
||||
public boolean canSyncFolderType(final int type) {
|
||||
switch (type) {
|
||||
case Mailbox.TYPE_INBOX:
|
||||
case Mailbox.TYPE_MAIL:
|
||||
case Mailbox.TYPE_SENT:
|
||||
case Mailbox.TYPE_TRASH:
|
||||
case Mailbox.TYPE_JUNK:
|
||||
return true;
|
||||
case Mailbox.TYPE_NONE:
|
||||
case Mailbox.TYPE_PARENT:
|
||||
case Mailbox.TYPE_DRAFTS:
|
||||
case Mailbox.TYPE_OUTBOX:
|
||||
case Mailbox.TYPE_SEARCH:
|
||||
case Mailbox.TYPE_STARRED:
|
||||
case Mailbox.TYPE_UNREAD:
|
||||
default:
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
@VisibleForTesting
|
||||
Collection<ImapConnection> getConnectionPoolForTest() {
|
||||
return mConnectionPool;
|
||||
@ -373,6 +394,11 @@ public class ImapStore extends Store {
|
||||
// outside of #saveMailboxList()
|
||||
folder.mHash = mailbox.getHashes();
|
||||
// We must save this here to make sure we have a valid ID for later
|
||||
|
||||
// This is a newly created folder from the server. By definition, if it came from
|
||||
// the server, it can be synched. We need to set the uiSyncStatus so that the UI
|
||||
// will not try to display the empty state until the sync completes.
|
||||
mailbox.mUiSyncStatus = EmailContent.SYNC_STATUS_INITIAL_SYNC_NEEDED;
|
||||
mailbox.save(mContext);
|
||||
}
|
||||
folder.mMailbox = mailbox;
|
||||
|
@ -293,10 +293,18 @@ public abstract class EmailServiceStub extends IEmailService.Stub implements IEm
|
||||
Cursor localFolderCursor = null;
|
||||
Store store = null;
|
||||
try {
|
||||
store = Store.getInstance(account, mContext);
|
||||
|
||||
// Step 0: Make sure the default system mailboxes exist.
|
||||
for (final int type : Mailbox.REQUIRED_FOLDER_TYPES) {
|
||||
if (Mailbox.findMailboxOfType(mContext, accountId, type) == Mailbox.NO_MAILBOX) {
|
||||
final Mailbox mailbox = Mailbox.newSystemMailbox(mContext, accountId, type);
|
||||
if (store.canSyncFolderType(type)) {
|
||||
// If this folder is syncable, then we should set its UISyncStatus.
|
||||
// Otherwise the UI could show the empty state until the sync
|
||||
// actually occurs.
|
||||
mailbox.mUiSyncStatus = Mailbox.SYNC_STATUS_INITIAL_SYNC_NEEDED;
|
||||
}
|
||||
mailbox.save(mContext);
|
||||
if (type == Mailbox.TYPE_INBOX) {
|
||||
inboxId = mailbox.mId;
|
||||
@ -305,7 +313,6 @@ public abstract class EmailServiceStub extends IEmailService.Stub implements IEm
|
||||
}
|
||||
|
||||
// Step 1: Get remote mailboxes
|
||||
store = Store.getInstance(account, mContext);
|
||||
final Folder[] remoteFolders = store.updateFolders();
|
||||
final HashSet<String> remoteFolderNames = new HashSet<String>();
|
||||
for (final Folder remoteFolder : remoteFolders) {
|
||||
|
Loading…
Reference in New Issue
Block a user