fix in DateTimeTrigger management and executions when service already stopped

This commit is contained in:
jens 2022-04-04 20:21:34 +02:00
parent 391edc59bf
commit 62c97832a9
5 changed files with 68 additions and 61 deletions

View File

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

View File

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

View File

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

View File

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

View File

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