Debug: rule needs headers/body

pull/213/head
M66B 1 year ago
parent 7b67d308da
commit 7e4c9731b2

@ -21,6 +21,7 @@ package eu.faircode.email;
import android.content.Context; import android.content.Context;
import android.content.Intent; import android.content.Intent;
import android.content.SharedPreferences;
import android.graphics.Typeface; import android.graphics.Typeface;
import android.os.Bundle; import android.os.Bundle;
import android.text.SpannableString; import android.text.SpannableString;
@ -45,6 +46,7 @@ import androidx.lifecycle.LifecycleObserver;
import androidx.lifecycle.LifecycleOwner; import androidx.lifecycle.LifecycleOwner;
import androidx.lifecycle.OnLifecycleEvent; import androidx.lifecycle.OnLifecycleEvent;
import androidx.localbroadcastmanager.content.LocalBroadcastManager; import androidx.localbroadcastmanager.content.LocalBroadcastManager;
import androidx.preference.PreferenceManager;
import androidx.recyclerview.widget.DiffUtil; import androidx.recyclerview.widget.DiffUtil;
import androidx.recyclerview.widget.ListUpdateCallback; import androidx.recyclerview.widget.ListUpdateCallback;
import androidx.recyclerview.widget.RecyclerView; import androidx.recyclerview.widget.RecyclerView;
@ -57,6 +59,7 @@ import java.text.Collator;
import java.text.DateFormat; import java.text.DateFormat;
import java.text.NumberFormat; import java.text.NumberFormat;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections; import java.util.Collections;
import java.util.Comparator; import java.util.Comparator;
import java.util.List; import java.util.List;
@ -70,6 +73,7 @@ public class AdapterRule extends RecyclerView.Adapter<AdapterRule.ViewHolder> {
private LifecycleOwner owner; private LifecycleOwner owner;
private LayoutInflater inflater; private LayoutInflater inflater;
private boolean debug;
private DateFormat DF; private DateFormat DF;
private NumberFormat NF = NumberFormat.getNumberInstance(); private NumberFormat NF = NumberFormat.getNumberInstance();
@ -82,6 +86,8 @@ public class AdapterRule extends RecyclerView.Adapter<AdapterRule.ViewHolder> {
public class ViewHolder extends RecyclerView.ViewHolder implements View.OnClickListener, View.OnLongClickListener { public class ViewHolder extends RecyclerView.ViewHolder implements View.OnClickListener, View.OnLongClickListener {
private View view; private View view;
private ImageView ivDaily; private ImageView ivDaily;
private ImageView ivHeaders;
private ImageView ivBody;
private TextView tvName; private TextView tvName;
private TextView tvOrder; private TextView tvOrder;
private ImageView ivStop; private ImageView ivStop;
@ -97,6 +103,8 @@ public class AdapterRule extends RecyclerView.Adapter<AdapterRule.ViewHolder> {
view = itemView.findViewById(R.id.clItem); view = itemView.findViewById(R.id.clItem);
ivDaily = itemView.findViewById(R.id.ivDaily); ivDaily = itemView.findViewById(R.id.ivDaily);
ivHeaders = itemView.findViewById(R.id.ivHeaders);
ivBody = itemView.findViewById(R.id.ivBody);
tvName = itemView.findViewById(R.id.tvName); tvName = itemView.findViewById(R.id.tvName);
tvOrder = itemView.findViewById(R.id.tvOrder); tvOrder = itemView.findViewById(R.id.tvOrder);
ivStop = itemView.findViewById(R.id.ivStop); ivStop = itemView.findViewById(R.id.ivStop);
@ -117,8 +125,15 @@ public class AdapterRule extends RecyclerView.Adapter<AdapterRule.ViewHolder> {
} }
private void bindTo(TupleRuleEx rule) { private void bindTo(TupleRuleEx rule) {
boolean needsHeaders = (debug || BuildConfig.DEBUG) &&
EntityRule.needsHeaders(Arrays.asList(rule));
boolean needsBody = (debug || BuildConfig.DEBUG) &&
EntityRule.needsBody(Arrays.asList(rule));
view.setActivated(!rule.enabled); view.setActivated(!rule.enabled);
ivDaily.setVisibility(rule.daily ? View.VISIBLE : View.GONE); ivDaily.setVisibility(rule.daily ? View.VISIBLE : View.GONE);
ivHeaders.setVisibility(needsHeaders ? View.VISIBLE : View.GONE);
ivBody.setVisibility(needsBody ? View.VISIBLE : View.GONE);
tvName.setText(rule.name); tvName.setText(rule.name);
tvOrder.setText(Integer.toString(rule.order)); tvOrder.setText(Integer.toString(rule.order));
ivStop.setVisibility(rule.stop ? View.VISIBLE : View.INVISIBLE); ivStop.setVisibility(rule.stop ? View.VISIBLE : View.INVISIBLE);
@ -586,6 +601,9 @@ public class AdapterRule extends RecyclerView.Adapter<AdapterRule.ViewHolder> {
this.owner = parentFragment.getViewLifecycleOwner(); this.owner = parentFragment.getViewLifecycleOwner();
this.inflater = LayoutInflater.from(context); this.inflater = LayoutInflater.from(context);
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context);
this.debug = prefs.getBoolean("debug", false);
this.DF = Helper.getDateTimeInstance(this.context); this.DF = Helper.getDateTimeInstance(this.context);
setHasStableIds(true); setHasStableIds(true);

@ -141,12 +141,20 @@ public class EntityRule {
private static final int MAX_NOTES_LENGTH = 512; // characters private static final int MAX_NOTES_LENGTH = 512; // characters
static boolean needsHeaders(EntityMessage message, List<EntityRule> rules) { static boolean needsHeaders(EntityMessage message, List<EntityRule> rules) {
return needsHeaders(rules);
}
static boolean needsHeaders(List<EntityRule> rules) {
return needs(rules, "header"); return needs(rules, "header");
} }
static boolean needsBody(EntityMessage message, List<EntityRule> rules) { static boolean needsBody(EntityMessage message, List<EntityRule> rules) {
if (message.encrypt != null && !EntityMessage.ENCRYPT_NONE.equals(message.encrypt)) if (message.encrypt != null && !EntityMessage.ENCRYPT_NONE.equals(message.encrypt))
return false; return false;
return needsBody(rules);
}
static boolean needsBody(List<EntityRule> rules) {
return needs(rules, "body") || needs(rules, "notes_jsoup"); return needs(rules, "body") || needs(rules, "notes_jsoup");
} }

@ -22,10 +22,33 @@
android:layout_height="24dp" android:layout_height="24dp"
android:contentDescription="@string/title_rule_daily" android:contentDescription="@string/title_rule_daily"
app:layout_constraintBottom_toBottomOf="@+id/ivStop" app:layout_constraintBottom_toBottomOf="@+id/ivStop"
app:layout_constraintEnd_toStartOf="@id/ivHeaders"
app:layout_constraintStart_toStartOf="parent" app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="@+id/ivStop" app:layout_constraintTop_toTopOf="@+id/ivStop"
app:srcCompat="@drawable/twotone_hourglass_top_24" /> app:srcCompat="@drawable/twotone_hourglass_top_24" />
<ImageView
android:id="@+id/ivHeaders"
android:layout_width="24dp"
android:layout_height="24dp"
android:contentDescription="@string/title_rule_daily"
app:layout_constraintBottom_toBottomOf="@+id/ivStop"
app:layout_constraintStart_toEndOf="@id/ivDaily"
app:layout_constraintTop_toTopOf="@+id/ivStop"
app:srcCompat="@drawable/twotone_code_24"
app:tint="?attr/colorWarning" />
<ImageView
android:id="@+id/ivBody"
android:layout_width="24dp"
android:layout_height="24dp"
android:contentDescription="@string/title_rule_daily"
app:layout_constraintBottom_toBottomOf="@+id/ivStop"
app:layout_constraintStart_toEndOf="@id/ivHeaders"
app:layout_constraintTop_toTopOf="@+id/ivStop"
app:srcCompat="@drawable/twotone_text_snippet_24"
app:tint="?attr/colorWarning" />
<TextView <TextView
android:id="@+id/tvName" android:id="@+id/tvName"
android:layout_width="0dp" android:layout_width="0dp"
@ -37,7 +60,7 @@
android:textAppearance="@style/TextAppearance.AppCompat.Medium" android:textAppearance="@style/TextAppearance.AppCompat.Medium"
app:layout_constraintBottom_toBottomOf="@+id/ivStop" app:layout_constraintBottom_toBottomOf="@+id/ivStop"
app:layout_constraintEnd_toStartOf="@+id/tvOrder" app:layout_constraintEnd_toStartOf="@+id/tvOrder"
app:layout_constraintStart_toEndOf="@id/ivDaily" app:layout_constraintStart_toEndOf="@id/ivBody"
app:layout_constraintTop_toTopOf="@+id/ivStop" /> app:layout_constraintTop_toTopOf="@+id/ivStop" />
<TextView <TextView

Loading…
Cancel
Save