1
0
Fork 0
mirror of https://github.com/M66B/FairEmail.git synced 2024-12-27 18:27:43 +00:00

Show filter rule condition values

This commit is contained in:
M66B 2022-03-20 12:10:10 +01:00
parent d6e493c841
commit 644b4c2e6a
2 changed files with 34 additions and 9 deletions

View file

@ -24,9 +24,11 @@ import android.content.Intent;
import android.graphics.Typeface;
import android.os.Bundle;
import android.text.SpannableString;
import android.text.SpannableStringBuilder;
import android.text.TextUtils;
import android.text.style.RelativeSizeSpan;
import android.text.style.StyleSpan;
import android.util.Pair;
import android.view.LayoutInflater;
import android.view.Menu;
import android.view.MenuItem;
@ -116,23 +118,45 @@ public class AdapterRule extends RecyclerView.Adapter<AdapterRule.ViewHolder> {
ivStop.setVisibility(rule.stop ? View.VISIBLE : View.INVISIBLE);
try {
List<String> condition = new ArrayList<>();
List<Pair<String, String>> conditions = new ArrayList<>();
JSONObject jcondition = new JSONObject(rule.condition);
if (jcondition.has("sender"))
condition.add(context.getString(R.string.title_rule_sender));
conditions.add(new Pair<>(context.getString(R.string.title_rule_sender),
jcondition.getJSONObject("sender").optString("value")));
if (jcondition.has("recipient"))
condition.add(context.getString(R.string.title_rule_recipient));
conditions.add(new Pair<>(context.getString(R.string.title_rule_recipient),
jcondition.getJSONObject("recipient").optString("value")));
if (jcondition.has("subject"))
condition.add(context.getString(R.string.title_rule_subject));
conditions.add(new Pair<>(context.getString(R.string.title_rule_subject),
jcondition.getJSONObject("subject").optString("value")));
if (jcondition.has("header"))
condition.add(context.getString(R.string.title_rule_header));
conditions.add(new Pair<>(context.getString(R.string.title_rule_header),
jcondition.getJSONObject("header").optString("value")));
if (jcondition.has("body"))
condition.add(context.getString(R.string.title_rule_body));
conditions.add(new Pair<>(context.getString(R.string.title_rule_body),
jcondition.getJSONObject("body").optString("value")));
if (jcondition.has("date"))
condition.add(context.getString(R.string.title_rule_time_abs));
conditions.add(new Pair<>(context.getString(R.string.title_rule_time_abs),
null));
if (jcondition.has("schedule"))
condition.add(context.getString(R.string.title_rule_time_rel));
tvCondition.setText(TextUtils.join(" & ", condition));
conditions.add(new Pair<>(context.getString(R.string.title_rule_time_rel),
null));
SpannableStringBuilder ssb = new SpannableStringBuilderEx();
for (Pair<String, String> condition : conditions) {
if (ssb.length() > 0)
ssb.append("\n");
ssb.append(condition.first);
if (!TextUtils.isEmpty(condition.second)) {
ssb.append(" \"");
int start = ssb.length();
ssb.append(condition.second);
ssb.setSpan(new StyleSpan(Typeface.ITALIC), start, ssb.length(), 0);
ssb.append("\"");
}
}
tvCondition.setText(ssb);
} catch (Throwable ex) {
tvCondition.setText(ex.getMessage());
}

View file

@ -67,6 +67,7 @@
android:layout_height="wrap_content"
android:text="Action"
android:textAppearance="@style/TextAppearance.AppCompat.Small"
android:textStyle="bold"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/tvCondition" />