src/main/java/de/blau/android/easyedit/route/RouteSegmentActionModeCallback.java
/**
     * Add the selected element as a segment
     * 
     * In the simplest case this selects the next segment, in the worst it splits both the current and the next segment
     * and restarts the process.
     * 
     * @param element the clicked OSM element
     */
Add the selected element as a segment

In the simplest case this selects the next segment, in the worst it splits both the current and the next segment
and restarts the process.

@param element the clicked OSM element
Add the selected element as a segment In the simplest case this selects the next segment in the worst it splits both the current and the next segment and restarts the process . @param element the clicked OSM element
private void addSegment(@NonNull OsmElement element) {
        if (!Way.NAME.equals(element.getName())) {
            Log.e(DEBUG_TAG, element.getName() + " clicked");
            return;
        }
        final int size = segments.size();
        final Way currentSegment = segments.get(size - 1);
        Way nextSegment = (Way) element;
        Node commonNode = currentSegment.getCommonNode(nextSegment);
        boolean currentNeedsSplit = !currentSegment.isClosed() && !currentSegment.isEndNode(commonNode);
        boolean nextNeedsSplit = !nextSegment.isClosed() && !nextSegment.isEndNode(commonNode);
        if (currentNeedsSplit) {
            splitSafe(Util.wrapInList(currentSegment), () -> {
                Way tempCurrentSegment = currentSegment;
                try {
                    List<Result> result = logic.performSplit(main, currentSegment, commonNode);
                    Way newCurrentSegment = newWayFromSplitResult(result);
                    saveSplitResult(currentSegment, result);
                    if (size > 1) { 
                        Way prevSegment = segments.get(size - 2);
                        Node currentFirst = currentSegment.getFirstNode();
                        Node currentLast = currentSegment.getLastNode();
                        Node prevFirst = prevSegment.getFirstNode();
                        Node prevLast = prevSegment.getLastNode();
                        if (prevFirst.equals(currentFirst) || prevFirst.equals(currentLast) || prevLast.equals(currentFirst) || prevLast.equals(currentLast)) {
                            newCurrentSegment = null;
                        } else {
                            segments.set(size - 1, newCurrentSegment);
                            tempCurrentSegment = newCurrentSegment;
                            newCurrentSegment = null;
                        }
                        logic.setSelectedRelationWays(segments);
                    }
                    if (nextNeedsSplit) {
                        splitNext(nextSegment, commonNode, tempCurrentSegment, newCurrentSegment);
                    } else {
                        nextStep(tempCurrentSegment, nextSegment, newCurrentSegment, null);
                    }
                } catch (OsmIllegalOperationException | StorageException ex) {
                    manager.finish();
                }
            });
        } else if (nextNeedsSplit) {
            splitNext(nextSegment, commonNode, currentSegment, null);
        } else {
            nextStep(currentSegment, nextSegment, null, null);
        }
    }
private void addSegment ( @ NonNull OsmElement element ) { if ( ! Way . NAME . equals ( element . getName ( ) ) ) { Log . e ( DEBUG_TAG , element . getName ( ) + " clicked" ) ; return ; } final int size = segments . size ( ) ; final Way currentSegment = segments . get ( size - 1 ) ; Way nextSegment = ( Way ) element ; Node commonNode = currentSegment . getCommonNode ( nextSegment ) ; boolean currentNeedsSplit = ! currentSegment . isClosed ( ) && ! currentSegment . isEndNode ( commonNode ) ; boolean nextNeedsSplit = ! nextSegment . isClosed ( ) && ! nextSegment . isEndNode ( commonNode ) ; if ( currentNeedsSplit ) { splitSafe ( Util . wrapInList ( currentSegment ) , ( ) -> { Way tempCurrentSegment = currentSegment ; try { List < Result > result = logic . performSplit ( main , currentSegment , commonNode ) ; Way newCurrentSegment = newWayFromSplitResult ( result ) ; saveSplitResult ( currentSegment , result ) ; if ( size > 1 ) { Way prevSegment = segments . get ( size - 2 ) ; Node currentFirst = currentSegment . getFirstNode ( ) ; Node currentLast = currentSegment . getLastNode ( ) ; Node prevFirst = prevSegment . getFirstNode ( ) ; Node prevLast = prevSegment . getLastNode ( ) ; if ( prevFirst . equals ( currentFirst ) || prevFirst . equals ( currentLast ) || prevLast . equals ( currentFirst ) || prevLast . equals ( currentLast ) ) { newCurrentSegment = null ; } else { segments . set ( size - 1 , newCurrentSegment ) ; tempCurrentSegment = newCurrentSegment ; newCurrentSegment = null ; } logic . setSelectedRelationWays ( segments ) ; } if ( nextNeedsSplit ) { splitNext ( nextSegment , commonNode , tempCurrentSegment , newCurrentSegment ) ; } else { nextStep ( tempCurrentSegment , nextSegment , newCurrentSegment , null ) ; } } catch ( OsmIllegalOperationException | StorageException ex ) { manager . finish ( ) ; } } ) ; } else if ( nextNeedsSplit ) { splitNext ( nextSegment , commonNode , currentSegment , null ) ; } else { nextStep ( currentSegment , nextSegment , null , null ) ; } }
Add the selected element as a segment
Add the selected element as a segment
// This shouldn't happen // check if we have to split this or the next segment // split from at node // not the first segment // keep the bit that connects to previous segment // toast has already been displayed