mirror of
https://github.com/moparisthebest/k-9
synced 2024-12-25 00:58:50 -05:00
extract out "sync one account"
This commit is contained in:
parent
4f376e8332
commit
36bb10fb2c
@ -264,25 +264,25 @@
|
||||
|
||||
</PreferenceScreen>
|
||||
|
||||
<PreferenceScreen
|
||||
<PreferenceScreen
|
||||
android:title="@string/notifications_title"
|
||||
android:key="notification_preferences">
|
||||
|
||||
<CheckBoxPreference
|
||||
|
||||
<CheckBoxPreference
|
||||
android:key="quiet_time_enabled"
|
||||
android:persistent="false"
|
||||
android:title="@string/quiet_time"
|
||||
android:summary="@string/quiet_time_description"
|
||||
/>
|
||||
<com.fsck.k9.preferences.TimePickerPreference
|
||||
android:key="quiet_time_starts"
|
||||
android:key="quiet_time_starts"
|
||||
android:persistent="false"
|
||||
android:dependency="quiet_time_enabled"
|
||||
android:dialogTitle="@string/quiet_time_starts"
|
||||
android:title="@string/quiet_time_starts"
|
||||
/>
|
||||
<com.fsck.k9.preferences.TimePickerPreference
|
||||
android:key="quiet_time_ends"
|
||||
android:key="quiet_time_ends"
|
||||
android:dependency="quiet_time_enabled"
|
||||
android:persistent="false"
|
||||
android:dialogTitle="@string/quiet_time_ends"
|
||||
|
@ -4283,188 +4283,9 @@ public class MessagingController implements Runnable
|
||||
|
||||
for (final Account account : accounts)
|
||||
{
|
||||
if (!account.isAvailable(context))
|
||||
{
|
||||
if (K9.DEBUG)
|
||||
{
|
||||
Log.i(K9.LOG_TAG, "Skipping synchronizing unavailable account " + account.getDescription());
|
||||
}
|
||||
continue;
|
||||
}
|
||||
final long accountInterval = account.getAutomaticCheckIntervalMinutes() * 60 * 1000;
|
||||
if (!ignoreLastCheckedTime && accountInterval <= 0)
|
||||
{
|
||||
if (K9.DEBUG)
|
||||
Log.i(K9.LOG_TAG, "Skipping synchronizing account " + account.getDescription());
|
||||
continue;
|
||||
}
|
||||
|
||||
if (K9.DEBUG)
|
||||
Log.i(K9.LOG_TAG, "Synchronizing account " + account.getDescription());
|
||||
|
||||
account.setRingNotified(false);
|
||||
|
||||
sendPendingMessages(account, listener);
|
||||
|
||||
try
|
||||
{
|
||||
Account.FolderMode aDisplayMode = account.getFolderDisplayMode();
|
||||
Account.FolderMode aSyncMode = account.getFolderSyncMode();
|
||||
|
||||
Store localStore = account.getLocalStore();
|
||||
for (final Folder folder : localStore.getPersonalNamespaces(false))
|
||||
{
|
||||
|
||||
folder.open(Folder.OpenMode.READ_WRITE);
|
||||
folder.refresh(prefs);
|
||||
|
||||
Folder.FolderClass fDisplayClass = folder.getDisplayClass();
|
||||
Folder.FolderClass fSyncClass = folder.getSyncClass();
|
||||
|
||||
if (modeMismatch(aDisplayMode, fDisplayClass))
|
||||
{
|
||||
// Never sync a folder that isn't displayed
|
||||
/*
|
||||
if (K9.DEBUG)
|
||||
Log.v(K9.LOG_TAG, "Not syncing folder " + folder.getName() +
|
||||
" which is in display mode " + fDisplayClass + " while account is in display mode " + aDisplayMode);
|
||||
*/
|
||||
|
||||
continue;
|
||||
}
|
||||
|
||||
if (modeMismatch(aSyncMode, fSyncClass))
|
||||
{
|
||||
// Do not sync folders in the wrong class
|
||||
/*
|
||||
if (K9.DEBUG)
|
||||
Log.v(K9.LOG_TAG, "Not syncing folder " + folder.getName() +
|
||||
" which is in sync mode " + fSyncClass + " while account is in sync mode " + aSyncMode);
|
||||
*/
|
||||
|
||||
continue;
|
||||
}
|
||||
|
||||
if (K9.DEBUG)
|
||||
Log.v(K9.LOG_TAG, "Folder " + folder.getName() + " was last synced @ " +
|
||||
new Date(folder.getLastChecked()));
|
||||
|
||||
if (!ignoreLastCheckedTime && folder.getLastChecked() >
|
||||
(System.currentTimeMillis() - accountInterval))
|
||||
{
|
||||
if (K9.DEBUG)
|
||||
Log.v(K9.LOG_TAG, "Not syncing folder " + folder.getName()
|
||||
+ ", previously synced @ " + new Date(folder.getLastChecked())
|
||||
+ " which would be too recent for the account period");
|
||||
|
||||
continue;
|
||||
}
|
||||
putBackground("sync" + folder.getName(), null, new Runnable()
|
||||
{
|
||||
public void run()
|
||||
{
|
||||
LocalFolder tLocalFolder = null;
|
||||
try
|
||||
{
|
||||
// In case multiple Commands get enqueued, don't run more than
|
||||
// once
|
||||
final LocalStore localStore = account.getLocalStore();
|
||||
tLocalFolder = localStore.getFolder(folder.getName());
|
||||
tLocalFolder.open(Folder.OpenMode.READ_WRITE);
|
||||
|
||||
if (!ignoreLastCheckedTime && tLocalFolder.getLastChecked() >
|
||||
(System.currentTimeMillis() - accountInterval))
|
||||
{
|
||||
if (K9.DEBUG)
|
||||
Log.v(K9.LOG_TAG, "Not running Command for folder " + folder.getName()
|
||||
+ ", previously synced @ " + new Date(folder.getLastChecked())
|
||||
+ " which would be too recent for the account period");
|
||||
return;
|
||||
}
|
||||
if (account.isShowOngoing())
|
||||
{
|
||||
Notification notif = new Notification(R.drawable.ic_menu_refresh,
|
||||
context.getString(R.string.notification_bg_sync_ticker, account.getDescription(), folder.getName()),
|
||||
System.currentTimeMillis());
|
||||
Intent intent = MessageList.actionHandleFolderIntent(context, account, K9.INBOX);
|
||||
PendingIntent pi = PendingIntent.getActivity(context, 0, intent, 0);
|
||||
notif.setLatestEventInfo(context, context.getString(R.string.notification_bg_sync_title), account.getDescription()
|
||||
+ context.getString(R.string.notification_bg_title_separator) + folder.getName(), pi);
|
||||
notif.flags = Notification.FLAG_ONGOING_EVENT;
|
||||
if (K9.NOTIFICATION_LED_WHILE_SYNCING)
|
||||
{
|
||||
notif.flags |= Notification.FLAG_SHOW_LIGHTS;
|
||||
notif.ledARGB = account.getNotificationSetting().getLedColor();
|
||||
notif.ledOnMS = K9.NOTIFICATION_LED_FAST_ON_TIME;
|
||||
notif.ledOffMS = K9.NOTIFICATION_LED_FAST_OFF_TIME;
|
||||
}
|
||||
|
||||
notifMgr.notify(K9.FETCHING_EMAIL_NOTIFICATION - account.getAccountNumber(), notif);
|
||||
}
|
||||
try
|
||||
{
|
||||
synchronizeMailboxSynchronous(account, folder.getName(), listener, null);
|
||||
}
|
||||
finally
|
||||
{
|
||||
if (account.isShowOngoing())
|
||||
{
|
||||
notifMgr.cancel(K9.FETCHING_EMAIL_NOTIFICATION - account.getAccountNumber());
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
|
||||
Log.e(K9.LOG_TAG, "Exception while processing folder " +
|
||||
account.getDescription() + ":" + folder.getName(), e);
|
||||
addErrorMessage(account, null, e);
|
||||
}
|
||||
finally
|
||||
{
|
||||
if (tLocalFolder != null)
|
||||
{
|
||||
tLocalFolder.close();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
);
|
||||
}
|
||||
}
|
||||
catch (MessagingException e)
|
||||
{
|
||||
Log.e(K9.LOG_TAG, "Unable to synchronize account " + account.getName(), e);
|
||||
addErrorMessage(account, null, e);
|
||||
}
|
||||
finally
|
||||
{
|
||||
putBackground("clear notification flag for " + account.getDescription(), null, new Runnable()
|
||||
{
|
||||
public void run()
|
||||
{
|
||||
if (K9.DEBUG)
|
||||
Log.v(K9.LOG_TAG, "Clearing notification flag for " + account.getDescription());
|
||||
account.setRingNotified(false);
|
||||
try
|
||||
{
|
||||
AccountStats stats = account.getStats(context);
|
||||
if (stats == null || stats.unreadMessageCount == 0)
|
||||
{
|
||||
notifyAccountCancel(context, account);
|
||||
}
|
||||
}
|
||||
catch (MessagingException e)
|
||||
{
|
||||
Log.e(K9.LOG_TAG, "Unable to getUnreadMessageCount for account: " + account, e);
|
||||
}
|
||||
}
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
checkMailForAccount(context, account,ignoreLastCheckedTime, notifMgr, prefs, listener);
|
||||
}
|
||||
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
@ -4495,6 +4316,200 @@ public class MessagingController implements Runnable
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
|
||||
private void checkMailForAccount(final Context context, final Account account,
|
||||
final boolean ignoreLastCheckedTime,
|
||||
final NotificationManager notifMgr,
|
||||
final Preferences prefs,
|
||||
final MessagingListener listener)
|
||||
{
|
||||
if (!account.isAvailable(context))
|
||||
{
|
||||
if (K9.DEBUG)
|
||||
{
|
||||
Log.i(K9.LOG_TAG, "Skipping synchronizing unavailable account " + account.getDescription());
|
||||
}
|
||||
return;
|
||||
}
|
||||
final long accountInterval = account.getAutomaticCheckIntervalMinutes() * 60 * 1000;
|
||||
if (!ignoreLastCheckedTime && accountInterval <= 0)
|
||||
{
|
||||
if (K9.DEBUG)
|
||||
Log.i(K9.LOG_TAG, "Skipping synchronizing account " + account.getDescription());
|
||||
return;
|
||||
}
|
||||
|
||||
if (K9.DEBUG)
|
||||
Log.i(K9.LOG_TAG, "Synchronizing account " + account.getDescription());
|
||||
|
||||
account.setRingNotified(false);
|
||||
|
||||
sendPendingMessages(account, listener);
|
||||
|
||||
try
|
||||
{
|
||||
Account.FolderMode aDisplayMode = account.getFolderDisplayMode();
|
||||
Account.FolderMode aSyncMode = account.getFolderSyncMode();
|
||||
|
||||
Store localStore = account.getLocalStore();
|
||||
for (final Folder folder : localStore.getPersonalNamespaces(false))
|
||||
{
|
||||
|
||||
folder.open(Folder.OpenMode.READ_WRITE);
|
||||
folder.refresh(prefs);
|
||||
|
||||
Folder.FolderClass fDisplayClass = folder.getDisplayClass();
|
||||
Folder.FolderClass fSyncClass = folder.getSyncClass();
|
||||
|
||||
if (modeMismatch(aDisplayMode, fDisplayClass))
|
||||
{
|
||||
// Never sync a folder that isn't displayed
|
||||
/*
|
||||
if (K9.DEBUG)
|
||||
Log.v(K9.LOG_TAG, "Not syncing folder " + folder.getName() +
|
||||
" which is in display mode " + fDisplayClass + " while account is in display mode " + aDisplayMode);
|
||||
*/
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
if (modeMismatch(aSyncMode, fSyncClass))
|
||||
{
|
||||
// Do not sync folders in the wrong class
|
||||
/*
|
||||
if (K9.DEBUG)
|
||||
Log.v(K9.LOG_TAG, "Not syncing folder " + folder.getName() +
|
||||
" which is in sync mode " + fSyncClass + " while account is in sync mode " + aSyncMode);
|
||||
*/
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
if (K9.DEBUG)
|
||||
Log.v(K9.LOG_TAG, "Folder " + folder.getName() + " was last synced @ " +
|
||||
new Date(folder.getLastChecked()));
|
||||
|
||||
if (!ignoreLastCheckedTime && folder.getLastChecked() >
|
||||
(System.currentTimeMillis() - accountInterval))
|
||||
{
|
||||
if (K9.DEBUG)
|
||||
Log.v(K9.LOG_TAG, "Not syncing folder " + folder.getName()
|
||||
+ ", previously synced @ " + new Date(folder.getLastChecked())
|
||||
+ " which would be too recent for the account period");
|
||||
|
||||
return;
|
||||
}
|
||||
putBackground("sync" + folder.getName(), null, new Runnable()
|
||||
{
|
||||
public void run()
|
||||
{
|
||||
LocalFolder tLocalFolder = null;
|
||||
try
|
||||
{
|
||||
// In case multiple Commands get enqueued, don't run more than
|
||||
// once
|
||||
final LocalStore localStore = account.getLocalStore();
|
||||
tLocalFolder = localStore.getFolder(folder.getName());
|
||||
tLocalFolder.open(Folder.OpenMode.READ_WRITE);
|
||||
|
||||
if (!ignoreLastCheckedTime && tLocalFolder.getLastChecked() >
|
||||
(System.currentTimeMillis() - accountInterval))
|
||||
{
|
||||
if (K9.DEBUG)
|
||||
Log.v(K9.LOG_TAG, "Not running Command for folder " + folder.getName()
|
||||
+ ", previously synced @ " + new Date(folder.getLastChecked())
|
||||
+ " which would be too recent for the account period");
|
||||
return;
|
||||
}
|
||||
if (account.isShowOngoing())
|
||||
{
|
||||
Notification notif = new Notification(R.drawable.ic_menu_refresh,
|
||||
context.getString(R.string.notification_bg_sync_ticker, account.getDescription(), folder.getName()),
|
||||
System.currentTimeMillis());
|
||||
Intent intent = MessageList.actionHandleFolderIntent(context, account, K9.INBOX);
|
||||
PendingIntent pi = PendingIntent.getActivity(context, 0, intent, 0);
|
||||
notif.setLatestEventInfo(context, context.getString(R.string.notification_bg_sync_title), account.getDescription()
|
||||
+ context.getString(R.string.notification_bg_title_separator) + folder.getName(), pi);
|
||||
notif.flags = Notification.FLAG_ONGOING_EVENT;
|
||||
if (K9.NOTIFICATION_LED_WHILE_SYNCING)
|
||||
{
|
||||
notif.flags |= Notification.FLAG_SHOW_LIGHTS;
|
||||
notif.ledARGB = account.getNotificationSetting().getLedColor();
|
||||
notif.ledOnMS = K9.NOTIFICATION_LED_FAST_ON_TIME;
|
||||
notif.ledOffMS = K9.NOTIFICATION_LED_FAST_OFF_TIME;
|
||||
}
|
||||
|
||||
notifMgr.notify(K9.FETCHING_EMAIL_NOTIFICATION - account.getAccountNumber(), notif);
|
||||
}
|
||||
try
|
||||
{
|
||||
synchronizeMailboxSynchronous(account, folder.getName(), listener, null);
|
||||
}
|
||||
finally
|
||||
{
|
||||
if (account.isShowOngoing())
|
||||
{
|
||||
notifMgr.cancel(K9.FETCHING_EMAIL_NOTIFICATION - account.getAccountNumber());
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
|
||||
Log.e(K9.LOG_TAG, "Exception while processing folder " +
|
||||
account.getDescription() + ":" + folder.getName(), e);
|
||||
addErrorMessage(account, null, e);
|
||||
}
|
||||
finally
|
||||
{
|
||||
if (tLocalFolder != null)
|
||||
{
|
||||
tLocalFolder.close();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
);
|
||||
}
|
||||
}
|
||||
catch (MessagingException e)
|
||||
{
|
||||
Log.e(K9.LOG_TAG, "Unable to synchronize account " + account.getName(), e);
|
||||
addErrorMessage(account, null, e);
|
||||
}
|
||||
finally
|
||||
{
|
||||
putBackground("clear notification flag for " + account.getDescription(), null, new Runnable()
|
||||
{
|
||||
public void run()
|
||||
{
|
||||
if (K9.DEBUG)
|
||||
Log.v(K9.LOG_TAG, "Clearing notification flag for " + account.getDescription());
|
||||
account.setRingNotified(false);
|
||||
try
|
||||
{
|
||||
AccountStats stats = account.getStats(context);
|
||||
if (stats == null || stats.unreadMessageCount == 0)
|
||||
{
|
||||
notifyAccountCancel(context, account);
|
||||
}
|
||||
}
|
||||
catch (MessagingException e)
|
||||
{
|
||||
Log.e(K9.LOG_TAG, "Unable to getUnreadMessageCount for account: " + account, e);
|
||||
}
|
||||
}
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
public void compact(final Account account, final MessagingListener ml)
|
||||
{
|
||||
putBackground("compact:" + account.getDescription(), ml, new Runnable()
|
||||
|
@ -224,5 +224,5 @@ public abstract class Message implements Part, Body
|
||||
MessageReference tmpReference = makeMessageReference();
|
||||
return tmpReference.equals(ref);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user