Added settings for days to sync/keep

This commit is contained in:
M66B 2018-11-14 10:49:59 +01:00
parent 172a1851fd
commit 85f860467d
11 changed files with 1163 additions and 301 deletions

File diff suppressed because it is too large Load Diff

View File

@ -137,7 +137,7 @@ public class AdapterFolder extends RecyclerView.Adapter<AdapterFolder.ViewHolder
tvAfter.setText(null);
ivSync.setImageResource(R.drawable.baseline_sync_24);
} else {
tvAfter.setText(Integer.toString(folder.after));
tvAfter.setText(String.format("%d/%d", folder.sync_days, folder.keep_days));
ivSync.setImageResource(folder.synchronize ? R.drawable.baseline_sync_24 : R.drawable.baseline_sync_disabled_24);
}

View File

@ -46,7 +46,7 @@ import io.requery.android.database.sqlite.RequerySQLiteOpenHelperFactory;
// https://developer.android.com/topic/libraries/architecture/room.html
@Database(
version = 1,
version = 2,
entities = {
EntityIdentity.class,
EntityAccount.class,
@ -124,267 +124,9 @@ public abstract class DB extends RoomDatabase {
@Override
public void migrate(SupportSQLiteDatabase db) {
Log.i(Helper.TAG, "DB migration from version " + startVersion + " to " + endVersion);
db.execSQL("ALTER TABLE `account` ADD COLUMN `poll_interval` INTEGER NOT NULL DEFAULT 9");
}
})
.addMigrations(new Migration(2, 3) {
@Override
public void migrate(SupportSQLiteDatabase db) {
Log.i(Helper.TAG, "DB migration from version " + startVersion + " to " + endVersion);
db.execSQL("ALTER TABLE `identity` ADD COLUMN `store_sent` INTEGER NOT NULL DEFAULT 0");
}
})
.addMigrations(new Migration(3, 4) {
@Override
public void migrate(SupportSQLiteDatabase db) {
Log.i(Helper.TAG, "DB migration from version " + startVersion + " to " + endVersion);
db.execSQL("CREATE TABLE IF NOT EXISTS `answer` (`id` INTEGER PRIMARY KEY AUTOINCREMENT, `name` TEXT NOT NULL, `text` TEXT NOT NULL)");
}
})
.addMigrations(new Migration(4, 5) {
@Override
public void migrate(SupportSQLiteDatabase db) {
Log.i(Helper.TAG, "DB migration from version " + startVersion + " to " + endVersion);
db.execSQL("ALTER TABLE `account` ADD COLUMN `auth_type` INTEGER NOT NULL DEFAULT 1");
db.execSQL("ALTER TABLE `identity` ADD COLUMN `auth_type` INTEGER NOT NULL DEFAULT 1");
}
})
.addMigrations(new Migration(5, 6) {
@Override
public void migrate(SupportSQLiteDatabase db) {
Log.i(Helper.TAG, "DB migration from version " + startVersion + " to " + endVersion);
db.execSQL("ALTER TABLE `message` ADD COLUMN `ui_found` INTEGER NOT NULL DEFAULT 0");
}
})
.addMigrations(new Migration(6, 7) {
@Override
public void migrate(SupportSQLiteDatabase db) {
Log.i(Helper.TAG, "DB migration from version " + startVersion + " to " + endVersion);
db.execSQL("CREATE TABLE IF NOT EXISTS `log` (`id` INTEGER PRIMARY KEY AUTOINCREMENT, `time` INTEGER NOT NULL, `data` TEXT NOT NULL)");
db.execSQL("CREATE INDEX `index_log_time` ON `log` (`time`)");
}
})
.addMigrations(new Migration(7, 8) {
@Override
public void migrate(SupportSQLiteDatabase db) {
Log.i(Helper.TAG, "DB migration from version " + startVersion + " to " + endVersion);
db.execSQL("CREATE INDEX `index_message_ui_found` ON `message` (`ui_found`)");
}
})
.addMigrations(new Migration(8, 9) {
@Override
public void migrate(SupportSQLiteDatabase db) {
Log.i(Helper.TAG, "DB migration from version " + startVersion + " to " + endVersion);
db.execSQL("ALTER TABLE `message` ADD COLUMN `headers` TEXT");
}
})
.addMigrations(new Migration(9, 10) {
@Override
public void migrate(SupportSQLiteDatabase db) {
Log.i(Helper.TAG, "DB migration from version " + startVersion + " to " + endVersion);
db.execSQL("ALTER TABLE `folder` ADD COLUMN `unified` INTEGER NOT NULL DEFAULT 0");
db.execSQL("CREATE INDEX `index_folder_unified` ON `folder` (`unified`)");
db.execSQL("UPDATE `folder` SET unified = 1 WHERE type = '" + EntityFolder.INBOX + "'");
}
})
.addMigrations(new Migration(10, 11) {
@Override
public void migrate(SupportSQLiteDatabase db) {
Log.i(Helper.TAG, "DB migration from version " + startVersion + " to " + endVersion);
db.execSQL("ALTER TABLE `account` ADD COLUMN `signature` TEXT");
}
})
.addMigrations(new Migration(11, 12) {
@Override
public void migrate(SupportSQLiteDatabase db) {
Log.i(Helper.TAG, "DB migration from version " + startVersion + " to " + endVersion);
db.execSQL("ALTER TABLE `message` ADD COLUMN `flagged` INTEGER NOT NULL DEFAULT 0");
db.execSQL("ALTER TABLE `message` ADD COLUMN `ui_flagged` INTEGER NOT NULL DEFAULT 0");
}
})
.addMigrations(new Migration(12, 13) {
@Override
public void migrate(SupportSQLiteDatabase db) {
Log.i(Helper.TAG, "DB migration from version " + startVersion + " to " + endVersion);
db.execSQL("ALTER TABLE `message` ADD COLUMN `avatar` TEXT");
}
})
.addMigrations(new Migration(13, 14) {
@Override
public void migrate(SupportSQLiteDatabase db) {
Log.i(Helper.TAG, "DB migration from version " + startVersion + " to " + endVersion);
db.execSQL("ALTER TABLE `account` ADD COLUMN `color` INTEGER");
}
})
.addMigrations(new Migration(14, 15) {
@Override
public void migrate(SupportSQLiteDatabase db) {
Log.i(Helper.TAG, "DB migration from version " + startVersion + " to " + endVersion);
db.execSQL("ALTER TABLE `attachment` ADD COLUMN `cid` TEXT");
db.execSQL("CREATE UNIQUE INDEX `index_attachment_message_cid` ON `attachment` (`message`, `cid`)");
}
})
.addMigrations(new Migration(15, 16) {
@Override
public void migrate(SupportSQLiteDatabase db) {
Log.i(Helper.TAG, "DB migration from version " + startVersion + " to " + endVersion);
db.execSQL("ALTER TABLE `message` ADD COLUMN `size` INTEGER");
db.execSQL("ALTER TABLE `message` ADD COLUMN `content` INTEGER NOT NULL DEFAULT 1");
}
})
.addMigrations(new Migration(16, 17) {
@Override
public void migrate(SupportSQLiteDatabase db) {
Log.i(Helper.TAG, "DB migration from version " + startVersion + " to " + endVersion);
db.execSQL("ALTER TABLE `message` ADD COLUMN `deliveredto` TEXT");
}
})
.addMigrations(new Migration(17, 18) {
@Override
public void migrate(SupportSQLiteDatabase db) {
Log.i(Helper.TAG, "DB migration from version " + startVersion + " to " + endVersion);
db.execSQL("ALTER TABLE `folder` ADD COLUMN `display` TEXT");
}
})
.addMigrations(new Migration(18, 19) {
@Override
public void migrate(SupportSQLiteDatabase db) {
Log.i(Helper.TAG, "DB migration from version " + startVersion + " to " + endVersion);
db.execSQL("ALTER TABLE `folder` ADD COLUMN `hide` INTEGER NOT NULL DEFAULT 0");
}
})
.addMigrations(new Migration(19, 20) {
@Override
public void migrate(SupportSQLiteDatabase db) {
Log.i(Helper.TAG, "DB migration from version " + startVersion + " to " + endVersion);
db.execSQL("ALTER TABLE `folder` ADD COLUMN `poll_interval` INTEGER");
}
})
.addMigrations(new Migration(20, 21) {
@Override
public void migrate(SupportSQLiteDatabase db) {
Log.i(Helper.TAG, "DB migration from version " + startVersion + " to " + endVersion);
db.execSQL("ALTER TABLE `message` ADD COLUMN `ui_ignored` INTEGER NOT NULL DEFAULT 0");
db.execSQL("CREATE INDEX `index_message_ui_ignored` ON `message` (`ui_ignored`)");
}
})
.addMigrations(new Migration(21, 22) {
@Override
public void migrate(SupportSQLiteDatabase db) {
Log.i(Helper.TAG, "DB migration from version " + startVersion + " to " + endVersion);
db.execSQL("DROP INDEX `index_message_folder_uid`");
db.execSQL("CREATE UNIQUE INDEX `index_message_folder_uid_ui_found` ON `message` (`folder`, `uid`, `ui_found`)");
db.execSQL("DROP INDEX `index_message_msgid_folder`");
db.execSQL("CREATE UNIQUE INDEX `index_message_msgid_folder_ui_found` ON `message` (`msgid`, `folder`, `ui_found`)");
}
})
.addMigrations(new Migration(22, 23) {
@Override
public void migrate(SupportSQLiteDatabase db) {
Log.i(Helper.TAG, "DB migration from version " + startVersion + " to " + endVersion);
db.execSQL("ALTER TABLE `account` ADD COLUMN `starttls` INTEGER NOT NULL DEFAULT 0");
db.execSQL("ALTER TABLE `account` ADD COLUMN `insecure` INTEGER NOT NULL DEFAULT 0");
db.execSQL("ALTER TABLE `identity` ADD COLUMN `insecure` INTEGER NOT NULL DEFAULT 0");
}
})
.addMigrations(new Migration(23, 24) {
@Override
public void migrate(SupportSQLiteDatabase db) {
Log.i(Helper.TAG, "DB migration from version " + startVersion + " to " + endVersion);
db.execSQL("ALTER TABLE `message` ADD COLUMN `preview` TEXT");
}
})
.addMigrations(new Migration(24, 25) {
@Override
public void migrate(SupportSQLiteDatabase db) {
Log.i(Helper.TAG, "DB migration from version " + startVersion + " to " + endVersion);
db.execSQL("ALTER TABLE `account` ADD COLUMN `created` INTEGER");
}
})
.addMigrations(new Migration(25, 26) {
@Override
public void migrate(SupportSQLiteDatabase db) {
Log.i(Helper.TAG, "DB migration from version " + startVersion + " to " + endVersion);
db.execSQL("ALTER TABLE `message` ADD COLUMN `extra` TEXT");
}
})
.addMigrations(new Migration(26, 27) {
@Override
public void migrate(SupportSQLiteDatabase db) {
Log.i(Helper.TAG, "DB migration from version " + startVersion + " to " + endVersion);
db.execSQL("ALTER TABLE `identity` ADD COLUMN `color` INTEGER");
db.execSQL("CREATE INDEX `index_identity_account_email` ON `identity` (`account`, `email`)");
}
})
.addMigrations(new Migration(27, 28) {
@Override
public void migrate(SupportSQLiteDatabase db) {
Log.i(Helper.TAG, "DB migration from version " + startVersion + " to " + endVersion);
// https://www.sqlite.org/lang_altertable.html
db.execSQL("PRAGMA foreign_keys=OFF;");
db.execSQL("CREATE TABLE `message_new`" +
" (`id` INTEGER PRIMARY KEY AUTOINCREMENT," +
" `account` INTEGER NOT NULL," +
" `folder` INTEGER NOT NULL," +
" `identity` INTEGER," +
" `extra` TEXT," +
" `replying` INTEGER," +
" `uid` INTEGER," +
" `msgid` TEXT," +
" `references` TEXT," +
" `deliveredto` TEXT," +
" `inreplyto` TEXT," +
" `thread` TEXT," +
" `avatar` TEXT," +
" `from` TEXT," +
" `to` TEXT," +
" `cc` TEXT," +
" `bcc` TEXT," +
" `reply` TEXT," +
" `headers` TEXT," +
" `subject` TEXT," +
" `size` INTEGER," +
" `content` INTEGER NOT NULL," +
" `preview` TEXT," +
" `sent` INTEGER," +
" `received` INTEGER NOT NULL," +
" `stored` INTEGER NOT NULL," +
" `seen` INTEGER NOT NULL," +
" `flagged` INTEGER NOT NULL," +
" `ui_seen` INTEGER NOT NULL," +
" `ui_flagged` INTEGER NOT NULL," +
" `ui_hide` INTEGER NOT NULL," +
" `ui_found` INTEGER NOT NULL," +
" `ui_ignored` INTEGER NOT NULL," +
" `error` TEXT," +
" FOREIGN KEY(`account`) REFERENCES `account`(`id`) ON UPDATE NO ACTION ON DELETE CASCADE ," +
" FOREIGN KEY(`folder`) REFERENCES `folder`(`id`) ON UPDATE NO ACTION ON DELETE CASCADE ," +
" FOREIGN KEY(`identity`) REFERENCES `identity`(`id`) ON UPDATE NO ACTION ON DELETE SET NULL ," +
" FOREIGN KEY(`replying`) REFERENCES `message`(`id`) ON UPDATE NO ACTION ON DELETE SET NULL" +
" )");
db.execSQL("DELETE from `message` WHERE account IS NULL;");
db.execSQL("INSERT INTO `message_new` SELECT * FROM `message`;");
db.execSQL("DROP TABLE `message`;");
db.execSQL("ALTER TABLE `message_new` RENAME TO `message`");
db.execSQL("CREATE INDEX `index_message_account` ON `message` (`account`)");
db.execSQL("CREATE INDEX `index_message_folder` ON `message` (`folder`)");
db.execSQL("CREATE INDEX `index_message_identity` ON `message` (`identity`)");
db.execSQL("CREATE INDEX `index_message_replying` ON `message` (`replying`)");
db.execSQL("CREATE UNIQUE INDEX `index_message_folder_uid_ui_found` ON `message` (`folder`, `uid`, `ui_found`)");
db.execSQL("CREATE UNIQUE INDEX `index_message_msgid_folder_ui_found` ON `message` (`msgid`, `folder`, `ui_found`)");
db.execSQL("CREATE INDEX `index_message_thread` ON `message` (`thread`)");
db.execSQL("CREATE INDEX `index_message_received` ON `message` (`received`)");
db.execSQL("CREATE INDEX `index_message_ui_seen` ON `message` (`ui_seen`)");
db.execSQL("CREATE INDEX `index_message_ui_hide` ON `message` (`ui_hide`)");
db.execSQL("CREATE INDEX `index_message_ui_found` ON `message` (`ui_found`)");
db.execSQL("CREATE INDEX `index_message_ui_ignored` ON `message` (`ui_ignored`)");
db.execSQL("PRAGMA foreign_key_check;");
db.execSQL("PRAGMA foreign_keys=ON;");
db.execSQL("ALTER TABLE `folder` RENAME COLUMN `after` TO `sync_days`");
db.execSQL("ALTER TABLE `folder` ADD COLUMN `keep_days` INTEGER NOT NULL DEFAULT 30");
db.execSQL("UPDATE `folder` SET keep_days = sync_days");
}
})
.build();

View File

@ -132,9 +132,10 @@ public interface DaoFolder {
", hide = :hide" +
", synchronize = :synchronize" +
", unified = :unified" +
", `after` = :after" +
", `sync_days` = :sync_days" +
", `keep_days` = :keep_days" +
" WHERE id = :id")
int setFolderProperties(long id, String name, String display, boolean hide, boolean synchronize, boolean unified, int after);
int setFolderProperties(long id, String name, String display, boolean hide, boolean synchronize, boolean unified, int sync_days, int keep_days);
@Query("UPDATE folder SET name = :name WHERE account = :account AND name = :old")
int renameFolder(long account, String old, String name);

View File

@ -61,7 +61,9 @@ public class EntityFolder implements Serializable {
@NonNull
public Boolean synchronize;
@NonNull
public Integer after; // days
public Integer sync_days;
@NonNull
public Integer keep_days;
public String display;
@NonNull
public Boolean hide = false;
@ -161,7 +163,8 @@ public class EntityFolder implements Serializable {
json.put("name", name);
json.put("type", type);
json.put("synchronize", synchronize);
json.put("after", after);
json.put("sync_days", sync_days);
json.put("keep_days", keep_days);
json.put("display", display);
json.put("hide", hide);
json.put("unified", unified);
@ -173,7 +176,17 @@ public class EntityFolder implements Serializable {
folder.name = json.getString("name");
folder.type = json.getString("type");
folder.synchronize = json.getBoolean("synchronize");
folder.after = json.getInt("after");
if (json.has("after"))
folder.sync_days = json.getInt("after");
else
folder.sync_days = json.getInt("sync_days");
if (json.has("keep_days"))
folder.keep_days = json.getInt("keep_days");
else
folder.keep_days = folder.sync_days;
if (json.has("display"))
folder.display = json.getString("display");
if (json.has("hide"))

View File

@ -521,7 +521,8 @@ public class FragmentAccount extends FragmentEx {
folder.name = ifolder.getFullName();
folder.type = (type == null ? EntityFolder.USER : type);
folder.synchronize = (type != null && EntityFolder.SYSTEM_FOLDER_SYNC.contains(type));
folder.after = (type == null ? EntityFolder.DEFAULT_USER_SYNC : EntityFolder.DEFAULT_SYSTEM_SYNC);
folder.sync_days = (type == null ? EntityFolder.DEFAULT_USER_SYNC : EntityFolder.DEFAULT_SYSTEM_SYNC);
folder.keep_days = folder.sync_days;
}
result.folders.add(folder);
@ -748,7 +749,8 @@ public class FragmentAccount extends FragmentEx {
inbox.type = EntityFolder.INBOX;
inbox.synchronize = true;
inbox.unified = true;
inbox.after = EntityFolder.DEFAULT_INBOX_SYNC;
inbox.sync_days = EntityFolder.DEFAULT_INBOX_SYNC;
inbox.keep_days = inbox.sync_days;
folders.add(inbox);

View File

@ -53,7 +53,8 @@ public class FragmentFolder extends FragmentEx {
private CheckBox cbHide;
private CheckBox cbSynchronize;
private CheckBox cbUnified;
private EditText etAfter;
private EditText etSyncDays;
private EditText etKeepDays;
private Button btnSave;
private ImageButton ibDelete;
private ProgressBar pbSave;
@ -85,7 +86,8 @@ public class FragmentFolder extends FragmentEx {
cbHide = view.findViewById(R.id.cbHide);
cbSynchronize = view.findViewById(R.id.cbSynchronize);
cbUnified = view.findViewById(R.id.cbUnified);
etAfter = view.findViewById(R.id.etAfter);
etSyncDays = view.findViewById(R.id.etSyncDays);
etKeepDays = view.findViewById(R.id.etKeepDays);
btnSave = view.findViewById(R.id.btnSave);
ibDelete = view.findViewById(R.id.ibDelete);
pbSave = view.findViewById(R.id.pbSave);
@ -107,7 +109,8 @@ public class FragmentFolder extends FragmentEx {
args.putBoolean("hide", cbHide.isChecked());
args.putBoolean("unified", cbUnified.isChecked());
args.putBoolean("synchronize", cbSynchronize.isChecked());
args.putString("after", etAfter.getText().toString());
args.putString("sync", etSyncDays.getText().toString());
args.putString("keep", etKeepDays.getText().toString());
new SimpleTask<Void>() {
@Override
@ -119,11 +122,15 @@ public class FragmentFolder extends FragmentEx {
boolean hide = args.getBoolean("hide");
boolean unified = args.getBoolean("unified");
boolean synchronize = args.getBoolean("synchronize");
String after = args.getString("after");
String sync = args.getString("sync");
String keep = args.getString("keep");
if (TextUtils.isEmpty(display) || display.equals(name))
display = null;
int days = (TextUtils.isEmpty(after) ? EntityFolder.DEFAULT_USER_SYNC : Integer.parseInt(after));
int sync_days = (TextUtils.isEmpty(sync) ? EntityFolder.DEFAULT_USER_SYNC : Integer.parseInt(sync));
int keep_days = (TextUtils.isEmpty(keep) ? sync_days : Integer.parseInt(keep));
if (keep_days < sync_days)
keep_days = sync_days;
IMAPStore istore = null;
DB db = DB.getInstance(getContext());
@ -156,7 +163,8 @@ public class FragmentFolder extends FragmentEx {
create.type = EntityFolder.USER;
create.unified = unified;
create.synchronize = synchronize;
create.after = days;
create.sync_days = sync_days;
create.keep_days = keep_days;
db.folder().insertFolder(create);
} else {
Log.i(Helper.TAG, "Renaming folder=" + name);
@ -171,7 +179,7 @@ public class FragmentFolder extends FragmentEx {
if (folder != null) {
Log.i(Helper.TAG, "Updating folder=" + name);
db.folder().setFolderProperties(id, name, display, hide, synchronize, unified, days);
db.folder().setFolderProperties(id, name, display, hide, synchronize, unified, sync_days, keep_days);
if (!synchronize)
db.folder().setFolderError(id, null);
}
@ -319,7 +327,8 @@ public class FragmentFolder extends FragmentEx {
cbHide.setChecked(folder == null ? false : folder.hide);
cbUnified.setChecked(folder == null ? false : folder.unified);
cbSynchronize.setChecked(folder == null || folder.synchronize);
etAfter.setText(Integer.toString(folder == null ? EntityFolder.DEFAULT_USER_SYNC : folder.after));
etSyncDays.setText(Integer.toString(folder == null ? EntityFolder.DEFAULT_USER_SYNC : folder.sync_days));
etKeepDays.setText(Integer.toString(folder == null ? EntityFolder.DEFAULT_USER_SYNC : folder.keep_days));
}
// Consider previous save as cancelled

View File

@ -298,7 +298,8 @@ public class FragmentSetup extends FragmentEx {
outbox.name = "OUTBOX";
outbox.type = EntityFolder.OUTBOX;
outbox.synchronize = false;
outbox.after = 0;
outbox.sync_days = 0;
outbox.keep_days = 0;
outbox.id = db.folder().insertFolder(outbox);
}

View File

@ -1631,7 +1631,8 @@ public class ServiceSynchronize extends LifecycleService {
folder.name = ifolder.getFullName();
folder.type = EntityFolder.USER;
folder.synchronize = false;
folder.after = EntityFolder.DEFAULT_USER_SYNC;
folder.sync_days = EntityFolder.DEFAULT_USER_SYNC;
folder.keep_days = EntityFolder.DEFAULT_USER_SYNC;
db.folder().insertFolder(folder);
Log.i(Helper.TAG, folder.name + " added");
} else {
@ -1657,35 +1658,46 @@ public class ServiceSynchronize extends LifecycleService {
private void synchronizeMessages(EntityAccount account, EntityFolder folder, IMAPFolder ifolder, ServiceState state) throws MessagingException, IOException {
DB db = DB.getInstance(this);
try {
Log.v(Helper.TAG, folder.name + " start sync after=" + folder.after);
Log.v(Helper.TAG, folder.name + " start sync after=" + folder.sync_days + "/" + folder.keep_days);
db.folder().setFolderState(folder.id, "syncing");
// Get reference times
Calendar cal = Calendar.getInstance();
cal.add(Calendar.DAY_OF_MONTH, -folder.after);
cal.set(Calendar.HOUR_OF_DAY, 0);
cal.set(Calendar.MINUTE, 0);
cal.set(Calendar.SECOND, 0);
cal.set(Calendar.MILLISECOND, 0);
Calendar cal_sync = Calendar.getInstance();
cal_sync.add(Calendar.DAY_OF_MONTH, -folder.sync_days);
cal_sync.set(Calendar.HOUR_OF_DAY, 0);
cal_sync.set(Calendar.MINUTE, 0);
cal_sync.set(Calendar.SECOND, 0);
cal_sync.set(Calendar.MILLISECOND, 0);
long ago = cal.getTimeInMillis();
if (ago < 0)
ago = 0;
Calendar cal_keep = Calendar.getInstance();
cal_keep.add(Calendar.DAY_OF_MONTH, -folder.keep_days);
cal_keep.set(Calendar.HOUR_OF_DAY, 0);
cal_keep.set(Calendar.MINUTE, 0);
cal_keep.set(Calendar.SECOND, 0);
cal_keep.set(Calendar.MILLISECOND, 0);
Log.i(Helper.TAG, folder.name + " ago=" + new Date(ago));
long sync = cal_sync.getTimeInMillis();
if (sync < 0)
sync = 0;
long keep = cal_sync.getTimeInMillis();
if (keep < 0)
keep = 0;
Log.i(Helper.TAG, folder.name + " sync=" + new Date(sync) + " keep=" + new Date(keep));
// Delete old local messages
int old = db.message().deleteMessagesBefore(folder.id, ago);
int old = db.message().deleteMessagesBefore(folder.id, keep);
Log.i(Helper.TAG, folder.name + " local old=" + old);
// Get list of local uids
List<Long> uids = db.message().getUids(folder.id, ago);
List<Long> uids = db.message().getUids(folder.id, sync);
Log.i(Helper.TAG, folder.name + " local count=" + uids.size());
// Reduce list of local uids
long search = SystemClock.elapsedRealtime();
Message[] imessages = ifolder.search(new ReceivedDateTerm(ComparisonTerm.GE, new Date(ago)));
Message[] imessages = ifolder.search(new ReceivedDateTerm(ComparisonTerm.GE, new Date(sync)));
Log.i(Helper.TAG, folder.name + " remote count=" + imessages.length +
" search=" + (SystemClock.elapsedRealtime() - search) + " ms");

View File

@ -83,24 +83,44 @@
<!-- after -->
<TextView
android:id="@+id/tvAfter"
android:id="@+id/tvSyncDays"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="12dp"
android:text="@string/title_after"
android:text="@string/title_sync_days"
android:textAppearance="@style/TextAppearance.AppCompat.Small"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/cbSynchronize" />
<EditText
android:id="@+id/etAfter"
android:id="@+id/etSyncDays"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="7"
android:inputType="number"
android:textAppearance="@style/TextAppearance.AppCompat.Medium"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/tvAfter" />
app:layout_constraintTop_toBottomOf="@id/tvSyncDays" />
<TextView
android:id="@+id/tvKeepDays"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="12dp"
android:text="@string/title_keep_days"
android:textAppearance="@style/TextAppearance.AppCompat.Small"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/etSyncDays" />
<EditText
android:id="@+id/etKeepDays"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="7"
android:inputType="number"
android:textAppearance="@style/TextAppearance.AppCompat.Medium"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/tvKeepDays" />
<Button
android:id="@+id/btnSave"
@ -109,7 +129,7 @@
android:layout_marginTop="12dp"
android:text="@string/title_save"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/etAfter" />
app:layout_constraintTop_toBottomOf="@id/etKeepDays" />
<ImageButton
android:id="@+id/ibDelete"
@ -118,7 +138,7 @@
android:layout_marginTop="12dp"
android:src="@drawable/baseline_delete_24"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintTop_toBottomOf="@id/etAfter" />
app:layout_constraintTop_toBottomOf="@id/etKeepDays" />
<ProgressBar
android:id="@+id/pbSave"

View File

@ -174,7 +174,8 @@
<string name="title_show_folders">Show hidden folders</string>
<string name="title_synchronize_folder">Synchronize (receive messages)</string>
<string name="title_unified_folder">Show in unified inbox</string>
<string name="title_after">Synchronize (days)</string>
<string name="title_sync_days">Synchronize messages (days)</string>
<string name="title_keep_days">Keep messages (days)</string>
<string name="title_folder_exists">Folder %1$s exists</string>
<string name="title_folder_delete">Delete folder permanently?</string>