Change trigger composition logic

This commit is contained in:
Nico Schmitz 2018-10-24 23:37:14 +02:00
parent d863e39046
commit 8dc40fb795
2 changed files with 11 additions and 12 deletions

View file

@ -200,21 +200,15 @@ public class AutomationFragment extends SubscriberFragment {
int pos = connector.pos(trigger) - 1; int pos = connector.pos(trigger) - 1;
TriggerConnector newConnector = new TriggerConnector(newConnectorType); 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); Trigger t = connector.get(pos);
newConnector.add(t); newConnector.add(t);
connector.remove(t); connector.remove(t);
} }
TriggerConnector subConnector = new TriggerConnector(connector.getConnectorType()); connector.add(pos, newConnector);
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);
} else { } else {
connector.changeConnectorType(newConnectorType); connector.changeConnectorType(newConnectorType);
} }

View file

@ -81,6 +81,11 @@ public class TriggerConnector extends Trigger {
t.connector = this; t.connector = this;
} }
public synchronized void add(int pos, Trigger t) {
list.add(pos, t);
t.connector = this;
}
public synchronized boolean remove(Trigger t) { public synchronized boolean remove(Trigger t) {
return list.remove(t); return list.remove(t);
} }
@ -218,14 +223,14 @@ public class TriggerConnector extends Trigger {
ChooseTriggerDialog dialog = ChooseTriggerDialog.newInstance(); ChooseTriggerDialog dialog = ChooseTriggerDialog.newInstance();
FragmentManager manager = AutomationFragment.fragmentManager(); FragmentManager manager = AutomationFragment.fragmentManager();
dialog.show(manager, "ChooseTriggerDialog"); dialog.show(manager, "ChooseTriggerDialog");
dialog.setOnClickListener(newTriggerObject -> addTrigger(adapter, newTriggerObject, getConnectorType())); dialog.setOnClickListener(newTriggerObject -> addNewTrigger(adapter, newTriggerObject, getConnectorType()));
}); });
buttonLayout.addView(buttonAdd); buttonLayout.addView(buttonAdd);
return root; 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)) { if (getConnectorType().equals(connection)) {
add(trigger); add(trigger);
} else { } else {