diff --git a/app/src/apkFlavor/java/com/jens/automation2/Rule.java b/app/src/apkFlavor/java/com/jens/automation2/Rule.java index 731df84c..8253480f 100644 --- a/app/src/apkFlavor/java/com/jens/automation2/Rule.java +++ b/app/src/apkFlavor/java/com/jens/automation2/Rule.java @@ -345,6 +345,11 @@ public class Rule implements Comparable return false; } + + public boolean getsGreenLight(Context context) + { + return isRuleActive() && applies(context) && (hasNotAppliedSinceLastExecution() || isActuallyToggable()); + } public boolean applies(Context context) { diff --git a/app/src/apkFlavor/java/com/jens/automation2/receivers/ActivityDetectionReceiver.java b/app/src/apkFlavor/java/com/jens/automation2/receivers/ActivityDetectionReceiver.java index 8dd7755f..91ac3501 100644 --- a/app/src/apkFlavor/java/com/jens/automation2/receivers/ActivityDetectionReceiver.java +++ b/app/src/apkFlavor/java/com/jens/automation2/receivers/ActivityDetectionReceiver.java @@ -294,7 +294,7 @@ public class ActivityDetectionReceiver extends IntentService implements Automati ArrayList allRulesWithActivityDetection = Rule.findRuleCandidatesByActivityDetection(); for(int i=0; i for(int i=0; i Miscellaneous.logEvent("i", "POI", "POI " + this.getName() + " found in " + ruleCandidates.size() + " rule(s).", 2); for(int i=0; i getParentRule().getLastExecution().getTimeInMillis()) { + Miscellaneous.logEvent("i", "Trigger", "Trigger " + this.toString() + " of rule " + getParentRule().getName() + " has NOT applied since the parent rule\'s last activation.", 4); return true; } } - Miscellaneous.logEvent("i", "Trigger", "Trigger " + this.toString() + " of rule " + getParentRule().getName() + " may apply currently, but has not NOT applied since the rule\'s last execution.", 5); + Miscellaneous.logEvent("i", "Trigger", "Trigger " + this.toString() + " of rule " + getParentRule().getName() + " may apply currently, but has not NOT applied since the rule\'s last execution.", 4); return false; } diff --git a/app/src/main/java/com/jens/automation2/location/LocationProvider.java b/app/src/main/java/com/jens/automation2/location/LocationProvider.java index d8e44f31..c67643e3 100644 --- a/app/src/main/java/com/jens/automation2/location/LocationProvider.java +++ b/app/src/main/java/com/jens/automation2/location/LocationProvider.java @@ -201,7 +201,7 @@ public class LocationProvider ArrayList ruleCandidates = Rule.findRuleCandidatesBySpeed(); for (Rule oneRule : ruleCandidates) { - if ((oneRule.applies(this.getParentService()) && oneRule.hasNotAppliedSinceLastExecution()) || oneRule.isActuallyToggable()) + if(oneRule.getsGreenLight(this.getParentService())) oneRule.activate(getParentService(), false); } } diff --git a/app/src/main/java/com/jens/automation2/location/WifiBroadcastReceiver.java b/app/src/main/java/com/jens/automation2/location/WifiBroadcastReceiver.java index b1673b80..c354e9a4 100644 --- a/app/src/main/java/com/jens/automation2/location/WifiBroadcastReceiver.java +++ b/app/src/main/java/com/jens/automation2/location/WifiBroadcastReceiver.java @@ -147,7 +147,7 @@ public class WifiBroadcastReceiver extends BroadcastReceiver ArrayList ruleCandidates = Rule.findRuleCandidatesByWifiConnection(); for(Rule oneRule : ruleCandidates) { - if((oneRule.applies(automationServiceInstance) && oneRule.hasNotAppliedSinceLastExecution()) || oneRule.isActuallyToggable()) + if(oneRule.getsGreenLight(automationServiceInstance)) oneRule.activate(automationServiceInstance, false); } } diff --git a/app/src/main/java/com/jens/automation2/receivers/BatteryReceiver.java b/app/src/main/java/com/jens/automation2/receivers/BatteryReceiver.java index 2fd8db3e..0a457548 100644 --- a/app/src/main/java/com/jens/automation2/receivers/BatteryReceiver.java +++ b/app/src/main/java/com/jens/automation2/receivers/BatteryReceiver.java @@ -206,7 +206,7 @@ public class BatteryReceiver extends BroadcastReceiver implements AutomationList ArrayList ruleCandidates = Rule.findRuleCandidatesByCharging(true); for(int i=0; i ruleCandidates = Rule.findRuleCandidatesByBatteryLevel(); for(int i=0; i ruleCandidates = Rule.findRuleCandidatesByCharging(false); for(int i=0; i ruleCandidates = Rule.findRuleCandidatesByUsbHost(true); for(Rule oneRule : ruleCandidates) { - if((oneRule.applies(context) && oneRule.hasNotAppliedSinceLastExecution()) || oneRule.isActuallyToggable()) + if(oneRule.getsGreenLight(context)) oneRule.activate(automationServiceRef, false); } @@ -278,7 +278,7 @@ public class BatteryReceiver extends BroadcastReceiver implements AutomationList ArrayList ruleCandidates = Rule.findRuleCandidatesByUsbHost(false); for(Rule oneRule : ruleCandidates) { - if((oneRule.applies(context) && oneRule.hasNotAppliedSinceLastExecution()) || oneRule.isActuallyToggable()) + if(oneRule.getsGreenLight(context)) oneRule.activate(automationServiceRef, false); } } diff --git a/app/src/main/java/com/jens/automation2/receivers/BluetoothReceiver.java b/app/src/main/java/com/jens/automation2/receivers/BluetoothReceiver.java index 2fc23ce1..91c6dbff 100644 --- a/app/src/main/java/com/jens/automation2/receivers/BluetoothReceiver.java +++ b/app/src/main/java/com/jens/automation2/receivers/BluetoothReceiver.java @@ -127,7 +127,7 @@ public class BluetoothReceiver extends BroadcastReceiver implements AutomationLi ArrayList ruleCandidates = Rule.findRuleCandidatesByBluetoothConnection(); for(int i=0; i ruleCandidates = Rule.findRuleCandidatesByAirplaneMode(isAirplaneMode); for(int i=0; i ruleCandidates = Rule.findRuleCandidatesByRoaming(isRoaming); for(int i=0; i allRulesWithNowInTimeFrame = Rule.findRuleCandidatesByTime(passTime); for(int i=0; i ruleCandidates = Rule.findRuleCandidates(Trigger.Trigger_Enum.devicePosition); for (int i = 0; i < ruleCandidates.size(); i++) { - applies = ruleCandidates.get(i).applies(Miscellaneous.getAnyContext()); - flipped = ruleCandidates.get(i).hasNotAppliedSinceLastExecution(); - toggable = ruleCandidates.get(i).isActuallyToggable(); - - if((applies && flipped) || toggable) + if(ruleCandidates.get(i).getsGreenLight(Miscellaneous.getAnyContext())) ruleCandidates.get(i).activate(AutomationService.getInstance(), false); } } diff --git a/app/src/main/java/com/jens/automation2/receivers/HeadphoneJackListener.java b/app/src/main/java/com/jens/automation2/receivers/HeadphoneJackListener.java index 748f083f..83a8865a 100644 --- a/app/src/main/java/com/jens/automation2/receivers/HeadphoneJackListener.java +++ b/app/src/main/java/com/jens/automation2/receivers/HeadphoneJackListener.java @@ -77,7 +77,7 @@ public class HeadphoneJackListener extends BroadcastReceiver implements Automati ArrayList ruleCandidates = Rule.findRuleCandidatesByHeadphoneJack(isHeadsetConnected()); for(int i=0; i allRulesWithNfcTags = Rule.findRuleCandidatesByNfc(); for(int i=0; i ruleCandidates = Rule.findRuleCandidatesByNoiseLevel(); for(Rule oneRule : ruleCandidates) { - if((oneRule.applies(automationService) && oneRule.hasNotAppliedSinceLastExecution()) || oneRule.isActuallyToggable()) + if(oneRule.getsGreenLight(automationService)) oneRule.activate(automationService, false); } } diff --git a/app/src/main/java/com/jens/automation2/receivers/NotificationListener.java b/app/src/main/java/com/jens/automation2/receivers/NotificationListener.java index efffeed6..28ef525b 100644 --- a/app/src/main/java/com/jens/automation2/receivers/NotificationListener.java +++ b/app/src/main/java/com/jens/automation2/receivers/NotificationListener.java @@ -92,7 +92,7 @@ public class NotificationListener extends NotificationListenerService ArrayList ruleCandidates = Rule.findRuleCandidates(Trigger.Trigger_Enum.notification); for (int i = 0; i < ruleCandidates.size(); i++) { - if ((ruleCandidates.get(i).applies(NotificationListener.this) && ruleCandidates.get(i).hasNotAppliedSinceLastExecution()) || ruleCandidates.get(i).isActuallyToggable()) + if(ruleCandidates.get(i).getsGreenLight(NotificationListener.this)) ruleCandidates.get(i).activate(AutomationService.getInstance(), false); } } diff --git a/app/src/main/java/com/jens/automation2/receivers/PhoneStatusListener.java b/app/src/main/java/com/jens/automation2/receivers/PhoneStatusListener.java index 98e633c0..a0c9baa5 100644 --- a/app/src/main/java/com/jens/automation2/receivers/PhoneStatusListener.java +++ b/app/src/main/java/com/jens/automation2/receivers/PhoneStatusListener.java @@ -114,7 +114,7 @@ public class PhoneStatusListener implements AutomationListenerInterface { AutomationService asInstance = AutomationService.getInstance(); if(asInstance != null) - if((ruleCandidates.get(i).applies(asInstance) && ruleCandidates.get(i).hasNotAppliedSinceLastExecution()) || ruleCandidates.get(i).isActuallyToggable()) + if(ruleCandidates.get(i).getsGreenLight(asInstance)) ruleCandidates.get(i).activate(asInstance, false); } } @@ -146,7 +146,7 @@ public class PhoneStatusListener implements AutomationListenerInterface { AutomationService asInstance = AutomationService.getInstance(); if (asInstance != null) - if ((ruleCandidates.get(i).applies(asInstance) && ruleCandidates.get(i).hasNotAppliedSinceLastExecution()) || ruleCandidates.get(i).isActuallyToggable()) + if (ruleCandidates.get(i).getsGreenLight(asInstance)) ruleCandidates.get(i).activate(asInstance, false); } } @@ -183,7 +183,7 @@ public class PhoneStatusListener implements AutomationListenerInterface { AutomationService asInstance = AutomationService.getInstance(); if(asInstance != null) - if((ruleCandidates.get(i).applies(asInstance) && ruleCandidates.get(i).hasNotAppliedSinceLastExecution()) || ruleCandidates.get(i).isActuallyToggable()) + if(ruleCandidates.get(i).getsGreenLight(asInstance)) ruleCandidates.get(i).activate(asInstance, false); } } diff --git a/app/src/main/java/com/jens/automation2/receivers/ProcessListener.java b/app/src/main/java/com/jens/automation2/receivers/ProcessListener.java index a0eec0aa..be377144 100644 --- a/app/src/main/java/com/jens/automation2/receivers/ProcessListener.java +++ b/app/src/main/java/com/jens/automation2/receivers/ProcessListener.java @@ -60,7 +60,7 @@ public class ProcessListener implements AutomationListenerInterface ArrayList ruleCandidates = Rule.findRuleCandidatesByProcess(); for(int i=0; i