Added reply with selected text

pull/177/head
M66B 5 years ago
parent 94648051c4
commit c949cc6e01

@ -3297,7 +3297,7 @@ public class AdapterMessage extends RecyclerView.Adapter<AdapterMessage.ViewHold
} }
private void onActionAnswer(TupleMessageEx message, View anchor) { private void onActionAnswer(TupleMessageEx message, View anchor) {
((FragmentMessages) parentFragment).onReply(message, anchor); ((FragmentMessages) parentFragment).onReply(message, getSelectedText(), anchor);
} }
private void onActionMove(TupleMessageEx message, final boolean copy) { private void onActionMove(TupleMessageEx message, final boolean copy) {
@ -4224,6 +4224,26 @@ public class AdapterMessage extends RecyclerView.Adapter<AdapterMessage.ViewHold
return getKeyAtPosition(getAdapterPosition()); return getKeyAtPosition(getAdapterPosition());
} }
String getSelectedText() {
int start = tvBody.getSelectionStart();
int end = tvBody.getSelectionEnd();
if (start == end)
return null;
if (start < 0)
start = 0;
if (end < 0)
end = 0;
if (start > end) {
int tmp = start;
start = end;
end = tmp;
}
return tvBody.getText().subSequence(start, end).toString();
}
private View.AccessibilityDelegate accessibilityDelegateHeader = new View.AccessibilityDelegate() { private View.AccessibilityDelegate accessibilityDelegateHeader = new View.AccessibilityDelegate() {
@Override @Override
public void onInitializeAccessibilityEvent(View host, AccessibilityEvent event) { public void onInitializeAccessibilityEvent(View host, AccessibilityEvent event) {

@ -971,6 +971,7 @@ public class FragmentCompose extends FragmentBase {
args.putString("subject", a.getString("subject")); args.putString("subject", a.getString("subject"));
args.putString("body", a.getString("body")); args.putString("body", a.getString("body"));
args.putString("text", a.getString("text")); args.putString("text", a.getString("text"));
args.putString("selected", a.getString("selected"));
args.putParcelableArrayList("attachments", a.getParcelableArrayList("attachments")); args.putParcelableArrayList("attachments", a.getParcelableArrayList("attachments"));
draftLoader.execute(this, args, "compose:new"); draftLoader.execute(this, args, "compose:new");
} else { } else {
@ -3101,13 +3102,14 @@ public class FragmentCompose extends FragmentBase {
} }
} }
String s = args.getString("selected");
if (ref.content && if (ref.content &&
!"editasnew".equals(action) && !"editasnew".equals(action) &&
!"list".equals(action) && !("list".equals(action) && TextUtils.isEmpty(s)) &&
!"receipt".equals(action)) { !"receipt".equals(action)) {
// Reply/forward // Reply/forward
Element div = document.createElement("div"); Element reply = document.createElement("div");
div.attr("fairemail", "reference"); reply.attr("fairemail", "reference");
// Build reply header // Build reply header
Element p = document.createElement("p"); Element p = document.createElement("p");
@ -3152,53 +3154,69 @@ public class FragmentCompose extends FragmentBase {
} else } else
p.text(DF.format(new Date(ref.received)) + " " + MessageHelper.formatAddresses(ref.from) + ":"); p.text(DF.format(new Date(ref.received)) + " " + MessageHelper.formatAddresses(ref.from) + ":");
div.appendChild(p); reply.appendChild(p);
// Get referenced message body Document d;
Document d = JsoupEx.parse(ref.getFile(context)); if (TextUtils.isEmpty(s)) {
// Get referenced message body
// Remove signature separators d = JsoupEx.parse(ref.getFile(context));
boolean remove_signatures = prefs.getBoolean("remove_signatures", false);
if (remove_signatures) // Remove signature separators
d.body().filter(new NodeFilter() { boolean remove_signatures = prefs.getBoolean("remove_signatures", false);
private boolean remove = false; if (remove_signatures)
d.body().filter(new NodeFilter() {
@Override private boolean remove = false;
public FilterResult head(Node node, int depth) {
if (node instanceof TextNode) { @Override
TextNode tnode = (TextNode) node; public FilterResult head(Node node, int depth) {
String text = tnode.getWholeText() if (node instanceof TextNode) {
.replaceAll("[\r\n]+$", "") TextNode tnode = (TextNode) node;
.replaceAll("^[\r\n]+", ""); String text = tnode.getWholeText()
if ("-- ".equals(text)) { .replaceAll("[\r\n]+$", "")
if (tnode.getWholeText().endsWith("\n")) .replaceAll("^[\r\n]+", "");
remove = true; if ("-- ".equals(text)) {
else { if (tnode.getWholeText().endsWith("\n"))
Node next = node.nextSibling();
if (next != null && "br".equals(next.nodeName()))
remove = true; remove = true;
else {
Node next = node.nextSibling();
if (next != null && "br".equals(next.nodeName()))
remove = true;
}
} }
} }
return (remove ? FilterResult.REMOVE : FilterResult.CONTINUE);
} }
return (remove ? FilterResult.REMOVE : FilterResult.CONTINUE); @Override
} public FilterResult tail(Node node, int depth) {
return FilterResult.CONTINUE;
}
});
} else {
// Selected text
d = Document.createShell("");
@Override Element div = d.createElement("div");
public FilterResult tail(Node node, int depth) { for (String line : s.split("\\r?\\n")) {
return FilterResult.CONTINUE; Element span = document.createElement("span");
} span.text(line);
}); div.appendChild(span);
div.appendElement("br");
}
d.body().appendChild(div);
}
// Quote referenced message body // Quote referenced message body
Element e = d.body(); Element e = d.body();
boolean quote_reply = prefs.getBoolean("quote_reply", true); boolean quote_reply = prefs.getBoolean("quote_reply", true);
boolean quote = (quote_reply && ("reply".equals(action) || "reply_all".equals(action))); boolean quote = (quote_reply &&
("reply".equals(action) || "reply_all".equals(action) || "list".equals(action)));
e.tagName(quote ? "blockquote" : "p"); e.tagName(quote ? "blockquote" : "p");
div.appendChild(e); reply.appendChild(e);
document.body().appendChild(div); document.body().appendChild(reply);
addSignature(context, document, data.draft, selected); addSignature(context, document, data.draft, selected);
} }

@ -1996,13 +1996,16 @@ public class FragmentMessages extends FragmentBase implements SharedPreferences.
long id = values.get("expanded").get(0); long id = values.get("expanded").get(0);
int pos = adapter.getPositionForKey(id); int pos = adapter.getPositionForKey(id);
TupleMessageEx message = adapter.getItemAtPosition(pos); TupleMessageEx message = adapter.getItemAtPosition(pos);
AdapterMessage.ViewHolder holder =
(AdapterMessage.ViewHolder) rvMessage.findViewHolderForAdapterPosition(pos);
String selected = (holder == null ? null : holder.getSelectedText());
if (message == null) if (message == null)
return; return;
onReply(message, fabReply); onReply(message, selected, fabReply);
} }
} }
void onReply(final TupleMessageEx message, final View anchor) { void onReply(final TupleMessageEx message, final String selected, final View anchor) {
Bundle args = new Bundle(); Bundle args = new Bundle();
args.putLong("id", message.id); args.putLong("id", message.id);
@ -2054,13 +2057,13 @@ public class FragmentMessages extends FragmentBase implements SharedPreferences.
public boolean onMenuItemClick(MenuItem target) { public boolean onMenuItemClick(MenuItem target) {
switch (target.getItemId()) { switch (target.getItemId()) {
case R.id.menu_reply_to_sender: case R.id.menu_reply_to_sender:
onMenuReply(message, "reply"); onMenuReply(message, "reply", selected);
return true; return true;
case R.id.menu_reply_to_all: case R.id.menu_reply_to_all:
onMenuReply(message, "reply_all"); onMenuReply(message, "reply_all", selected);
return true; return true;
case R.id.menu_reply_list: case R.id.menu_reply_list:
onMenuReply(message, "list"); onMenuReply(message, "list", selected);
return true; return true;
case R.id.menu_reply_receipt: case R.id.menu_reply_receipt:
onMenuReply(message, "receipt"); onMenuReply(message, "receipt");
@ -2093,9 +2096,14 @@ public class FragmentMessages extends FragmentBase implements SharedPreferences.
} }
private void onMenuReply(TupleMessageEx message, String action) { private void onMenuReply(TupleMessageEx message, String action) {
onMenuReply(message, action, null);
}
private void onMenuReply(TupleMessageEx message, String action, String selected) {
Intent reply = new Intent(getContext(), ActivityCompose.class) Intent reply = new Intent(getContext(), ActivityCompose.class)
.putExtra("action", action) .putExtra("action", action)
.putExtra("reference", message.id); .putExtra("reference", message.id)
.putExtra("selected", selected);
startActivity(reply); startActivity(reply);
} }

Loading…
Cancel
Save