mirror of
https://github.com/M66B/FairEmail.git
synced 2024-12-26 09:47:13 +00:00
Added reply with selected text
This commit is contained in:
parent
94648051c4
commit
c949cc6e01
3 changed files with 87 additions and 41 deletions
|
@ -3297,7 +3297,7 @@ public class AdapterMessage extends RecyclerView.Adapter<AdapterMessage.ViewHold
|
|||
}
|
||||
|
||||
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) {
|
||||
|
@ -4224,6 +4224,26 @@ public class AdapterMessage extends RecyclerView.Adapter<AdapterMessage.ViewHold
|
|||
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() {
|
||||
@Override
|
||||
public void onInitializeAccessibilityEvent(View host, AccessibilityEvent event) {
|
||||
|
|
|
@ -971,6 +971,7 @@ public class FragmentCompose extends FragmentBase {
|
|||
args.putString("subject", a.getString("subject"));
|
||||
args.putString("body", a.getString("body"));
|
||||
args.putString("text", a.getString("text"));
|
||||
args.putString("selected", a.getString("selected"));
|
||||
args.putParcelableArrayList("attachments", a.getParcelableArrayList("attachments"));
|
||||
draftLoader.execute(this, args, "compose:new");
|
||||
} else {
|
||||
|
@ -3101,13 +3102,14 @@ public class FragmentCompose extends FragmentBase {
|
|||
}
|
||||
}
|
||||
|
||||
String s = args.getString("selected");
|
||||
if (ref.content &&
|
||||
!"editasnew".equals(action) &&
|
||||
!"list".equals(action) &&
|
||||
!("list".equals(action) && TextUtils.isEmpty(s)) &&
|
||||
!"receipt".equals(action)) {
|
||||
// Reply/forward
|
||||
Element div = document.createElement("div");
|
||||
div.attr("fairemail", "reference");
|
||||
Element reply = document.createElement("div");
|
||||
reply.attr("fairemail", "reference");
|
||||
|
||||
// Build reply header
|
||||
Element p = document.createElement("p");
|
||||
|
@ -3152,53 +3154,69 @@ public class FragmentCompose extends FragmentBase {
|
|||
} else
|
||||
p.text(DF.format(new Date(ref.received)) + " " + MessageHelper.formatAddresses(ref.from) + ":");
|
||||
|
||||
div.appendChild(p);
|
||||
reply.appendChild(p);
|
||||
|
||||
// Get referenced message body
|
||||
Document d = JsoupEx.parse(ref.getFile(context));
|
||||
Document d;
|
||||
if (TextUtils.isEmpty(s)) {
|
||||
// Get referenced message body
|
||||
d = JsoupEx.parse(ref.getFile(context));
|
||||
|
||||
// Remove signature separators
|
||||
boolean remove_signatures = prefs.getBoolean("remove_signatures", false);
|
||||
if (remove_signatures)
|
||||
d.body().filter(new NodeFilter() {
|
||||
private boolean remove = false;
|
||||
// Remove signature separators
|
||||
boolean remove_signatures = prefs.getBoolean("remove_signatures", false);
|
||||
if (remove_signatures)
|
||||
d.body().filter(new NodeFilter() {
|
||||
private boolean remove = false;
|
||||
|
||||
@Override
|
||||
public FilterResult head(Node node, int depth) {
|
||||
if (node instanceof TextNode) {
|
||||
TextNode tnode = (TextNode) node;
|
||||
String text = tnode.getWholeText()
|
||||
.replaceAll("[\r\n]+$", "")
|
||||
.replaceAll("^[\r\n]+", "");
|
||||
if ("-- ".equals(text)) {
|
||||
if (tnode.getWholeText().endsWith("\n"))
|
||||
remove = true;
|
||||
else {
|
||||
Node next = node.nextSibling();
|
||||
if (next != null && "br".equals(next.nodeName()))
|
||||
@Override
|
||||
public FilterResult head(Node node, int depth) {
|
||||
if (node instanceof TextNode) {
|
||||
TextNode tnode = (TextNode) node;
|
||||
String text = tnode.getWholeText()
|
||||
.replaceAll("[\r\n]+$", "")
|
||||
.replaceAll("^[\r\n]+", "");
|
||||
if ("-- ".equals(text)) {
|
||||
if (tnode.getWholeText().endsWith("\n"))
|
||||
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
|
||||
public FilterResult tail(Node node, int depth) {
|
||||
return FilterResult.CONTINUE;
|
||||
}
|
||||
});
|
||||
Element div = d.createElement("div");
|
||||
for (String line : s.split("\\r?\\n")) {
|
||||
Element span = document.createElement("span");
|
||||
span.text(line);
|
||||
div.appendChild(span);
|
||||
div.appendElement("br");
|
||||
}
|
||||
d.body().appendChild(div);
|
||||
}
|
||||
|
||||
// Quote referenced message body
|
||||
Element e = d.body();
|
||||
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");
|
||||
div.appendChild(e);
|
||||
reply.appendChild(e);
|
||||
|
||||
document.body().appendChild(div);
|
||||
document.body().appendChild(reply);
|
||||
|
||||
addSignature(context, document, data.draft, selected);
|
||||
}
|
||||
|
|
|
@ -1996,13 +1996,16 @@ public class FragmentMessages extends FragmentBase implements SharedPreferences.
|
|||
long id = values.get("expanded").get(0);
|
||||
int pos = adapter.getPositionForKey(id);
|
||||
TupleMessageEx message = adapter.getItemAtPosition(pos);
|
||||
AdapterMessage.ViewHolder holder =
|
||||
(AdapterMessage.ViewHolder) rvMessage.findViewHolderForAdapterPosition(pos);
|
||||
String selected = (holder == null ? null : holder.getSelectedText());
|
||||
if (message == null)
|
||||
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();
|
||||
args.putLong("id", message.id);
|
||||
|
||||
|
@ -2054,13 +2057,13 @@ public class FragmentMessages extends FragmentBase implements SharedPreferences.
|
|||
public boolean onMenuItemClick(MenuItem target) {
|
||||
switch (target.getItemId()) {
|
||||
case R.id.menu_reply_to_sender:
|
||||
onMenuReply(message, "reply");
|
||||
onMenuReply(message, "reply", selected);
|
||||
return true;
|
||||
case R.id.menu_reply_to_all:
|
||||
onMenuReply(message, "reply_all");
|
||||
onMenuReply(message, "reply_all", selected);
|
||||
return true;
|
||||
case R.id.menu_reply_list:
|
||||
onMenuReply(message, "list");
|
||||
onMenuReply(message, "list", selected);
|
||||
return true;
|
||||
case R.id.menu_reply_receipt:
|
||||
onMenuReply(message, "receipt");
|
||||
|
@ -2093,9 +2096,14 @@ public class FragmentMessages extends FragmentBase implements SharedPreferences.
|
|||
}
|
||||
|
||||
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)
|
||||
.putExtra("action", action)
|
||||
.putExtra("reference", message.id);
|
||||
.putExtra("reference", message.id)
|
||||
.putExtra("selected", selected);
|
||||
startActivity(reply);
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue