From 659900f6d7eeca495d4faab6c983a61acf005b38 Mon Sep 17 00:00:00 2001 From: M66B Date: Thu, 9 Aug 2018 07:02:41 +0000 Subject: [PATCH] Refactoring --- .../java/eu/faircode/email/AdapterFolder.java | 2 +- .../eu/faircode/email/AdapterMessage.java | 10 ++-- .../java/eu/faircode/email/DaoAccount.java | 2 +- .../java/eu/faircode/email/DaoFolder.java | 6 +-- .../java/eu/faircode/email/DaoMessage.java | 4 +- .../java/eu/faircode/email/EntityFolder.java | 54 +++++++++---------- .../eu/faircode/email/FragmentAccount.java | 6 +-- .../eu/faircode/email/FragmentCompose.java | 2 +- .../eu/faircode/email/FragmentMessage.java | 32 +++++------ .../java/eu/faircode/email/FragmentSetup.java | 2 +- .../eu/faircode/email/ServiceSynchronize.java | 8 +-- 11 files changed, 64 insertions(+), 64 deletions(-) diff --git a/app/src/main/java/eu/faircode/email/AdapterFolder.java b/app/src/main/java/eu/faircode/email/AdapterFolder.java index 5d6c1309..4ad2c034 100644 --- a/app/src/main/java/eu/faircode/email/AdapterFolder.java +++ b/app/src/main/java/eu/faircode/email/AdapterFolder.java @@ -122,7 +122,7 @@ public class AdapterFolder extends RecyclerView.Adapter account.seen_until)" + - " AND folder.type = '" + EntityFolder.TYPE_INBOX + "') AS unseen") + " AND folder.type = '" + EntityFolder.INBOX + "') AS unseen") LiveData liveStats(); @Insert(onConflict = OnConflictStrategy.REPLACE) diff --git a/app/src/main/java/eu/faircode/email/DaoFolder.java b/app/src/main/java/eu/faircode/email/DaoFolder.java index 6f5b3a7a..f8f56a34 100644 --- a/app/src/main/java/eu/faircode/email/DaoFolder.java +++ b/app/src/main/java/eu/faircode/email/DaoFolder.java @@ -36,7 +36,7 @@ public interface DaoFolder { @Query("SELECT * FROM folder WHERE account = :account AND synchronize = :synchronize") List getFolders(long account, boolean synchronize); - @Query("SELECT * FROM folder WHERE account = :account AND type = '" + EntityFolder.TYPE_USER + "'") + @Query("SELECT * FROM folder WHERE account = :account AND type = '" + EntityFolder.USER + "'") List getUserFolders(long account); @Query("SELECT folder.*, account.name AS accountName" + @@ -71,10 +71,10 @@ public interface DaoFolder { " WHERE account = :account AND type = :type") EntityFolder getFolderByType(long account, String type); - @Query("SELECT * FROM folder WHERE account IS NULL AND type = '" + EntityFolder.TYPE_DRAFTS + "'") + @Query("SELECT * FROM folder WHERE account IS NULL AND type = '" + EntityFolder.DRAFTS + "'") EntityFolder getLocalDrafts(); - @Query("SELECT * FROM folder WHERE type = '" + EntityFolder.TYPE_OUTBOX + "'") + @Query("SELECT * FROM folder WHERE type = '" + EntityFolder.OUTBOX + "'") EntityFolder getOutbox(); @Insert(onConflict = OnConflictStrategy.REPLACE) diff --git a/app/src/main/java/eu/faircode/email/DaoMessage.java b/app/src/main/java/eu/faircode/email/DaoMessage.java index 16b74aeb..d96e139b 100644 --- a/app/src/main/java/eu/faircode/email/DaoMessage.java +++ b/app/src/main/java/eu/faircode/email/DaoMessage.java @@ -40,12 +40,12 @@ public interface DaoMessage { ", COUNT(message.id) as count" + ", SUM(CASE WHEN message.ui_seen THEN 0 ELSE 1 END) as unseen" + ", (SELECT COUNT(a.id) FROM attachment a WHERE a.message = message.id) AS attachments" + - ", MAX(CASE WHEN folder.type = '" + EntityFolder.TYPE_INBOX + "' THEN message.id ELSE 0 END) as dummy" + + ", MAX(CASE WHEN folder.type = '" + EntityFolder.INBOX + "' THEN message.id ELSE 0 END) as dummy" + " FROM message" + " JOIN folder ON folder.id = message.folder" + " WHERE (NOT message.ui_hide OR :debug)" + " GROUP BY CASE WHEN message.thread IS NULL THEN message.id ELSE message.thread END" + - " HAVING SUM(CASE WHEN folder.type = '" + EntityFolder.TYPE_INBOX + "' THEN 1 ELSE 0 END) > 0" + + " HAVING SUM(CASE WHEN folder.type = '" + EntityFolder.INBOX + "' THEN 1 ELSE 0 END) > 0" + " ORDER BY message.received DESC") DataSource.Factory pagedUnifiedInbox(boolean debug); diff --git a/app/src/main/java/eu/faircode/email/EntityFolder.java b/app/src/main/java/eu/faircode/email/EntityFolder.java index d499b033..ed1a5af4 100644 --- a/app/src/main/java/eu/faircode/email/EntityFolder.java +++ b/app/src/main/java/eu/faircode/email/EntityFolder.java @@ -47,14 +47,14 @@ import static androidx.room.ForeignKey.CASCADE; public class EntityFolder { static final String TABLE_NAME = "folder"; - static final String TYPE_INBOX = "Inbox"; - static final String TYPE_OUTBOX = "Outbox"; - static final String TYPE_ARCHIVE = "All"; - static final String TYPE_DRAFTS = "Drafts"; - static final String TYPE_TRASH = "Trash"; - static final String TYPE_JUNK = "Junk"; - static final String TYPE_SENT = "Sent"; - static final String TYPE_USER = "User"; + static final String INBOX = "Inbox"; + static final String OUTBOX = "Outbox"; + static final String ARCHIVE = "All"; + static final String DRAFTS = "Drafts"; + static final String TRASH = "Trash"; + static final String JUNK = "Junk"; + static final String SENT = "Sent"; + static final String USER = "User"; static final List SYSTEM_FOLDER_ATTR = Arrays.asList( "All", @@ -64,22 +64,22 @@ public class EntityFolder { "Sent" ); static final List SYSTEM_FOLDER_TYPE = Arrays.asList( - TYPE_ARCHIVE, - TYPE_DRAFTS, - TYPE_TRASH, - TYPE_JUNK, - TYPE_SENT + ARCHIVE, + DRAFTS, + TRASH, + JUNK, + SENT ); // MUST match SYSTEM_FOLDER_ATTR static final List FOLDER_SORT_ORDER = Arrays.asList( - TYPE_INBOX, - TYPE_OUTBOX, - TYPE_DRAFTS, - TYPE_SENT, - TYPE_ARCHIVE, - TYPE_TRASH, - TYPE_JUNK, - TYPE_USER + INBOX, + OUTBOX, + DRAFTS, + SENT, + ARCHIVE, + TRASH, + JUNK, + USER ); static final int DEFAULT_INBOX_SYNC = 30; // days @@ -87,10 +87,10 @@ public class EntityFolder { static final int DEFAULT_USER_SYNC = 7; // days static final List SYSTEM_FOLDER_SYNC = Arrays.asList( - TYPE_ARCHIVE, - TYPE_DRAFTS, - TYPE_TRASH, - TYPE_SENT + ARCHIVE, + DRAFTS, + TRASH, + SENT ); @PrimaryKey(autoGenerate = true) @@ -106,13 +106,13 @@ public class EntityFolder { public Integer after; // days static EntityFolder getDrafts(Context context, DB db, long account) { - EntityFolder drafts = db.folder().getFolderByType(account, EntityFolder.TYPE_DRAFTS); + EntityFolder drafts = db.folder().getFolderByType(account, EntityFolder.DRAFTS); if (drafts == null) drafts = db.folder().getLocalDrafts(); if (drafts == null) { drafts = new EntityFolder(); drafts.name = context.getString(R.string.title_folder_local_drafts); - drafts.type = EntityFolder.TYPE_DRAFTS; + drafts.type = EntityFolder.DRAFTS; drafts.synchronize = false; drafts.after = 0; drafts.id = db.folder().insertFolder(drafts); diff --git a/app/src/main/java/eu/faircode/email/FragmentAccount.java b/app/src/main/java/eu/faircode/email/FragmentAccount.java index 17c94910..f017eb12 100644 --- a/app/src/main/java/eu/faircode/email/FragmentAccount.java +++ b/app/src/main/java/eu/faircode/email/FragmentAccount.java @@ -320,7 +320,7 @@ public class FragmentAccount extends FragmentEx { " system=" + folder.name + " type=" + folder.type + " attr=" + TextUtils.join(",", attrs)); - if (EntityFolder.TYPE_DRAFTS.equals(folder.type)) + if (EntityFolder.DRAFTS.equals(folder.type)) drafts = true; } } @@ -328,7 +328,7 @@ public class FragmentAccount extends FragmentEx { if (!drafts) { EntityFolder folder = new EntityFolder(); folder.name = getContext().getString(R.string.title_folder_local_drafts); - folder.type = EntityFolder.TYPE_DRAFTS; + folder.type = EntityFolder.DRAFTS; folder.synchronize = false; folder.after = 0; folders.add(folder); @@ -351,7 +351,7 @@ public class FragmentAccount extends FragmentEx { EntityFolder inbox = new EntityFolder(); inbox.name = "INBOX"; - inbox.type = EntityFolder.TYPE_INBOX; + inbox.type = EntityFolder.INBOX; inbox.synchronize = true; inbox.after = EntityFolder.DEFAULT_INBOX_SYNC; folders.add(0, inbox); diff --git a/app/src/main/java/eu/faircode/email/FragmentCompose.java b/app/src/main/java/eu/faircode/email/FragmentCompose.java index b4096e27..1259f33e 100644 --- a/app/src/main/java/eu/faircode/email/FragmentCompose.java +++ b/app/src/main/java/eu/faircode/email/FragmentCompose.java @@ -581,7 +581,7 @@ public class FragmentCompose extends FragmentEx { else if ("trash".equals(action)) { EntityOperation.queue(getContext(), draft, EntityOperation.DELETE); - EntityFolder trash = db.folder().getFolderByType(ident.account, EntityFolder.TYPE_TRASH); + EntityFolder trash = db.folder().getFolderByType(ident.account, EntityFolder.TRASH); if (trash != null) { draft.id = null; draft.folder = trash.id; diff --git a/app/src/main/java/eu/faircode/email/FragmentMessage.java b/app/src/main/java/eu/faircode/email/FragmentMessage.java index 4768a22b..527b868e 100644 --- a/app/src/main/java/eu/faircode/email/FragmentMessage.java +++ b/app/src/main/java/eu/faircode/email/FragmentMessage.java @@ -303,26 +303,26 @@ public class FragmentMessage extends FragmentEx { db.folder().liveFolders(message.account).observe(getViewLifecycleOwner(), new Observer>() { @Override public void onChanged(@Nullable final List folders) { - boolean inbox = EntityFolder.TYPE_INBOX.equals(message.folderType); - boolean outbox = EntityFolder.TYPE_OUTBOX.equals(message.folderType); - boolean archive = EntityFolder.TYPE_ARCHIVE.equals(message.folderType); - boolean drafts = EntityFolder.TYPE_DRAFTS.equals(message.folderType); - boolean trash = EntityFolder.TYPE_TRASH.equals(message.folderType); - boolean junk = EntityFolder.TYPE_JUNK.equals(message.folderType); - boolean sent = EntityFolder.TYPE_SENT.equals(message.folderType); + boolean inbox = EntityFolder.INBOX.equals(message.folderType); + boolean outbox = EntityFolder.OUTBOX.equals(message.folderType); + boolean archive = EntityFolder.ARCHIVE.equals(message.folderType); + boolean drafts = EntityFolder.DRAFTS.equals(message.folderType); + boolean trash = EntityFolder.TRASH.equals(message.folderType); + boolean junk = EntityFolder.JUNK.equals(message.folderType); + boolean sent = EntityFolder.SENT.equals(message.folderType); boolean hasTrash = false; boolean hasJunk = false; boolean hasArchive = false; boolean hasUser = false; for (EntityFolder folder : folders) { - if (EntityFolder.TYPE_TRASH.equals(folder.type)) + if (EntityFolder.TRASH.equals(folder.type)) hasTrash = true; - else if (EntityFolder.TYPE_JUNK.equals(folder.type)) + else if (EntityFolder.JUNK.equals(folder.type)) hasJunk = true; - else if (EntityFolder.TYPE_ARCHIVE.equals(folder.type)) + else if (EntityFolder.ARCHIVE.equals(folder.type)) hasArchive = true; - else if (EntityFolder.TYPE_USER.equals(folder.type)) + else if (EntityFolder.USER.equals(folder.type)) hasUser = true; } @@ -451,7 +451,7 @@ public class FragmentMessage extends FragmentEx { message.ui_hide = true; db.message().updateMessage(message); - EntityFolder spam = db.folder().getFolderByType(message.account, EntityFolder.TYPE_JUNK); + EntityFolder spam = db.folder().getFolderByType(message.account, EntityFolder.JUNK); EntityOperation.queue(getContext(), message, EntityOperation.MOVE, spam.id); EntityOperation.process(getContext()); } catch (Throwable ex) { @@ -466,7 +466,7 @@ public class FragmentMessage extends FragmentEx { private void onActionDelete(final long id) { String folderType = (String) bottom_navigation.getTag(); - if (EntityFolder.TYPE_TRASH.equals(folderType)) { + if (EntityFolder.TRASH.equals(folderType)) { AlertDialog.Builder builder = new AlertDialog.Builder(getContext()); builder .setMessage(R.string.title_ask_delete) @@ -502,7 +502,7 @@ public class FragmentMessage extends FragmentEx { message.ui_hide = true; db.message().updateMessage(message); - EntityFolder trash = db.folder().getFolderByType(message.account, EntityFolder.TYPE_TRASH); + EntityFolder trash = db.folder().getFolderByType(message.account, EntityFolder.TRASH); EntityOperation.queue(getContext(), message, EntityOperation.MOVE, trash.id); EntityOperation.process(getContext()); } catch (Throwable ex) { @@ -530,7 +530,7 @@ public class FragmentMessage extends FragmentEx { message.ui_hide = true; db.message().updateMessage(message); - EntityFolder archive = db.folder().getFolderByType(message.account, EntityFolder.TYPE_ARCHIVE); + EntityFolder archive = db.folder().getFolderByType(message.account, EntityFolder.ARCHIVE); EntityOperation.queue(getContext(), message, EntityOperation.MOVE, archive.id); EntityOperation.process(getContext()); } catch (Throwable ex) { @@ -579,7 +579,7 @@ public class FragmentMessage extends FragmentEx { } }); - EntityFolder inbox = db.folder().getFolderByType(message.account, EntityFolder.TYPE_INBOX); + EntityFolder inbox = db.folder().getFolderByType(message.account, EntityFolder.INBOX); if (!message.folder.equals(inbox.id)) folders.add(0, inbox); diff --git a/app/src/main/java/eu/faircode/email/FragmentSetup.java b/app/src/main/java/eu/faircode/email/FragmentSetup.java index 54225d4c..73a0e8ad 100644 --- a/app/src/main/java/eu/faircode/email/FragmentSetup.java +++ b/app/src/main/java/eu/faircode/email/FragmentSetup.java @@ -161,7 +161,7 @@ public class FragmentSetup extends FragmentEx { if (outbox == null) { outbox = new EntityFolder(); outbox.name = "OUTBOX"; - outbox.type = EntityFolder.TYPE_OUTBOX; + outbox.type = EntityFolder.OUTBOX; outbox.synchronize = false; outbox.after = 0; outbox.id = db.folder().insertFolder(outbox); diff --git a/app/src/main/java/eu/faircode/email/ServiceSynchronize.java b/app/src/main/java/eu/faircode/email/ServiceSynchronize.java index c3440620..b10ec9bc 100644 --- a/app/src/main/java/eu/faircode/email/ServiceSynchronize.java +++ b/app/src/main/java/eu/faircode/email/ServiceSynchronize.java @@ -411,7 +411,7 @@ public class ServiceSynchronize extends LifecycleService { lbm.registerReceiver(processReceiver, f); Log.i(Helper.TAG, "listen process folder"); for (final EntityFolder folder : db.folder().getFolders(account.id)) - if (!EntityFolder.TYPE_OUTBOX.equals(folder.type)) + if (!EntityFolder.OUTBOX.equals(folder.type)) lbm.sendBroadcast(new Intent(ACTION_PROCESS_FOLDER) .setType("account/" + account.id) .putExtra("folder", folder.id)); @@ -826,7 +826,7 @@ public class ServiceSynchronize extends LifecycleService { msg.seen = true; msg.ui_seen = true; - EntityFolder sent = db.folder().getFolderByType(ident.account, EntityFolder.TYPE_SENT); + EntityFolder sent = db.folder().getFolderByType(ident.account, EntityFolder.SENT); if (sent != null) { Log.i(Helper.TAG, "Moving to sent folder=" + sent.id); msg.folder = sent.id; @@ -956,7 +956,7 @@ public class ServiceSynchronize extends LifecycleService { folder = new EntityFolder(); folder.account = account.id; folder.name = ifolder.getFullName(); - folder.type = EntityFolder.TYPE_USER; + folder.type = EntityFolder.USER; folder.synchronize = false; folder.after = EntityFolder.DEFAULT_USER_SYNC; dao.insertFolder(folder); @@ -1086,7 +1086,7 @@ public class ServiceSynchronize extends LifecycleService { long id = MimeMessageEx.getId(imessage); message = db.message().getMessage(id); if (message != null && message.folder != folder.id) { - if (EntityFolder.TYPE_ARCHIVE.equals(folder.type)) + if (EntityFolder.ARCHIVE.equals(folder.type)) message = null; else // Outbox to sent message.folder = folder.id;