Default encrypt on replying to encrypted message

pull/159/head
M66B 5 years ago
parent 369a476513
commit a8215cd7bd

File diff suppressed because it is too large Load Diff

@ -54,7 +54,7 @@ import io.requery.android.database.sqlite.RequerySQLiteOpenHelperFactory;
// https://developer.android.com/topic/libraries/architecture/room.html
@Database(
version = 93,
version = 94,
entities = {
EntityIdentity.class,
EntityAccount.class,
@ -911,6 +911,13 @@ public abstract class DB extends RoomDatabase {
db.execSQL("ALTER TABLE `message` ADD COLUMN `mx` INTEGER");
}
})
.addMigrations(new Migration(93, 94) {
@Override
public void migrate(SupportSQLiteDatabase db) {
Log.i("DB migration from version " + startVersion + " to " + endVersion);
db.execSQL("ALTER TABLE `message` ADD COLUMN `encrypt` INTEGER");
}
})
.build();
}

@ -410,6 +410,9 @@ public interface DaoMessage {
@Query("UPDATE message SET plain_only = :plain_only WHERE id = :id")
int setMessagePlainOnly(long id, boolean plain_only);
@Query("UPDATE message SET encrypt = :encrypt WHERE id = :id")
int setMessageEncrypt(long id, boolean encrypt);
@Query("UPDATE message SET last_attempt = :last_attempt WHERE id = :id")
int setMessageLastAttempt(long id, long last_attempt);

@ -115,6 +115,7 @@ public class EntityMessage implements Serializable {
@NonNull
public Boolean content = false;
public Boolean plain_only = null;
public Boolean encrypt = null;
public String preview;
public Long sent; // compose = null
@NonNull

@ -796,6 +796,7 @@ public class FragmentCompose extends FragmentBase {
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);
}
@ -918,6 +919,7 @@ public class FragmentCompose extends FragmentBase {
private void onMenuEncrypt() {
encrypt = !encrypt;
getActivity().invalidateOptionsMenu();
onAction(R.id.action_save);
}
private void onMenuSendAfter() {
@ -1744,6 +1746,7 @@ public class FragmentCompose extends FragmentBase {
args.putString("subject", etSubject.getText().toString().trim());
args.putString("body", HtmlHelper.toHtml(etBody.getText()));
args.putBoolean("plain_only", plain_only);
args.putBoolean("encrypt", encrypt);
args.putBoolean("empty", isEmpty());
Log.i("Run execute id=" + working);
@ -2174,7 +2177,12 @@ public class FragmentCompose extends FragmentBase {
int sequence = 0;
List<EntityAttachment> attachments = db.attachment().getAttachments(ref.id);
for (EntityAttachment attachment : attachments)
if (attachment.encryption == null &&
if (attachment.encryption != null &&
attachment.encryption.equals(EntityAttachment.PGP_MESSAGE)) {
draft.encrypt = true;
db.message().setMessageEncrypt(draft.id, true);
} else if (attachment.encryption == null &&
("forward".equals(action) ||
(attachment.isInline() && attachment.isImage()))) {
if (attachment.available) {
@ -2241,6 +2249,7 @@ public class FragmentCompose extends FragmentBase {
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);
encrypt = (draft.encrypt != null && draft.encrypt);
getActivity().invalidateOptionsMenu();
if (args.getBoolean("incomplete"))
@ -2402,6 +2411,7 @@ public class FragmentCompose extends FragmentBase {
String subject = args.getString("subject");
String body = args.getString("body");
boolean plain_only = args.getBoolean("plain_only");
boolean encrypt = args.getBoolean("encrypt");
boolean empty = args.getBoolean("empty");
EntityMessage draft;
@ -2520,6 +2530,7 @@ public class FragmentCompose extends FragmentBase {
!MessageHelper.equal(draft.cc, acc) ||
!MessageHelper.equal(draft.bcc, abcc) ||
!Objects.equals(draft.subject, subject) ||
((draft.encrypt != null && draft.encrypt) != encrypt) ||
last_available != available);
last_available = available;
@ -2533,6 +2544,7 @@ public class FragmentCompose extends FragmentBase {
draft.cc = acc;
draft.bcc = abcc;
draft.subject = subject;
draft.encrypt = encrypt;
draft.received = new Date().getTime();
draft.sender = MessageHelper.getSortKey(draft.from);
Uri lookupUri = ContactInfo.getLookupUri(context, draft.from);
@ -3069,8 +3081,10 @@ public class FragmentCompose extends FragmentBase {
public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {
EntityIdentity identity = (EntityIdentity) parent.getAdapter().getItem(position);
encrypt = (identity != null && identity.encrypt && Helper.isPro(getContext()));
getActivity().invalidateOptionsMenu();
if (identity != null && identity.encrypt) {
encrypt = true;
getActivity().invalidateOptionsMenu();
}
int at = (identity == null ? -1 : identity.email.indexOf('@'));
etExtra.setHint(at < 0 ? null : identity.email.substring(0, at));

@ -116,6 +116,7 @@ public class FragmentIdentity extends FragmentBase {
private CheckBox cbSenderExtra;
private EditText etReplyTo;
private EditText etBcc;
private TextView tvEncryptPro;
private CheckBox cbEncrypt;
private CheckBox cbDeliveryReceipt;
private CheckBox cbReadReceipt;
@ -193,6 +194,7 @@ public class FragmentIdentity extends FragmentBase {
cbSenderExtra = view.findViewById(R.id.cbSenderExtra);
etReplyTo = view.findViewById(R.id.etReplyTo);
etBcc = view.findViewById(R.id.etBcc);
tvEncryptPro = view.findViewById(R.id.tvEncryptPro);
cbEncrypt = view.findViewById(R.id.cbEncrypt);
cbDeliveryReceipt = view.findViewById(R.id.cbDeliveryReceipt);
cbReadReceipt = view.findViewById(R.id.cbReadReceipt);
@ -423,6 +425,8 @@ public class FragmentIdentity extends FragmentBase {
cbInsecure.setVisibility(View.GONE);
tilPassword.setEndIconMode(id < 0 ? END_ICON_PASSWORD_TOGGLE : END_ICON_NONE);
Helper.linkPro(tvEncryptPro);
btnAdvanced.setVisibility(View.GONE);
btnSave.setVisibility(View.GONE);

@ -824,7 +824,7 @@ public class Helper {
}
static void linkPro(final TextView tv) {
if (isPro(tv.getContext()))
if (isPro(tv.getContext()) && !BuildConfig.DEBUG)
hide(tv);
else {
final Intent pro = new Intent(Intent.ACTION_VIEW, Uri.parse(BuildConfig.PRO_FEATURES_URI));

@ -543,6 +543,18 @@
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/etBcc" />
<TextView
android:id="@+id/tvEncryptPro"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginEnd="48dp"
android:text="@string/title_pro_feature"
android:textAppearance="@style/TextAppearance.AppCompat.Small"
android:textColor="?attr/colorAccent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/cbEncrypt" />
<CheckBox
android:id="@+id/cbDeliveryReceipt"
android:layout_width="wrap_content"
@ -550,7 +562,7 @@
android:layout_marginTop="12dp"
android:text="@string/title_identity_delivery_receipt"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/cbEncrypt" />
app:layout_constraintTop_toBottomOf="@id/tvEncryptPro" />
<CheckBox
android:id="@+id/cbReadReceipt"
@ -681,7 +693,8 @@
cbSynchronize,cbPrimary,
cbSenderExtra,tvSenderExtraHint,
tvReplyTo,etReplyTo,tvBcc,etBcc,
cbEncrypt,cbDeliveryReceipt,cbReadReceipt,tvReceipt,
cbEncrypt,tvEncryptPro,
cbDeliveryReceipt,cbReadReceipt,tvReceipt,
cbStoreSent,tvStoreSent" />
</androidx.constraintlayout.widget.ConstraintLayout>
</ScrollView>

Loading…
Cancel
Save