Auto extend sync period

pull/147/head
M66B 6 years ago
parent 8c3e1bba4d
commit 189655b39f

File diff suppressed because it is too large Load Diff

@ -47,7 +47,7 @@ import io.requery.android.database.sqlite.RequerySQLiteOpenHelperFactory;
// https://developer.android.com/topic/libraries/architecture/room.html
@Database(
version = 28,
version = 29,
entities = {
EntityIdentity.class,
EntityAccount.class,
@ -366,6 +366,13 @@ public abstract class DB extends RoomDatabase {
}
}
})
.addMigrations(new Migration(28, 29) {
@Override
public void migrate(SupportSQLiteDatabase db) {
Log.i("DB migration from version " + startVersion + " to " + endVersion);
db.execSQL("ALTER TABLE `folder` ADD COLUMN `last_sync` INTEGER");
}
})
.build();
}

@ -191,6 +191,9 @@ public interface DaoFolder {
@Query("UPDATE folder SET initialize = 0 WHERE id = :id")
int setFolderInitialized(long id);
@Query("UPDATE folder SET last_sync = :last_sync WHERE id = :id")
int setFolderSync(long id, long last_sync);
@Query("UPDATE folder SET tbc = 0 WHERE id = :id")
int resetFolderTbc(long id);

@ -91,6 +91,7 @@ public class EntityFolder implements Serializable {
public String state;
public String sync_state;
public String error;
public Long last_sync;
static final String INBOX = "Inbox";
static final String OUTBOX = "Outbox";
@ -197,7 +198,8 @@ public class EntityFolder implements Serializable {
(this.tbd == null ? other.tbd == null : this.tbd.equals(other.tbd)) &&
(this.state == null ? other.state == null : this.state.equals(other.state)) &&
(this.sync_state == null ? other.sync_state == null : this.sync_state.equals(other.sync_state)) &&
(this.error == null ? other.error == null : this.error.equals(other.error)));
(this.error == null ? other.error == null : this.error.equals(other.error)) &&
(this.last_sync == null ? other.last_sync == null : this.last_sync.equals(other.last_sync)));
} else
return false;
}

@ -92,9 +92,18 @@ public class EntityOperation {
static void sync(DB db, long fid) {
if (db.operation().getOperationCount(fid, EntityOperation.SYNC) == 0) {
EntityFolder folder = db.folder().getFolder(fid);
int sync_days = folder.sync_days;
if (folder.last_sync != null) {
int ago_days = (int) ((new Date().getTime() - folder.last_sync) / (24 * 3600 * 1000L)) + 1;
if (ago_days > sync_days)
sync_days = ago_days;
}
JSONArray jargs = new JSONArray();
jargs.put(folder.initialize ? Math.min(EntityFolder.DEFAULT_INIT, folder.keep_days) : folder.sync_days);
jargs.put(folder.initialize ? Math.min(EntityFolder.DEFAULT_INIT, folder.keep_days) : sync_days);
jargs.put(folder.keep_days);
jargs.put(folder.download);

@ -2248,6 +2248,7 @@ public class ServiceSynchronize extends LifecycleService {
if (state.running)
db.folder().setFolderInitialized(folder.id);
db.folder().setFolderSync(folder.id, new Date().getTime());
db.folder().setFolderError(folder.id, null);
} finally {

Loading…
Cancel
Save