-
Notifications
You must be signed in to change notification settings - Fork 4
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Result Screen - Advanced options #613
Merged
puneet-pdx
merged 41 commits into
feature-branches/utilitynetworktrace
from
puneet/4526_advancedOptions
Oct 23, 2024
Merged
Changes from all commits
Commits
Show all changes
41 commits
Select commit
Hold shift + click to select a range
dff4256
WIP
puneet-pdx aaff9d6
WIP
puneet-pdx 9e576c5
Merge branch 'feature-branches/utilitynetworktrace' into puneet/4521_…
puneet-pdx 632e96e
Merge branch 'feature-branches/utilitynetworktrace' into puneet/4521_…
puneet-pdx 358f5fa
WIP
puneet-pdx 5c26280
Merge branch 'feature-branches/utilitynetworktrace' into puneet/4521_…
puneet-pdx 07385d9
WIP
puneet-pdx f4584e9
more changes
puneet-pdx 7d44f92
remove string
puneet-pdx 7850acd
don't throw exceptions
puneet-pdx 729cddd
add copyright
puneet-pdx 6af33b2
update formatting
puneet-pdx df4318c
WIP
puneet-pdx 2864df1
WIP
puneet-pdx c1cc09b
WIP
puneet-pdx 7c9eb1a
WIP
puneet-pdx 2c184bb
fix to show multiple results
puneet-pdx d541349
address code review comments
puneet-pdx c7ec782
address comments
puneet-pdx 1bfe941
Merge branch 'feature-branches/utilitynetworktrace' into puneet/4521_…
puneet-pdx ef3aa56
add backhandler
puneet-pdx 2d68538
Merge branch 'puneet/4521_FeatureResults' into puneet/4526_advancedOp…
puneet-pdx b0c8a20
add string resource
puneet-pdx 4d6acfa
Merge branch 'puneet/4521_FeatureResults' into puneet/4526_advancedOp…
puneet-pdx fc8ba83
WIP
puneet-pdx b1f95ae
update deletion logic
puneet-pdx f46a466
update logic
puneet-pdx 26d42db
changes for color picker
puneet-pdx af5cf86
refactor colorpicker
puneet-pdx bb1edaa
add newline
puneet-pdx 4ba402e
Save selected color in options screen
puneet-pdx c38e23f
remove padding changes
puneet-pdx 5535b98
revert changes to navigation
puneet-pdx 94b3439
add copyright
puneet-pdx 0b0c71a
update indentation
puneet-pdx 2482c05
Merge branch 'puneet/4521_FeatureResults' into puneet/4526_advancedOp…
puneet-pdx c60126e
Merge branch 'feature-branches/utilitynetworktrace' into puneet/4526_…
puneet-pdx 7fa50be
clear all the starting points
puneet-pdx 767b7a8
address code review comments
puneet-pdx 376f6d8
address code review comments
puneet-pdx 630768d
address code review feedback
puneet-pdx File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -135,9 +135,6 @@ public class TraceState( | |
|
||
private val currentTraceGeometryResultsGraphics: MutableList<Graphic> = mutableListOf() | ||
|
||
private val _currentScreen: MutableState<TraceNavRoute> = mutableStateOf(TraceNavRoute.TraceOptions) | ||
internal var currentScreen: State<TraceNavRoute> = _currentScreen | ||
|
||
private val _completedTraces: SnapshotStateList<TraceRun> = mutableStateListOf() | ||
internal val completedTraces: List<TraceRun> = _completedTraces | ||
|
||
|
@@ -164,27 +161,6 @@ public class TraceState( | |
private var _currentTraceZoomToResults: MutableState<Boolean> = mutableStateOf(true) | ||
internal var currentTraceZoomToResults: State<Boolean> = _currentTraceZoomToResults | ||
|
||
private val currentTraceResultGeometriesExtent: Envelope? | ||
get() { | ||
val utilityGeometryTraceResult = currentTraceRun?.geometryTraceResult ?: return null | ||
|
||
val geometries = listOf( | ||
utilityGeometryTraceResult.polygon, | ||
utilityGeometryTraceResult.polyline, | ||
utilityGeometryTraceResult.multipoint | ||
).mapNotNull { geometry -> | ||
if (geometry != null && !geometry.isEmpty) { | ||
geometry | ||
} else { | ||
null | ||
} | ||
} | ||
val combinedExtents = GeometryEngine.combineExtentsOrNull(geometries) ?: return null | ||
val expandedEnvelope = GeometryEngine.bufferOrNull(combinedExtents, 200.0) ?: return null | ||
|
||
return expandedEnvelope.extent | ||
} | ||
|
||
private var navigateToRoute: ((TraceNavRoute) -> Unit)? = null | ||
|
||
internal fun setNavigationCallback(navigateToRoute: (TraceNavRoute) -> Unit) { | ||
|
@@ -360,11 +336,18 @@ public class TraceState( | |
} | ||
} | ||
} | ||
|
||
val currentTraceResultGeometriesExtent = currentTraceGeometryResults?.let { | ||
getResultGeometriesExtent(it) | ||
} | ||
|
||
currentTraceRun = TraceRun( | ||
name = _currentTraceName.value, | ||
configuration = traceConfiguration, | ||
startingPoints = _currentTraceStartingPoints.toList(), | ||
geometryResultsGraphics = currentTraceGeometryResultsGraphics.toList(), | ||
resultsGraphicExtent = currentTraceResultGeometriesExtent, | ||
resultGraphicColor = currentTraceGraphicsColorAsComposeColor, | ||
featureResults = currentTraceElementResults, | ||
functionResults = currentTraceFunctionResults, | ||
geometryTraceResult = currentTraceGeometryResults | ||
|
@@ -393,6 +376,24 @@ public class TraceState( | |
_currentTraceZoomToResults.value = true | ||
} | ||
|
||
private fun getResultGeometriesExtent(utilityGeometryTraceResult: UtilityGeometryTraceResult): Envelope? { | ||
val geometries = listOf( | ||
utilityGeometryTraceResult.polygon, | ||
utilityGeometryTraceResult.polyline, | ||
utilityGeometryTraceResult.multipoint | ||
).mapNotNull { geometry -> | ||
if (geometry != null && !geometry.isEmpty) { | ||
geometry | ||
} else { | ||
null | ||
} | ||
} | ||
val combinedExtents = GeometryEngine.combineExtentsOrNull(geometries) ?: return null | ||
val expandedEnvelope = GeometryEngine.bufferOrNull(combinedExtents, 200.0) ?: return null | ||
|
||
return expandedEnvelope.extent | ||
} | ||
|
||
private fun createGraphicForSimpleLineSymbol(geometry: Geometry, style: SimpleLineSymbolStyle, color: Color) = | ||
Graphic( | ||
geometry = geometry, | ||
|
@@ -572,6 +573,30 @@ public class TraceState( | |
} | ||
} | ||
|
||
internal fun setGraphicsColorForSelectedTraceRun(color: androidx.compose.ui.graphics.Color) { | ||
val arcgisColor = Color.fromRgba( | ||
color.red.toInt() * 255, | ||
color.green.toInt() * 255, | ||
color.blue.toInt() * 255, | ||
color.alpha.toInt() * 255 | ||
) | ||
val selectedTraceRun = completedTraces[_selectedCompletedTraceIndex.value] | ||
selectedTraceRun.resultGraphicColor = color | ||
|
||
// update the color of the starting points | ||
selectedTraceRun.startingPoints.forEach { startingPoint -> | ||
val symbol = startingPoint.graphic.symbol as SimpleMarkerSymbol | ||
symbol.color = arcgisColor | ||
} | ||
// update the color of the trace results graphics | ||
selectedTraceRun.geometryResultsGraphics.forEach { graphic -> | ||
if (graphic.symbol is SimpleLineSymbol) { | ||
val symbol = graphic.symbol as SimpleLineSymbol | ||
symbol.color = arcgisColor | ||
} | ||
} | ||
} | ||
|
||
/** | ||
* Set whether to zoom to the results. | ||
* | ||
|
@@ -596,6 +621,35 @@ public class TraceState( | |
return completedTraces[_selectedCompletedTraceIndex.value].featureResults.filter { it.assetGroup.name == selectedAssetGroupName } | ||
} | ||
|
||
internal fun clearAllResults() { | ||
_completedTraces.clear() | ||
_selectedCompletedTraceIndex.value = 0 | ||
currentTraceGeometryResultsGraphics.clear() | ||
_currentTraceStartingPoints.clear() | ||
graphicsOverlay.graphics.clear() | ||
} | ||
|
||
internal fun clearSelectedTraceResult() { | ||
val selectedTrace = _completedTraces[_selectedCompletedTraceIndex.value] | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It seems like the SimpleMarkerSymbol added for a starting point should be removed here as well. But that is probably better done in a separate issue. |
||
selectedTrace.geometryResultsGraphics.forEach { graphicsOverlay.graphics.remove(it) } | ||
selectedTrace.startingPoints.forEach { it.graphic.isSelected = false } | ||
_completedTraces.removeAt(_selectedCompletedTraceIndex.value) | ||
if (_selectedCompletedTraceIndex.value - 1 >= 0) { | ||
_selectedCompletedTraceIndex.value -= 1 | ||
updateSelectedStateForTraceResultsGraphics(_selectedCompletedTraceIndex.value, true) | ||
} | ||
} | ||
|
||
internal suspend fun zoomToSelectedTrace() { | ||
val currentTrace = completedTraces[_selectedCompletedTraceIndex.value] | ||
val extent = currentTrace.resultsGraphicExtent ?: return | ||
mapViewProxy.setViewpointAnimated( | ||
Viewpoint(extent.extent), | ||
1.0.seconds, | ||
AnimationCurve.EaseInOutCubic | ||
) | ||
} | ||
|
||
/** | ||
* Set the [error] that occurred during the trace. | ||
* | ||
|
@@ -680,7 +734,8 @@ internal enum class TraceNavRoute { | |
TraceResults, | ||
FeatureResultsDetails, | ||
StartingPointDetails, | ||
TraceError | ||
TraceError, | ||
ClearResults | ||
} | ||
|
||
@Immutable | ||
|
@@ -702,6 +757,8 @@ internal data class TraceRun( | |
val configuration: UtilityNamedTraceConfiguration, | ||
val startingPoints: List<StartingPoint>, | ||
val geometryResultsGraphics: List<Graphic>, | ||
val resultsGraphicExtent: Envelope? = null, | ||
var resultGraphicColor: androidx.compose.ui.graphics.Color, | ||
val featureResults: List<UtilityElement>, | ||
val functionResults: List<UtilityTraceFunctionOutput>, | ||
val geometryTraceResult: UtilityGeometryTraceResult? | ||
|
173 changes: 173 additions & 0 deletions
173
.../src/main/java/com/arcgismaps/toolkit/utilitynetworks/internal/util/AdvancedOptionsRow.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,173 @@ | ||
/* | ||
* Copyright 2024 Esri | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package com.arcgismaps.toolkit.utilitynetworks.internal.util | ||
|
||
import androidx.compose.foundation.background | ||
import androidx.compose.foundation.clickable | ||
import androidx.compose.foundation.layout.Arrangement | ||
import androidx.compose.foundation.layout.Box | ||
import androidx.compose.foundation.layout.PaddingValues | ||
import androidx.compose.foundation.layout.Row | ||
import androidx.compose.foundation.layout.fillMaxWidth | ||
import androidx.compose.foundation.layout.height | ||
import androidx.compose.foundation.layout.padding | ||
import androidx.compose.foundation.layout.size | ||
import androidx.compose.foundation.shape.CircleShape | ||
import androidx.compose.foundation.shape.RoundedCornerShape | ||
import androidx.compose.material3.DropdownMenu | ||
import androidx.compose.material3.DropdownMenuItem | ||
import androidx.compose.material3.MaterialTheme | ||
import androidx.compose.material3.Switch | ||
import androidx.compose.runtime.Composable | ||
import androidx.compose.runtime.LaunchedEffect | ||
import androidx.compose.runtime.MutableState | ||
import androidx.compose.runtime.getValue | ||
import androidx.compose.runtime.mutableStateOf | ||
import androidx.compose.runtime.remember | ||
import androidx.compose.runtime.saveable.Saver | ||
import androidx.compose.runtime.saveable.listSaver | ||
import androidx.compose.runtime.saveable.rememberSaveable | ||
import androidx.compose.runtime.setValue | ||
import androidx.compose.ui.Alignment | ||
import androidx.compose.ui.Modifier | ||
import androidx.compose.ui.draw.clip | ||
import androidx.compose.ui.graphics.Color | ||
import androidx.compose.ui.res.stringResource | ||
import androidx.compose.ui.semantics.contentDescription | ||
import androidx.compose.ui.semantics.semantics | ||
import androidx.compose.ui.tooling.preview.Preview | ||
import androidx.compose.ui.unit.DpOffset | ||
import androidx.compose.ui.unit.dp | ||
import com.arcgismaps.toolkit.utilitynetworks.R | ||
import com.arcgismaps.toolkit.utilitynetworks.ui.ReadOnlyTextField | ||
import com.arcgismaps.toolkit.utilitynetworks.ui.TraceColors | ||
|
||
@Composable | ||
internal fun AdvancedOptionsRow(name: String, modifier: Modifier = Modifier, trailingTool: @Composable () -> Unit) { | ||
Row( | ||
modifier = modifier | ||
.fillMaxWidth() | ||
.height(80.dp) | ||
.padding(10.dp), | ||
verticalAlignment = Alignment.CenterVertically, | ||
horizontalArrangement = Arrangement.SpaceBetween | ||
) { | ||
ReadOnlyTextField( | ||
text = name, | ||
modifier = Modifier | ||
.padding(horizontal = 2.dp) | ||
.weight(1f) | ||
.align(Alignment.CenterVertically), | ||
) | ||
|
||
trailingTool() | ||
} | ||
} | ||
|
||
/** | ||
* A simple ColorPicker which spans the colors defined in [TraceColors.colors]. | ||
* | ||
* @since 200.6.0 | ||
*/ | ||
@Composable | ||
internal fun ColorPicker(selectedColor: Color, onColorChanged: (Color) -> Unit = {}) { | ||
var currentSelectedColor by rememberSaveable(saver = ColorSaver.Saver()) { mutableStateOf(selectedColor) } | ||
LaunchedEffect(selectedColor) { | ||
currentSelectedColor = selectedColor | ||
} | ||
var displayPicker by rememberSaveable { mutableStateOf(false) } | ||
Box { | ||
TraceColors.SpectralRing( | ||
currentSelectedColor, | ||
modifier = Modifier | ||
.padding(4.dp) | ||
.size(36.dp) | ||
.clip(CircleShape) | ||
.clickable { | ||
displayPicker = true | ||
} | ||
) | ||
|
||
MaterialTheme(shapes = MaterialTheme.shapes.copy(extraSmall = RoundedCornerShape(16.dp))) { | ||
DropdownMenu( | ||
expanded = displayPicker, | ||
offset = DpOffset.Zero, | ||
onDismissRequest = { displayPicker = false }, | ||
) { | ||
DropdownMenuItem( | ||
text = { | ||
Row( | ||
verticalAlignment = Alignment.CenterVertically, | ||
horizontalArrangement = Arrangement.SpaceBetween | ||
) { | ||
TraceColors.colors.forEach { | ||
Box(modifier = Modifier | ||
.size(40.dp) | ||
.padding(8.dp) | ||
.clip(CircleShape) | ||
.background(it) | ||
.clickable { | ||
currentSelectedColor = it | ||
displayPicker = false | ||
onColorChanged(currentSelectedColor) | ||
} | ||
) | ||
} | ||
|
||
} | ||
}, | ||
onClick = { /* No action needed here */ }, | ||
contentPadding = PaddingValues(vertical = 0.dp, horizontal = 10.dp) | ||
) | ||
} | ||
} | ||
} | ||
} | ||
|
||
private object ColorSaver { | ||
fun Saver(): Saver<MutableState<Color>, Any> = listSaver( | ||
save = { | ||
listOf( | ||
it.value.component1(), | ||
it.value.component2(), | ||
it.value.component3(), | ||
it.value.component4() | ||
) | ||
}, | ||
restore = { | ||
mutableStateOf(Color(red = it[0], green = it[1], blue = it[2], alpha = it[3])) | ||
} | ||
) | ||
} | ||
|
||
@Preview(showBackground = true) | ||
@Composable | ||
private fun AdvancedOptionsRowPreview() { | ||
var isEnabled by remember { mutableStateOf(false) } | ||
AdvancedOptionsRow(name = stringResource(id = R.string.zoom_to_result)) { | ||
Switch( | ||
checked = isEnabled, | ||
onCheckedChange = { newState -> | ||
isEnabled = newState | ||
}, | ||
modifier = Modifier | ||
.semantics { contentDescription = "switch" } | ||
.padding(horizontal = 4.dp), | ||
enabled = isEnabled | ||
) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
with the navigation changes this is not being used anymore