mirror of https://github.com/M66B/FairEmail.git
Added template groups
This commit is contained in:
parent
532930b710
commit
9364c8b520
File diff suppressed because it is too large
Load Diff
|
@ -62,6 +62,7 @@ public class AdapterAnswer extends RecyclerView.Adapter<AdapterAnswer.ViewHolder
|
|||
public class ViewHolder extends RecyclerView.ViewHolder implements View.OnClickListener, View.OnLongClickListener {
|
||||
private View view;
|
||||
private TextView tvName;
|
||||
private TextView tvGroup;
|
||||
|
||||
private TwoStateOwner powner = new TwoStateOwner(owner, "RulePopup");
|
||||
|
||||
|
@ -70,6 +71,7 @@ public class AdapterAnswer extends RecyclerView.Adapter<AdapterAnswer.ViewHolder
|
|||
|
||||
view = itemView.findViewById(R.id.clItem);
|
||||
tvName = itemView.findViewById(R.id.tvName);
|
||||
tvGroup = itemView.findViewById(R.id.tvGroup);
|
||||
}
|
||||
|
||||
private void wire() {
|
||||
|
@ -85,6 +87,7 @@ public class AdapterAnswer extends RecyclerView.Adapter<AdapterAnswer.ViewHolder
|
|||
private void bindTo(EntityAnswer answer) {
|
||||
view.setAlpha(answer.hide ? Helper.LOW_LIGHT : 1.0f);
|
||||
tvName.setText(answer.toString());
|
||||
tvGroup.setText(answer.group);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -62,7 +62,7 @@ import io.requery.android.database.sqlite.SQLiteDatabase;
|
|||
// https://developer.android.com/topic/libraries/architecture/room.html
|
||||
|
||||
@Database(
|
||||
version = 173,
|
||||
version = 174,
|
||||
entities = {
|
||||
EntityIdentity.class,
|
||||
EntityAccount.class,
|
||||
|
@ -1708,6 +1708,13 @@ public abstract class DB extends RoomDatabase {
|
|||
db.execSQL("DROP INDEX `index_attachment_message_sequence`");
|
||||
db.execSQL("CREATE UNIQUE INDEX IF NOT EXISTS `index_attachment_message_sequence_subsequence` ON `attachment` (`message`, `sequence`, `subsequence`)");
|
||||
}
|
||||
})
|
||||
.addMigrations(new Migration(173, 174) {
|
||||
@Override
|
||||
public void migrate(@NonNull SupportSQLiteDatabase db) {
|
||||
Log.i("DB migration from version " + startVersion + " to " + endVersion);
|
||||
db.execSQL("ALTER TABLE `answer` ADD COLUMN `group` TEXT");
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
|
|
|
@ -27,6 +27,7 @@ import org.json.JSONException;
|
|||
import org.json.JSONObject;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.util.Objects;
|
||||
|
||||
import javax.mail.Address;
|
||||
import javax.mail.internet.InternetAddress;
|
||||
|
@ -47,6 +48,7 @@ public class EntityAnswer implements Serializable {
|
|||
public Long id;
|
||||
@NonNull
|
||||
public String name;
|
||||
public String group;
|
||||
@NonNull
|
||||
public Boolean favorite;
|
||||
@NonNull
|
||||
|
@ -102,6 +104,7 @@ public class EntityAnswer implements Serializable {
|
|||
JSONObject json = new JSONObject();
|
||||
json.put("id", id);
|
||||
json.put("name", name);
|
||||
json.put("group", group);
|
||||
json.put("favorite", favorite);
|
||||
json.put("hide", hide);
|
||||
json.put("text", text);
|
||||
|
@ -112,6 +115,7 @@ public class EntityAnswer implements Serializable {
|
|||
EntityAnswer answer = new EntityAnswer();
|
||||
answer.id = json.getLong("id");
|
||||
answer.name = json.getString("name");
|
||||
answer.group = json.optString("group");
|
||||
answer.favorite = json.optBoolean("favorite");
|
||||
answer.hide = json.optBoolean("hide");
|
||||
answer.text = json.getString("text");
|
||||
|
@ -123,6 +127,7 @@ public class EntityAnswer implements Serializable {
|
|||
if (obj instanceof EntityAnswer) {
|
||||
EntityAnswer other = (EntityAnswer) obj;
|
||||
return (this.name.equals(other.name) &&
|
||||
Objects.equals(this.group, other.group) &&
|
||||
this.favorite.equals(other.favorite) &&
|
||||
this.hide.equals(other.hide) &&
|
||||
this.text.equals(other.text)
|
||||
|
|
|
@ -56,6 +56,7 @@ import static android.app.Activity.RESULT_OK;
|
|||
public class FragmentAnswer extends FragmentBase {
|
||||
private ViewGroup view;
|
||||
private EditText etName;
|
||||
private EditText etGroup;
|
||||
private CheckBox cbFavorite;
|
||||
private CheckBox cbHide;
|
||||
private EditTextCompose etText;
|
||||
|
@ -94,6 +95,7 @@ public class FragmentAnswer extends FragmentBase {
|
|||
|
||||
// Get controls
|
||||
etName = view.findViewById(R.id.etName);
|
||||
etGroup = view.findViewById(R.id.etGroup);
|
||||
cbFavorite = view.findViewById(R.id.cbFavorite);
|
||||
cbHide = view.findViewById(R.id.cbHide);
|
||||
etText = view.findViewById(R.id.etText);
|
||||
|
@ -174,6 +176,7 @@ public class FragmentAnswer extends FragmentBase {
|
|||
protected void onExecuted(Bundle args, EntityAnswer answer) {
|
||||
if (savedInstanceState == null) {
|
||||
etName.setText(answer == null ? null : answer.name);
|
||||
etGroup.setText(answer == null ? null : answer.group);
|
||||
cbFavorite.setChecked(answer == null ? false : answer.favorite);
|
||||
cbHide.setChecked(answer == null ? false : answer.hide);
|
||||
if (answer == null)
|
||||
|
@ -246,6 +249,7 @@ public class FragmentAnswer extends FragmentBase {
|
|||
Bundle args = new Bundle();
|
||||
args.putLong("id", id);
|
||||
args.putString("name", etName.getText().toString().trim());
|
||||
args.putString("group", etGroup.getText().toString().trim());
|
||||
args.putBoolean("favorite", cbFavorite.isChecked());
|
||||
args.putBoolean("hide", cbHide.isChecked());
|
||||
args.putString("html", HtmlHelper.toHtml(etText.getText(), getContext()));
|
||||
|
@ -265,12 +269,15 @@ public class FragmentAnswer extends FragmentBase {
|
|||
protected Void onExecute(Context context, Bundle args) {
|
||||
long id = args.getLong("id");
|
||||
String name = args.getString("name");
|
||||
String group = args.getString("group");
|
||||
boolean favorite = args.getBoolean("favorite");
|
||||
boolean hide = args.getBoolean("hide");
|
||||
String html = args.getString("html");
|
||||
|
||||
if (TextUtils.isEmpty(name))
|
||||
throw new IllegalArgumentException(context.getString(R.string.title_no_name));
|
||||
if (TextUtils.isEmpty(group))
|
||||
group = null;
|
||||
|
||||
Document document = JsoupEx.parse(html);
|
||||
|
||||
|
@ -278,6 +285,7 @@ public class FragmentAnswer extends FragmentBase {
|
|||
if (id < 0) {
|
||||
EntityAnswer answer = new EntityAnswer();
|
||||
answer.name = name;
|
||||
answer.group = group;
|
||||
answer.favorite = favorite;
|
||||
answer.hide = hide;
|
||||
answer.text = document.body().html();
|
||||
|
@ -285,6 +293,7 @@ public class FragmentAnswer extends FragmentBase {
|
|||
} else {
|
||||
EntityAnswer answer = db.answer().getAnswer(id);
|
||||
answer.name = name;
|
||||
answer.group = group;
|
||||
answer.favorite = favorite;
|
||||
answer.hide = hide;
|
||||
answer.text = document.body().html();
|
||||
|
|
|
@ -2426,12 +2426,23 @@ public class FragmentMessages extends FragmentBase implements SharedPreferences.
|
|||
snackbar.show();
|
||||
} else {
|
||||
PopupMenuLifecycle popupMenu = new PopupMenuLifecycle(getContext(), getViewLifecycleOwner(), fabReply);
|
||||
Menu main = popupMenu.getMenu();
|
||||
|
||||
Map<String, SubMenu> map = new HashMap<>();
|
||||
|
||||
int order = 0;
|
||||
for (EntityAnswer answer : answers) {
|
||||
order++;
|
||||
popupMenu.getMenu().add(Menu.NONE, order, order++, answer.toString())
|
||||
.setIntent(new Intent().putExtra("id", answer.id));
|
||||
if (answer.group == null)
|
||||
main.add(Menu.NONE, order, order++, answer.toString())
|
||||
.setIntent(new Intent().putExtra("id", answer.id));
|
||||
else {
|
||||
if (!map.containsKey(answer.group))
|
||||
map.put(answer.group, main.addSubMenu(Menu.NONE, order, order++, answer.group));
|
||||
SubMenu smenu = map.get(answer.group);
|
||||
smenu.add(Menu.NONE, smenu.size(), smenu.size() + 1, answer.toString())
|
||||
.setIntent(new Intent().putExtra("id", answer.id));
|
||||
}
|
||||
}
|
||||
|
||||
popupMenu.setOnMenuItemClickListener(new PopupMenu.OnMenuItemClickListener() {
|
||||
|
|
|
@ -26,6 +26,21 @@
|
|||
app:layout_constraintStart_toStartOf="parent"
|
||||
app:layout_constraintTop_toTopOf="parent" />
|
||||
|
||||
<eu.faircode.email.EditTextPlain
|
||||
android:id="@+id/etGroup"
|
||||
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_group"
|
||||
android:imeOptions="actionNext"
|
||||
android:inputType="textCapSentences|textAutoCorrect"
|
||||
android:textAppearance="@style/TextAppearance.AppCompat.Small"
|
||||
app:layout_constraintEnd_toEndOf="parent"
|
||||
app:layout_constraintStart_toStartOf="parent"
|
||||
app:layout_constraintTop_toBottomOf="@+id/etName" />
|
||||
|
||||
<CheckBox
|
||||
android:id="@+id/cbFavorite"
|
||||
android:layout_width="wrap_content"
|
||||
|
@ -34,7 +49,7 @@
|
|||
android:layout_marginTop="6dp"
|
||||
android:text="@string/title_answer_favorite"
|
||||
app:layout_constraintStart_toStartOf="parent"
|
||||
app:layout_constraintTop_toBottomOf="@+id/etName" />
|
||||
app:layout_constraintTop_toBottomOf="@+id/etGroup" />
|
||||
|
||||
<CheckBox
|
||||
android:id="@+id/cbHide"
|
||||
|
|
|
@ -27,6 +27,18 @@
|
|||
app:layout_constraintEnd_toEndOf="parent"
|
||||
app:layout_constraintStart_toStartOf="parent"
|
||||
app:layout_constraintTop_toTopOf="parent" />
|
||||
|
||||
<eu.faircode.email.FixedTextView
|
||||
android:id="@+id/tvGroup"
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="wrap_content"
|
||||
android:ellipsize="end"
|
||||
android:maxLines="1"
|
||||
android:text="Group"
|
||||
android:textAppearance="@style/TextAppearance.AppCompat.Small"
|
||||
app:layout_constraintEnd_toEndOf="parent"
|
||||
app:layout_constraintStart_toStartOf="parent"
|
||||
app:layout_constraintTop_toBottomOf="@+id/tvName" />
|
||||
</androidx.constraintlayout.widget.ConstraintLayout>
|
||||
</eu.faircode.email.ViewCardOptional>
|
||||
</FrameLayout>
|
|
@ -1086,6 +1086,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_group">Template group (optional)</string>
|
||||
<string name="title_answer_favorite">Favorite</string>
|
||||
<string name="title_answer_hide">Hide from menus</string>
|
||||
<string name="title_answer_text">Template text</string>
|
||||
|
|
Loading…
Reference in New Issue