Display placeholder for encrypted messages

pull/208/head
M66B 3 years ago
parent ea96d3d1be
commit 43fc00a6d1

@ -2540,15 +2540,23 @@ public class AdapterMessage extends RecyclerView.Adapter<AdapterMessage.ViewHold
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O)
ibImages.setTooltipText(ibImages.getContentDescription()); ibImages.setTooltipText(ibImages.getContentDescription());
if (show_full) { if (message.isEncrypted() && !message.isUnlocked()) {
// Create web view SpannableStringBuilder ssb = new SpannableStringBuilderEx("...");
WebViewEx webView; ssb.setSpan(new StyleSpan(Typeface.BOLD), 0, ssb.length(), 0);
if (wvBody instanceof WebView) tvBody.setText(ssb);
webView = (WebViewEx) wvBody; tvBody.setVisibility(View.VISIBLE);
else { wvBody.setVisibility(View.GONE);
try { bindExtras(message);
webView = new WebViewEx(context); } else {
} catch (Throwable ex) { if (show_full) {
// Create web view
WebViewEx webView;
if (wvBody instanceof WebView)
webView = (WebViewEx) wvBody;
else {
try {
webView = new WebViewEx(context);
} catch (Throwable ex) {
/* /*
android.util.AndroidRuntimeException: java.lang.reflect.InvocationTargetException android.util.AndroidRuntimeException: java.lang.reflect.InvocationTargetException
at android.webkit.WebViewFactory.getProvider(WebViewFactory.java:270) at android.webkit.WebViewFactory.getProvider(WebViewFactory.java:270)
@ -2565,83 +2573,84 @@ public class AdapterMessage extends RecyclerView.Adapter<AdapterMessage.ViewHold
at android.webkit.WebView.<init>(WebView.java:574) at android.webkit.WebView.<init>(WebView.java:574)
at android.webkit.WebView.<init>(WebView.java:564) at android.webkit.WebView.<init>(WebView.java:564)
*/ */
Log.unexpectedError(parentFragment.getParentFragmentManager(), ex, false); Log.unexpectedError(parentFragment.getParentFragmentManager(), ex, false);
return; return;
} }
webView.setId(wvBody.getId()); webView.setId(wvBody.getId());
ConstraintLayout cl = (ConstraintLayout) vsBody; ConstraintLayout cl = (ConstraintLayout) vsBody;
cl.removeView(wvBody); cl.removeView(wvBody);
cl.addView(webView, wvBody.getLayoutParams()); cl.addView(webView, wvBody.getLayoutParams());
cl.setPadding( cl.setPadding(
wvBody.getPaddingLeft(), wvBody.getPaddingTop(), wvBody.getPaddingLeft(), wvBody.getPaddingTop(),
wvBody.getPaddingRight(), wvBody.getPaddingBottom()); wvBody.getPaddingRight(), wvBody.getPaddingBottom());
wvBody = webView; wvBody = webView;
} }
webView.setMinimumHeight(dp60); webView.setMinimumHeight(dp60);
int maxHeight = (rv == null ? 0 : rv.getHeight() - rv.getPaddingTop()); int maxHeight = (rv == null ? 0 : rv.getHeight() - rv.getPaddingTop());
webView.init(height, maxHeight, size, position, force_light, webView.init(height, maxHeight, size, position, force_light,
new WebViewEx.IWebView() { new WebViewEx.IWebView() {
@Override @Override
public void onSizeChanged(int w, int h, int ow, int oh) { public void onSizeChanged(int w, int h, int ow, int oh) {
if (h > dp60) if (h > dp60)
properties.setHeight(message.id, h); properties.setHeight(message.id, h);
} }
@Override @Override
public void onScaleChanged(float newScale) { public void onScaleChanged(float newScale) {
properties.setSize(message.id, newScale); properties.setSize(message.id, newScale);
} }
@Override @Override
public void onScrollChange(int scrollX, int scrollY) { public void onScrollChange(int scrollX, int scrollY) {
properties.setPosition(message.id, new Pair<Integer, Integer>(scrollX, scrollY)); properties.setPosition(message.id, new Pair<Integer, Integer>(scrollX, scrollY));
} }
@Override @Override
public void onOverScrolled(int scrollX, int scrollY, int dx, int dy, boolean clampedX, boolean clampedY) { public void onOverScrolled(int scrollX, int scrollY, int dx, int dy, boolean clampedX, boolean clampedY) {
if (clampedY && ((WebViewEx) wvBody).isZoomedY()) { if (clampedY && ((WebViewEx) wvBody).isZoomedY()) {
boolean flinged = false; boolean flinged = false;
try { try {
if (!webview_legacy && rv != null) if (!webview_legacy && rv != null)
flinged = rv.fling(dx * 10, dy * 10); flinged = rv.fling(dx * 10, dy * 10);
} catch (Throwable ex) { } catch (Throwable ex) {
Log.e(ex); Log.e(ex);
}
if (!flinged)
properties.scrollBy(dx, dy);
} }
if (!flinged)
properties.scrollBy(dx, dy);
} }
}
@Override @Override
public boolean onOpenLink(String url) { public boolean onOpenLink(String url) {
if (parentFragment == null) if (parentFragment == null)
return false; return false;
Uri uri = Uri.parse(url); Uri uri = Uri.parse(url);
return ViewHolder.this.onOpenLink(uri, null, false); return ViewHolder.this.onOpenLink(uri, null, false);
} }
}); });
webView.setImages(show_images, inline); webView.setImages(show_images, inline);
webView.setOnTouchListener(touchListener); webView.setOnTouchListener(touchListener);
tvBody.setVisibility(View.GONE); tvBody.setVisibility(View.GONE);
wvBody.setVisibility(View.VISIBLE); wvBody.setVisibility(View.VISIBLE);
} else { } else {
tvBody.setMinHeight(height); tvBody.setMinHeight(height);
if (size != 0) if (size != 0)
tvBody.setTextSize(TypedValue.COMPLEX_UNIT_PX, size); tvBody.setTextSize(TypedValue.COMPLEX_UNIT_PX, size);
tvBody.setTextColor(contrast ? textColorPrimary : colorRead); tvBody.setTextColor(contrast ? textColorPrimary : colorRead);
tvBody.setTypeface(StyleHelper.getTypeface(display_font, context)); tvBody.setTypeface(StyleHelper.getTypeface(display_font, context));
tvBody.setVisibility(View.VISIBLE); tvBody.setVisibility(View.VISIBLE);
wvBody.setVisibility(View.GONE); wvBody.setVisibility(View.GONE);
}
} }
final Bundle args = new Bundle(); final Bundle args = new Bundle();
@ -2936,13 +2945,8 @@ public class AdapterMessage extends RecyclerView.Adapter<AdapterMessage.ViewHold
// Show images // Show images
ibImages.setVisibility(has_images && !(show_full && always_images) ? View.VISIBLE : View.INVISIBLE); ibImages.setVisibility(has_images && !(show_full && always_images) ? View.VISIBLE : View.INVISIBLE);
boolean verifyable = (EntityMessage.PGP_SIGNONLY.equals(message.encrypt) || boolean verifiable = message.isVerifiable();
EntityMessage.SMIME_SIGNONLY.equals(message.encrypt)); boolean unlocked = message.isUnlocked();
boolean unlocked = (EntityMessage.PGP_SIGNENCRYPT.equals(message.ui_encrypt) &&
!EntityMessage.PGP_SIGNENCRYPT.equals(message.encrypt)) ||
(EntityMessage.SMIME_SIGNENCRYPT.equals(message.ui_encrypt) &&
!EntityMessage.SMIME_SIGNENCRYPT.equals(message.encrypt));
// Show AMP // Show AMP
boolean has_amp = args.getBoolean("has_amp"); boolean has_amp = args.getBoolean("has_amp");
@ -2950,7 +2954,7 @@ public class AdapterMessage extends RecyclerView.Adapter<AdapterMessage.ViewHold
? View.VISIBLE : View.GONE); ? View.VISIBLE : View.GONE);
// Show encrypt actions // Show encrypt actions
ibVerify.setVisibility(verifyable ? View.VISIBLE : View.GONE); ibVerify.setVisibility(verifiable ? View.VISIBLE : View.GONE);
ibDecrypt.setImageResource(unlocked ibDecrypt.setImageResource(unlocked
? R.drawable.twotone_lock_24 : R.drawable.twotone_lock_open_24); ? R.drawable.twotone_lock_24 : R.drawable.twotone_lock_open_24);
ibDecrypt.setImageTintList(ColorStateList.valueOf(unlocked ibDecrypt.setImageTintList(ColorStateList.valueOf(unlocked
@ -2965,44 +2969,46 @@ public class AdapterMessage extends RecyclerView.Adapter<AdapterMessage.ViewHold
boolean signed_data = args.getBoolean("signed_data"); boolean signed_data = args.getBoolean("signed_data");
tvSignedData.setVisibility(signed_data ? View.VISIBLE : View.GONE); tvSignedData.setVisibility(signed_data ? View.VISIBLE : View.GONE);
if (show_full) { if (!message.isEncrypted() || message.isUnlocked()) {
((WebViewEx) wvBody).setOnPageLoaded(new Runnable() { if (show_full) {
@Override ((WebViewEx) wvBody).setOnPageLoaded(new Runnable() {
public void run() { @Override
try { public void run() {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q) try {
bindConversationActions(message, args.getParcelable("actions")); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q)
bindExtras(message); bindConversationActions(message, args.getParcelable("actions"));
bindExtras(message);
cowner.start(); // Show attachments cowner.start(); // Show attachments
} catch (Throwable ex) { } catch (Throwable ex) {
Log.e(ex); Log.e(ex);
}
} }
} });
});
if (result == null) if (result == null)
((WebView) wvBody).loadDataWithBaseURL(null, "", "text/html", StandardCharsets.UTF_8.name(), null); ((WebView) wvBody).loadDataWithBaseURL(null, "", "text/html", StandardCharsets.UTF_8.name(), null);
else else
((WebView) wvBody).loadDataWithBaseURL(null, (String) result, "text/html", StandardCharsets.UTF_8.name(), null); ((WebView) wvBody).loadDataWithBaseURL(null, (String) result, "text/html", StandardCharsets.UTF_8.name(), null);
} else { } else {
tvBody.post(new Runnable() { tvBody.post(new Runnable() {
@Override @Override
public void run() { public void run() {
try { try {
tvBody.setText((Spanned) result); tvBody.setText((Spanned) result);
vwRipple.setVisibility(View.VISIBLE); vwRipple.setVisibility(View.VISIBLE);
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q) if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q)
bindConversationActions(message, args.getParcelable("actions")); bindConversationActions(message, args.getParcelable("actions"));
bindExtras(message); bindExtras(message);
cowner.start(); // Show attachments cowner.start(); // Show attachments
} catch (Throwable ex) { } catch (Throwable ex) {
Log.e(ex); Log.e(ex);
}
} }
} });
}); }
} }
if (scroll) if (scroll)

@ -354,6 +354,18 @@ public class EntityMessage implements Serializable {
EntityMessage.SMIME_SIGNENCRYPT.equals(ui_encrypt)); EntityMessage.SMIME_SIGNENCRYPT.equals(ui_encrypt));
} }
boolean isVerifiable(){
return (EntityMessage.PGP_SIGNONLY.equals(encrypt) ||
EntityMessage.SMIME_SIGNONLY.equals(encrypt));
}
boolean isUnlocked() {
return (EntityMessage.PGP_SIGNENCRYPT.equals(ui_encrypt) &&
!EntityMessage.PGP_SIGNENCRYPT.equals(encrypt)) ||
(EntityMessage.SMIME_SIGNENCRYPT.equals(ui_encrypt) &&
!EntityMessage.SMIME_SIGNENCRYPT.equals(encrypt));
}
String[] checkFromDomain(Context context) { String[] checkFromDomain(Context context) {
return MessageHelper.equalRootDomain(context, from, smtp_from); return MessageHelper.equalRootDomain(context, from, smtp_from);
} }

Loading…
Cancel
Save