Experiment: answer/label

This commit is contained in:
M66B 2023-03-12 18:57:41 +01:00
parent 4665640835
commit 61834ee7bd
7 changed files with 2964 additions and 2 deletions

File diff suppressed because it is too large Load Diff

View File

@ -68,7 +68,7 @@ import javax.mail.internet.InternetAddress;
// https://developer.android.com/topic/libraries/architecture/room.html
@Database(
version = 273,
version = 274,
entities = {
EntityIdentity.class,
EntityAccount.class,
@ -2774,6 +2774,13 @@ public abstract class DB extends RoomDatabase {
logMigration(startVersion, endVersion);
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) {
@Override
public void migrate(@NonNull SupportSQLiteDatabase db) {

View File

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

View File

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

View File

@ -5358,6 +5358,8 @@ public class FragmentCompose extends FragmentBase {
if (a != null) {
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.body().append(d.body().html());
}

View File

@ -37,6 +37,21 @@
app:layout_constraintStart_toStartOf="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
android:id="@+id/etGroup"
android:layout_width="0dp"
@ -50,7 +65,7 @@
android:textAppearance="@style/TextAppearance.AppCompat.Small"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/etName" />
app:layout_constraintTop_toBottomOf="@+id/etLabel" />
<CheckBox
android:id="@+id/cbStandard"

View File

@ -1809,6 +1809,7 @@
<string name="title_answer_caption">Edit template</string>
<string name="title_answer_reply">Reply template</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_standard">Default</string>
<string name="title_answer_favorite">Favorite</string>