mirror of
https://github.com/M66B/FairEmail.git
synced 2025-01-01 12:44:42 +00:00
Added insert template
This commit is contained in:
parent
c57d49b643
commit
4920a76e19
5 changed files with 75 additions and 4 deletions
|
@ -19,6 +19,8 @@ package eu.faircode.email;
|
|||
Copyright 2018-2019 by Marcel Bokhorst (M66B)
|
||||
*/
|
||||
|
||||
import android.database.Cursor;
|
||||
|
||||
import androidx.lifecycle.LiveData;
|
||||
import androidx.room.Dao;
|
||||
import androidx.room.Insert;
|
||||
|
@ -29,6 +31,11 @@ import java.util.List;
|
|||
|
||||
@Dao
|
||||
public interface DaoAnswer {
|
||||
@Query("SELECT id AS _id, name, text FROM answer" +
|
||||
" WHERE NOT hide" +
|
||||
" ORDER BY name COLLATE NOCASE")
|
||||
Cursor getAnswerList();
|
||||
|
||||
@Query("SELECT * FROM answer" +
|
||||
" WHERE :all OR NOT hide" +
|
||||
" ORDER BY name COLLATE NOCASE")
|
||||
|
|
|
@ -77,10 +77,14 @@ public class EntityAnswer implements Serializable {
|
|||
}
|
||||
}
|
||||
|
||||
String text = answer.text;
|
||||
text = text.replace("$name$", name == null ? "" : name);
|
||||
text = text.replace("$firstname$", first == null ? "" : first);
|
||||
text = text.replace("$lastname$", last == null ? "" : last);
|
||||
return replacePlaceholders(answer.text, name, first, last, email);
|
||||
}
|
||||
|
||||
static String replacePlaceholders(
|
||||
String text, String fullName, String firstName, String lastName, String email) {
|
||||
text = text.replace("$name$", fullName == null ? "" : fullName);
|
||||
text = text.replace("$firstname$", firstName == null ? "" : firstName);
|
||||
text = text.replace("$lastname$", lastName == null ? "" : lastName);
|
||||
text = text.replace("$email$", email == null ? "" : email);
|
||||
|
||||
return text;
|
||||
|
|
|
@ -755,6 +755,7 @@ public class FragmentCompose extends FragmentBase {
|
|||
menu.findItem(R.id.menu_attachment).setVisible(state == State.LOADED && !style);
|
||||
menu.findItem(R.id.menu_clear).setVisible(state == State.LOADED);
|
||||
menu.findItem(R.id.menu_contact_group).setVisible(state == State.LOADED);
|
||||
menu.findItem(R.id.menu_template).setVisible(state == State.LOADED);
|
||||
menu.findItem(R.id.menu_encrypt).setVisible(state == State.LOADED);
|
||||
menu.findItem(R.id.menu_send_after).setVisible(state == State.LOADED);
|
||||
|
||||
|
@ -763,6 +764,7 @@ public class FragmentCompose extends FragmentBase {
|
|||
menu.findItem(R.id.menu_attachment).setEnabled(!busy);
|
||||
menu.findItem(R.id.menu_clear).setEnabled(!busy);
|
||||
menu.findItem(R.id.menu_contact_group).setEnabled(!busy);
|
||||
menu.findItem(R.id.menu_template).setEnabled(!busy && Helper.isPro(getContext()));
|
||||
menu.findItem(R.id.menu_encrypt).setEnabled(!busy);
|
||||
menu.findItem(R.id.menu_send_after).setEnabled(!busy);
|
||||
|
||||
|
@ -801,6 +803,9 @@ public class FragmentCompose extends FragmentBase {
|
|||
case R.id.menu_contact_group:
|
||||
onMenuContactGroup();
|
||||
return true;
|
||||
case R.id.menu_template:
|
||||
onMenuTemplate();
|
||||
return true;
|
||||
case R.id.menu_encrypt:
|
||||
onMenuEncrypt();
|
||||
return true;
|
||||
|
@ -1092,6 +1097,55 @@ public class FragmentCompose extends FragmentBase {
|
|||
dialog.show();
|
||||
}
|
||||
|
||||
private void onMenuTemplate() {
|
||||
new SimpleTask<Cursor>() {
|
||||
@Override
|
||||
protected Cursor onExecute(Context context, Bundle args) {
|
||||
DB db = DB.getInstance(getContext());
|
||||
return db.answer().getAnswerList();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onExecuted(Bundle args, Cursor cursor) {
|
||||
ListView lv = new ListView(getContext());
|
||||
|
||||
final SimpleCursorAdapter adapter = new SimpleCursorAdapter(
|
||||
getContext(),
|
||||
R.layout.spinner_item1_dropdown,
|
||||
cursor,
|
||||
new String[]{"name"},
|
||||
new int[]{android.R.id.text1},
|
||||
0);
|
||||
lv.setAdapter(adapter);
|
||||
|
||||
final AlertDialog dialog = new DialogBuilderLifecycle(getContext(), getViewLifecycleOwner())
|
||||
.setView(lv)
|
||||
.create();
|
||||
|
||||
lv.setOnItemClickListener(new AdapterView.OnItemClickListener() {
|
||||
@Override
|
||||
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
|
||||
dialog.dismiss();
|
||||
|
||||
Cursor cursor = (Cursor) adapter.getItem(position);
|
||||
String text = cursor.getString(cursor.getColumnIndex("text"));
|
||||
text = EntityAnswer.replacePlaceholders(text, null, null, null, null);
|
||||
Spanned spanned = HtmlHelper.fromHtml(text);
|
||||
|
||||
etBody.getText().insert(etBody.getSelectionStart(), spanned);
|
||||
}
|
||||
});
|
||||
|
||||
dialog.show();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onException(Bundle args, Throwable ex) {
|
||||
Helper.unexpectedError(getContext(), getViewLifecycleOwner(), ex);
|
||||
}
|
||||
}.execute(this, new Bundle(), "compose:template");
|
||||
}
|
||||
|
||||
private void onMenuEncrypt() {
|
||||
encrypt = !encrypt;
|
||||
getActivity().invalidateOptionsMenu();
|
||||
|
|
|
@ -39,6 +39,11 @@
|
|||
android:title="@string/title_insert_contact_group"
|
||||
app:showAsAction="never" />
|
||||
|
||||
<item
|
||||
android:id="@+id/menu_template"
|
||||
android:title="@string/title_insert_template"
|
||||
app:showAsAction="never" />
|
||||
|
||||
<item
|
||||
android:id="@+id/menu_encrypt"
|
||||
android:checkable="true"
|
||||
|
|
|
@ -438,6 +438,7 @@
|
|||
<string name="title_add_attachment">Add attachment</string>
|
||||
<string name="title_show_addresses">Show CC/BCC</string>
|
||||
<string name="title_insert_contact_group">Insert contact group</string>
|
||||
<string name="title_insert_template">Insert template</string>
|
||||
|
||||
<string name="title_from_missing">Sender missing</string>
|
||||
<string name="title_to_missing">Recipient missing</string>
|
||||
|
|
Loading…
Reference in a new issue