Skip to content

Validate geopoly on changes when question has incremental param#6989

Merged
grzesiek2010 merged 31 commits intogetodk:masterfrom
seadowg:incremental
Dec 17, 2025
Merged

Validate geopoly on changes when question has incremental param#6989
grzesiek2010 merged 31 commits intogetodk:masterfrom
seadowg:incremental

Conversation

@seadowg
Copy link
Member

@seadowg seadowg commented Dec 12, 2025

Closes #6969

As well as adding the feature I made two other changes:

  • Improved how (transient) snackbars are asserted on in UI tests. I was running into flakes that were getting in my way.
  • Removed PMD exclusions for deleted rules. These were making it hard to read some quality errors I was seeing.

Why is this the best possible solution? Were any other approaches considered?

There's probably not a lot of surprising here after the last sets of changes made for this feature: I basically just hooked up FormEntryViewModel's currentIndex and onAnswerQuestion to GeoPolyFragment through GeoPolyDialogFragment so that the question is answered (and constraints validated) every time a point is added or removed.

How does this change affect users? Describe intentional changes to behavior and behavior that could have accidentally been affected by code changes. In other words, what are the regression risks?

I did convert the geopoly UI from Java to Kotlin, so outside of testing the new feature, it's worth testing the geopoly flow as a whole. Again, nothing with the actual map integration has changed, so I think it's safe to just use one engine.

Before submitting this PR, please make sure you have:

  • added or modified tests for any new or changed behavior
  • run ./gradlew connectedAndroidTest (or ./gradlew testLab) and confirmed all checks still pass
  • added a comment above any new strings describing it for translators
  • added any new strings with date formatting to DateFormatsTest
  • verified that any code or assets from external sources are properly credited in comments and/or in the about file.
  • verified that any new UI elements use theme colors. UI Components Style guidelines

@seadowg seadowg marked this pull request as ready for review December 12, 2025 14:24
@seadowg seadowg requested a review from grzesiek2010 December 12, 2025 14:24
import android.os.Bundle
import androidx.fragment.app.FragmentResultListener
import androidx.lifecycle.Lifecycle
import androidx.lifecycle.MutableLiveData
Copy link
Member

Choose a reason for hiding this comment

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

There is a lot of !! in kotlin version. Can we review the class and improve that?

Copy link
Member Author

Choose a reason for hiding this comment

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

As far as I can see we only use !! for accessing result in FragmentResultRecorder. I'm not sure I have a better solution for asserting on nullable values (as doing something like assertNotNull won't get you smart cast and lateinit isn't really correct), but it is something that comes up in tests as a lot. Maybe we should write a helper to avoid it that asserts and casts for us? Maybe something like:

assertNotNull(result) {
    assertThat(it, equalTo(GeoPolyFragment.REQUEST_GEOPOLY))
}

Copy link
Member

Choose a reason for hiding this comment

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

Sorry this comments was mant to be added in GeoPolyFragment, not in the test class.

Copy link
Member Author

Choose a reason for hiding this comment

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

Ah I see! I can take a look there.

Copy link
Member Author

Choose a reason for hiding this comment

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

I've removed a chunk of them, but there's still quite a few for map. I think these should really be reworked by moving the polyline state to MapViewModel so that hosts don't have to interact with a child Fragment. I can hopefully do that refactor as part of the upcoming restyle of the screen.

val geopoly = result.getString(GeoPolyFragment.RESULT_GEOPOLY)
val incremental = FormEntryPromptUtils.getBindAttribute(prompt, "incremental")

if (incremental == "true" && geopolyChange != null) {
Copy link
Member

Choose a reason for hiding this comment

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

Shouldn't we perform a case-insensitive check for true?
Maybe we should introduce getBooleanBindAttribute function?

Copy link
Member Author

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 need to be that permissive, but I do recall we might do that elsewhere?

Copy link
Member

Choose a reason for hiding this comment

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

We already sanitize appearances here:
https://github.com/getodk/collect/blob/master/collect_app/src/main/java/org/odk/collect/android/utilities/Appearances.kt#L97
In theory, we could rely on pyxform, but for various reasons probably because it’s not guaranteed to be perfect, or because other tools can be used to parse XLS forms, we started doing this ourselves.
That’s why I thought we might want to do the same for bind attributes as well. If you’re not sure about this approach, we can always file a separate issue and discuss it there.

Copy link
Member Author

Choose a reason for hiding this comment

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

Let's go with another issue. The current implementation fits the spec and I think doing anything else is something we need to discuss.

@seadowg seadowg requested a review from grzesiek2010 December 16, 2025 16:15
Copy link
Member

@grzesiek2010 grzesiek2010 left a comment

Choose a reason for hiding this comment

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

@seadowg seadowg requested a review from grzesiek2010 December 17, 2025 09:36
@seadowg seadowg requested a review from grzesiek2010 December 17, 2025 10:44
@grzesiek2010 grzesiek2010 merged commit cba0e5a into getodk:master Dec 17, 2025
7 checks passed
@dbemke
Copy link

dbemke commented Dec 17, 2025

Could you check if the form I created is ok? When I try to upload it to Central there's information that Central doesn't know the incremental parameter.
geoshapeTraceInvalidPolygonIncremental.xlsx.txt
incrementalCentral

@dbemke
Copy link

dbemke commented Dec 17, 2025

When I try to upload it to Central there's information that Central doesn't know the incremental parameter.

Central only allows adding xml with incremental

@seadowg
Copy link
Member Author

seadowg commented Dec 17, 2025

Central only allows adding xml with incremental

Sorry should have specified this in the PR description. Yes you'll need to add incremental to the bind for the question in the XML rather than in the XLSForm for the moment.

@seadowg seadowg deleted the incremental branch December 17, 2025 13:20
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add support for incremental=true to geoshape and geotrace

3 participants