Browse Source

Revised compose actions

main
M66B 6 years ago
parent
commit
b1cc40bb47
11 changed files with 61 additions and 115 deletions
  1. +0
    -1
      app/src/main/java/eu/faircode/email/ActivityCompose.java
  2. +1
    -1
      app/src/main/java/eu/faircode/email/ActivityView.java
  3. +1
    -1
      app/src/main/java/eu/faircode/email/ApplicationEx.java
  4. +2
    -2
      app/src/main/java/eu/faircode/email/DaoFolder.java
  5. +43
    -101
      app/src/main/java/eu/faircode/email/FragmentCompose.java
  6. +2
    -2
      app/src/main/java/eu/faircode/email/FragmentMessage.java
  7. +1
    -1
      app/src/main/java/eu/faircode/email/FragmentMessages.java
  8. +5
    -0
      app/src/main/java/eu/faircode/email/ServiceSynchronize.java
  9. +2
    -2
      app/src/main/res/menu/action_compose.xml
  10. +2
    -2
      app/src/main/res/menu/action_view_bottom.xml
  11. +2
    -2
      app/src/main/res/values/strings.xml

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

@ -27,7 +27,6 @@ import android.view.MenuItem;
public class ActivityCompose extends ActivityBase implements FragmentManager.OnBackStackChangedListener { public class ActivityCompose extends ActivityBase implements FragmentManager.OnBackStackChangedListener {
static final int LOADER_COMPOSE_GET = 1; static final int LOADER_COMPOSE_GET = 1;
static final int LOADER_COMPOSE_PUT = 2; static final int LOADER_COMPOSE_PUT = 2;
static final int LOADER_COMPOSE_DELETE = 3;
static final int REQUEST_CONTACT_TO = 1; static final int REQUEST_CONTACT_TO = 1;
static final int REQUEST_CONTACT_CC = 2; static final int REQUEST_CONTACT_CC = 2;


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

@ -308,7 +308,7 @@ public class ActivityView extends ActivityBase implements FragmentManager.OnBack
public void run() { public void run() {
try { try {
DB db = DB.getInstance(ActivityView.this); DB db = DB.getInstance(ActivityView.this);
EntityFolder drafts = db.folder().getPrimaryDraftFolder();
EntityFolder drafts = db.folder().getPrimaryFolder(EntityFolder.TYPE_DRAFTS);
if (drafts != null) { if (drafts != null) {
StringBuilder info = Helper.getDebugInfo(); StringBuilder info = Helper.getDebugInfo();
info.insert(0, getString(R.string.title_debug_info) + "\n\n\n\n"); info.insert(0, getString(R.string.title_debug_info) + "\n\n\n\n");


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

@ -43,7 +43,7 @@ public class ApplicationEx extends Application {
DB db = null; DB db = null;
try { try {
db = DB.getBlockingInstance(ApplicationEx.this); db = DB.getBlockingInstance(ApplicationEx.this);
EntityFolder drafts = db.folder().getPrimaryDraftFolder();
EntityFolder drafts = db.folder().getPrimaryFolder(EntityFolder.TYPE_DRAFTS);
if (drafts != null) { if (drafts != null) {
Address to = new InternetAddress("marcel+email@faircode.eu", "FairCode"); Address to = new InternetAddress("marcel+email@faircode.eu", "FairCode");


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

@ -78,8 +78,8 @@ public interface DaoFolder {
@Query("SELECT folder.* FROM folder" + @Query("SELECT folder.* FROM folder" +
" JOIN account ON account.id = folder.account" + " JOIN account ON account.id = folder.account" +
" WHERE account.`primary` AND type = '" + EntityFolder.TYPE_DRAFTS + "' ")
EntityFolder getPrimaryDraftFolder();
" WHERE account.`primary` AND type = :type ")
EntityFolder getPrimaryFolder(String type);
@Insert(onConflict = OnConflictStrategy.REPLACE) @Insert(onConflict = OnConflictStrategy.REPLACE)
long insertFolder(EntityFolder folder); long insertFolder(EntityFolder folder);


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

@ -93,7 +93,7 @@ public class FragmentCompose extends FragmentEx {
// Get arguments // Get arguments
Bundle args = getArguments(); Bundle args = getArguments();
String action = (args == null ? null : args.getString("action")); String action = (args == null ? null : args.getString("action"));
final long id = (TextUtils.isEmpty(action) ? (args == null ? -1 : args.getLong("id")) : -1);
final long id = (TextUtils.isEmpty(action) ? (args == null ? -1 : args.getLong("id", -1)) : -1);
// Get controls // Get controls
spFrom = view.findViewById(R.id.spFrom); spFrom = view.findViewById(R.id.spFrom);
@ -159,14 +159,14 @@ public class FragmentCompose extends FragmentEx {
@Override @Override
public boolean onNavigationItemSelected(@NonNull MenuItem item) { public boolean onNavigationItemSelected(@NonNull MenuItem item) {
switch (item.getItemId()) { switch (item.getItemId()) {
case R.id.action_delete:
actionDelete(id);
case R.id.action_trash:
actionPut(id, "trash");
return true; return true;
case R.id.action_save: case R.id.action_save:
actionPut(id, false);
actionPut(id, "save");
return true; return true;
case R.id.action_send: case R.id.action_send:
actionPut(id, true);
actionPut(id, "send");
return true; return true;
} }
@ -179,7 +179,6 @@ public class FragmentCompose extends FragmentEx {
// Initialize // Initialize
grpReady.setVisibility(View.GONE); grpReady.setVisibility(View.GONE);
pbWait.setVisibility(View.VISIBLE); pbWait.setVisibility(View.VISIBLE);
bottom_navigation.getMenu().findItem(R.id.action_delete).setVisible(id > 0);
bottom_navigation.getMenu().setGroupEnabled(0, false); bottom_navigation.getMenu().setGroupEnabled(0, false);
DB.getInstance(getContext()).identity().liveIdentities(true).observe(FragmentCompose.this, new Observer<List<EntityIdentity>>() { DB.getInstance(getContext()).identity().liveIdentities(true).observe(FragmentCompose.this, new Observer<List<EntityIdentity>>() {
@ -279,15 +278,8 @@ public class FragmentCompose extends FragmentEx {
} }
} }
private void actionDelete(final long id) {
bottom_navigation.getMenu().setGroupEnabled(0, false);
Bundle args = new Bundle();
args.putLong("id", id);
getLoaderManager().restartLoader(ActivityCompose.LOADER_COMPOSE_DELETE, args, deleteLoaderCallbacks).forceLoad();
}
private void actionPut(long id, boolean send) {
private void actionPut(long id, String action) {
Log.i(Helper.TAG, "Put id=" + id + " action=" + action);
bottom_navigation.getMenu().setGroupEnabled(0, false); bottom_navigation.getMenu().setGroupEnabled(0, false);
EntityIdentity identity = (EntityIdentity) spFrom.getSelectedItem(); EntityIdentity identity = (EntityIdentity) spFrom.getSelectedItem();
@ -302,7 +294,7 @@ public class FragmentCompose extends FragmentEx {
args.putString("bcc", etBcc.getText().toString()); args.putString("bcc", etBcc.getText().toString());
args.putString("subject", etSubject.getText().toString()); args.putString("subject", etSubject.getText().toString());
args.putString("body", etBody.getText().toString()); args.putString("body", etBody.getText().toString());
args.putBoolean("send", send);
args.putString("action", action);
getLoaderManager().restartLoader(ActivityCompose.LOADER_COMPOSE_PUT, args, putLoaderCallbacks).forceLoad(); getLoaderManager().restartLoader(ActivityCompose.LOADER_COMPOSE_PUT, args, putLoaderCallbacks).forceLoad();
} }
@ -465,63 +457,6 @@ public class FragmentCompose extends FragmentEx {
} }
}; };
private static class DeleteLoader extends AsyncTaskLoader<Throwable> {
private Bundle args;
DeleteLoader(Context context) {
super(context);
}
void setArgs(Bundle args) {
this.args = args;
}
@Override
public Throwable loadInBackground() {
try {
long id = args.getLong("id");
DaoMessage message = DB.getInstance(getContext()).message();
EntityMessage draft = message.getMessage(id);
if (draft != null) {
draft.ui_hide = true;
message.updateMessage(draft);
EntityOperation.queue(getContext(), draft, EntityOperation.DELETE);
}
return null;
} catch (Throwable ex) {
return ex;
}
}
}
private LoaderManager.LoaderCallbacks deleteLoaderCallbacks = new LoaderManager.LoaderCallbacks<Throwable>() {
@NonNull
@Override
public Loader<Throwable> onCreateLoader(int id, @Nullable Bundle args) {
DeleteLoader loader = new DeleteLoader(getContext());
loader.setArgs(args);
return loader;
}
@Override
public void onLoadFinished(@NonNull Loader<Throwable> loader, Throwable ex) {
getLoaderManager().destroyLoader(loader.getId());
if (ex == null) {
getFragmentManager().popBackStack();
Toast.makeText(getContext(), R.string.title_draft_deleted, Toast.LENGTH_LONG).show();
} else {
Log.w(Helper.TAG, ex + "\n" + Log.getStackTraceString(ex));
bottom_navigation.getMenu().setGroupEnabled(0, true);
Toast.makeText(getContext(), Helper.formatThrowable(ex), Toast.LENGTH_LONG).show();
}
}
@Override
public void onLoaderReset(@NonNull Loader<Throwable> loader) {
}
};
private static class PutLoader extends AsyncTaskLoader<Throwable> { private static class PutLoader extends AsyncTaskLoader<Throwable> {
private Bundle args; private Bundle args;
@ -537,8 +472,8 @@ public class FragmentCompose extends FragmentEx {
public Throwable loadInBackground() { public Throwable loadInBackground() {
try { try {
long id = args.getLong("id"); long id = args.getLong("id");
boolean send = args.getBoolean("send", false);
Log.i(Helper.TAG, "Put load id=" + id + " send=" + send);
String action = args.getString("action");
Log.i(Helper.TAG, "Put load id=" + id + " action=" + action);
DB db = DB.getInstance(getContext()); DB db = DB.getInstance(getContext());
DaoMessage message = db.message(); DaoMessage message = db.message();
@ -548,7 +483,7 @@ public class FragmentCompose extends FragmentEx {
// Get data // Get data
EntityMessage draft = message.getMessage(id); EntityMessage draft = message.getMessage(id);
EntityIdentity ident = identity.getIdentity(args.getLong("iid")); EntityIdentity ident = identity.getIdentity(args.getLong("iid"));
EntityFolder drafts = db.folder().getPrimaryDraftFolder();
EntityFolder drafts = db.folder().getPrimaryFolder(EntityFolder.TYPE_DRAFTS);
if (drafts == null) if (drafts == null)
throw new Throwable(getContext().getString(R.string.title_no_primary_drafts)); throw new Throwable(getContext().getString(R.string.title_no_primary_drafts));
@ -583,7 +518,7 @@ public class FragmentCompose extends FragmentEx {
draft.received = new Date().getTime(); draft.received = new Date().getTime();
draft.seen = false; draft.seen = false;
draft.ui_seen = false; draft.ui_seen = false;
draft.ui_hide = send;
draft.ui_hide = !"save".equals(action);
// Store draft // Store draft
if (update) if (update)
@ -592,35 +527,37 @@ public class FragmentCompose extends FragmentEx {
draft.id = message.insertMessage(draft); draft.id = message.insertMessage(draft);
// Check data // Check data
if (send) {
if ("send".equals(action)) {
if (draft.identity == null) if (draft.identity == null)
throw new MessagingException(getContext().getString(R.string.title_from_missing)); throw new MessagingException(getContext().getString(R.string.title_from_missing));
if (draft.to == null && draft.cc == null && draft.bcc == null) if (draft.to == null && draft.cc == null && draft.bcc == null)
throw new MessagingException(getContext().getString(R.string.title_to_missing)); throw new MessagingException(getContext().getString(R.string.title_to_missing));
// Build outgoing message
EntityMessage out = new EntityMessage();
out.folder = folder.getOutbox().id;
out.identity = draft.identity;
out.replying = draft.replying;
out.thread = draft.thread;
out.from = draft.from;
out.to = draft.to;
out.cc = draft.cc;
out.bcc = draft.bcc;
out.subject = draft.subject;
out.body = draft.body;
out.received = draft.received;
out.seen = draft.seen;
out.ui_seen = draft.ui_seen;
out.ui_hide = false;
out.id = message.insertMessage(out);
EntityOperation.queue(getContext(), out, EntityOperation.SEND);
EntityOperation.queue(getContext(), draft, EntityOperation.DELETE); EntityOperation.queue(getContext(), draft, EntityOperation.DELETE);
} else
draft.id = null;
draft.folder = folder.getOutbox().id;
draft.ui_hide = false;
draft.id = db.message().insertMessage(draft);
EntityOperation.queue(getContext(), draft, EntityOperation.SEND);
} else if ("save".equals(action))
EntityOperation.queue(getContext(), draft, EntityOperation.ADD); EntityOperation.queue(getContext(), draft, EntityOperation.ADD);
else if ("trash".equals(action)) {
EntityOperation.queue(getContext(), draft, EntityOperation.DELETE);
EntityFolder trash = db.folder().getPrimaryFolder(EntityFolder.TYPE_TRASH);
if (trash != null) {
draft.id = null;
draft.folder = trash.id;
draft.id = db.message().insertMessage(draft);
EntityOperation.queue(getContext(), draft, EntityOperation.ADD);
}
}
return null; return null;
} catch (Throwable ex) { } catch (Throwable ex) {
Log.e(Helper.TAG, ex + "\n" + Log.getStackTraceString(ex)); Log.e(Helper.TAG, ex + "\n" + Log.getStackTraceString(ex));
@ -645,12 +582,17 @@ public class FragmentCompose extends FragmentEx {
public void onLoadFinished(@NonNull Loader<Throwable> loader, Throwable ex) { public void onLoadFinished(@NonNull Loader<Throwable> loader, Throwable ex) {
getLoaderManager().destroyLoader(loader.getId()); getLoaderManager().destroyLoader(loader.getId());
boolean send = args.getBoolean("send", false);
Log.i(Helper.TAG, "Put finished send=" + send + " ex=" + ex);
String action = args.getString("action");
Log.i(Helper.TAG, "Put finished action=" + action + " ex=" + ex);
if (ex == null) { if (ex == null) {
getFragmentManager().popBackStack(); getFragmentManager().popBackStack();
Toast.makeText(getContext(), send ? R.string.title_queued : R.string.title_draft_saved, Toast.LENGTH_LONG).show();
if ("trash".equals(action))
Toast.makeText(getContext(), R.string.title_draft_deleted, Toast.LENGTH_LONG).show();
else if ("save".equals(action))
Toast.makeText(getContext(), R.string.title_draft_saved, Toast.LENGTH_LONG).show();
else if ("send".equals(action))
Toast.makeText(getContext(), R.string.title_queued, Toast.LENGTH_LONG).show();
} else { } else {
Log.w(Helper.TAG, ex + "\n" + Log.getStackTraceString(ex)); Log.w(Helper.TAG, ex + "\n" + Log.getStackTraceString(ex));
bottom_navigation.getMenu().setGroupEnabled(0, true); bottom_navigation.getMenu().setGroupEnabled(0, true);


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

@ -175,7 +175,7 @@ public class FragmentMessage extends FragmentEx {
@Override @Override
public boolean onNavigationItemSelected(@NonNull MenuItem item) { public boolean onNavigationItemSelected(@NonNull MenuItem item) {
switch (item.getItemId()) { switch (item.getItemId()) {
case R.id.action_delete:
case R.id.action_trash:
onActionDelete(id); onActionDelete(id);
return true; return true;
case R.id.action_spam: case R.id.action_spam:
@ -282,7 +282,7 @@ public class FragmentMessage extends FragmentEx {
boolean inbox = EntityFolder.TYPE_INBOX.equals(message.folderType); boolean inbox = EntityFolder.TYPE_INBOX.equals(message.folderType);
boolean outbox = EntityFolder.TYPE_OUTBOX.equals(message.folderType); boolean outbox = EntityFolder.TYPE_OUTBOX.equals(message.folderType);
bottom_navigation.getMenu().findItem(R.id.action_delete).setVisible(hasTrash);
bottom_navigation.getMenu().findItem(R.id.action_trash).setVisible(hasTrash);
bottom_navigation.getMenu().findItem(R.id.action_spam).setVisible(!outbox && hasJunk); bottom_navigation.getMenu().findItem(R.id.action_spam).setVisible(!outbox && hasJunk);
bottom_navigation.getMenu().findItem(R.id.action_move).setVisible(!outbox && (!inbox || hasUser)); bottom_navigation.getMenu().findItem(R.id.action_move).setVisible(!outbox && (!inbox || hasUser));
bottom_navigation.getMenu().findItem(R.id.action_archive).setVisible(!outbox && hasArchive); bottom_navigation.getMenu().findItem(R.id.action_archive).setVisible(!outbox && hasArchive);


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

@ -146,7 +146,7 @@ public class FragmentMessages extends FragmentEx {
public Bundle loadInBackground() { public Bundle loadInBackground() {
Bundle result = new Bundle(); Bundle result = new Bundle();
try { try {
EntityFolder drafts = DB.getInstance(getContext()).folder().getPrimaryDraftFolder();
EntityFolder drafts = DB.getInstance(getContext()).folder().getPrimaryFolder(EntityFolder.TYPE_DRAFTS);
result.putBoolean("drafts", drafts != null); result.putBoolean("drafts", drafts != null);
} catch (Throwable ex) { } catch (Throwable ex) {
Log.e(Helper.TAG, ex + "\n" + Log.getStackTraceString(ex)); Log.e(Helper.TAG, ex + "\n" + Log.getStackTraceString(ex));


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

@ -48,6 +48,7 @@ import com.sun.mail.imap.IMAPFolder;
import com.sun.mail.imap.IMAPMessage; import com.sun.mail.imap.IMAPMessage;
import com.sun.mail.imap.IMAPStore; import com.sun.mail.imap.IMAPStore;
import com.sun.mail.imap.protocol.IMAPProtocol; import com.sun.mail.imap.protocol.IMAPProtocol;
import com.sun.mail.smtp.SMTPSendFailedException;
import org.json.JSONArray; import org.json.JSONArray;
import org.json.JSONException; import org.json.JSONException;
@ -852,6 +853,10 @@ public class ServiceSynchronize extends LifecycleService {
// There is no use in repeating // There is no use in repeating
operation.deleteOperation(op.id); operation.deleteOperation(op.id);
} catch (SMTPSendFailedException ex) {
Log.w(Helper.TAG, ex + "\n" + Log.getStackTraceString(ex));
operation.deleteOperation(op.id);
reportError(null, folder.name, ex);
} }
} finally { } finally {
Log.i(Helper.TAG, folder.name + " end op=" + op.id + "/" + op.name); Log.i(Helper.TAG, folder.name + " end op=" + op.id + "/" + op.name);


+ 2
- 2
app/src/main/res/menu/action_compose.xml View File

@ -3,9 +3,9 @@
xmlns:app="http://schemas.android.com/apk/res-auto"> xmlns:app="http://schemas.android.com/apk/res-auto">
<item <item
android:id="@+id/action_delete"
android:id="@+id/action_trash"
android:icon="@drawable/baseline_delete_24" android:icon="@drawable/baseline_delete_24"
android:title="@string/title_delete"
android:title="@string/title_trash"
app:showAsAction="ifRoom" /> app:showAsAction="ifRoom" />
<item <item


+ 2
- 2
app/src/main/res/menu/action_view_bottom.xml View File

@ -3,9 +3,9 @@
xmlns:app="http://schemas.android.com/apk/res-auto"> xmlns:app="http://schemas.android.com/apk/res-auto">
<item <item
android:id="@+id/action_delete"
android:id="@+id/action_trash"
android:icon="@drawable/baseline_delete_24" android:icon="@drawable/baseline_delete_24"
android:title="@string/title_delete"
android:title="@string/title_trash"
app:showAsAction="ifRoom" /> app:showAsAction="ifRoom" />
<item <item


+ 2
- 2
app/src/main/res/values/strings.xml View File

@ -89,7 +89,7 @@
<string name="title_forward">Forward</string> <string name="title_forward">Forward</string>
<string name="title_reply_all">Reply to all</string> <string name="title_reply_all">Reply to all</string>
<string name="title_delete">Delete</string>
<string name="title_trash">Trash</string>
<string name="title_spam">Spam</string> <string name="title_spam">Spam</string>
<string name="title_move">Move</string> <string name="title_move">Move</string>
<string name="title_archive">Archive</string> <string name="title_archive">Archive</string>
@ -113,7 +113,7 @@
<string name="title_from_missing">Sender missing</string> <string name="title_from_missing">Sender missing</string>
<string name="title_to_missing">Recipient missing</string> <string name="title_to_missing">Recipient missing</string>
<string name="title_draft_deleted">Draft deleted</string>
<string name="title_draft_trashed">Draft trashed</string>
<string name="title_draft_saved">Draft saved</string> <string name="title_draft_saved">Draft saved</string>
<string name="title_queued">Message queued</string> <string name="title_queued">Message queued</string>


Loading…
Cancel
Save