Change trigger composition logic
This commit is contained in:
parent
d863e39046
commit
8dc40fb795
|
@ -200,21 +200,15 @@ public class AutomationFragment extends SubscriberFragment {
|
|||
int pos = connector.pos(trigger) - 1;
|
||||
|
||||
TriggerConnector newConnector = new TriggerConnector(newConnectorType);
|
||||
{
|
||||
|
||||
// move trigger from pos and pos+1 into new connector
|
||||
for(int i = 0; i < 2; ++i) {
|
||||
Trigger t = connector.get(pos);
|
||||
newConnector.add(t);
|
||||
connector.remove(t);
|
||||
}
|
||||
|
||||
TriggerConnector subConnector = new TriggerConnector(connector.getConnectorType());
|
||||
int count = connector.size() - pos;
|
||||
for (int i = 0; i < count; ++i) {
|
||||
Trigger t = connector.get(pos);
|
||||
subConnector.add(t);
|
||||
connector.remove(t);
|
||||
}
|
||||
newConnector.add(subConnector);
|
||||
connector.add(newConnector);
|
||||
connector.add(pos, newConnector);
|
||||
} else {
|
||||
connector.changeConnectorType(newConnectorType);
|
||||
}
|
||||
|
|
|
@ -81,6 +81,11 @@ public class TriggerConnector extends Trigger {
|
|||
t.connector = this;
|
||||
}
|
||||
|
||||
public synchronized void add(int pos, Trigger t) {
|
||||
list.add(pos, t);
|
||||
t.connector = this;
|
||||
}
|
||||
|
||||
public synchronized boolean remove(Trigger t) {
|
||||
return list.remove(t);
|
||||
}
|
||||
|
@ -218,14 +223,14 @@ public class TriggerConnector extends Trigger {
|
|||
ChooseTriggerDialog dialog = ChooseTriggerDialog.newInstance();
|
||||
FragmentManager manager = AutomationFragment.fragmentManager();
|
||||
dialog.show(manager, "ChooseTriggerDialog");
|
||||
dialog.setOnClickListener(newTriggerObject -> addTrigger(adapter, newTriggerObject, getConnectorType()));
|
||||
dialog.setOnClickListener(newTriggerObject -> addNewTrigger(adapter, newTriggerObject, getConnectorType()));
|
||||
});
|
||||
buttonLayout.addView(buttonAdd);
|
||||
|
||||
return root;
|
||||
}
|
||||
|
||||
private void addTrigger(AutomationFragment.TriggerListAdapter adapter, Trigger trigger, Type connection) {
|
||||
private void addNewTrigger(AutomationFragment.TriggerListAdapter adapter, Trigger trigger, Type connection) {
|
||||
if (getConnectorType().equals(connection)) {
|
||||
add(trigger);
|
||||
} else {
|
||||
|
|
Loading…
Reference in a new issue