Reply/forward original message

pull/147/head
M66B 6 years ago
parent dd97f7c6f8
commit ae9d35c084

@ -874,7 +874,7 @@ public class AdapterMessage extends RecyclerView.Adapter<AdapterMessage.ViewHold
onArchive(data);
return true;
case R.id.action_reply:
onReply(data);
onReply(data, false);
return true;
default:
return false;
@ -965,12 +965,6 @@ public class AdapterMessage extends RecyclerView.Adapter<AdapterMessage.ViewHold
}.load(context, owner, args);
}
private void onReplyAll(ActionData data) {
context.startActivity(new Intent(context, ActivityCompose.class)
.putExtra("action", "reply_all")
.putExtra("reference", data.message.id));
}
private void onAnswer(final ActionData data) {
new SimpleTask<List<EntityAnswer>>() {
@Override
@ -1313,7 +1307,7 @@ public class AdapterMessage extends RecyclerView.Adapter<AdapterMessage.ViewHold
onForward(data, true);
return true;
case R.id.menu_reply_all:
onReplyAll(data);
onReply(data, true);
return true;
case R.id.menu_answer:
onAnswer(data);
@ -1468,10 +1462,46 @@ public class AdapterMessage extends RecyclerView.Adapter<AdapterMessage.ViewHold
properties.move(data.message.id, EntityFolder.ARCHIVE, true);
}
private void onReply(ActionData data) {
context.startActivity(new Intent(context, ActivityCompose.class)
.putExtra("action", "reply")
.putExtra("reference", data.message.id));
private void onReply(final ActionData data, final boolean all) {
Bundle args = new Bundle();
args.putLong("id", data.message.id);
new SimpleTask<Boolean>() {
@Override
protected Boolean onLoad(Context context, Bundle args) {
long id = args.getLong("id");
List<EntityAttachment> attachments = DB.getInstance(context).attachment().getAttachments(id);
for (EntityAttachment attachment : attachments)
if (attachment.cid != null && !attachment.available)
return false;
return true;
}
@Override
protected void onLoaded(Bundle args, Boolean available) {
final Intent reply = new Intent(context, ActivityCompose.class)
.putExtra("action", all ? "reply_all" : "reply")
.putExtra("reference", data.message.id);
if (available)
context.startActivity(reply);
else
new DialogBuilderLifecycle(context, owner)
.setMessage(R.string.title_image_unavailable)
.setPositiveButton(android.R.string.ok, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
context.startActivity(reply);
}
})
.setNegativeButton(android.R.string.cancel, null)
.show();
}
@Override
protected void onException(Bundle args, Throwable ex) {
Helper.unexpectedError(context, owner, ex);
}
}.load(context, owner, args);
}
ItemDetailsLookup.ItemDetails<Long> getItemDetails(@NonNull MotionEvent motionEvent) {

@ -25,7 +25,6 @@ import android.content.Context;
import android.content.pm.PackageManager;
import android.database.Cursor;
import android.provider.ContactsContract;
import android.text.Html;
import android.text.TextUtils;
import android.util.Log;
@ -250,14 +249,6 @@ public class EntityMessage implements Serializable {
return false;
}
static String getQuote(Context context, long id) throws IOException {
EntityMessage message = DB.getInstance(context).message().getMessage(id);
return String.format("<p>%s %s:</p><blockquote>%s</blockquote>",
Html.escapeHtml(new Date(message.received).toString()),
Html.escapeHtml(MessageHelper.getFormattedAddresses(message.from, true)),
HtmlHelper.sanitize(EntityMessage.read(context, id)));
}
public boolean uiEquals(Object obj) {
if (obj instanceof EntityMessage) {
EntityMessage other = (EntityMessage) obj;

@ -1217,11 +1217,12 @@ public class FragmentCompose extends FragmentEx {
if (uris != null)
for (Uri uri : uris)
addAttachment(context, result.draft.id, uri, false);
} else if ("forward".equals(action)) {
} else {
int sequence = 0;
List<EntityAttachment> attachments = db.attachment().getAttachments(ref.id);
for (EntityAttachment attachment : attachments)
if (attachment.available) {
if (attachment.available &&
("forward".equals(action) || attachment.cid != null)) {
EntityAttachment copy = new EntityAttachment();
copy.message = result.draft.id;
copy.sequence = ++sequence;
@ -1300,14 +1301,21 @@ public class FragmentCompose extends FragmentEx {
@Override
protected Spanned[] onLoad(final Context context, Bundle args) throws Throwable {
long id = args.getLong("id");
long reference = args.getLong("reference", -1);
final long reference = args.getLong("reference", -1);
String body = EntityMessage.read(context, id);
String quote = (reference < 0 ? null : EntityMessage.getQuote(context, reference));
String quote = (reference < 0 ? null : HtmlHelper.getQuote(context, reference, true));
return new Spanned[]{
Html.fromHtml(body, cidGetter, null),
quote == null ? null : Html.fromHtml(quote)};
quote == null ? null : Html.fromHtml(quote,
new Html.ImageGetter() {
@Override
public Drawable getDrawable(String source) {
return HtmlHelper.decodeImage(source, context, reference, false);
}
},
null)};
}
@Override

@ -24,6 +24,7 @@ import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.graphics.drawable.BitmapDrawable;
import android.graphics.drawable.Drawable;
import android.text.Html;
import android.text.TextUtils;
import android.util.Base64;
import android.util.Log;
@ -43,6 +44,7 @@ import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.net.URL;
import java.util.Date;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
@ -218,4 +220,13 @@ public class HtmlHelper {
return d;
}
}
static String getQuote(Context context, long id, boolean sanitize) throws IOException {
EntityMessage message = DB.getInstance(context).message().getMessage(id);
String html = EntityMessage.read(context, id);
return String.format("<p>%s %s:</p><blockquote>%s</blockquote>",
Html.escapeHtml(new Date(message.received).toString()),
Html.escapeHtml(MessageHelper.getFormattedAddresses(message.from, true)),
sanitize ? HtmlHelper.sanitize(html) : html);
}
}

@ -293,7 +293,8 @@ public class MessageHelper {
}
if (message.replying != null || message.forwarding != null)
body += EntityMessage.getQuote(context, message.replying == null ? message.forwarding : message.replying);
body += HtmlHelper.getQuote(context,
message.replying == null ? message.forwarding : message.replying, false);
BodyPart plain = new MimeBodyPart();
plain.setContent(Jsoup.parse(body).text(), "text/plain; charset=" + Charset.defaultCharset().name());

@ -250,6 +250,7 @@
<string name="title_no_contacts">Contact picker not available</string>
<string name="title_attachment_saved">Attachment saved</string>
<string name="title_attachment_unavailable">Some attachments are not downloaded and will not be forwarded, continue?</string>
<string name="title_image_unavailable">Some images are not downloaded and will not be added, continue?</string>
<string name="title_ask_delete">Delete message permanently?</string>
<string name="title_ask_delete_selected">Delete selected messages permanently?</string>
<string name="title_ask_delete_answer">Delete reply template permanently?</string>

Loading…
Cancel
Save