From 4ed1064d183f95d01ffcb06fe9adf1d215fe6862 Mon Sep 17 00:00:00 2001 From: M66B Date: Tue, 14 Aug 2018 13:45:18 +0000 Subject: [PATCH] Save drafts with content only --- .../java/eu/faircode/email/EntityMessage.java | 2 ++ .../eu/faircode/email/FragmentCompose.java | 25 +++++++++++++------ app/src/main/res/layout/fragment_compose.xml | 1 - 3 files changed, 19 insertions(+), 9 deletions(-) diff --git a/app/src/main/java/eu/faircode/email/EntityMessage.java b/app/src/main/java/eu/faircode/email/EntityMessage.java index 55c34a81dd..24ad79b689 100644 --- a/app/src/main/java/eu/faircode/email/EntityMessage.java +++ b/app/src/main/java/eu/faircode/email/EntityMessage.java @@ -19,6 +19,8 @@ package eu.faircode.email; Copyright 2018 by Marcel Bokhorst (M66B) */ +import android.text.TextUtils; + import java.util.Date; import java.util.Random; diff --git a/app/src/main/java/eu/faircode/email/FragmentCompose.java b/app/src/main/java/eu/faircode/email/FragmentCompose.java index f36d01934b..e6de0aebac 100644 --- a/app/src/main/java/eu/faircode/email/FragmentCompose.java +++ b/app/src/main/java/eu/faircode/email/FragmentCompose.java @@ -95,7 +95,7 @@ public class FragmentCompose extends FragmentEx { private EditText etBody; private BottomNavigationView bottom_navigation; private ProgressBar pbWait; - private Group grpFrom; + //private Group grpFrom; private Group grpAddresses; private Group grpAttachments; private Group grpReady; @@ -128,7 +128,7 @@ public class FragmentCompose extends FragmentEx { etBody = view.findViewById(R.id.etBody); bottom_navigation = view.findViewById(R.id.bottom_navigation); pbWait = view.findViewById(R.id.pbWait); - grpFrom = view.findViewById(R.id.grpFrom); + //grpFrom = view.findViewById(R.id.grpFrom); grpAddresses = view.findViewById(R.id.grpAddresses); grpAttachments = view.findViewById(R.id.grpAttachments); grpReady = view.findViewById(R.id.grpReady); @@ -186,7 +186,8 @@ public class FragmentCompose extends FragmentEx { setHasOptionsMenu(true); // Initialize - grpFrom.setVisibility(View.GONE); + spFrom.setEnabled(false); + //grpFrom.setVisibility(View.GONE); grpAddresses.setVisibility(View.GONE); grpAttachments.setVisibility(View.GONE); grpReady.setVisibility(View.GONE); @@ -643,6 +644,7 @@ public class FragmentCompose extends FragmentEx { DB db = DB.getInstance(getContext()); + db.identity().liveIdentities(true).removeObservers(getViewLifecycleOwner()); db.identity().liveIdentities(true).observe(getViewLifecycleOwner(), new Observer>() { @Override public void onChanged(@Nullable List identities) { @@ -696,7 +698,8 @@ public class FragmentCompose extends FragmentEx { break; } - grpFrom.setVisibility(View.VISIBLE); + spFrom.setEnabled(true); + //grpFrom.setVisibility(View.VISIBLE); } }); @@ -784,6 +787,11 @@ public class FragmentCompose extends FragmentEx { EntityOperation.queue(db, draft, EntityOperation.MOVE, trash.id); } else if (action == R.id.action_save) { + if (ato == null && acc == null && abcc == null && + TextUtils.isEmpty(subject) && TextUtils.isEmpty(body) && + db.attachment().getAttachmentCount(draft.id) == 0) + return null; + db.message().updateMessage(draft); EntityOperation.queue(db, draft, EntityOperation.ADD); @@ -844,7 +852,7 @@ public class FragmentCompose extends FragmentEx { @Override protected void onLoaded(Bundle args, EntityMessage draft) { int action = args.getInt("action"); - Log.i(Helper.TAG, "Loaded action id=" + draft.id + " action=" + action); + Log.i(Helper.TAG, "Loaded action id=" + (draft == null ? null : draft.id) + " action=" + action); Helper.setViewsEnabled(view, true); getActivity().invalidateOptionsMenu(); @@ -854,10 +862,11 @@ public class FragmentCompose extends FragmentEx { getFragmentManager().popBackStack(); Toast.makeText(getContext(), R.string.title_draft_trashed, Toast.LENGTH_LONG).show(); - } else if (action == R.id.action_save) - Toast.makeText(getContext(), R.string.title_draft_saved, Toast.LENGTH_LONG).show(); + } else if (action == R.id.action_save) { + if (draft != null) + Toast.makeText(getContext(), R.string.title_draft_saved, Toast.LENGTH_LONG).show(); - else if (action == R.id.action_send) { + } else if (action == R.id.action_send) { autosave = false; getFragmentManager().popBackStack(); Toast.makeText(getContext(), R.string.title_queued, Toast.LENGTH_LONG).show(); diff --git a/app/src/main/res/layout/fragment_compose.xml b/app/src/main/res/layout/fragment_compose.xml index de54ac9049..cb865994df 100644 --- a/app/src/main/res/layout/fragment_compose.xml +++ b/app/src/main/res/layout/fragment_compose.xml @@ -8,7 +8,6 @@ android:id="@+id/spFrom" android:layout_width="0dp" android:layout_height="wrap_content" - android:layout_marginStart="6dp" android:layout_marginTop="6dp" app:layout_constraintEnd_toStartOf="@+id/ivIdentityAdd" app:layout_constraintStart_toStartOf="parent"