Skip to content

Commit db07f4d

Browse files
committed
Added an error message template for the pgp decrypt error "FORMAT_ERROR".| #104.
1 parent 4c18d11 commit db07f4d

File tree

5 files changed

+116
-7
lines changed

5 files changed

+116
-7
lines changed

FlowCrypt/src/main/java/com/flowcrypt/email/ui/activity/fragment/MessageDetailsFragment.java

Lines changed: 46 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
import android.text.TextUtils;
2121
import android.text.format.DateFormat;
2222
import android.text.format.Formatter;
23+
import android.transition.TransitionManager;
2324
import android.view.LayoutInflater;
2425
import android.view.Menu;
2526
import android.view.MenuInflater;
@@ -578,7 +579,7 @@ private String prepareViewportHtml(String incomingHtml) {
578579
private View generatePublicKeyPart(final MessagePartPgpPublicKey messagePartPgpPublicKey,
579580
LayoutInflater layoutInflater) {
580581

581-
View messagePartPublicKeyView = layoutInflater.inflate(
582+
final ViewGroup messagePartPublicKeyView = (ViewGroup) layoutInflater.inflate(
582583
R.layout.message_part_public_key, layoutMessageParts, false);
583584

584585
TextView textViewKeyOwnerTemplate = messagePartPublicKeyView.findViewById(R.id.textViewKeyOwnerTemplate);
@@ -593,6 +594,7 @@ private View generatePublicKeyPart(final MessagePartPgpPublicKey messagePartPgpP
593594
@Override
594595
public void onCheckedChanged(CompoundButton buttonView, boolean
595596
isChecked) {
597+
TransitionManager.beginDelayedTransition(messagePartPublicKeyView);
596598
textViewPgpPublicKey.setVisibility(isChecked ? View.VISIBLE : View.GONE);
597599

598600
buttonView.setText(isChecked ? R.string.hide_the_public_key :
@@ -725,14 +727,23 @@ private TextView generateTextPart(MessagePart messagePart, LayoutInflater layout
725727
}
726728

727729
@NonNull
728-
private TextView generatePgpMessagePart(MessagePartPgpMessage messagePartPgpMessage,
729-
LayoutInflater layoutInflater) {
730+
private View generatePgpMessagePart(MessagePartPgpMessage messagePartPgpMessage,
731+
LayoutInflater layoutInflater) {
730732
if (messagePartPgpMessage != null) {
731733
if (TextUtils.isEmpty(messagePartPgpMessage.getErrorMessage())) {
732734
return generateMessagePart(messagePartPgpMessage, layoutInflater, R.layout.message_part_pgp_message,
733735
layoutMessageParts);
734736
} else {
735737
switch (messagePartPgpMessage.getPgpMessageDecryptError()) {
738+
case FORMAT_ERROR:
739+
final ViewGroup formatErrorLayout = (ViewGroup) layoutInflater.inflate(
740+
R.layout.message_part_pgp_message_format_error, layoutMessageParts, false);
741+
TextView textViewFormatError = formatErrorLayout.findViewById(R.id.textViewFormatError);
742+
textViewFormatError.setText(messagePartPgpMessage.getErrorMessage());
743+
formatErrorLayout.addView(generateShowOriginalMessageLayout
744+
(messagePartPgpMessage.getValue(), layoutInflater, formatErrorLayout));
745+
return formatErrorLayout;
746+
736747
default:
737748
TextView textViewMessagePartOther = (TextView) layoutInflater.inflate(
738749
R.layout.message_part_pgp_message_error, layoutMessageParts, false);
@@ -744,6 +755,38 @@ private TextView generatePgpMessagePart(MessagePartPgpMessage messagePartPgpMess
744755
} else return new TextView(getContext());
745756
}
746757

758+
/**
759+
* Generate a layout with switch button which will be regulate visibility of original message info.
760+
*
761+
* @param originalPgpMessage The original pgp message info.
762+
* @param layoutInflater The {@link LayoutInflater} instance.
763+
* @param rootView The root view which will be used while we create a new layout using
764+
* {@link LayoutInflater}.
765+
* @return A generated layout.
766+
*/
767+
@NonNull
768+
private ViewGroup generateShowOriginalMessageLayout(String originalPgpMessage, LayoutInflater layoutInflater,
769+
final ViewGroup rootView) {
770+
ViewGroup showOriginalMessageLayout = (ViewGroup) layoutInflater.inflate(
771+
R.layout.pgp_show_original_message, rootView, false);
772+
final TextView textViewOriginalPgpMessage
773+
= showOriginalMessageLayout.findViewById(R.id.textViewOriginalPgpMessage);
774+
textViewOriginalPgpMessage.setText(originalPgpMessage);
775+
776+
Switch switchShowOriginalMessage = showOriginalMessageLayout.findViewById(R.id
777+
.switchShowOriginalMessage);
778+
779+
switchShowOriginalMessage.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
780+
@Override
781+
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
782+
TransitionManager.beginDelayedTransition(rootView);
783+
textViewOriginalPgpMessage.setVisibility(isChecked ? View.VISIBLE : View.GONE);
784+
buttonView.setText(isChecked ? R.string.hide_original_message : R.string.show_original_message);
785+
}
786+
});
787+
return showOriginalMessageLayout;
788+
}
789+
747790
public interface OnActionListener {
748791
void onArchiveMessageClicked();
749792

FlowCrypt/src/main/java/com/flowcrypt/email/ui/loader/DecryptMessageAsyncTaskLoader.java

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -211,7 +211,7 @@ private List<MessagePart> getMessagePartsFromProcessedMime(Js js, ProcessedMime
211211
@NonNull
212212
private MessagePartPgpMessage generateMessagePartPgpMessage(Js js, MessageBlock messageBlock) {
213213
String encryptedContent = messageBlock.getContent();
214-
String decryptedContent = null;
214+
String value = encryptedContent;
215215
String errorMessage = null;
216216
MessagePartPgpMessage.PgpMessageDecryptError pgpMessageDecryptError = null;
217217

@@ -223,9 +223,10 @@ private MessagePartPgpMessage generateMessagePartPgpMessage(Js js, MessageBlock
223223

224224
if (pgpDecrypted != null) {
225225
if (pgpDecrypted.isSuccess()) {
226-
decryptedContent = pgpDecrypted.getString();
226+
value = pgpDecrypted.getString();
227227
} else if (!TextUtils.isEmpty(pgpDecrypted.getFormatError())) {
228-
errorMessage = pgpDecrypted.getFormatError();
228+
errorMessage = getContext().getString(R.string.decrypt_error_message_badly_formatted) + "\n\n" +
229+
pgpDecrypted.getFormatError();
229230
pgpMessageDecryptError = MessagePartPgpMessage.PgpMessageDecryptError.FORMAT_ERROR;
230231
} else if (pgpDecrypted.getMissingPassphraseLongids() != null
231232
&& pgpDecrypted.getMissingPassphraseLongids().length > 0) {
@@ -265,6 +266,6 @@ private MessagePartPgpMessage generateMessagePartPgpMessage(Js js, MessageBlock
265266
getContext().getString(R.string.decrypt_error_please_write_me);
266267
}
267268

268-
return new MessagePartPgpMessage(decryptedContent, errorMessage, pgpMessageDecryptError);
269+
return new MessagePartPgpMessage(value, errorMessage, pgpMessageDecryptError);
269270
}
270271
}
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
<?xml version="1.0" encoding="utf-8"?><!--
2+
~ Business Source License 1.0 © 2017 FlowCrypt Limited ([email protected]).
3+
~ Use limitations apply. See https://github.com/FlowCrypt/flowcrypt-android/blob/master/LICENSE
4+
~ Contributors: DenBond7
5+
-->
6+
7+
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
8+
xmlns:tools="http://schemas.android.com/tools"
9+
android:layout_width="match_parent"
10+
android:layout_height="wrap_content"
11+
android:background="@drawable/bg_message_part_pgp_message_error"
12+
android:orientation="vertical">
13+
14+
<TextView
15+
android:id="@+id/textViewFormatError"
16+
android:layout_width="match_parent"
17+
android:layout_height="wrap_content"
18+
android:layout_marginBottom="@dimen/default_margin_medium"
19+
android:autoLink="web"
20+
android:textColor="@android:color/black"
21+
android:textIsSelectable="true"
22+
android:textSize="@dimen/default_text_size_medium"
23+
tools:text="At nihil sequi quo maiores molestiae consequatur. Id aut nam voluptate doloribus saepe consequatur molestias. Eos sunt est ipsam accusantium saepe doloribus veritatis.
24+
25+
Recusandae velit sit veniam asperiores nisi. Eius tempore ab voluptatum dolorum nihil qui beatae. Et cum au" />
26+
</LinearLayout>
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
<?xml version="1.0" encoding="utf-8"?><!--
2+
~ Business Source License 1.0 © 2017 FlowCrypt Limited ([email protected]).
3+
~ Use limitations apply. See https://github.com/FlowCrypt/flowcrypt-android/blob/master/LICENSE
4+
~ Contributors: DenBond7
5+
-->
6+
7+
<android.support.constraint.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
8+
xmlns:app="http://schemas.android.com/apk/res-auto"
9+
xmlns:tools="http://schemas.android.com/tools"
10+
android:layout_width="match_parent"
11+
android:layout_height="wrap_content">
12+
13+
<Switch
14+
android:id="@+id/switchShowOriginalMessage"
15+
android:layout_width="wrap_content"
16+
android:layout_height="wrap_content"
17+
android:layout_gravity="center"
18+
android:switchPadding="@dimen/default_margin_small"
19+
android:text="@string/show_original_message"
20+
app:layout_constraintEnd_toEndOf="parent"
21+
app:layout_constraintStart_toStartOf="parent"
22+
app:layout_constraintTop_toTopOf="parent" />
23+
24+
<TextView
25+
android:id="@+id/textViewOriginalPgpMessage"
26+
android:layout_width="match_parent"
27+
android:layout_height="wrap_content"
28+
android:layout_marginTop="@dimen/default_margin_content_small"
29+
android:textIsSelectable="true"
30+
android:visibility="gone"
31+
app:layout_constraintEnd_toEndOf="parent"
32+
app:layout_constraintStart_toStartOf="parent"
33+
app:layout_constraintTop_toBottomOf="@+id/switchShowOriginalMessage"
34+
tools:text="-----BEGIN PGP PUBLIC KEY-----\nxxxxx\nxxxxx\nxxxxx\nxxxxx\nxxxxx\nxxxxx\nxxxxx\n-----END PGP PUBLIC KEY-----"
35+
tools:visibility="visible" />
36+
37+
</android.support.constraint.ConstraintLayout>

FlowCrypt/src/main/res/values/strings.xml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -214,4 +214,6 @@
214214
<string name="email_does_not_available_in_this_folder">Message not found, it may have been moved to another folder.</string>
215215
<string name="from">From</string>
216216
<string name="google_api_is_not_available">Error: Google API is not available</string>
217+
<string name="show_original_message">Show the original message</string>
218+
<string name="hide_original_message">Hide the original message</string>
217219
</resources>

0 commit comments

Comments
 (0)