|
|
|
@ -45,25 +45,7 @@ public class WorkerPoll extends Worker {
|
|
|
|
|
public Result doWork() {
|
|
|
|
|
Log.i("Running " + getName());
|
|
|
|
|
|
|
|
|
|
DB db = DB.getInstance(getApplicationContext());
|
|
|
|
|
try {
|
|
|
|
|
db.beginTransaction();
|
|
|
|
|
|
|
|
|
|
List<EntityAccount> accounts = db.account().getSynchronizingAccounts();
|
|
|
|
|
for (EntityAccount account : accounts) {
|
|
|
|
|
List<EntityFolder> folders = db.folder().getSynchronizingFolders(account.id);
|
|
|
|
|
if (folders.size() > 0)
|
|
|
|
|
Collections.sort(folders, folders.get(0).getComparator(getApplicationContext()));
|
|
|
|
|
for (EntityFolder folder : folders)
|
|
|
|
|
EntityOperation.sync(getApplicationContext(), folder.id, false);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
db.setTransactionSuccessful();
|
|
|
|
|
} finally {
|
|
|
|
|
db.endTransaction();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
ServiceSynchronize.eval(getApplicationContext(), false, "refresh/poll");
|
|
|
|
|
sync(getApplicationContext());
|
|
|
|
|
|
|
|
|
|
return Result.success();
|
|
|
|
|
}
|
|
|
|
@ -94,6 +76,28 @@ public class WorkerPoll extends Worker {
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void sync(Context context) {
|
|
|
|
|
DB db = DB.getInstance(context);
|
|
|
|
|
try {
|
|
|
|
|
db.beginTransaction();
|
|
|
|
|
|
|
|
|
|
List<EntityAccount> accounts = db.account().getSynchronizingAccounts();
|
|
|
|
|
for (EntityAccount account : accounts) {
|
|
|
|
|
List<EntityFolder> folders = db.folder().getSynchronizingFolders(account.id);
|
|
|
|
|
if (folders.size() > 0)
|
|
|
|
|
Collections.sort(folders, folders.get(0).getComparator(context));
|
|
|
|
|
for (EntityFolder folder : folders)
|
|
|
|
|
EntityOperation.sync(context, folder.id, false);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
db.setTransactionSuccessful();
|
|
|
|
|
} finally {
|
|
|
|
|
db.endTransaction();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
ServiceSynchronize.eval(context, false, "refresh/poll");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private static String getName() {
|
|
|
|
|
return WorkerPoll.class.getSimpleName();
|
|
|
|
|
}
|
|
|
|
|