1
0
Fork 0
mirror of https://github.com/M66B/FairEmail.git synced 2025-01-01 04:35:57 +00:00

Simplification

This commit is contained in:
M66B 2019-04-27 22:10:18 +02:00
parent 5918571c68
commit 16665e71c8
2 changed files with 18 additions and 39 deletions

View file

@ -19,8 +19,6 @@ 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;
@ -31,11 +29,6 @@ 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")

View file

@ -1136,46 +1136,32 @@ public class FragmentCompose extends FragmentBase {
fragmentTransaction.commit();
return;
}
new SimpleTask<Cursor>() {
new SimpleTask<List<EntityAnswer>>() {
@Override
protected Cursor onExecute(Context context, Bundle args) {
protected List<EntityAnswer> onExecute(Context context, Bundle args) {
DB db = DB.getInstance(getContext());
return db.answer().getAnswerList();
return db.answer().getAnswers(false);
}
@Override
protected void onExecuted(Bundle args, Cursor cursor) {
ListView lv = new ListView(getContext());
protected void onExecuted(Bundle args, List<EntityAnswer> answers) {
final ArrayAdapter<EntityAnswer> adapter =
new ArrayAdapter<>(getContext(), R.layout.spinner_item1, android.R.id.text1, answers);
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);
new DialogBuilderLifecycle(getContext(), getViewLifecycleOwner())
.setAdapter(adapter, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
dialog.dismiss();
EntityAnswer answer = adapter.getItem(which);
final AlertDialog dialog = new DialogBuilderLifecycle(getContext(), getViewLifecycleOwner())
.setTitle(R.string.title_insert_template)
.setView(lv)
.create();
String text = EntityAnswer.replacePlaceholders(answer.text, null, null, null, null);
Spanned spanned = HtmlHelper.fromHtml(text);
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();
etBody.getText().insert(etBody.getSelectionStart(), spanned);
}
})
.show();
}
@Override