Add changeConnector()

This commit is contained in:
Nico Schmitz 2018-10-24 23:13:55 +02:00
parent 7659f58776
commit d863e39046
2 changed files with 44 additions and 27 deletions

View file

@ -176,33 +176,7 @@ public class AutomationFragment extends SubscriberFragment {
public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {
if (position != initialPosition) {
// conector type changed
final TriggerConnector.Type newConnectorType = TriggerConnector.Type.values()[position];
if (connector.size() > 2) {
// split connector
int pos = connector.pos(trigger) - 1;
TriggerConnector newConnector = new TriggerConnector(newConnectorType);
{
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);
} else {
connector.changeConnectorType(newConnectorType);
}
connector.simplify().rebuildView();
changeConnector(trigger, connector, TriggerConnector.Type.values()[position]);
}
}
@ -220,6 +194,34 @@ public class AutomationFragment extends SubscriberFragment {
}
}
public static void changeConnector(final Trigger trigger, final TriggerConnector connector, final TriggerConnector.Type newConnectorType) {
if (connector.size() > 2) {
// split connector
int pos = connector.pos(trigger) - 1;
TriggerConnector newConnector = new TriggerConnector(newConnectorType);
{
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);
} else {
connector.changeConnectorType(newConnectorType);
}
connector.simplify().rebuildView();
}
public void rebuild() {
destroy();
build();

View file

@ -0,0 +1,15 @@
package info.nightscout.androidaps.plugins.general.automation;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.powermock.core.classloader.annotations.PrepareForTest;
import org.powermock.modules.junit4.PowerMockRunner;
@RunWith(PowerMockRunner.class)
@PrepareForTest({})
public class ComposeTriggerTest {
@Test
public void testTriggerList() {
}
}