Added rule condition has attachments

pull/163/head
M66B 5 years ago
parent 3446c88630
commit 7d3ccebc83

@ -200,6 +200,13 @@ public class EntityRule {
return false;
}
// Attachments
if (jcondition.optBoolean("attachments")) {
DB db = DB.getInstance(context);
if (db.attachment().getAttachments(message.id).size() == 0)
return false;
}
// Header
JSONObject jheader = jcondition.optJSONObject("header");
if (jheader != null && imessage != null) {
@ -238,7 +245,12 @@ public class EntityRule {
}
// Safeguard
if (jsender == null && jrecipient == null && jsubject == null && jheader == null && jschedule == null)
if (jsender == null &&
jrecipient == null &&
jsubject == null &&
!jcondition.optBoolean("attachments") &&
jheader == null &&
jschedule == null)
return false;
} catch (JSONException ex) {
Log.e(ex);

@ -97,6 +97,8 @@ public class FragmentRule extends FragmentBase {
private EditText etSubject;
private CheckBox cbSubject;
private CheckBox cbAttachments;
private EditText etHeader;
private CheckBox cbHeader;
@ -201,6 +203,8 @@ public class FragmentRule extends FragmentBase {
etSubject = view.findViewById(R.id.etSubject);
cbSubject = view.findViewById(R.id.cbSubject);
cbAttachments = view.findViewById(R.id.cbAttachments);
etHeader = view.findViewById(R.id.etHeader);
cbHeader = view.findViewById(R.id.cbHeader);
@ -643,6 +647,8 @@ public class FragmentRule extends FragmentBase {
etSubject.setText(jsubject == null ? args.getString("subject") : jsubject.getString("value"));
cbSubject.setChecked(jsubject != null && jsubject.getBoolean("regex"));
cbAttachments.setChecked(jcondition.optBoolean("attachments"));
etHeader.setText(jheader == null ? null : jheader.getString("value"));
cbHeader.setChecked(jheader != null && jheader.getBoolean("regex"));
@ -837,7 +843,12 @@ public class FragmentRule extends FragmentBase {
JSONObject jheader = jcondition.optJSONObject("header");
JSONObject jschedule = jcondition.optJSONObject("schedule");
if (jsender == null && jrecipient == null && jsubject == null && jheader == null && jschedule == null)
if (jsender == null &&
jrecipient == null &&
jsubject == null &&
!jcondition.optBoolean("attachments") &&
jheader == null &&
jschedule == null)
throw new IllegalArgumentException(context.getString(R.string.title_rule_condition_missing));
if (TextUtils.isEmpty(order))
@ -916,6 +927,8 @@ public class FragmentRule extends FragmentBase {
jcondition.put("subject", jsubject);
}
jcondition.put("attachments", cbAttachments.isChecked());
String header = etHeader.getText().toString();
if (!TextUtils.isEmpty(header)) {
JSONObject jheader = new JSONObject();

@ -303,13 +303,41 @@
app:layout_constraintTop_toBottomOf="@+id/etSubject" />
<View
android:id="@+id/vSeparatorHeader"
android:id="@+id/vSeparatorAttachments"
android:layout_width="match_parent"
android:layout_height="1dp"
android:background="?attr/colorSeparator"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/tvAndSubject" />
<CheckBox
android:id="@+id/cbAttachments"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/title_rule_attachments"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/vSeparatorAttachments" />
<TextView
android:id="@+id/tvAndAttachments"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="12dp"
android:text="@string/title_rule_and"
android:textAppearance="@style/Base.TextAppearance.AppCompat.Medium"
android:textColor="?android:attr/textColorPrimary"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/cbAttachments" />
<View
android:id="@+id/vSeparatorHeader"
android:layout_width="match_parent"
android:layout_height="1dp"
android:background="?attr/colorSeparator"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/tvAndAttachments" />
<TextView
android:id="@+id/tvHeader"
android:layout_width="0dp"

@ -712,6 +712,7 @@
<string name="title_rule_sender_known">Sender is a contact</string>
<string name="title_rule_recipient">Recipient contains</string>
<string name="title_rule_subject">Subject contains</string>
<string name="title_rule_attachments">Has attachments</string>
<string name="title_rule_header">Header contains</string>
<string name="title_rule_time">Time between</string>
<string name="title_rule_regex">Regex</string>

Loading…
Cancel
Save