Refactoring

pull/207/head
M66B 3 years ago
parent 1c9dec0467
commit d4b48bceda

@ -305,6 +305,56 @@ public class EntityFolder extends EntityOrder implements Serializable {
return (sync < 0 || EntityFolder.SYSTEM_FOLDER_POLL.get(sync));
}
static List<EntityFolder> getPopFolders(Context context) {
List<EntityFolder> result = new ArrayList<>();
EntityFolder inbox = new EntityFolder();
inbox.name = "INBOX";
inbox.type = EntityFolder.INBOX;
inbox.synchronize = true;
inbox.unified = true;
inbox.notify = true;
inbox.sync_days = Integer.MAX_VALUE;
inbox.keep_days = Integer.MAX_VALUE;
inbox.initialize = 0;
result.add(inbox);
EntityFolder drafts = new EntityFolder();
drafts.name = context.getString(R.string.title_folder_drafts);
drafts.type = EntityFolder.DRAFTS;
drafts.synchronize = false;
drafts.unified = false;
drafts.notify = false;
drafts.sync_days = Integer.MAX_VALUE;
drafts.keep_days = Integer.MAX_VALUE;
drafts.initialize = 0;
result.add(drafts);
EntityFolder sent = new EntityFolder();
sent.name = context.getString(R.string.title_folder_sent);
sent.type = EntityFolder.SENT;
sent.synchronize = false;
sent.unified = false;
sent.notify = false;
sent.sync_days = Integer.MAX_VALUE;
sent.keep_days = Integer.MAX_VALUE;
sent.initialize = 0;
result.add(sent);
EntityFolder trash = new EntityFolder();
trash.name = context.getString(R.string.title_folder_trash);
trash.type = EntityFolder.TRASH;
trash.synchronize = false;
trash.unified = false;
trash.notify = false;
trash.sync_days = Integer.MAX_VALUE;
trash.keep_days = Integer.MAX_VALUE;
trash.initialize = 0;
result.add(trash);
return result;
}
static EntityFolder getOutbox() {
EntityFolder outbox = new EntityFolder();
outbox.name = "OUTBOX";

@ -558,67 +558,16 @@ public class FragmentPop extends FragmentBase {
account.deleteNotificationChannel(context);
}
EntityFolder inbox = db.folder().getFolderByType(account.id, EntityFolder.INBOX);
if (inbox == null) {
inbox = new EntityFolder();
inbox.account = account.id;
inbox.name = "INBOX";
inbox.type = EntityFolder.INBOX;
inbox.synchronize = true;
inbox.unified = true;
inbox.notify = true;
inbox.sync_days = Integer.MAX_VALUE;
inbox.keep_days = Integer.MAX_VALUE;
inbox.initialize = 0;
inbox.id = db.folder().insertFolder(inbox);
if (account.synchronize)
EntityOperation.sync(context, inbox.id, true);
}
EntityFolder drafts = db.folder().getFolderByType(account.id, EntityFolder.DRAFTS);
if (drafts == null) {
drafts = new EntityFolder();
drafts.account = account.id;
drafts.name = context.getString(R.string.title_folder_drafts);
drafts.type = EntityFolder.DRAFTS;
drafts.synchronize = false;
drafts.unified = false;
drafts.notify = false;
drafts.sync_days = Integer.MAX_VALUE;
drafts.keep_days = Integer.MAX_VALUE;
drafts.initialize = 0;
drafts.id = db.folder().insertFolder(drafts);
}
EntityFolder sent = db.folder().getFolderByType(account.id, EntityFolder.SENT);
if (sent == null) {
sent = new EntityFolder();
sent.account = account.id;
sent.name = context.getString(R.string.title_folder_sent);
sent.type = EntityFolder.SENT;
sent.synchronize = false;
sent.unified = false;
sent.notify = false;
sent.sync_days = Integer.MAX_VALUE;
sent.keep_days = Integer.MAX_VALUE;
sent.initialize = 0;
sent.id = db.folder().insertFolder(sent);
}
EntityFolder trash = db.folder().getFolderByType(account.id, EntityFolder.TRASH);
if (trash == null) {
trash = new EntityFolder();
trash.account = account.id;
trash.name = context.getString(R.string.title_folder_trash);
trash.type = EntityFolder.TRASH;
trash.synchronize = false;
trash.unified = false;
trash.notify = false;
trash.sync_days = Integer.MAX_VALUE;
trash.keep_days = Integer.MAX_VALUE;
trash.initialize = 0;
trash.id = db.folder().insertFolder(trash);
for (EntityFolder folder : EntityFolder.getPopFolders(context)) {
EntityFolder existing = db.folder().getFolderByType(account.id, folder.type);
if (existing == null) {
folder.account = account.id;
folder.id = db.folder().insertFolder(folder);
existing = folder;
}
if (account.synchronize && existing.synchronize)
EntityOperation.sync(context, existing.id, true);
}
db.setTransactionSuccessful();

Loading…
Cancel
Save