Implemented external poll

pull/169/head
M66B 5 years ago
parent 14628c4d22
commit 252ffa8ee4

@ -76,7 +76,13 @@ public class ServiceExternal extends Service {
String action = intent.getAction();
if (ACTION_POLL.equals(action)) {
// TODO: sync all
final Context context = getApplicationContext();
executor.submit(new Runnable() {
@Override
public void run() {
WorkerPoll.sync(context);
}
});
return START_NOT_STICKY;
}

@ -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();
}

Loading…
Cancel
Save