mirror of
https://github.com/M66B/FairEmail.git
synced 2024-12-27 18:27:43 +00:00
Auto discard empty drafts
This commit is contained in:
parent
599e98840b
commit
8f0f809c86
1 changed files with 34 additions and 8 deletions
|
@ -70,6 +70,7 @@ import android.widget.Toast;
|
||||||
import com.google.android.material.bottomnavigation.BottomNavigationView;
|
import com.google.android.material.bottomnavigation.BottomNavigationView;
|
||||||
import com.google.android.material.snackbar.Snackbar;
|
import com.google.android.material.snackbar.Snackbar;
|
||||||
|
|
||||||
|
import org.jsoup.Jsoup;
|
||||||
import org.openintents.openpgp.OpenPgpError;
|
import org.openintents.openpgp.OpenPgpError;
|
||||||
import org.openintents.openpgp.util.OpenPgpApi;
|
import org.openintents.openpgp.util.OpenPgpApi;
|
||||||
import org.openintents.openpgp.util.OpenPgpServiceConnection;
|
import org.openintents.openpgp.util.OpenPgpServiceConnection;
|
||||||
|
@ -890,7 +891,9 @@ public class FragmentCompose extends FragmentEx {
|
||||||
}
|
}
|
||||||
|
|
||||||
private void handleExit() {
|
private void handleExit() {
|
||||||
if (getLifecycle().getCurrentState().isAtLeast(Lifecycle.State.RESUMED))
|
if (isEmpty())
|
||||||
|
onAction(R.id.action_delete);
|
||||||
|
else
|
||||||
new DialogBuilderLifecycle(getContext(), getViewLifecycleOwner())
|
new DialogBuilderLifecycle(getContext(), getViewLifecycleOwner())
|
||||||
.setMessage(R.string.title_ask_discard)
|
.setMessage(R.string.title_ask_discard)
|
||||||
.setPositiveButton(R.string.title_yes, new DialogInterface.OnClickListener() {
|
.setPositiveButton(R.string.title_yes, new DialogInterface.OnClickListener() {
|
||||||
|
@ -931,6 +934,7 @@ public class FragmentCompose extends FragmentEx {
|
||||||
args.putString("cc", etCc.getText().toString());
|
args.putString("cc", etCc.getText().toString());
|
||||||
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.putBoolean("empty", isEmpty());
|
||||||
|
|
||||||
Spannable spannable = etBody.getText();
|
Spannable spannable = etBody.getText();
|
||||||
UnderlineSpan[] uspans = spannable.getSpans(0, spannable.length(), UnderlineSpan.class);
|
UnderlineSpan[] uspans = spannable.getSpans(0, spannable.length(), UnderlineSpan.class);
|
||||||
|
@ -943,6 +947,24 @@ public class FragmentCompose extends FragmentEx {
|
||||||
actionLoader.load(this, args);
|
actionLoader.load(this, args);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private boolean isEmpty() {
|
||||||
|
if (!TextUtils.isEmpty(etExtra.getText().toString().trim()))
|
||||||
|
return false;
|
||||||
|
if (!TextUtils.isEmpty(etTo.getText().toString().trim()))
|
||||||
|
return false;
|
||||||
|
if (!TextUtils.isEmpty(etCc.getText().toString().trim()))
|
||||||
|
return false;
|
||||||
|
if (!TextUtils.isEmpty(etBcc.getText().toString().trim()))
|
||||||
|
return false;
|
||||||
|
if (!TextUtils.isEmpty(etSubject.getText().toString().trim()))
|
||||||
|
return false;
|
||||||
|
if (!TextUtils.isEmpty(Jsoup.parse(Html.toHtml(etBody.getText())).text().trim()))
|
||||||
|
return false;
|
||||||
|
if (rvAttachment.getAdapter().getItemCount() > 0)
|
||||||
|
return false;
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
private static EntityAttachment addAttachment(Context context, long id, Uri uri,
|
private static EntityAttachment addAttachment(Context context, long id, Uri uri,
|
||||||
boolean image) throws IOException {
|
boolean image) throws IOException {
|
||||||
EntityAttachment attachment = new EntityAttachment();
|
EntityAttachment attachment = new EntityAttachment();
|
||||||
|
@ -1518,6 +1540,7 @@ public class FragmentCompose extends FragmentEx {
|
||||||
String bcc = args.getString("bcc");
|
String bcc = args.getString("bcc");
|
||||||
String subject = args.getString("subject");
|
String subject = args.getString("subject");
|
||||||
String body = args.getString("body");
|
String body = args.getString("body");
|
||||||
|
boolean empty = args.getBoolean("empty");
|
||||||
|
|
||||||
EntityMessage draft;
|
EntityMessage draft;
|
||||||
|
|
||||||
|
@ -1605,12 +1628,14 @@ public class FragmentCompose extends FragmentEx {
|
||||||
if (action == R.id.action_delete) {
|
if (action == R.id.action_delete) {
|
||||||
EntityOperation.queue(db, draft, EntityOperation.DELETE);
|
EntityOperation.queue(db, draft, EntityOperation.DELETE);
|
||||||
|
|
||||||
|
if (!empty) {
|
||||||
Handler handler = new Handler(Looper.getMainLooper());
|
Handler handler = new Handler(Looper.getMainLooper());
|
||||||
handler.post(new Runnable() {
|
handler.post(new Runnable() {
|
||||||
public void run() {
|
public void run() {
|
||||||
Toast.makeText(context, R.string.title_draft_deleted, Toast.LENGTH_LONG).show();
|
Toast.makeText(context, R.string.title_draft_deleted, Toast.LENGTH_LONG).show();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
}
|
||||||
} else if (action == R.id.action_save || action == R.id.menu_encrypt) {
|
} else if (action == R.id.action_save || action == R.id.menu_encrypt) {
|
||||||
EntityOperation.queue(db, draft, EntityOperation.ADD);
|
EntityOperation.queue(db, draft, EntityOperation.ADD);
|
||||||
|
|
||||||
|
@ -1852,6 +1877,7 @@ public class FragmentCompose extends FragmentEx {
|
||||||
private ActivityBase.IBackPressedListener onBackPressedListener = new ActivityBase.IBackPressedListener() {
|
private ActivityBase.IBackPressedListener onBackPressedListener = new ActivityBase.IBackPressedListener() {
|
||||||
@Override
|
@Override
|
||||||
public boolean onBackPressed() {
|
public boolean onBackPressed() {
|
||||||
|
if (getLifecycle().getCurrentState().isAtLeast(Lifecycle.State.RESUMED))
|
||||||
handleExit();
|
handleExit();
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue