mirror of https://github.com/M66B/FairEmail.git
Signature: fixed/improved inserting links
This commit is contained in:
parent
4a0a4eca92
commit
d96bccc191
|
@ -19,7 +19,6 @@ package eu.faircode.email;
|
|||
Copyright 2018-2022 by Marcel Bokhorst (M66B)
|
||||
*/
|
||||
|
||||
import android.content.ClipboardManager;
|
||||
import android.content.Context;
|
||||
import android.content.DialogInterface;
|
||||
import android.content.Intent;
|
||||
|
@ -41,7 +40,6 @@ import android.view.MenuInflater;
|
|||
import android.view.MenuItem;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
import android.widget.EditText;
|
||||
import android.widget.ImageButton;
|
||||
import android.widget.TextView;
|
||||
|
||||
|
@ -74,6 +72,7 @@ public class ActivitySignature extends ActivityBase {
|
|||
|
||||
private static final int REQUEST_IMAGE = 1;
|
||||
private static final int REQUEST_FILE = 2;
|
||||
private static final int REQUEST_LINK = 3;
|
||||
|
||||
@Override
|
||||
protected void onCreate(Bundle savedInstanceState) {
|
||||
|
@ -295,6 +294,10 @@ public class ActivitySignature extends ActivityBase {
|
|||
if (resultCode == RESULT_OK && data != null)
|
||||
onFileSelected(data.getData());
|
||||
break;
|
||||
case REQUEST_LINK:
|
||||
if (resultCode == RESULT_OK && data != null)
|
||||
onLinkSelected(data.getBundleExtra("args"));
|
||||
break;
|
||||
}
|
||||
} catch (Throwable ex) {
|
||||
Log.e(ex);
|
||||
|
@ -386,37 +389,10 @@ public class ActivitySignature extends ActivityBase {
|
|||
Log.i("Style action=" + action);
|
||||
|
||||
if (action == R.id.menu_link) {
|
||||
Uri uri = null;
|
||||
final int start = etText.getSelectionStart();
|
||||
final int end = etText.getSelectionEnd();
|
||||
|
||||
ClipboardManager cbm = Helper.getSystemService(this, ClipboardManager.class);
|
||||
if (cbm != null && cbm.hasPrimaryClip()) {
|
||||
String link = cbm.getPrimaryClip().getItemAt(0).coerceToText(this).toString();
|
||||
uri = Uri.parse(link);
|
||||
if (uri.getScheme() == null)
|
||||
uri = null;
|
||||
}
|
||||
|
||||
View view = LayoutInflater.from(this).inflate(R.layout.dialog_insert_link, null);
|
||||
EditText etLink = view.findViewById(R.id.etLink);
|
||||
TextView tvInsecure = view.findViewById(R.id.tvInsecure);
|
||||
|
||||
etLink.setText(uri == null ? "https://" : uri.toString());
|
||||
tvInsecure.setVisibility(View.GONE);
|
||||
|
||||
new AlertDialog.Builder(this)
|
||||
.setView(view)
|
||||
.setPositiveButton(android.R.string.ok, new DialogInterface.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(DialogInterface dialog, int which) {
|
||||
String link = etLink.getText().toString();
|
||||
etText.setSelection(start, end);
|
||||
StyleHelper.apply(R.id.menu_link, ActivitySignature.this, null, etText, link);
|
||||
}
|
||||
})
|
||||
.setNegativeButton(android.R.string.cancel, null)
|
||||
.show();
|
||||
FragmentDialogInsertLink fragment = new FragmentDialogInsertLink();
|
||||
fragment.setArguments(FragmentDialogInsertLink.getArguments(etText));
|
||||
fragment.setTargetActivity(this, REQUEST_LINK);
|
||||
fragment.show(getSupportFragmentManager(), "signature:link");
|
||||
|
||||
return true;
|
||||
} else
|
||||
|
@ -495,4 +471,13 @@ public class ActivitySignature extends ActivityBase {
|
|||
}
|
||||
}.execute(this, args, "signature:file");
|
||||
}
|
||||
|
||||
private void onLinkSelected(Bundle args) {
|
||||
String link = args.getString("link");
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue