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

Update project geometry sample #292

Open
wants to merge 14 commits into
base: v.next
Choose a base branch
from
Open

Conversation

darryl-lynch
Copy link
Collaborator

Description

Migrate the project geometry sample from XML to Compose

Links and Data

Issue: https://devtopia.esri.com/runtime/kotlin/issues/4978
vTest: https://runtime-kotlin.esri.com/view/all/job/vtest/job/sampleviewer/63/

How to Test

Run the sample on the sample viewer or the repo.

@alan-edi alan-edi self-requested a review December 17, 2024 15:13
Copy link
Collaborator

@alan-edi alan-edi left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@darryl-lynch Looks good! One very minor comment below. Also, the epic that this issue belongs to mentions a couple of extra things that are supposed to be done to each of the samples we're migrating:

  • Add the line to the "Additional information section": This sample uses the GeoCompose Toolkit module to be able to implement a Composable MapView.
  • Add the tags: geoviewcompose, toolkit to readme and metadata.json file

width = 30f
height = 30f
// offset in +y axis so the marker spawned
// is right on the touch point
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could put this comment all on one line

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've done these, but as per this discussion it seems like there may be some question over the suitability of the of geoviewcompose tag

@@ -5,8 +5,7 @@

<application><activity
android:exported="true"
android:name=".MainActivity"
android:label="@string/project_geometry_app_name">
Copy link
Collaborator

@alan-edi alan-edi Dec 18, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just come upon this statement in the Kotlin Samples Contribution Guide:

The sample viewer will only correctly name each individual sample if android:label="@string/app_name" is contained within the activity. So please make sure that in addition to any other lines, your activity contains the label. For example:

        <activity
            android:name=".MainActivity"
            android:label="@string/app_name">

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's interesting. The sample seems to be named correctly in the sample viewer without it, and I checked a few other compose based samples and they seem to lack it as well. I wonder if perhaps that document is outdated or if there is some other mechanism at play that I've missed?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good questions. I've posted a comment about it here: https://devtopia.esri.com/runtime/kotlin/issues/5111

@darryl-lynch darryl-lynch force-pushed the project-geometry-sample branch from 4bbe9c6 to 33eeeba Compare December 18, 2024 14:46
Copy link
Collaborator

@alan-edi alan-edi left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@darryl-lynch Looks good 👍 . Just one little typo to fix, but then ready for second review.

Copy link
Collaborator

@01smito01 01smito01 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sample is perfectly functional, but I have a few suggestions around UX and separation of concerns.

I've made my changes available at oliver/project-geometry if you want to copy bits over or just get a sense for how that might work.

samples/project-geometry/README.md Show resolved Hide resolved
Comment on lines +86 to +87
"Failed to load map",
error.message.toString()
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Comment from Shubham on one of my PRs at the moment - use named parameters for function calls with more than 1 argument. It helps people looking at samples via Github/the website understand what each parameter is.

Suggested change
"Failed to load map",
error.message.toString()
title = "Failed to load map",
description = error.message.toString()

Android Studio has a handy context action to do it.
image

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There might be a few other places where you could do this, have a look.

Comment on lines +69 to +73
Text(
text =
stringResource(R.string.title_text) + "\n" +
infoText
)
Copy link
Collaborator

@01smito01 01smito01 Dec 20, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The "coordinates" text probably shouldn't be there until we have coordinates to display.

When the user taps on the map, this text goes from two lines to three, causing the MapView to change size which is a bit jarring. Use the minLines parameter on Text composables to avoid that.

Comment on lines +102 to +105
_infoText.value = app.resources.getString(
R.string.projection_info_text,
point.toDisplayFormat(),
projectedPoint?.toDisplayFormat()
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This sort of string interpolation is essentially a UI task, so we should do it in the MainScreen.

Comment on lines +111 to +116
/**
* Extension function for the Point type that returns
* a float-precision formatted string suitable for display
*/
private fun Point.toDisplayFormat() =
"${String.format(Locale.getDefault(),"%.5f", x)}, ${String.format(Locale.getDefault(),"%.5f", y)}"
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Move this extension function to the main screen.

Comment on lines +79 to +80
private val _infoText = MutableStateFlow(app.resources.getString(R.string.tap_to_begin))
val infoText: StateFlow<String> = _infoText
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think we should be formatting the text in the viewmodel if we can do it in the main screen - and we can. We should move text formatting concerns to the screen, and instead expose the point and its projection from the view model.

Suggested change
private val _infoText = MutableStateFlow(app.resources.getString(R.string.tap_to_begin))
val infoText: StateFlow<String> = _infoText
// state flow of a point and its projection for presentation in UI
private val _pointProjectionFlow = MutableStateFlow<PointProjection?>(null)
val pointFlow = _pointProjectionFlow.asStateFlow()

This uses a very simple data class:

data class PointProjection (val original: Point, val projection: Point)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants