Skip to content
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
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
41 commits
Select commit Hold shift + click to select a range
dff4256
WIP
puneet-pdx Oct 11, 2024
aaff9d6
WIP
puneet-pdx Oct 11, 2024
9e576c5
Merge branch 'feature-branches/utilitynetworktrace' into puneet/4521_…
puneet-pdx Oct 14, 2024
632e96e
Merge branch 'feature-branches/utilitynetworktrace' into puneet/4521_…
puneet-pdx Oct 15, 2024
358f5fa
WIP
puneet-pdx Oct 15, 2024
5c26280
Merge branch 'feature-branches/utilitynetworktrace' into puneet/4521_…
puneet-pdx Oct 15, 2024
07385d9
WIP
puneet-pdx Oct 15, 2024
f4584e9
more changes
puneet-pdx Oct 15, 2024
7d44f92
remove string
puneet-pdx Oct 15, 2024
7850acd
don't throw exceptions
puneet-pdx Oct 15, 2024
729cddd
add copyright
puneet-pdx Oct 15, 2024
6af33b2
update formatting
puneet-pdx Oct 16, 2024
df4318c
WIP
puneet-pdx Oct 16, 2024
2864df1
WIP
puneet-pdx Oct 16, 2024
c1cc09b
WIP
puneet-pdx Oct 16, 2024
7c9eb1a
WIP
puneet-pdx Oct 17, 2024
2c184bb
fix to show multiple results
puneet-pdx Oct 17, 2024
d541349
address code review comments
puneet-pdx Oct 17, 2024
c7ec782
address comments
puneet-pdx Oct 17, 2024
1bfe941
Merge branch 'feature-branches/utilitynetworktrace' into puneet/4521_…
puneet-pdx Oct 17, 2024
ef3aa56
add backhandler
puneet-pdx Oct 17, 2024
2d68538
Merge branch 'puneet/4521_FeatureResults' into puneet/4526_advancedOp…
puneet-pdx Oct 18, 2024
b0c8a20
add string resource
puneet-pdx Oct 18, 2024
4d6acfa
Merge branch 'puneet/4521_FeatureResults' into puneet/4526_advancedOp…
puneet-pdx Oct 18, 2024
fc8ba83
WIP
puneet-pdx Oct 18, 2024
b1f95ae
update deletion logic
puneet-pdx Oct 18, 2024
f46a466
update logic
puneet-pdx Oct 18, 2024
26d42db
changes for color picker
puneet-pdx Oct 21, 2024
af5cf86
refactor colorpicker
puneet-pdx Oct 21, 2024
bb1edaa
add newline
puneet-pdx Oct 21, 2024
4ba402e
Save selected color in options screen
puneet-pdx Oct 21, 2024
c38e23f
remove padding changes
puneet-pdx Oct 21, 2024
5535b98
revert changes to navigation
puneet-pdx Oct 21, 2024
94b3439
add copyright
puneet-pdx Oct 21, 2024
0b0c71a
update indentation
puneet-pdx Oct 21, 2024
2482c05
Merge branch 'puneet/4521_FeatureResults' into puneet/4526_advancedOp…
puneet-pdx Oct 21, 2024
c60126e
Merge branch 'feature-branches/utilitynetworktrace' into puneet/4526_…
puneet-pdx Oct 21, 2024
7fa50be
clear all the starting points
puneet-pdx Oct 21, 2024
767b7a8
address code review comments
puneet-pdx Oct 22, 2024
376f6d8
address code review comments
puneet-pdx Oct 23, 2024
630768d
address code review feedback
puneet-pdx Oct 23, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -135,9 +135,6 @@ public class TraceState(

private val currentTraceGeometryResultsGraphics: MutableList<Graphic> = mutableListOf()

private val _currentScreen: MutableState<TraceNavRoute> = mutableStateOf(TraceNavRoute.TraceOptions)
Copy link
Collaborator Author

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

internal var currentScreen: State<TraceNavRoute> = _currentScreen

private val _completedTraces: SnapshotStateList<TraceRun> = mutableStateListOf()
internal val completedTraces: List<TraceRun> = _completedTraces

Expand All @@ -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) {
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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.
*
Expand All @@ -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]
Copy link
Collaborator

Choose a reason for hiding this comment

The 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.
*
Expand Down Expand Up @@ -680,7 +734,8 @@ internal enum class TraceNavRoute {
TraceResults,
FeatureResultsDetails,
StartingPointDetails,
TraceError
TraceError,
ClearResults
}

@Immutable
Expand All @@ -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?
Expand Down
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
)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,12 @@ import androidx.compose.ui.unit.dp
import com.arcgismaps.toolkit.utilitynetworks.R

@Composable
internal fun Title(name: String, onZoomTo: () -> Unit, onDelete: () -> Unit) {
internal fun Title(
name: String,
onZoomTo: () -> Unit,
onDelete: () -> Unit,
showZoomToOption: Boolean = true,
) {
var expanded by rememberSaveable { mutableStateOf(false) }
Row(
modifier = Modifier
Expand Down Expand Up @@ -83,20 +88,22 @@ internal fun Title(name: String, onZoomTo: () -> Unit, onDelete: () -> Unit) {
onDismissRequest = {
expanded = false
}) {
DropdownMenuItem(
text = { Text(stringResource(R.string.zoom_to)) },
onClick = {
expanded = false
onZoomTo()
},
leadingIcon = {
Icon(
Icons.Outlined.LocationOn, contentDescription = stringResource(
R.string.zoom_to
if (showZoomToOption) {
DropdownMenuItem(
text = { Text(stringResource(R.string.zoom_to)) },
onClick = {
expanded = false
onZoomTo()
},
leadingIcon = {
Icon(
Icons.Outlined.LocationOn, contentDescription = stringResource(
R.string.zoom_to
)
)
)
}
)
}
)
}
DropdownMenuItem(
text = { Text(stringResource(R.string.delete)) },
onClick = {
Expand Down
Loading