Added insert link as image

pull/212/head
M66B 2 years ago
parent c118b753cd
commit 1bfebb36ca

@ -502,10 +502,11 @@ public class ActivitySignature extends ActivityBase {
private void onLinkSelected(Bundle args) {
String link = args.getString("link");
boolean image = args.getBoolean("image");
int start = args.getInt("start");
int end = args.getInt("end");
String title = args.getString("title");
etText.setSelection(start, end);
StyleHelper.apply(R.id.menu_link, this, null, etText, link, title);
StyleHelper.apply(R.id.menu_link, this, null, etText, -1L, 0, link, image, title);
}
}

@ -572,11 +572,12 @@ public class FragmentAnswer extends FragmentBase {
private void onLinkSelected(Bundle args) {
String link = args.getString("link");
boolean image = args.getBoolean("image");
int start = args.getInt("start");
int end = args.getInt("end");
String title = args.getString("title");
etText.setSelection(start, end);
StyleHelper.apply(R.id.menu_link, getViewLifecycleOwner(), null, etText, link, title);
StyleHelper.apply(R.id.menu_link, getViewLifecycleOwner(), null, etText, -1L, 0, link, image, title);
}
private void onDelete() {

@ -4248,11 +4248,12 @@ public class FragmentCompose extends FragmentBase {
private void onLinkSelected(Bundle args) {
String link = args.getString("link");
boolean image = args.getBoolean("image");
int start = args.getInt("start");
int end = args.getInt("end");
String title = args.getString("title");
etBody.setSelection(start, end);
StyleHelper.apply(R.id.menu_link, getViewLifecycleOwner(), null, etBody, link, title);
StyleHelper.apply(R.id.menu_link, getViewLifecycleOwner(), null, etBody, working, zoom, link, image, title);
}
private void onActionDiscardConfirmed() {

@ -37,6 +37,7 @@ import android.text.style.URLSpan;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.Button;
import android.widget.CheckBox;
import android.widget.EditText;
import android.widget.ProgressBar;
import android.widget.SeekBar;
@ -61,6 +62,7 @@ import java.nio.charset.StandardCharsets;
public class FragmentDialogInsertLink extends FragmentDialogBase {
private EditText etLink;
private CheckBox cbImage;
private EditText etTitle;
private Button btnUpload;
private ProgressBar pbUpload;
@ -96,6 +98,7 @@ public class FragmentDialogInsertLink extends FragmentDialogBase {
final Context context = getContext();
View view = LayoutInflater.from(context).inflate(R.layout.dialog_insert_link, null);
etLink = view.findViewById(R.id.etLink);
cbImage = view.findViewById(R.id.cbImage);
final TextView tvInsecure = view.findViewById(R.id.tvInsecure);
etTitle = view.findViewById(R.id.etTitle);
final Button btnMetadata = view.findViewById(R.id.btnMetadata);
@ -343,6 +346,7 @@ public class FragmentDialogInsertLink extends FragmentDialogBase {
@Override
public void onClick(DialogInterface dialog, int which) {
args.putString("link", etLink.getText().toString());
args.putBoolean("image", cbImage.isChecked());
args.putString("title", etTitle.getText().toString());
sendResult(RESULT_OK);
}

@ -25,6 +25,8 @@ import android.content.Intent;
import android.content.SharedPreferences;
import android.graphics.Color;
import android.graphics.Typeface;
import android.graphics.drawable.Drawable;
import android.net.Uri;
import android.os.Build;
import android.os.Bundle;
import android.text.Editable;
@ -41,6 +43,7 @@ import android.text.style.BackgroundColorSpan;
import android.text.style.BulletSpan;
import android.text.style.CharacterStyle;
import android.text.style.ForegroundColorSpan;
import android.text.style.ImageSpan;
import android.text.style.ParagraphStyle;
import android.text.style.QuoteSpan;
import android.text.style.RelativeSizeSpan;
@ -59,6 +62,7 @@ import android.widget.Toast;
import androidx.annotation.NonNull;
import androidx.appcompat.widget.PopupMenu;
import androidx.core.content.ContextCompat;
import androidx.core.content.res.ResourcesCompat;
import androidx.lifecycle.LifecycleOwner;
import androidx.preference.PreferenceManager;
@ -67,6 +71,9 @@ import com.flask.colorpicker.ColorPickerView;
import com.flask.colorpicker.builder.ColorPickerClickListener;
import com.flask.colorpicker.builder.ColorPickerDialogBuilder;
import org.jsoup.nodes.Document;
import org.jsoup.nodes.Element;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
@ -1326,28 +1333,50 @@ public class StyleHelper {
static boolean setLink(EditText etBody, int start, int end, Object... args) {
Log.breadcrumb("style", "action", "link");
String url = (String) args[0];
String title = (String) args[1];
long working = (Long) args[0];
int zoom = (Integer) args[1];
String url = (String) args[2];
boolean image = (Boolean) args[3];
String title = (String) args[4];
Editable edit = etBody.getText();
URLSpan[] spans = edit.getSpans(start, end, URLSpan.class);
for (URLSpan span : spans)
edit.removeSpan(span);
if (image) {
Uri uri = Uri.parse(url);
if (!UriHelper.isHyperLink(uri))
return false;
if (!TextUtils.isEmpty(url)) {
if (TextUtils.isEmpty(title))
title = url;
SpannableStringBuilder ssb = new SpannableStringBuilderEx(edit);
if (start == end)
edit.insert(start, title);
else if (!title.equals(edit.subSequence(start, end).toString()))
edit.replace(start, end, title);
ssb.insert(start, "\n\uFFFC\n"); // Object replacement character
edit.setSpan(new URLSpan(url), start, start + title.length(), Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
}
Drawable img = ImageHelper.decodeImage(etBody.getContext(),
working, url, true, zoom, 1.0f, etBody);
etBody.setText(edit);
etBody.setSelection(start + title.length());
ImageSpan is = new ImageSpan(img, url);
ssb.setSpan(is, start + 1, start + 2, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
etBody.setText(ssb);
etBody.setSelection(start + 3);
} else {
URLSpan[] spans = edit.getSpans(start, end, URLSpan.class);
for (URLSpan span : spans)
edit.removeSpan(span);
if (!TextUtils.isEmpty(url)) {
if (TextUtils.isEmpty(title))
title = url;
if (start == end)
edit.insert(start, title);
else if (!title.equals(edit.subSequence(start, end).toString()))
edit.replace(start, end, title);
edit.setSpan(new URLSpan(url), start, start + title.length(), Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
}
etBody.setText(edit);
etBody.setSelection(start + title.length());
}
return true;

@ -57,6 +57,15 @@
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/etLink" />
<CheckBox
android:id="@+id/cbImage"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="12dp"
android:text="@string/title_style_link_image"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/tvInsecure" />
<TextView
android:id="@+id/tvTitle"
android:layout_width="wrap_content"
@ -66,7 +75,7 @@
android:text="@string/title_style_link_title"
android:textAppearance="@style/TextAppearance.AppCompat.Medium"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/tvInsecure" />
app:layout_constraintTop_toBottomOf="@id/cbImage" />
<eu.faircode.email.EditTextPlain
android:id="@+id/etTitle"

@ -1530,6 +1530,7 @@
<string name="title_style_clear">Clear formatting</string>
<string name="title_style_link">Insert link</string>
<string name="title_style_link_address">Address</string>
<string name="title_style_link_image">Insert as an image</string>
<string name="title_style_link_title">Title</string>
<string name="title_style_link_metadata">Fetch title</string>
<string name="title_style_link_metadata_remark">This will fetch the title at the entered address</string>

Loading…
Cancel
Save