Simplified inserting template place holders

pull/194/head
M66B 4 years ago
parent 7098d95b0f
commit 26f726e04f

@ -19,7 +19,6 @@ package eu.faircode.email;
Copyright 2018-2021 by Marcel Bokhorst (M66B)
*/
import android.app.Dialog;
import android.content.ClipboardManager;
import android.content.Context;
import android.content.Intent;
@ -41,11 +40,9 @@ import android.view.View;
import android.view.ViewGroup;
import android.widget.CheckBox;
import android.widget.EditText;
import android.widget.TextView;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.appcompat.app.AlertDialog;
import androidx.constraintlayout.widget.Group;
import androidx.preference.PreferenceManager;
@ -223,17 +220,52 @@ public class FragmentAnswer extends FragmentBase {
super.onCreateOptionsMenu(menu, inflater);
}
@Override
public void onPrepareOptionsMenu(@NonNull Menu menu) {
menu.findItem(R.id.menu_placeholder_firstname).setVisible(BuildConfig.DEBUG);
menu.findItem(R.id.menu_placeholder_lastname).setVisible(BuildConfig.DEBUG);
super.onPrepareOptionsMenu(menu);
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
if (item.getItemId() == R.id.menu_help) {
onMenuHelp();
int itemId = item.getItemId();
if (itemId == R.id.menu_placeholder_name) {
onMenuPlaceholder("$name$");
return true;
} else if (itemId == R.id.menu_placeholder_email) {
onMenuPlaceholder("$email$");
return true;
} else if (itemId == R.id.menu_placeholder_firstname) {
onMenuPlaceholder("$firstname$");
return true;
} else if (itemId == R.id.menu_placeholder_lastname) {
onMenuPlaceholder("$lastname$");
return true;
}
return super.onOptionsItemSelected(item);
}
private void onMenuHelp() {
new FragmentInfo().show(getParentFragmentManager(), "answer:info");
private void onMenuPlaceholder(String name) {
int start = etText.getSelectionStart();
int end = etText.getSelectionEnd();
if (start > end) {
int tmp = start;
start = end;
end = tmp;
}
if (start >= 0 && start < end)
etText.getText().replace(start, end, name);
else {
if (start < 0) {
start = etText.length() - 1;
if (start < 0)
start = 0;
}
etText.getText().insert(start, name);
}
}
private void onInsertImage() {
@ -470,28 +502,4 @@ public class FragmentAnswer extends FragmentBase {
} else
return StyleHelper.apply(action, getViewLifecycleOwner(), view.findViewById(action), etText);
}
public static class FragmentInfo extends FragmentDialogBase {
@NonNull
@Override
public Dialog onCreateDialog(@Nullable Bundle savedInstanceState) {
Spanned spanned = HtmlHelper.fromHtml("<p>" +
getString(R.string.title_answer_template_name) +
"<br>" +
getString(R.string.title_answer_template_email) +
"</p>", getContext());
View dview = LayoutInflater.from(getContext()).inflate(R.layout.dialog_ask_again, null);
TextView tvMessage = dview.findViewById(R.id.tvMessage);
CheckBox cbNotAgain = dview.findViewById(R.id.cbNotAgain);
tvMessage.setText(spanned);
cbNotAgain.setVisibility(View.GONE);
return new AlertDialog.Builder(getContext())
.setView(dview)
.setNegativeButton(android.R.string.cancel, null)
.create();
}
}
}

@ -1,9 +1,19 @@
<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto">
<menu xmlns:android="http://schemas.android.com/apk/res/android">
<item android:title="@string/title_answer_placeholder">
<menu>
<item
android:id="@+id/menu_help"
android:icon="@drawable/twotone_help_24"
android:title=""
app:showAsAction="always" />
android:id="@+id/menu_placeholder_name"
android:title="@string/title_answer_placeholder_name" />
<item
android:id="@+id/menu_placeholder_email"
android:title="@string/title_answer_placeholder_email" />
<item
android:id="@+id/menu_placeholder_firstname"
android:title="@string/title_answer_placeholder_firstname" />
<item
android:id="@+id/menu_placeholder_lastname"
android:title="@string/title_answer_placeholder_lastname" />
</menu>
</item>
</menu>

@ -1194,8 +1194,11 @@
<string name="title_answer_favorite">Favorite</string>
<string name="title_answer_hide">Hide from menus</string>
<string name="title_answer_text">Template text</string>
<string name="title_answer_template_name">$name$ will be replaced by the sender full name</string>
<string name="title_answer_template_email">$email$ will be replaced by the sender email address</string>
<string name="title_answer_placeholder">Placeholder</string>
<string name="title_answer_placeholder_name">Sender\'s full name</string>
<string name="title_answer_placeholder_email">Sender\'s email address</string>
<string name="title_answer_placeholder_firstname">Sender\'s first name</string>
<string name="title_answer_placeholder_lastname">Sender\'s last name</string>
<string name="title_rule_noop">No action</string>
<string name="title_rule_seen">Mark read</string>

Loading…
Cancel
Save