Moved plain only to compose menu

pull/156/head
M66B 5 years ago
parent 375a97a724
commit 18d63048c1

File diff suppressed because it is too large Load Diff

@ -659,8 +659,11 @@ class Core {
MessageHelper.MessageParts parts = helper.getMessageParts();
String body = parts.getHtml(context);
Helper.writeText(message.getFile(context), body);
db.message().setMessageContent(message.id, true,
HtmlHelper.getPreview(body), parts.getWarnings(message.warning));
db.message().setMessageContent(message.id,
true,
parts.isPlainOnly(),
HtmlHelper.getPreview(body),
parts.getWarnings(message.warning));
updateMessageSize(context, message.id);
}
@ -1526,8 +1529,11 @@ class Core {
if (state.getNetworkState().isUnmetered() || (message.size != null && message.size < maxSize)) {
String body = parts.getHtml(context);
Helper.writeText(message.getFile(context), body);
db.message().setMessageContent(message.id, true,
HtmlHelper.getPreview(body), parts.getWarnings(message.warning));
db.message().setMessageContent(message.id,
true,
parts.isPlainOnly(),
HtmlHelper.getPreview(body),
parts.getWarnings(message.warning));
Log.i(folder.name + " downloaded message id=" + message.id + " size=" + message.size);
}
}

@ -51,7 +51,7 @@ import io.requery.android.database.sqlite.RequerySQLiteOpenHelperFactory;
// https://developer.android.com/topic/libraries/architecture/room.html
@Database(
version = 78,
version = 79,
entities = {
EntityIdentity.class,
EntityAccount.class,
@ -794,6 +794,13 @@ public abstract class DB extends RoomDatabase {
db.execSQL("ALTER TABLE `folder` ADD COLUMN `auto_delete` INTEGER NOT NULL DEFAULT 0");
}
})
.addMigrations(new Migration(78, 79) {
@Override
public void migrate(SupportSQLiteDatabase db) {
Log.i("DB migration from version " + startVersion + " to " + endVersion);
db.execSQL("ALTER TABLE `message` ADD COLUMN `plain_only` INTEGER");
}
})
.build();
}

@ -358,8 +358,8 @@ public interface DaoMessage {
@Query("UPDATE message SET revisions = :revisions WHERE id = :id")
int setMessageRevisions(long id, Integer revisions);
@Query("UPDATE message SET content = :content, preview = :preview, warning = :warning WHERE id = :id")
int setMessageContent(long id, boolean content, String preview, String warning);
@Query("UPDATE message SET content = :content, plain_only = :plain_only, preview = :preview, warning = :warning WHERE id = :id")
int setMessageContent(long id, boolean content, Boolean plain_only, String preview, String warning);
@Query("UPDATE message SET size = :size WHERE id = :id")
int setMessageSize(long id, Long size);

@ -82,7 +82,7 @@ public class EntityIdentity {
public String replyto;
public String bcc;
@NonNull
public Boolean plain_only = false;
public Boolean plain_only = false; // obsolete
@NonNull
public Boolean encrypt = false;
@NonNull
@ -129,7 +129,6 @@ public class EntityIdentity {
json.put("replyto", replyto);
json.put("bcc", bcc);
json.put("plain_only", plain_only);
json.put("encrypt", encrypt);
json.put("delivery_receipt", delivery_receipt);
json.put("read_receipt", read_receipt);
@ -173,8 +172,6 @@ public class EntityIdentity {
if (json.has("bcc") && !json.isNull("bcc"))
identity.bcc = json.getString("bcc");
if (json.has("plain_only"))
identity.plain_only = json.getBoolean("plain_only");
if (json.has("encrypt"))
identity.encrypt = json.getBoolean("encrypt");
if (json.has("delivery_receipt"))
@ -212,7 +209,6 @@ public class EntityIdentity {
this.sender_extra.equals(sender_extra) &&
Objects.equals(this.replyto, other.replyto) &&
Objects.equals(this.bcc, other.bcc) &&
this.plain_only.equals(other.plain_only) &&
this.encrypt.equals(other.encrypt) &&
this.delivery_receipt.equals(other.delivery_receipt) &&
this.read_receipt.equals(other.read_receipt) &&

@ -109,6 +109,7 @@ public class EntityMessage implements Serializable {
public Long size;
@NonNull
public Boolean content = false;
public Boolean plain_only = null;
public String preview;
public Long sent; // compose = null
@NonNull
@ -222,6 +223,7 @@ public class EntityMessage implements Serializable {
Objects.equals(this.subject, other.subject) &&
Objects.equals(this.size, other.size) &&
this.content == other.content &&
// plain_only
Objects.equals(this.preview, other.preview) &&
// sent
this.received.equals(other.received) &&
@ -276,6 +278,7 @@ public class EntityMessage implements Serializable {
Objects.equals(this.subject, other.subject) &&
Objects.equals(this.size, other.size) &&
this.content == other.content &&
Objects.equals(this.plain_only, other.plain_only) &&
Objects.equals(this.preview, other.preview) &&
Objects.equals(this.sent, other.sent) &&
this.received.equals(other.received) &&

@ -174,7 +174,7 @@ public class EntityOperation {
Helper.copy(msource, mtarget);
} catch (IOException ex) {
Log.e(ex);
db.message().setMessageContent(tmpid, false, null, null);
db.message().setMessageContent(tmpid, false, null, null, null);
db.message().setMessageSize(message.id, null);
}

@ -265,7 +265,11 @@ public class EntityRule {
reply.id = db.message().insertMessage(reply);
Helper.writeText(reply.getFile(context), body);
db.message().setMessageContent(reply.id, true, HtmlHelper.getPreview(body), null);
db.message().setMessageContent(reply.id,
true,
false,
HtmlHelper.getPreview(body),
null);
Core.updateMessageSize(context, reply.id);

@ -191,6 +191,7 @@ public class FragmentCompose extends FragmentBase {
private boolean prefix_once = false;
private boolean monospaced = false;
private boolean style = true;
private boolean plain_only = false;
private boolean encrypt = false;
private OpenPgpServiceConnection pgpService;
private long[] pgpKeyIds;
@ -744,6 +745,7 @@ public class FragmentCompose extends FragmentBase {
menu.findItem(R.id.menu_clear).setVisible(state == State.LOADED);
menu.findItem(R.id.menu_contact_group).setVisible(state == State.LOADED);
menu.findItem(R.id.menu_answer).setVisible(state == State.LOADED);
menu.findItem(R.id.menu_plain_only).setVisible(state == State.LOADED);
menu.findItem(R.id.menu_encrypt).setVisible(state == State.LOADED);
menu.findItem(R.id.menu_send_after).setVisible(state == State.LOADED);
@ -754,11 +756,13 @@ public class FragmentCompose extends FragmentBase {
menu.findItem(R.id.menu_clear).setEnabled(!busy);
menu.findItem(R.id.menu_contact_group).setEnabled(!busy);
menu.findItem(R.id.menu_answer).setEnabled(!busy);
menu.findItem(R.id.menu_plain_only).setEnabled(!busy);
menu.findItem(R.id.menu_encrypt).setEnabled(!busy);
menu.findItem(R.id.menu_send_after).setEnabled(!busy);
menu.findItem(R.id.menu_style_toolbar).setChecked(style);
menu.findItem(R.id.menu_plain_only).setChecked(plain_only);
menu.findItem(R.id.menu_encrypt).setChecked(encrypt);
bottom_navigation.getMenu().findItem(R.id.action_send)
.setTitle(encrypt ? R.string.title_encrypt : R.string.title_send);
@ -798,6 +802,9 @@ public class FragmentCompose extends FragmentBase {
case R.id.menu_answer:
onMenuAnswer();
return true;
case R.id.menu_plain_only:
onMenuPlainOnly();
return true;
case R.id.menu_encrypt:
onMenuEncrypt();
return true;
@ -1043,6 +1050,12 @@ public class FragmentCompose extends FragmentBase {
}.execute(this, new Bundle(), "compose:answer");
}
private void onMenuPlainOnly() {
plain_only = !plain_only;
getActivity().invalidateOptionsMenu();
onAction(R.id.action_save);
}
private void onMenuEncrypt() {
encrypt = !encrypt;
getActivity().invalidateOptionsMenu();
@ -1687,6 +1700,7 @@ public class FragmentCompose extends FragmentBase {
args.putString("bcc", etBcc.getText().toString().trim());
args.putString("subject", etSubject.getText().toString().trim());
args.putString("body", HtmlHelper.toHtml(etBody.getText()));
args.putBoolean("plain_only", plain_only);
args.putBoolean("empty", isEmpty());
Log.i("Run execute id=" + working);
@ -2047,6 +2061,7 @@ public class FragmentCompose extends FragmentBase {
draft.subject = ref.subject;
}
draft.plain_only = ref.plain_only;
if (answer > 0)
body = EntityAnswer.getAnswerText(db, answer, draft.to) + body;
}
@ -2105,7 +2120,11 @@ public class FragmentCompose extends FragmentBase {
draft.id = db.message().insertMessage(draft);
Helper.writeText(draft.getFile(context), body);
db.message().setMessageContent(draft.id, true, HtmlHelper.getPreview(body), null);
db.message().setMessageContent(draft.id,
true,
draft.plain_only,
HtmlHelper.getPreview(body),
null);
Core.updateMessageSize(context, draft.id);
@ -2187,6 +2206,7 @@ public class FragmentCompose extends FragmentBase {
bottom_navigation.getMenu().findItem(R.id.action_undo).setVisible(draft.revision != null && draft.revision > 1);
bottom_navigation.getMenu().findItem(R.id.action_redo).setVisible(draft.revision != null && !draft.revision.equals(draft.revisions));
plain_only = (draft.plain_only != null && draft.plain_only);
getActivity().invalidateOptionsMenu();
new SimpleTask<List<TupleIdentityEx>>() {
@ -2344,6 +2364,7 @@ public class FragmentCompose extends FragmentBase {
String bcc = args.getString("bcc");
String subject = args.getString("subject");
String body = args.getString("body");
boolean plain_only = args.getBoolean("plain_only");
boolean empty = args.getBoolean("empty");
EntityMessage draft;
@ -2489,12 +2510,17 @@ public class FragmentCompose extends FragmentBase {
db.message().setMessageRevision(draft.id, draft.revision);
db.message().setMessageContent(draft.id, true, HtmlHelper.getPreview(body), null);
db.message().setMessageContent(draft.id,
true,
draft.plain_only, // unchanged
HtmlHelper.getPreview(body),
null);
Core.updateMessageSize(context, draft.id);
}
} else {
String previous = Helper.readText(draft.getFile(context));
if (!body.equals(previous)) {
if (!body.equals(previous) ||
plain_only != (draft.plain_only != null && draft.plain_only)) {
dirty = true;
if (draft.revisions == null)
@ -2509,7 +2535,12 @@ public class FragmentCompose extends FragmentBase {
db.message().setMessageRevision(draft.id, draft.revision);
db.message().setMessageRevisions(draft.id, draft.revisions);
db.message().setMessageContent(draft.id, true, HtmlHelper.getPreview(body), null);
draft.plain_only = plain_only;
db.message().setMessageContent(draft.id,
true,
draft.plain_only,
HtmlHelper.getPreview(body),
null);
Core.updateMessageSize(context, draft.id);
}
}

@ -105,7 +105,6 @@ public class FragmentIdentity extends FragmentBase {
private CheckBox cbSenderExtra;
private EditText etReplyTo;
private EditText etBcc;
private CheckBox cbPlainOnly;
private CheckBox cbEncrypt;
private CheckBox cbDeliveryReceipt;
private CheckBox cbReadReceipt;
@ -177,7 +176,6 @@ public class FragmentIdentity extends FragmentBase {
cbSenderExtra = view.findViewById(R.id.cbSenderExtra);
etReplyTo = view.findViewById(R.id.etReplyTo);
etBcc = view.findViewById(R.id.etBcc);
cbPlainOnly = view.findViewById(R.id.cbPlainOnly);
cbEncrypt = view.findViewById(R.id.cbEncrypt);
cbDeliveryReceipt = view.findViewById(R.id.cbDeliveryReceipt);
cbReadReceipt = view.findViewById(R.id.cbReadReceipt);
@ -501,7 +499,6 @@ public class FragmentIdentity extends FragmentBase {
args.putBoolean("sender_extra", cbSenderExtra.isChecked());
args.putString("replyto", etReplyTo.getText().toString().trim());
args.putString("bcc", etBcc.getText().toString().trim());
args.putBoolean("plain_only", cbPlainOnly.isChecked());
args.putBoolean("encrypt", cbEncrypt.isChecked());
args.putBoolean("delivery_receipt", cbDeliveryReceipt.isChecked());
args.putBoolean("read_receipt", cbReadReceipt.isChecked());
@ -565,7 +562,6 @@ public class FragmentIdentity extends FragmentBase {
boolean sender_extra = args.getBoolean("sender_extra");
String replyto = args.getString("replyto");
String bcc = args.getString("bcc");
boolean plain_only = args.getBoolean("plain_only");
boolean encrypt = args.getBoolean("encrypt");
boolean delivery_receipt = args.getBoolean("delivery_receipt");
boolean read_receipt = args.getBoolean("read_receipt");
@ -686,7 +682,6 @@ public class FragmentIdentity extends FragmentBase {
identity.sender_extra = sender_extra;
identity.replyto = replyto;
identity.bcc = bcc;
identity.plain_only = plain_only;
identity.encrypt = encrypt;
identity.delivery_receipt = delivery_receipt;
identity.read_receipt = read_receipt;
@ -793,7 +788,6 @@ public class FragmentIdentity extends FragmentBase {
cbSenderExtra.setChecked(identity != null && identity.sender_extra);
etReplyTo.setText(identity == null ? null : identity.replyto);
etBcc.setText(identity == null ? null : identity.bcc);
cbPlainOnly.setChecked(identity == null ? false : identity.plain_only);
cbEncrypt.setChecked(identity == null ? false : identity.encrypt);
cbDeliveryReceipt.setChecked(identity == null ? false : identity.delivery_receipt);
cbReadReceipt.setChecked(identity == null ? false : identity.read_receipt);

@ -427,7 +427,11 @@ public class Helper {
draft.ui_seen = true;
draft.id = db.message().insertMessage(draft);
writeText(draft.getFile(context), body);
db.message().setMessageContent(draft.id, true, HtmlHelper.getPreview(body), null);
db.message().setMessageContent(draft.id,
true,
false,
HtmlHelper.getPreview(body),
null);
attachSettings(context, draft.id, 1);
attachAccounts(context, draft.id, 2);

@ -355,7 +355,7 @@ public class MessageHelper {
Log.i("Attachments available=" + available);
if (available == 0)
if (identity != null && identity.plain_only)
if (message.plain_only != null && message.plain_only)
imessage.setContent(plainContent, "text/plain; charset=" + Charset.defaultCharset().name());
else
imessage.setContent(alternativePart);
@ -363,7 +363,7 @@ public class MessageHelper {
Multipart mixedPart = new MimeMultipart("mixed");
BodyPart attachmentPart = new MimeBodyPart();
if (identity != null && identity.plain_only)
if (message.plain_only != null && message.plain_only)
attachmentPart.setContent(plainContent, "text/plain; charset=" + Charset.defaultCharset().name());
else
attachmentPart.setContent(alternativePart);
@ -762,6 +762,12 @@ public class MessageHelper {
private List<AttachmentPart> attachments = new ArrayList<>();
private ArrayList<String> warnings = new ArrayList<>();
Boolean isPlainOnly() {
if (plain == null && html == null)
return null;
return (html == null);
}
String getHtml(Context context) throws MessagingException {
if (plain == null && html == null) {
warnings.add(context.getString(R.string.title_no_body));

@ -511,15 +511,6 @@
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/tvBcc" />
<CheckBox
android:id="@+id/cbPlainOnly"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="12dp"
android:text="@string/title_identity_plain_text"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/etBcc" />
<CheckBox
android:id="@+id/cbEncrypt"
android:layout_width="wrap_content"
@ -527,7 +518,7 @@
android:layout_marginTop="12dp"
android:text="@string/title_identity_encrypt"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/cbPlainOnly" />
app:layout_constraintTop_toBottomOf="@id/etBcc" />
<CheckBox
android:id="@+id/cbDeliveryReceipt"
@ -645,7 +636,7 @@
cbSynchronize,cbPrimary,
cbSenderExtra,tvSenderExtraHint,
tvReplyTo,etReplyTo,tvBcc,etBcc,
cbPlainOnly,cbEncrypt,cbDeliveryReceipt,cbReadReceipt,tvReceipt,
cbEncrypt,cbDeliveryReceipt,cbReadReceipt,tvReceipt,
cbStoreSent,tvStoreSent" />
</androidx.constraintlayout.widget.ConstraintLayout>
</ScrollView>

@ -49,6 +49,12 @@
android:title="@string/title_insert_template"
app:showAsAction="never" />
<item
android:id="@+id/menu_plain_only"
android:checkable="true"
android:title="@string/title_identity_plain_text"
app:showAsAction="never" />
<item
android:id="@+id/menu_encrypt"
android:checkable="true"

Loading…
Cancel
Save