fix in DateTimeTrigger management and executions when service already stopped

pull/1/head
jens 1 year ago
parent 391edc59bf
commit 62c97832a9

@ -21,23 +21,23 @@ import java.util.List;
public class Rule implements Comparable<Rule>
{
private static ArrayList<Rule> ruleCollection = new ArrayList<Rule>();
protected static ArrayList<Rule> ruleCollection = new ArrayList<Rule>();
private static List<Rule> ruleRunHistory = new ArrayList<Rule>();
protected static List<Rule> ruleRunHistory = new ArrayList<Rule>();
public static List<Rule> getRuleRunHistory()
{
return ruleRunHistory;
}
private ArrayList<Trigger> triggerSet;
private ArrayList<Action> actionSet;
private String name;
private boolean ruleActive = true; // rules can be deactivated, so they won't fire if you don't want them temporarily
private boolean ruleToggle = false; // rule will run again and do the opposite of its actions if applicable
private Calendar lastExecution;
private static Date lastActivatedRuleActivationTime;
protected ArrayList<Trigger> triggerSet;
protected ArrayList<Action> actionSet;
protected String name;
protected boolean ruleActive = true; // rules can be deactivated, so they won't fire if you don't want them temporarily
protected boolean ruleToggle = false; // rule will run again and do the opposite of its actions if applicable
protected Calendar lastExecution;
protected static Date lastActivatedRuleActivationTime;
public Calendar getLastExecution()
{
@ -185,6 +185,7 @@ public class Rule implements Comparable<Rule>
if(this.checkBeforeSaving(context, true))
{
Miscellaneous.logEvent("i", "Rule", "Changing rule: " + this.toString(), 3);
boolean returnValue = XmlFileInterface.writeFile();
if(returnValue)

@ -18,23 +18,23 @@ import java.util.List;
public class Rule implements Comparable<Rule>
{
private static ArrayList<Rule> ruleCollection = new ArrayList<Rule>();
protected static ArrayList<Rule> ruleCollection = new ArrayList<Rule>();
private static List<Rule> ruleRunHistory = new ArrayList<Rule>();
protected static List<Rule> ruleRunHistory = new ArrayList<Rule>();
public static List<Rule> getRuleRunHistory()
{
return ruleRunHistory;
}
private ArrayList<Trigger> triggerSet;
private ArrayList<Action> actionSet;
private String name;
private boolean ruleActive = true; // rules can be deactivated, so they won't fire if you don't want them temporarily
private boolean ruleToggle = false; // rule will run again and do the opposite of its actions if applicable
private Calendar lastExecution;
private static Date lastActivatedRuleActivationTime;
protected ArrayList<Trigger> triggerSet;
protected ArrayList<Action> actionSet;
protected String name;
protected boolean ruleActive = true; // rules can be deactivated, so they won't fire if you don't want them temporarily
protected boolean ruleToggle = false; // rule will run again and do the opposite of its actions if applicable
protected Calendar lastExecution;
protected static Date lastActivatedRuleActivationTime;
public Calendar getLastExecution()
{
@ -182,6 +182,7 @@ public class Rule implements Comparable<Rule>
if(this.checkBeforeSaving(context, true))
{
Miscellaneous.logEvent("i", "Rule", "Changing rule: " + this.toString(), 3);
boolean returnValue = XmlFileInterface.writeFile();
if(returnValue)
@ -230,20 +231,24 @@ public class Rule implements Comparable<Rule>
}
if(!changeExistingRule)
for(Rule rule : Rule.ruleCollection)
if(rule.getName().equals(this.getName()))
{
for (Rule rule : Rule.ruleCollection)
{
if (rule.getName().equals(this.getName()))
{
Toast.makeText(context, context.getResources().getString(R.string.anotherRuleByThatName), Toast.LENGTH_LONG).show();
return false;
}
if(this.getTriggerSet().size()==0)
}
}
if(this.getTriggerSet().size() == 0)
{
Toast.makeText(context, context.getResources().getString(R.string.pleaseSpecifiyTrigger), Toast.LENGTH_LONG).show();
return false;
}
if(this.getActionSet().size()==0)
if(this.getActionSet().size() == 0)
{
Toast.makeText(context, context.getResources().getString(R.string.pleaseSpecifiyAction), Toast.LENGTH_LONG).show();
return false;

@ -21,23 +21,23 @@ import java.util.List;
public class Rule implements Comparable<Rule>
{
private static ArrayList<Rule> ruleCollection = new ArrayList<Rule>();
protected static ArrayList<Rule> ruleCollection = new ArrayList<Rule>();
private static List<Rule> ruleRunHistory = new ArrayList<Rule>();
protected static List<Rule> ruleRunHistory = new ArrayList<Rule>();
public static List<Rule> getRuleRunHistory()
{
return ruleRunHistory;
}
private ArrayList<Trigger> triggerSet;
private ArrayList<Action> actionSet;
private String name;
private boolean ruleActive = true; // rules can be deactivated, so they won't fire if you don't want them temporarily
private boolean ruleToggle = false; // rule will run again and do the opposite of its actions if applicable
private Calendar lastExecution;
private static Date lastActivatedRuleActivationTime;
protected ArrayList<Trigger> triggerSet;
protected ArrayList<Action> actionSet;
protected String name;
protected boolean ruleActive = true; // rules can be deactivated, so they won't fire if you don't want them temporarily
protected boolean ruleToggle = false; // rule will run again and do the opposite of its actions if applicable
protected Calendar lastExecution;
protected static Date lastActivatedRuleActivationTime;
public Calendar getLastExecution()
{
@ -185,6 +185,7 @@ public class Rule implements Comparable<Rule>
if(this.checkBeforeSaving(context, true))
{
Miscellaneous.logEvent("i", "Rule", "Changing rule: " + this.toString(), 3);
boolean returnValue = XmlFileInterface.writeFile();
if(returnValue)
@ -233,20 +234,24 @@ public class Rule implements Comparable<Rule>
}
if(!changeExistingRule)
for(Rule rule : Rule.ruleCollection)
if(rule.getName().equals(this.getName()))
{
for (Rule rule : Rule.ruleCollection)
{
if (rule.getName().equals(this.getName()))
{
Toast.makeText(context, context.getResources().getString(R.string.anotherRuleByThatName), Toast.LENGTH_LONG).show();
return false;
}
if(this.getTriggerSet().size()==0)
}
}
if(this.getTriggerSet().size() == 0)
{
Toast.makeText(context, context.getResources().getString(R.string.pleaseSpecifiyTrigger), Toast.LENGTH_LONG).show();
return false;
}
if(this.getActionSet().size()==0)
if(this.getActionSet().size() == 0)
{
Toast.makeText(context, context.getResources().getString(R.string.pleaseSpecifiyAction), Toast.LENGTH_LONG).show();
return false;

@ -25,6 +25,7 @@ import java.util.ArrayList;
public class ActivityMainRules extends ActivityGeneric
{
public static final String intentNameRuleName = "ruleName";
private ListView ruleListView;
ArrayList<Rule> ruleList = new ArrayList<>();
private ArrayAdapter<Rule> ruleListViewAdapter;
@ -207,8 +208,8 @@ public class ActivityMainRules extends ActivityGeneric
Toast.makeText(ActivityMainRules.this, getResources().getString(R.string.serviceHasToRunForThat), Toast.LENGTH_LONG).show();
break;
case 1:
ruleToEdit = ruleThisIsAbout;
Intent manageSpecificRuleIntent = new Intent (ActivityMainRules.this, ActivityManageRule.class);
manageSpecificRuleIntent.putExtra(intentNameRuleName, ruleThisIsAbout.getName());
startActivityForResult(manageSpecificRuleIntent, requestCodeChangeRule);
break;
case 2:

@ -71,11 +71,12 @@ public class ActivityManageRule extends Activity
static double triggerSpeed;
static double triggerNoise;
static Rule ruleToEdit;
static boolean newRule;
static Trigger newTrigger;
static Action newAction;
Rule ruleToEdit = null;
ArrayAdapter<Trigger> triggerListViewAdapter;
ArrayAdapter<Action> actionListViewAdapter;
@ -130,10 +131,10 @@ public class ActivityManageRule extends Activity
@Override
protected void onCreate(Bundle savedInstanceState)
{
context = this;
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_manage_specific_rule);
context = this;
instance = this;
cmdTriggerAdd = (Button)findViewById(R.id.cmdTriggerAdd);
@ -147,7 +148,17 @@ public class ActivityManageRule extends Activity
imageHelpButton = (ImageView)findViewById(R.id.imageHelpButton);
//decide if it will be created anew or loaded to edit an existing one
if(ActivityMainRules.ruleToEdit == null)
if(getIntent().hasExtra(ActivityMainRules.intentNameRuleName))
{
// change existing rule
Miscellaneous.logEvent("i", "Rule", "Cache not empty, assuming change request.", 3);
newRule = false;
ruleToEdit = Rule.getByName(getIntent().getStringExtra(ActivityMainRules.intentNameRuleName));
triggerListViewAdapter = new ArrayAdapter<Trigger>(this, R.layout.text_view_for_poi_listview_mediumtextsize, ruleToEdit.getTriggerSet());
actionListViewAdapter = new ArrayAdapter<Action>(this, R.layout.text_view_for_poi_listview_mediumtextsize, ruleToEdit.getActionSet());
loadVariablesIntoGui();
}
else
{
// new rule
Miscellaneous.logEvent("i", "Rule", "Cache empty, assuming create request.", 3);
@ -158,16 +169,6 @@ public class ActivityManageRule extends Activity
triggerListViewAdapter = new ArrayAdapter<Trigger>(this, R.layout.text_view_for_poi_listview_mediumtextsize, ruleToEdit.getTriggerSet());
actionListViewAdapter = new ArrayAdapter<Action>(this, R.layout.text_view_for_poi_listview_mediumtextsize, ruleToEdit.getActionSet());
}
else
{
// change existing rule
Miscellaneous.logEvent("i", "Rule", "Cache not empty, assuming change request.", 3);
newRule = false;
ruleToEdit = ActivityMainRules.ruleToEdit;
triggerListViewAdapter = new ArrayAdapter<Trigger>(this, R.layout.text_view_for_poi_listview_mediumtextsize, ruleToEdit.getTriggerSet());
actionListViewAdapter = new ArrayAdapter<Action>(this, R.layout.text_view_for_poi_listview_mediumtextsize, ruleToEdit.getActionSet());
loadVariablesIntoGui();
}
cmdTriggerAdd.setOnClickListener(new OnClickListener()
{
@ -225,11 +226,6 @@ public class ActivityManageRule extends Activity
loadFormValuesToVariable();
if(ruleToEdit.change(context))
{
for(Rule r : Rule.ruleCollection)
{
r.get
}
ActivityPermissions.getRequiredPermissions(false);
finish();
}
@ -261,7 +257,6 @@ public class ActivityManageRule extends Activity
switch(selectedTrigger.getTriggerType())
{
case timeFrame:
// ActivityManageTriggerTimeFrame.editedTimeFrameTrigger = selectedTrigger;
Intent timeFrameEditor = new Intent(ActivityManageRule.this, ActivityManageTriggerTimeFrame.class);
timeFrameEditor.putExtra(intentNameTriggerParameter1, selectedTrigger.getTriggerParameter());
timeFrameEditor.putExtra(intentNameTriggerParameter2, selectedTrigger.getTriggerParameter2());

Loading…
Cancel
Save