Experiment: answer/label

pull/212/head
M66B 2 years ago
parent 4665640835
commit 61834ee7bd

File diff suppressed because it is too large Load Diff

@ -68,7 +68,7 @@ import javax.mail.internet.InternetAddress;
// https://developer.android.com/topic/libraries/architecture/room.html // https://developer.android.com/topic/libraries/architecture/room.html
@Database( @Database(
version = 273, version = 274,
entities = { entities = {
EntityIdentity.class, EntityIdentity.class,
EntityAccount.class, EntityAccount.class,
@ -2774,6 +2774,13 @@ public abstract class DB extends RoomDatabase {
logMigration(startVersion, endVersion); logMigration(startVersion, endVersion);
db.execSQL("ALTER TABLE `account` ADD COLUMN `client_delete` INTEGER NOT NULL DEFAULT 0"); db.execSQL("ALTER TABLE `account` ADD COLUMN `client_delete` INTEGER NOT NULL DEFAULT 0");
} }
}).addMigrations(new Migration(273, 274) {
@Override
public void migrate(@NonNull SupportSQLiteDatabase db) {
logMigration(startVersion, endVersion);
db.execSQL("ALTER TABLE `answer` ADD COLUMN `label` TEXT");
db.execSQL("CREATE UNIQUE INDEX IF NOT EXISTS `index_answer_label` ON `answer` (`label`)");
}
}).addMigrations(new Migration(998, 999) { }).addMigrations(new Migration(998, 999) {
@Override @Override
public void migrate(@NonNull SupportSQLiteDatabase db) { public void migrate(@NonNull SupportSQLiteDatabase db) {

@ -40,6 +40,7 @@ import androidx.annotation.NonNull;
import androidx.core.view.MenuCompat; import androidx.core.view.MenuCompat;
import androidx.preference.PreferenceManager; import androidx.preference.PreferenceManager;
import androidx.room.Entity; import androidx.room.Entity;
import androidx.room.Index;
import androidx.room.PrimaryKey; import androidx.room.PrimaryKey;
import org.json.JSONException; import org.json.JSONException;
@ -70,6 +71,7 @@ import javax.mail.internet.InternetAddress;
foreignKeys = { foreignKeys = {
}, },
indices = { indices = {
@Index(value = {"label"}, unique = true),
} }
) )
public class EntityAnswer implements Serializable { public class EntityAnswer implements Serializable {
@ -81,6 +83,7 @@ public class EntityAnswer implements Serializable {
public String uuid = UUID.randomUUID().toString(); public String uuid = UUID.randomUUID().toString();
@NonNull @NonNull
public String name; public String name;
public String label;
public String group; public String group;
@NonNull @NonNull
public Boolean standard; public Boolean standard;

@ -63,6 +63,7 @@ import java.util.List;
public class FragmentAnswer extends FragmentBase { public class FragmentAnswer extends FragmentBase {
private ViewGroup view; private ViewGroup view;
private EditText etName; private EditText etName;
private EditText etLabel;
private EditText etGroup; private EditText etGroup;
private CheckBox cbStandard; private CheckBox cbStandard;
private CheckBox cbReceipt; private CheckBox cbReceipt;
@ -115,6 +116,7 @@ public class FragmentAnswer extends FragmentBase {
// Get controls // Get controls
etName = view.findViewById(R.id.etName); etName = view.findViewById(R.id.etName);
etLabel = view.findViewById(R.id.etLabel);
etGroup = view.findViewById(R.id.etGroup); etGroup = view.findViewById(R.id.etGroup);
cbStandard = view.findViewById(R.id.cbStandard); cbStandard = view.findViewById(R.id.cbStandard);
cbReceipt = view.findViewById(R.id.cbReceipt); cbReceipt = view.findViewById(R.id.cbReceipt);
@ -187,6 +189,7 @@ public class FragmentAnswer extends FragmentBase {
// Initialize // Initialize
FragmentDialogTheme.setBackground(context, view, true); FragmentDialogTheme.setBackground(context, view, true);
etLabel.setVisibility(BuildConfig.DEBUG ? View.VISIBLE : View.GONE);
cbExternal.setVisibility(View.GONE); cbExternal.setVisibility(View.GONE);
cbSnippet.setVisibility(View.GONE); cbSnippet.setVisibility(View.GONE);
grpReady.setVisibility(View.GONE); grpReady.setVisibility(View.GONE);
@ -259,6 +262,7 @@ public class FragmentAnswer extends FragmentBase {
if (savedInstanceState == null) { if (savedInstanceState == null) {
etName.setText(answer == null ? args.getString("subject") : answer.name); etName.setText(answer == null ? args.getString("subject") : answer.name);
etLabel.setText(answer == null ? null : answer.label);
etGroup.setText(answer == null ? null : answer.group); etGroup.setText(answer == null ? null : answer.group);
cbStandard.setChecked(answer == null ? false : answer.standard); cbStandard.setChecked(answer == null ? false : answer.standard);
cbReceipt.setChecked(answer == null ? false : answer.receipt); cbReceipt.setChecked(answer == null ? false : answer.receipt);
@ -417,6 +421,7 @@ public class FragmentAnswer extends FragmentBase {
Bundle args = new Bundle(); Bundle args = new Bundle();
args.putLong("id", id); args.putLong("id", id);
args.putString("name", etName.getText().toString().trim()); args.putString("name", etName.getText().toString().trim());
args.putString("label", etLabel.getText().toString().trim());
args.putString("group", etGroup.getText().toString().trim()); args.putString("group", etGroup.getText().toString().trim());
args.putBoolean("standard", cbStandard.isChecked()); args.putBoolean("standard", cbStandard.isChecked());
args.putBoolean("receipt", cbReceipt.isChecked()); args.putBoolean("receipt", cbReceipt.isChecked());
@ -442,6 +447,7 @@ public class FragmentAnswer extends FragmentBase {
protected Void onExecute(Context context, Bundle args) { protected Void onExecute(Context context, Bundle args) {
long id = args.getLong("id"); long id = args.getLong("id");
String name = args.getString("name"); String name = args.getString("name");
String label = args.getString("label");
String group = args.getString("group"); String group = args.getString("group");
boolean standard = args.getBoolean("standard"); boolean standard = args.getBoolean("standard");
boolean receipt = args.getBoolean("receipt"); boolean receipt = args.getBoolean("receipt");
@ -454,6 +460,8 @@ public class FragmentAnswer extends FragmentBase {
if (TextUtils.isEmpty(name)) if (TextUtils.isEmpty(name))
throw new IllegalArgumentException(context.getString(R.string.title_no_name)); throw new IllegalArgumentException(context.getString(R.string.title_no_name));
if (TextUtils.isEmpty(label))
label = null;
if (TextUtils.isEmpty(group)) if (TextUtils.isEmpty(group))
group = null; group = null;
if (color == Color.TRANSPARENT) if (color == Color.TRANSPARENT)
@ -477,6 +485,7 @@ public class FragmentAnswer extends FragmentBase {
answer = db.answer().getAnswer(id); answer = db.answer().getAnswer(id);
answer.name = name; answer.name = name;
answer.label = label;
answer.group = group; answer.group = group;
answer.standard = standard; answer.standard = standard;
answer.receipt = receipt; answer.receipt = receipt;

@ -5358,6 +5358,8 @@ public class FragmentCompose extends FragmentBase {
if (a != null) { if (a != null) {
db.answer().applyAnswer(a.id, new Date().getTime()); db.answer().applyAnswer(a.id, new Date().getTime());
if (a.label != null && ref != null)
EntityOperation.queue(context, ref, EntityOperation.LABEL, a.label, true);
Document d = JsoupEx.parse(a.getHtml(context, data.draft.to)); Document d = JsoupEx.parse(a.getHtml(context, data.draft.to));
document.body().append(d.body().html()); document.body().append(d.body().html());
} }

@ -37,6 +37,21 @@
app:layout_constraintStart_toStartOf="parent" app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" /> app:layout_constraintTop_toTopOf="parent" />
<eu.faircode.email.EditTextPlain
android:id="@+id/etLabel"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginStart="6dp"
android:layout_marginTop="6dp"
android:layout_marginEnd="6dp"
android:hint="@string/title_answer_label"
android:imeOptions="actionNext"
android:inputType="textNoSuggestions"
android:textAppearance="@style/TextAppearance.AppCompat.Small"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/etName" />
<eu.faircode.email.EditTextPlain <eu.faircode.email.EditTextPlain
android:id="@+id/etGroup" android:id="@+id/etGroup"
android:layout_width="0dp" android:layout_width="0dp"
@ -50,7 +65,7 @@
android:textAppearance="@style/TextAppearance.AppCompat.Small" android:textAppearance="@style/TextAppearance.AppCompat.Small"
app:layout_constraintEnd_toEndOf="parent" app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent" app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/etName" /> app:layout_constraintTop_toBottomOf="@+id/etLabel" />
<CheckBox <CheckBox
android:id="@+id/cbStandard" android:id="@+id/cbStandard"

@ -1809,6 +1809,7 @@
<string name="title_answer_caption">Edit template</string> <string name="title_answer_caption">Edit template</string>
<string name="title_answer_reply">Reply template</string> <string name="title_answer_reply">Reply template</string>
<string name="title_answer_name">Template name</string> <string name="title_answer_name">Template name</string>
<string name="title_answer_label" translatable="false">Template label</string>
<string name="title_answer_group">Template group (optional)</string> <string name="title_answer_group">Template group (optional)</string>
<string name="title_answer_standard">Default</string> <string name="title_answer_standard">Default</string>
<string name="title_answer_favorite">Favorite</string> <string name="title_answer_favorite">Favorite</string>

Loading…
Cancel
Save