Reenable Load More Messages for IMAP/POP
* Properly reset all mailbox limit values * When load more messages is clicked, increment limit and resync * Also fixed a race condition in provider Resolves bug 2065626 Change-Id: If50f25a5cb3b549b3acc48406c78533ad86ed4d5
This commit is contained in:
parent
bfe94e6eaa
commit
77398c4289
|
@ -21,8 +21,10 @@ import com.android.email.mail.Store;
|
|||
import com.android.email.provider.AttachmentProvider;
|
||||
import com.android.email.provider.EmailContent;
|
||||
import com.android.email.provider.EmailContent.Account;
|
||||
import com.android.email.provider.EmailContent.AccountColumns;
|
||||
import com.android.email.provider.EmailContent.Attachment;
|
||||
import com.android.email.provider.EmailContent.Mailbox;
|
||||
import com.android.email.provider.EmailContent.MailboxColumns;
|
||||
import com.android.email.provider.EmailContent.Message;
|
||||
import com.android.email.service.EmailServiceProxy;
|
||||
import com.android.exchange.EmailServiceStatus;
|
||||
|
@ -394,6 +396,46 @@ public class Controller {
|
|||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Reset visible limits for all accounts.
|
||||
* For each account:
|
||||
* look up limit
|
||||
* write limit into all mailboxes for that account
|
||||
*/
|
||||
public void resetVisibleLimits() {
|
||||
new Thread() {
|
||||
@Override
|
||||
public void run() {
|
||||
ContentResolver resolver = mContext.getContentResolver();
|
||||
Cursor c = null;
|
||||
try {
|
||||
c = resolver.query(
|
||||
Account.CONTENT_URI,
|
||||
Account.ID_PROJECTION,
|
||||
null, null, null);
|
||||
while (c.moveToNext()) {
|
||||
long accountId = c.getLong(Account.ID_PROJECTION_COLUMN);
|
||||
Account account = Account.restoreAccountWithId(mContext, accountId);
|
||||
if (account != null) {
|
||||
Store.StoreInfo info = Store.StoreInfo.getStoreInfo(
|
||||
account.getStoreUri(mContext), mContext);
|
||||
if (info != null && info.mVisibleLimitDefault > 0) {
|
||||
int limit = info.mVisibleLimitDefault;
|
||||
ContentValues cv = new ContentValues();
|
||||
cv.put(MailboxColumns.VISIBLE_LIMIT, limit);
|
||||
resolver.update(Mailbox.CONTENT_URI, cv,
|
||||
MailboxColumns.ACCOUNT_KEY + "=?",
|
||||
new String[] { Long.toString(accountId) });
|
||||
}
|
||||
}
|
||||
}
|
||||
} finally {
|
||||
c.close();
|
||||
}
|
||||
}
|
||||
}.start();
|
||||
}
|
||||
|
||||
/**
|
||||
* Increase the load count for a given mailbox, and trigger a refresh. Applies only to
|
||||
* IMAP and POP.
|
||||
|
@ -401,8 +443,33 @@ public class Controller {
|
|||
* @param mailboxId the mailbox
|
||||
* @param callback
|
||||
*/
|
||||
public void loadMoreMessages(long mailboxId, Result callback) {
|
||||
//...
|
||||
public void loadMoreMessages(final long mailboxId, Result callback) {
|
||||
new Thread() {
|
||||
@Override
|
||||
public void run() {
|
||||
Mailbox mailbox = Mailbox.restoreMailboxWithId(mContext, mailboxId);
|
||||
if (mailbox == null) {
|
||||
return;
|
||||
}
|
||||
Account account = Account.restoreAccountWithId(mContext, mailbox.mAccountKey);
|
||||
if (account == null) {
|
||||
return;
|
||||
}
|
||||
Store.StoreInfo info = Store.StoreInfo.getStoreInfo(
|
||||
account.getStoreUri(mContext), mContext);
|
||||
if (info != null && info.mVisibleLimitIncrement > 0) {
|
||||
// Use provider math to increment the field
|
||||
ContentValues cv = new ContentValues();;
|
||||
cv.put(EmailContent.FIELD_COLUMN_NAME, MailboxColumns.VISIBLE_LIMIT);
|
||||
cv.put(EmailContent.ADD_COLUMN_NAME, info.mVisibleLimitIncrement);
|
||||
Uri uri = ContentUris.withAppendedId(Mailbox.ADD_TO_FIELD_URI, mailboxId);
|
||||
mContext.getContentResolver().update(uri, cv, null, null);
|
||||
// Trigger a refresh using the new, longer limit
|
||||
mailbox.mVisibleLimit += info.mVisibleLimitIncrement;
|
||||
mLegacyController.synchronizeMailbox(account, mailbox, mLegacyListener);
|
||||
}
|
||||
}
|
||||
}.start();
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -207,21 +207,7 @@ public class Email extends Application {
|
|||
DEBUG_SENSITIVE = prefs.getEnableSensitiveLogging();
|
||||
|
||||
// Reset all accounts to default visible window
|
||||
Cursor c = null;
|
||||
try {
|
||||
c = getContentResolver().query(
|
||||
EmailContent.Account.CONTENT_URI,
|
||||
EmailContent.Account.CONTENT_PROJECTION,
|
||||
null, null, null);
|
||||
while (c.moveToNext()) {
|
||||
EmailContent.Account account = EmailContent.getContent(c, EmailContent.Account.class);
|
||||
MessagingController.getInstance(this).resetVisibleLimits(account);
|
||||
}
|
||||
} finally {
|
||||
if (c != null) {
|
||||
c.close();
|
||||
}
|
||||
}
|
||||
Controller.getInstance(this).resetVisibleLimits();
|
||||
|
||||
/*
|
||||
* We have to give MimeMessage a temp directory because File.createTempFile(String, String)
|
||||
|
|
|
@ -447,50 +447,6 @@ public class MessagingController implements Runnable {
|
|||
}
|
||||
*/
|
||||
|
||||
/**
|
||||
* Increase the window size for a given mailbox, and load more from server.
|
||||
*/
|
||||
public void loadMoreMessages(EmailContent.Account account, EmailContent.Mailbox folder,
|
||||
MessagingListener listener) {
|
||||
|
||||
// TODO redo implementation
|
||||
/*
|
||||
try {
|
||||
Store.StoreInfo info = Store.StoreInfo.getStoreInfo(account.getStoreUri(mContext),
|
||||
mContext);
|
||||
LocalStore localStore = (LocalStore) Store.getInstance(
|
||||
account.getLocalStoreUri(mContext), mContext, null);
|
||||
LocalFolder localFolder = (LocalFolder) localStore.getFolder(folder);
|
||||
int oldLimit = localFolder.getVisibleLimit();
|
||||
if (oldLimit <= 0) {
|
||||
oldLimit = info.mVisibleLimitDefault;
|
||||
}
|
||||
localFolder.setVisibleLimit(oldLimit + info.mVisibleLimitIncrement);
|
||||
synchronizeMailbox(account, folder, listener);
|
||||
}
|
||||
catch (MessagingException me) {
|
||||
throw new RuntimeException("Unable to set visible limit on folder", me);
|
||||
}
|
||||
*/
|
||||
}
|
||||
|
||||
public void resetVisibleLimits(EmailContent.Account account) {
|
||||
try {
|
||||
Store.StoreInfo info = Store.StoreInfo.getStoreInfo(account.getStoreUri(mContext),
|
||||
mContext);
|
||||
// check for null to handle semi-initialized accounts created during unit tests
|
||||
// store info should not be null in production scenarios
|
||||
if (info != null) {
|
||||
LocalStore localStore = (LocalStore) Store.getInstance(
|
||||
account.getLocalStoreUri(mContext), mContext, null);
|
||||
localStore.resetVisibleLimits(info.mVisibleLimitDefault);
|
||||
}
|
||||
}
|
||||
catch (MessagingException e) {
|
||||
Log.e(Email.LOG_TAG, "Unable to reset visible limits", e);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Start background synchronization of the specified folder.
|
||||
* @param account
|
||||
|
@ -679,13 +635,11 @@ public class MessagingController implements Runnable {
|
|||
int remoteMessageCount = remoteFolder.getMessageCount();
|
||||
|
||||
// 6. Determine the limit # of messages to download
|
||||
// TODO decide where to persist the visible limit (account?) until we switch UI model
|
||||
int visibleLimit = -1; // localFolder.getVisibleLimit();
|
||||
int visibleLimit = folder.mVisibleLimit;
|
||||
if (visibleLimit <= 0) {
|
||||
Store.StoreInfo info = Store.StoreInfo.getStoreInfo(account.getStoreUri(mContext),
|
||||
mContext);
|
||||
visibleLimit = info.mVisibleLimitDefault;
|
||||
// localFolder.setVisibleLimit(visibleLimit);
|
||||
}
|
||||
|
||||
// 7. Create a list of messages to download
|
||||
|
|
|
@ -797,6 +797,7 @@ public class MessageList extends ListActivity implements OnItemClickListener, On
|
|||
break;
|
||||
case LIST_FOOTER_MODE_MORE:
|
||||
onLoadMoreMessages();
|
||||
break;
|
||||
case LIST_FOOTER_MODE_SEND:
|
||||
onSendPendingMessages();
|
||||
break;
|
||||
|
|
|
@ -513,7 +513,7 @@ public class EmailProvider extends ContentProvider {
|
|||
private SQLiteDatabase mBodyDatabase;
|
||||
private boolean mInTransaction = false;
|
||||
|
||||
public SQLiteDatabase getDatabase(Context context) {
|
||||
public synchronized SQLiteDatabase getDatabase(Context context) {
|
||||
if (mDatabase != null) {
|
||||
return mDatabase;
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue