Browse Source

Refactoring

main
M66B 6 years ago
parent
commit
659900f6d7
11 changed files with 64 additions and 64 deletions
  1. +1
    -1
      app/src/main/java/eu/faircode/email/AdapterFolder.java
  2. +5
    -5
      app/src/main/java/eu/faircode/email/AdapterMessage.java
  3. +1
    -1
      app/src/main/java/eu/faircode/email/DaoAccount.java
  4. +3
    -3
      app/src/main/java/eu/faircode/email/DaoFolder.java
  5. +2
    -2
      app/src/main/java/eu/faircode/email/DaoMessage.java
  6. +27
    -27
      app/src/main/java/eu/faircode/email/EntityFolder.java
  7. +3
    -3
      app/src/main/java/eu/faircode/email/FragmentAccount.java
  8. +1
    -1
      app/src/main/java/eu/faircode/email/FragmentCompose.java
  9. +16
    -16
      app/src/main/java/eu/faircode/email/FragmentMessage.java
  10. +1
    -1
      app/src/main/java/eu/faircode/email/FragmentSetup.java
  11. +4
    -4
      app/src/main/java/eu/faircode/email/ServiceSynchronize.java

+ 1
- 1
app/src/main/java/eu/faircode/email/AdapterFolder.java View File

@ -122,7 +122,7 @@ public class AdapterFolder extends RecyclerView.Adapter<AdapterFolder.ViewHolder
return false; return false;
TupleFolderEx folder = filtered.get(pos); TupleFolderEx folder = filtered.get(pos);
if (!EntityFolder.TYPE_OUTBOX.equals(folder.type)) {
if (!EntityFolder.OUTBOX.equals(folder.type)) {
LocalBroadcastManager lbm = LocalBroadcastManager.getInstance(context); LocalBroadcastManager lbm = LocalBroadcastManager.getInstance(context);
lbm.sendBroadcast( lbm.sendBroadcast(
new Intent(ActivityView.ACTION_EDIT_FOLDER) new Intent(ActivityView.ACTION_EDIT_FOLDER)


+ 5
- 5
app/src/main/java/eu/faircode/email/AdapterMessage.java View File

@ -91,9 +91,9 @@ public class AdapterMessage extends PagedListAdapter<TupleMessageEx, AdapterMess
private void bindTo(TupleMessageEx message) { private void bindTo(TupleMessageEx message) {
pbLoading.setVisibility(View.GONE); pbLoading.setVisibility(View.GONE);
if (EntityFolder.TYPE_DRAFTS.equals(message.folderType) ||
EntityFolder.TYPE_OUTBOX.equals(message.folderType) ||
EntityFolder.TYPE_SENT.equals(message.folderType)) {
if (EntityFolder.DRAFTS.equals(message.folderType) ||
EntityFolder.OUTBOX.equals(message.folderType) ||
EntityFolder.SENT.equals(message.folderType)) {
tvFrom.setText(MessageHelper.getFormattedAddresses(message.to)); tvFrom.setText(MessageHelper.getFormattedAddresses(message.to));
tvTime.setText(DateUtils.getRelativeTimeSpanString(context, message.sent == null ? message.received : message.sent)); tvTime.setText(DateUtils.getRelativeTimeSpanString(context, message.sent == null ? message.received : message.sent));
} else { } else {
@ -137,12 +137,12 @@ public class AdapterMessage extends PagedListAdapter<TupleMessageEx, AdapterMess
@Override @Override
public void run() { public void run() {
try { try {
if (EntityFolder.TYPE_DRAFTS.equals(message.folderType))
if (EntityFolder.DRAFTS.equals(message.folderType))
context.startActivity( context.startActivity(
new Intent(context, ActivityCompose.class) new Intent(context, ActivityCompose.class)
.putExtra("id", message.id)); .putExtra("id", message.id));
else { else {
if (!EntityFolder.TYPE_OUTBOX.equals(message.folderType)) {
if (!EntityFolder.OUTBOX.equals(message.folderType)) {
if (!message.seen && !message.ui_seen) { if (!message.seen && !message.ui_seen) {
message.ui_seen = !message.ui_seen; message.ui_seen = !message.ui_seen;
DB.getInstance(context).message().updateMessage(message); DB.getInstance(context).message().updateMessage(message);


+ 1
- 1
app/src/main/java/eu/faircode/email/DaoAccount.java View File

@ -56,7 +56,7 @@ public interface DaoAccount {
" JOIN folder ON folder.id = message.folder" + " JOIN folder ON folder.id = message.folder" +
" WHERE NOT message.ui_seen AND NOT message.ui_hide" + " WHERE NOT message.ui_seen AND NOT message.ui_hide" +
" AND (account.seen_until IS NULL OR message.received > account.seen_until)" + " AND (account.seen_until IS NULL OR message.received > account.seen_until)" +
" AND folder.type = '" + EntityFolder.TYPE_INBOX + "') AS unseen")
" AND folder.type = '" + EntityFolder.INBOX + "') AS unseen")
LiveData<TupleAccountStats> liveStats(); LiveData<TupleAccountStats> liveStats();
@Insert(onConflict = OnConflictStrategy.REPLACE) @Insert(onConflict = OnConflictStrategy.REPLACE)


+ 3
- 3
app/src/main/java/eu/faircode/email/DaoFolder.java View File

@ -36,7 +36,7 @@ public interface DaoFolder {
@Query("SELECT * FROM folder WHERE account = :account AND synchronize = :synchronize") @Query("SELECT * FROM folder WHERE account = :account AND synchronize = :synchronize")
List<EntityFolder> getFolders(long account, boolean synchronize); List<EntityFolder> 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<EntityFolder> getUserFolders(long account); List<EntityFolder> getUserFolders(long account);
@Query("SELECT folder.*, account.name AS accountName" + @Query("SELECT folder.*, account.name AS accountName" +
@ -71,10 +71,10 @@ public interface DaoFolder {
" WHERE account = :account AND type = :type") " WHERE account = :account AND type = :type")
EntityFolder getFolderByType(long account, String 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(); EntityFolder getLocalDrafts();
@Query("SELECT * FROM folder WHERE type = '" + EntityFolder.TYPE_OUTBOX + "'")
@Query("SELECT * FROM folder WHERE type = '" + EntityFolder.OUTBOX + "'")
EntityFolder getOutbox(); EntityFolder getOutbox();
@Insert(onConflict = OnConflictStrategy.REPLACE) @Insert(onConflict = OnConflictStrategy.REPLACE)


+ 2
- 2
app/src/main/java/eu/faircode/email/DaoMessage.java View File

@ -40,12 +40,12 @@ public interface DaoMessage {
", COUNT(message.id) as count" + ", COUNT(message.id) as count" +
", SUM(CASE WHEN message.ui_seen THEN 0 ELSE 1 END) as unseen" + ", 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" + ", (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" + " FROM message" +
" JOIN folder ON folder.id = message.folder" + " JOIN folder ON folder.id = message.folder" +
" WHERE (NOT message.ui_hide OR :debug)" + " WHERE (NOT message.ui_hide OR :debug)" +
" GROUP BY CASE WHEN message.thread IS NULL THEN message.id ELSE message.thread END" + " 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") " ORDER BY message.received DESC")
DataSource.Factory<Integer, TupleMessageEx> pagedUnifiedInbox(boolean debug); DataSource.Factory<Integer, TupleMessageEx> pagedUnifiedInbox(boolean debug);


+ 27
- 27
app/src/main/java/eu/faircode/email/EntityFolder.java View File

@ -47,14 +47,14 @@ import static androidx.room.ForeignKey.CASCADE;
public class EntityFolder { public class EntityFolder {
static final String TABLE_NAME = "folder"; 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<String> SYSTEM_FOLDER_ATTR = Arrays.asList( static final List<String> SYSTEM_FOLDER_ATTR = Arrays.asList(
"All", "All",
@ -64,22 +64,22 @@ public class EntityFolder {
"Sent" "Sent"
); );
static final List<String> SYSTEM_FOLDER_TYPE = Arrays.asList( static final List<String> 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 ); // MUST match SYSTEM_FOLDER_ATTR
static final List<String> FOLDER_SORT_ORDER = Arrays.asList( static final List<String> 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 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 int DEFAULT_USER_SYNC = 7; // days
static final List<String> SYSTEM_FOLDER_SYNC = Arrays.asList( static final List<String> SYSTEM_FOLDER_SYNC = Arrays.asList(
TYPE_ARCHIVE,
TYPE_DRAFTS,
TYPE_TRASH,
TYPE_SENT
ARCHIVE,
DRAFTS,
TRASH,
SENT
); );
@PrimaryKey(autoGenerate = true) @PrimaryKey(autoGenerate = true)
@ -106,13 +106,13 @@ public class EntityFolder {
public Integer after; // days public Integer after; // days
static EntityFolder getDrafts(Context context, DB db, long account) { 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) if (drafts == null)
drafts = db.folder().getLocalDrafts(); drafts = db.folder().getLocalDrafts();
if (drafts == null) { if (drafts == null) {
drafts = new EntityFolder(); drafts = new EntityFolder();
drafts.name = context.getString(R.string.title_folder_local_drafts); drafts.name = context.getString(R.string.title_folder_local_drafts);
drafts.type = EntityFolder.TYPE_DRAFTS;
drafts.type = EntityFolder.DRAFTS;
drafts.synchronize = false; drafts.synchronize = false;
drafts.after = 0; drafts.after = 0;
drafts.id = db.folder().insertFolder(drafts); drafts.id = db.folder().insertFolder(drafts);


+ 3
- 3
app/src/main/java/eu/faircode/email/FragmentAccount.java View File

@ -320,7 +320,7 @@ public class FragmentAccount extends FragmentEx {
" system=" + folder.name + " system=" + folder.name +
" type=" + folder.type + " attr=" + TextUtils.join(",", attrs)); " type=" + folder.type + " attr=" + TextUtils.join(",", attrs));
if (EntityFolder.TYPE_DRAFTS.equals(folder.type))
if (EntityFolder.DRAFTS.equals(folder.type))
drafts = true; drafts = true;
} }
} }
@ -328,7 +328,7 @@ public class FragmentAccount extends FragmentEx {
if (!drafts) { if (!drafts) {
EntityFolder folder = new EntityFolder(); EntityFolder folder = new EntityFolder();
folder.name = getContext().getString(R.string.title_folder_local_drafts); folder.name = getContext().getString(R.string.title_folder_local_drafts);
folder.type = EntityFolder.TYPE_DRAFTS;
folder.type = EntityFolder.DRAFTS;
folder.synchronize = false; folder.synchronize = false;
folder.after = 0; folder.after = 0;
folders.add(folder); folders.add(folder);
@ -351,7 +351,7 @@ public class FragmentAccount extends FragmentEx {
EntityFolder inbox = new EntityFolder(); EntityFolder inbox = new EntityFolder();
inbox.name = "INBOX"; inbox.name = "INBOX";
inbox.type = EntityFolder.TYPE_INBOX;
inbox.type = EntityFolder.INBOX;
inbox.synchronize = true; inbox.synchronize = true;
inbox.after = EntityFolder.DEFAULT_INBOX_SYNC; inbox.after = EntityFolder.DEFAULT_INBOX_SYNC;
folders.add(0, inbox); folders.add(0, inbox);


+ 1
- 1
app/src/main/java/eu/faircode/email/FragmentCompose.java View File

@ -581,7 +581,7 @@ public class FragmentCompose extends FragmentEx {
else if ("trash".equals(action)) { else if ("trash".equals(action)) {
EntityOperation.queue(getContext(), draft, EntityOperation.DELETE); 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) { if (trash != null) {
draft.id = null; draft.id = null;
draft.folder = trash.id; draft.folder = trash.id;


+ 16
- 16
app/src/main/java/eu/faircode/email/FragmentMessage.java View File

@ -303,26 +303,26 @@ public class FragmentMessage extends FragmentEx {
db.folder().liveFolders(message.account).observe(getViewLifecycleOwner(), new Observer<List<TupleFolderEx>>() { db.folder().liveFolders(message.account).observe(getViewLifecycleOwner(), new Observer<List<TupleFolderEx>>() {
@Override @Override
public void onChanged(@Nullable final List<TupleFolderEx> folders) { public void onChanged(@Nullable final List<TupleFolderEx> 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 hasTrash = false;
boolean hasJunk = false; boolean hasJunk = false;
boolean hasArchive = false; boolean hasArchive = false;
boolean hasUser = false; boolean hasUser = false;
for (EntityFolder folder : folders) { for (EntityFolder folder : folders) {
if (EntityFolder.TYPE_TRASH.equals(folder.type))
if (EntityFolder.TRASH.equals(folder.type))
hasTrash = true; hasTrash = true;
else if (EntityFolder.TYPE_JUNK.equals(folder.type))
else if (EntityFolder.JUNK.equals(folder.type))
hasJunk = true; hasJunk = true;
else if (EntityFolder.TYPE_ARCHIVE.equals(folder.type))
else if (EntityFolder.ARCHIVE.equals(folder.type))
hasArchive = true; hasArchive = true;
else if (EntityFolder.TYPE_USER.equals(folder.type))
else if (EntityFolder.USER.equals(folder.type))
hasUser = true; hasUser = true;
} }
@ -451,7 +451,7 @@ public class FragmentMessage extends FragmentEx {
message.ui_hide = true; message.ui_hide = true;
db.message().updateMessage(message); 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.queue(getContext(), message, EntityOperation.MOVE, spam.id);
EntityOperation.process(getContext()); EntityOperation.process(getContext());
} catch (Throwable ex) { } catch (Throwable ex) {
@ -466,7 +466,7 @@ public class FragmentMessage extends FragmentEx {
private void onActionDelete(final long id) { private void onActionDelete(final long id) {
String folderType = (String) bottom_navigation.getTag(); String folderType = (String) bottom_navigation.getTag();
if (EntityFolder.TYPE_TRASH.equals(folderType)) {
if (EntityFolder.TRASH.equals(folderType)) {
AlertDialog.Builder builder = new AlertDialog.Builder(getContext()); AlertDialog.Builder builder = new AlertDialog.Builder(getContext());
builder builder
.setMessage(R.string.title_ask_delete) .setMessage(R.string.title_ask_delete)
@ -502,7 +502,7 @@ public class FragmentMessage extends FragmentEx {
message.ui_hide = true; message.ui_hide = true;
db.message().updateMessage(message); 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.queue(getContext(), message, EntityOperation.MOVE, trash.id);
EntityOperation.process(getContext()); EntityOperation.process(getContext());
} catch (Throwable ex) { } catch (Throwable ex) {
@ -530,7 +530,7 @@ public class FragmentMessage extends FragmentEx {
message.ui_hide = true; message.ui_hide = true;
db.message().updateMessage(message); 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.queue(getContext(), message, EntityOperation.MOVE, archive.id);
EntityOperation.process(getContext()); EntityOperation.process(getContext());
} catch (Throwable ex) { } 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)) if (!message.folder.equals(inbox.id))
folders.add(0, inbox); folders.add(0, inbox);


+ 1
- 1
app/src/main/java/eu/faircode/email/FragmentSetup.java View File

@ -161,7 +161,7 @@ public class FragmentSetup extends FragmentEx {
if (outbox == null) { if (outbox == null) {
outbox = new EntityFolder(); outbox = new EntityFolder();
outbox.name = "OUTBOX"; outbox.name = "OUTBOX";
outbox.type = EntityFolder.TYPE_OUTBOX;
outbox.type = EntityFolder.OUTBOX;
outbox.synchronize = false; outbox.synchronize = false;
outbox.after = 0; outbox.after = 0;
outbox.id = db.folder().insertFolder(outbox); outbox.id = db.folder().insertFolder(outbox);


+ 4
- 4
app/src/main/java/eu/faircode/email/ServiceSynchronize.java View File

@ -411,7 +411,7 @@ public class ServiceSynchronize extends LifecycleService {
lbm.registerReceiver(processReceiver, f); lbm.registerReceiver(processReceiver, f);
Log.i(Helper.TAG, "listen process folder"); Log.i(Helper.TAG, "listen process folder");
for (final EntityFolder folder : db.folder().getFolders(account.id)) 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) lbm.sendBroadcast(new Intent(ACTION_PROCESS_FOLDER)
.setType("account/" + account.id) .setType("account/" + account.id)
.putExtra("folder", folder.id)); .putExtra("folder", folder.id));
@ -826,7 +826,7 @@ public class ServiceSynchronize extends LifecycleService {
msg.seen = true; msg.seen = true;
msg.ui_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) { if (sent != null) {
Log.i(Helper.TAG, "Moving to sent folder=" + sent.id); Log.i(Helper.TAG, "Moving to sent folder=" + sent.id);
msg.folder = sent.id; msg.folder = sent.id;
@ -956,7 +956,7 @@ public class ServiceSynchronize extends LifecycleService {
folder = new EntityFolder(); folder = new EntityFolder();
folder.account = account.id; folder.account = account.id;
folder.name = ifolder.getFullName(); folder.name = ifolder.getFullName();
folder.type = EntityFolder.TYPE_USER;
folder.type = EntityFolder.USER;
folder.synchronize = false; folder.synchronize = false;
folder.after = EntityFolder.DEFAULT_USER_SYNC; folder.after = EntityFolder.DEFAULT_USER_SYNC;
dao.insertFolder(folder); dao.insertFolder(folder);
@ -1086,7 +1086,7 @@ public class ServiceSynchronize extends LifecycleService {
long id = MimeMessageEx.getId(imessage); long id = MimeMessageEx.getId(imessage);
message = db.message().getMessage(id); message = db.message().getMessage(id);
if (message != null && message.folder != folder.id) { if (message != null && message.folder != folder.id) {
if (EntityFolder.TYPE_ARCHIVE.equals(folder.type))
if (EntityFolder.ARCHIVE.equals(folder.type))
message = null; message = null;
else // Outbox to sent else // Outbox to sent
message.folder = folder.id; message.folder = folder.id;


Loading…
Cancel
Save