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) Copyright 2018-2021 by Marcel Bokhorst (M66B)
*/ */
import android.app.Dialog;
import android.content.ClipboardManager; import android.content.ClipboardManager;
import android.content.Context; import android.content.Context;
import android.content.Intent; import android.content.Intent;
@ -41,11 +40,9 @@ import android.view.View;
import android.view.ViewGroup; import android.view.ViewGroup;
import android.widget.CheckBox; import android.widget.CheckBox;
import android.widget.EditText; import android.widget.EditText;
import android.widget.TextView;
import androidx.annotation.NonNull; import androidx.annotation.NonNull;
import androidx.annotation.Nullable; import androidx.annotation.Nullable;
import androidx.appcompat.app.AlertDialog;
import androidx.constraintlayout.widget.Group; import androidx.constraintlayout.widget.Group;
import androidx.preference.PreferenceManager; import androidx.preference.PreferenceManager;
@ -223,17 +220,52 @@ public class FragmentAnswer extends FragmentBase {
super.onCreateOptionsMenu(menu, inflater); 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 @Override
public boolean onOptionsItemSelected(MenuItem item) { public boolean onOptionsItemSelected(MenuItem item) {
if (item.getItemId() == R.id.menu_help) { int itemId = item.getItemId();
onMenuHelp(); 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 true;
} }
return super.onOptionsItemSelected(item); return super.onOptionsItemSelected(item);
} }
private void onMenuHelp() { private void onMenuPlaceholder(String name) {
new FragmentInfo().show(getParentFragmentManager(), "answer:info"); 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() { private void onInsertImage() {
@ -470,28 +502,4 @@ public class FragmentAnswer extends FragmentBase {
} else } else
return StyleHelper.apply(action, getViewLifecycleOwner(), view.findViewById(action), etText); 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"?> <?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android" <menu xmlns:android="http://schemas.android.com/apk/res/android">
xmlns:app="http://schemas.android.com/apk/res-auto"> <item android:title="@string/title_answer_placeholder">
<item <menu>
android:id="@+id/menu_help" <item
android:icon="@drawable/twotone_help_24" android:id="@+id/menu_placeholder_name"
android:title="" android:title="@string/title_answer_placeholder_name" />
app:showAsAction="always" /> <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> </menu>

@ -1194,8 +1194,11 @@
<string name="title_answer_favorite">Favorite</string> <string name="title_answer_favorite">Favorite</string>
<string name="title_answer_hide">Hide from menus</string> <string name="title_answer_hide">Hide from menus</string>
<string name="title_answer_text">Template text</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_placeholder">Placeholder</string>
<string name="title_answer_template_email">$email$ will be replaced by the sender email address</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_noop">No action</string>
<string name="title_rule_seen">Mark read</string> <string name="title_rule_seen">Mark read</string>

Loading…
Cancel
Save