From a2e4f3043e9b0f99e8fc78b5c0dcfc3fe65955fa Mon Sep 17 00:00:00 2001 From: "Rui Zhao (renyuneyun)" Date: Sun, 20 May 2018 16:43:02 +0100 Subject: [PATCH] Fill `ConditionDataStorage.isSafeToDelete()` Fix #107 --- .../data/storage/ConditionDataStorage.java | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/app/src/main/java/ryey/easer/core/data/storage/ConditionDataStorage.java b/app/src/main/java/ryey/easer/core/data/storage/ConditionDataStorage.java index 1b28082b..5be616f2 100644 --- a/app/src/main/java/ryey/easer/core/data/storage/ConditionDataStorage.java +++ b/app/src/main/java/ryey/easer/core/data/storage/ConditionDataStorage.java @@ -50,6 +50,25 @@ public static ConditionDataStorage getInstance(Context context) { @Override boolean isSafeToDelete(String name) { + ScriptDataStorage scriptDataStorage = ScriptDataStorage.getInstance(context); + for (String scriptName : scriptDataStorage.list()) { + ScriptStructure script = scriptDataStorage.get(scriptName); + if (script.isCondition()) { + if (script.getCondition().getName().equals(name)) { + return false; + } + } + } + ScenarioDataStorage scenarioDataStorage = ScenarioDataStorage.getInstance(context); + for (String scenarioName : scenarioDataStorage.list()) { + ScenarioStructure scenario = scenarioDataStorage.get(scenarioName); + EventData eventData = scenario.getEventData(); + if (eventData instanceof ConditionEventEventData) { + if (name.equals(((ConditionEventEventData) eventData).conditionName)) { + return false; + } + } + } return true; }