Refactoring

pull/30/head
M66B 6 years ago
parent 7ea6ba1762
commit 659900f6d7

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

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

@ -56,7 +56,7 @@ public interface DaoAccount {
" JOIN folder ON folder.id = message.folder" +
" WHERE NOT message.ui_seen AND NOT message.ui_hide" +
" 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();
@Insert(onConflict = OnConflictStrategy.REPLACE)

@ -36,7 +36,7 @@ public interface DaoFolder {
@Query("SELECT * FROM folder WHERE account = :account AND synchronize = :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);
@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)

@ -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<Integer, TupleMessageEx> pagedUnifiedInbox(boolean debug);

@ -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<String> SYSTEM_FOLDER_ATTR = Arrays.asList(
"All",
@ -64,22 +64,22 @@ public class EntityFolder {
"Sent"
);
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
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
@ -87,10 +87,10 @@ public class EntityFolder {
static final int DEFAULT_USER_SYNC = 7; // days
static final List<String> 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);

@ -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);

@ -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;

@ -303,26 +303,26 @@ public class FragmentMessage extends FragmentEx {
db.folder().liveFolders(message.account).observe(getViewLifecycleOwner(), new Observer<List<TupleFolderEx>>() {
@Override
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 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);

@ -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);

@ -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;

Loading…
Cancel
Save