Show filter rule condition values

pull/207/head
M66B 3 years ago
parent d6e493c841
commit 644b4c2e6a

@ -24,9 +24,11 @@ import android.content.Intent;
import android.graphics.Typeface; import android.graphics.Typeface;
import android.os.Bundle; import android.os.Bundle;
import android.text.SpannableString; import android.text.SpannableString;
import android.text.SpannableStringBuilder;
import android.text.TextUtils; import android.text.TextUtils;
import android.text.style.RelativeSizeSpan; import android.text.style.RelativeSizeSpan;
import android.text.style.StyleSpan; import android.text.style.StyleSpan;
import android.util.Pair;
import android.view.LayoutInflater; import android.view.LayoutInflater;
import android.view.Menu; import android.view.Menu;
import android.view.MenuItem; import android.view.MenuItem;
@ -116,23 +118,45 @@ public class AdapterRule extends RecyclerView.Adapter<AdapterRule.ViewHolder> {
ivStop.setVisibility(rule.stop ? View.VISIBLE : View.INVISIBLE); ivStop.setVisibility(rule.stop ? View.VISIBLE : View.INVISIBLE);
try { try {
List<String> condition = new ArrayList<>(); List<Pair<String, String>> conditions = new ArrayList<>();
JSONObject jcondition = new JSONObject(rule.condition); JSONObject jcondition = new JSONObject(rule.condition);
if (jcondition.has("sender")) 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")) 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")) 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")) 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")) 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")) 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")) if (jcondition.has("schedule"))
condition.add(context.getString(R.string.title_rule_time_rel)); conditions.add(new Pair<>(context.getString(R.string.title_rule_time_rel),
tvCondition.setText(TextUtils.join(" & ", condition)); 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) { } catch (Throwable ex) {
tvCondition.setText(ex.getMessage()); tvCondition.setText(ex.getMessage());
} }

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

Loading…
Cancel
Save