Allow no template when forwarding

pull/197/head
M66B 4 years ago
parent 7e41786536
commit c2de70e91d

@ -405,11 +405,15 @@ public class EntityRule {
throw new IllegalArgumentException("Identity not found");
long aid = jargs.optLong("answer", -1);
if (aid < 0)
throw new IllegalArgumentException(context.getString(R.string.title_rule_answer_missing));
EntityAnswer answer = db.answer().getAnswer(aid);
if (answer == null)
throw new IllegalArgumentException("Answer not found");
if (aid < 0) {
String to = jargs.optString("to");
if (TextUtils.isEmpty(to))
throw new IllegalArgumentException(context.getString(R.string.title_rule_answer_missing));
} else {
EntityAnswer answer = db.answer().getAnswer(aid);
if (answer == null)
throw new IllegalArgumentException("Template not found");
}
return;
case TYPE_TTS:
return;
@ -541,9 +545,18 @@ public class EntityRule {
if (identity == null)
throw new IllegalArgumentException("Rule identity not found name=" + rule.name);
EntityAnswer answer = db.answer().getAnswer(aid);
if (answer == null)
throw new IllegalArgumentException("Rule answer not found name=" + rule.name);
EntityAnswer answer;
if (aid < 0) {
if (TextUtils.isEmpty(to))
throw new IllegalArgumentException("Rule template missing name=" + rule.name);
answer = new EntityAnswer();
answer.text = "";
} else {
answer = db.answer().getAnswer(aid);
if (answer == null)
throw new IllegalArgumentException("Rule template not found name=" + rule.name);
}
EntityFolder outbox = db.folder().getOutbox();
if (outbox == null) {

@ -632,6 +632,11 @@ public class FragmentRule extends FragmentBase {
adapterIdentity.clear();
adapterIdentity.addAll(data.identities);
EntityAnswer none = new EntityAnswer();
none.name = "-";
none.favorite = false;
data.answers.add(0, none);
adapterAnswer.clear();
adapterAnswer.addAll(data.answers);
@ -970,7 +975,7 @@ public class FragmentRule extends FragmentBase {
}
long answer = jaction.optLong("answer", -1);
for (int pos = 0; pos < adapterAnswer.getCount(); pos++)
for (int pos = 1; pos < adapterAnswer.getCount(); pos++)
if (adapterAnswer.getItem(pos).id.equals(answer)) {
spAnswer.setSelection(pos);
break;
@ -1117,6 +1122,7 @@ public class FragmentRule extends FragmentBase {
JSONObject jrecipient = jcondition.optJSONObject("recipient");
JSONObject jsubject = jcondition.optJSONObject("subject");
JSONObject jheader = jcondition.optJSONObject("header");
JSONObject jdate = jcondition.optJSONObject("date");
JSONObject jschedule = jcondition.optJSONObject("schedule");
if (jsender == null &&
@ -1124,6 +1130,7 @@ public class FragmentRule extends FragmentBase {
jsubject == null &&
!jcondition.optBoolean("attachments") &&
jheader == null &&
jdate == null &&
jschedule == null)
throw new IllegalArgumentException(context.getString(R.string.title_rule_condition_missing));
@ -1295,7 +1302,7 @@ public class FragmentRule extends FragmentBase {
EntityIdentity identity = (EntityIdentity) spIdent.getSelectedItem();
EntityAnswer answer = (EntityAnswer) spAnswer.getSelectedItem();
jaction.put("identity", identity == null ? -1 : identity.id);
jaction.put("answer", answer == null ? -1 : answer.id);
jaction.put("answer", answer == null || answer.id == null ? -1 : answer.id);
jaction.put("to", etTo.getText().toString().trim());
jaction.put("cc", cbCc.isChecked());
jaction.put("attachments", cbWithAttachments.isChecked());

Loading…
Cancel
Save