Message structure view improvements

pull/199/head
M66B 3 years ago
parent 9f7da17afc
commit 8cbfdee008

@ -32,6 +32,7 @@ import android.text.SpannableStringBuilder;
import android.text.Spanned; import android.text.Spanned;
import android.text.TextUtils; import android.text.TextUtils;
import android.text.method.ArrowKeyMovementMethod; import android.text.method.ArrowKeyMovementMethod;
import android.text.method.LinkMovementMethod;
import android.text.style.ForegroundColorSpan; import android.text.style.ForegroundColorSpan;
import android.text.style.URLSpan; import android.text.style.URLSpan;
import android.view.LayoutInflater; import android.view.LayoutInflater;
@ -64,6 +65,7 @@ import java.io.FileOutputStream;
import java.io.InputStream; import java.io.InputStream;
import java.io.OutputStream; import java.io.OutputStream;
import java.text.DateFormat; import java.text.DateFormat;
import java.util.ArrayList;
import java.util.Enumeration; import java.util.Enumeration;
import java.util.List; import java.util.List;
import java.util.Properties; import java.util.Properties;
@ -160,6 +162,8 @@ public class ActivityEML extends ActivityBase {
} }
}); });
tvStructure.setMovementMethod(LinkMovementMethod.getInstance());
// Initialize // Initialize
if (!Helper.isDarkTheme(this)) { if (!Helper.isDarkTheme(this)) {
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(this); SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(this);
@ -337,8 +341,38 @@ public class ActivityEML extends ActivityBase {
private void getStructure(Context context, Part part, SpannableStringBuilder ssb, int level, int textColorLink) { private void getStructure(Context context, Part part, SpannableStringBuilder ssb, int level, int textColorLink) {
try { try {
if (level > 0) { Enumeration<Header> headers;
Enumeration<Header> headers = part.getAllHeaders(); if (level == 0) {
List<Header> h = new ArrayList<>();
String[] cte = part.getHeader("Content-Transfer-Encoding");
if (cte != null)
for (String header : cte)
h.add(new Header("Content-Transfer-Encoding", header));
String[] ct = part.getHeader("Content-Type");
if (ct == null)
h.add(new Header("Content-Type", "text/plain"));
else
for (String header : ct)
h.add(new Header("Content-Type", header));
headers = new Enumeration<Header>() {
private int index = -1;
@Override
public boolean hasMoreElements() {
return (index + 1 < h.size());
}
@Override
public Header nextElement() {
return h.get(++index);
}
};
} else
headers = part.getAllHeaders();
while (headers.hasMoreElements()) { while (headers.hasMoreElements()) {
Header header = headers.nextElement(); Header header = headers.nextElement();
for (int i = 0; i < level; i++) for (int i = 0; i < level; i++)
@ -348,9 +382,15 @@ public class ActivityEML extends ActivityBase {
ssb.setSpan(new ForegroundColorSpan(textColorLink), start, ssb.length(), 0); ssb.setSpan(new ForegroundColorSpan(textColorLink), start, ssb.length(), 0);
ssb.append(": ").append(header.getValue()).append('\n'); ssb.append(": ").append(header.getValue()).append('\n');
} }
for (int i = 0; i < level; i++)
ssb.append(" ");
int size = part.getSize();
ssb.append("Size: ")
.append(size > 0 ? Helper.humanReadableByteCount(size) : "?")
.append('\n');
ssb.append('\n'); ssb.append('\n');
} else
ssb.append(part.getContentType()).append("\n\n");
if (part.isMimeType("multipart/*")) { if (part.isMimeType("multipart/*")) {
Multipart multipart = (Multipart) part.getContent(); Multipart multipart = (Multipart) part.getContent();
@ -358,10 +398,12 @@ public class ActivityEML extends ActivityBase {
try { try {
getStructure(context, multipart.getBodyPart(i), ssb, level + 1, textColorLink); getStructure(context, multipart.getBodyPart(i), ssb, level + 1, textColorLink);
} catch (Throwable ex) { } catch (Throwable ex) {
Log.w(ex);
ssb.append(ex.toString()).append('\n'); ssb.append(ex.toString()).append('\n');
} }
} }
} catch (Throwable ex) { } catch (Throwable ex) {
Log.w(ex);
ssb.append(ex.toString()).append('\n'); ssb.append(ex.toString()).append('\n');
} }
} }

Loading…
Cancel
Save