Expressions: experiment

This commit is contained in:
M66B 2024-04-17 19:51:52 +02:00
parent 55779ac915
commit 441812c561
2 changed files with 16 additions and 8 deletions

View File

@ -495,14 +495,18 @@ public class EntityRule {
// Expression
Expression expression = getExpression(this, message, headers, context);
if (expression != null) {
if (needsHeaders(expression) && headers == null && message.headers == null)
throw new IllegalArgumentException(context.getString(R.string.title_rule_no_headers));
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context);
boolean experiments = prefs.getBoolean("experiments", false);
if (experiments) {
if (needsHeaders(expression) && headers == null && message.headers == null)
throw new IllegalArgumentException(context.getString(R.string.title_rule_no_headers));
Log.i("EXPR evaluating='" + jcondition.getString("expression") + "'");
Boolean result = expression.evaluate().getBooleanValue();
Log.i("EXPR evaluated=" + result);
if (!Boolean.TRUE.equals(result))
return false;
Log.i("EXPR evaluating='" + jcondition.getString("expression") + "'");
Boolean result = expression.evaluate().getBooleanValue();
Log.i("EXPR evaluated=" + result);
if (!Boolean.TRUE.equals(result))
return false;
}
}
// Safeguard

View File

@ -25,6 +25,7 @@ import android.app.Dialog;
import android.app.TimePickerDialog;
import android.content.Context;
import android.content.Intent;
import android.content.SharedPreferences;
import android.database.Cursor;
import android.graphics.Color;
import android.media.RingtoneManager;
@ -64,6 +65,7 @@ import androidx.constraintlayout.widget.ConstraintLayout;
import androidx.constraintlayout.widget.Group;
import androidx.fragment.app.DialogFragment;
import androidx.lifecycle.Lifecycle;
import androidx.preference.PreferenceManager;
import com.google.android.material.bottomnavigation.BottomNavigationView;
import com.google.android.material.snackbar.Snackbar;
@ -1428,11 +1430,13 @@ public class FragmentRule extends FragmentBase {
showActionParameters(action.type);
}
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(getContext());
boolean experiments = prefs.getBoolean("experiments", false);
grpExpression.setVisibility(experiments ? View.VISIBLE : View.GONE);
} catch (Throwable ex) {
Log.e(ex);
} finally {
grpReady.setVisibility(View.VISIBLE);
grpExpression.setVisibility(BuildConfig.DEBUG ? View.VISIBLE : View.GONE);
grpAge.setVisibility(cbDaily.isChecked() ? View.VISIBLE : View.GONE);
if (id < 0)
bottom_navigation.getMenu().removeItem(R.id.action_delete);