Skip to content

Consolidate location capture tasks and add location lock support#3341

Closed
anandwana001 wants to merge 20 commits intomasterfrom
anandwana001/3148/combine-drop-pin-capture-location
Closed

Consolidate location capture tasks and add location lock support#3341
anandwana001 wants to merge 20 commits intomasterfrom
anandwana001/3148/combine-drop-pin-capture-location

Conversation

@anandwana001
Copy link
Copy Markdown
Collaborator

@anandwana001 anandwana001 commented Oct 30, 2025

Fixes #3148 and #3149

This PR consolidates the CaptureLocationTask functionality into the existing DropPinTask and adds configurable location lock behavior for both point and area drawing tasks. This reduces code duplication and provides more flexible location capture options based on task configuration.

Key Changes

  1. Merged CaptureLocationTask into DropPinTask
    Removed 3 separate CaptureLocationTask files 260 lines of code
    Extended DropPinTaskFragment, DropPinTaskViewModel, and DropPinTaskMapFragment to support both modes:
    Free placement mode: User can pan/zoom map to drop pin anywhere
    GPS-only mode: User can only capture their current device location
    Mode is determined by the new allowMovingPoint property on the Task model
    Appropriate UI buttons shown based on mode DROP_PIN vs CAPTURE_LOCATION
    Different instruction dialogs shown for each mode

  2. Added Location Lock Support for DrawAreaTask
    Added allowManualOverride property to Task model for area drawing tasks
    When allowManualOverride is false, location lock cannot be disengaged and map gestures are disabled
    When allowManualOverride is true default, location lock starts enabled but can be turned off by panning
    Added location permission dialog flow for enforced location lock scenarios

  3. Updated Task Model & Conversion
    Added two new boolean properties to Task:
    allowMovingPoint: Controls whether user can freely place points applies to DROP_PIN tasks
    allowManualOverride: Controls whether location lock can be overridden applies to DRAW_AREA tasks
    Updated TaskConverter to read these properties from Firebase proto schema
    Updated ValueJsonConverter for proper JSON serialization of new properties

  4. Data Submission Updates
    Modified SubmitDataUseCase to handle both DROP_PIN and legacy CAPTURE_LOCATION task types
    Both task types now submit point geometry data appropriately

  5. Removed Unused Resources
    Cleaned up unused string resources across all localization files es, fr, pt, vi
    Removed CaptureLocationTaskViewModel from ViewModelModule

Impact

Code reduction: Net reduction of 150 lines of code 456 insertions, 311 deletions
Improved maintainability: Single implementation for point-based location capture
Enhanced flexibility: Task behavior now configurable via proto schema
Backward compatibility: Legacy CAPTURE_LOCATION tasks still supported in data submission

Testing

Updated CaptureLocationTaskFragmentTest to work with consolidated implementation
Updated FakeData to include new task properties

@shobhitagarwal1612 PTAL?

@auto-assign auto-assign bot requested a review from scolsen October 30, 2025 10:22
@shobhitagarwal1612
Copy link
Copy Markdown
Member

Please use a better issue title and update description to explain the changes being made and how are the changes verified. Thanks!

@anandwana001 anandwana001 changed the title Combine droppin and capturelocation Unify “Add a Point” & “Capture Location” into a Single Task with allowMovingPoint Support Oct 30, 2025
@shobhitagarwal1612
Copy link
Copy Markdown
Member

shobhitagarwal1612 commented Nov 5, 2025

Can you please attach a screen recording of the new changes?

Also, I'm not able to follow the current PR description. Since the attached issue has a large thread, I would suggest adding the following details to the description.

  • Final proposed behavior changes
  • Final proposed UX changes
  • Will this also include merging the two tasks (CAPTURE_LOCATION & DROP_PIN) into a new task? If yes, what will happen to legacy surveys?

@anandwana001 anandwana001 changed the title Unify “Add a Point” & “Capture Location” into a Single Task with allowMovingPoint Support Consolidate location capture tasks and add location lock support Nov 8, 2025
@codecov
Copy link
Copy Markdown

codecov bot commented Nov 8, 2025

Codecov Report

❌ Patch coverage is 38.04348% with 114 lines in your changes missing coverage. Please review.
✅ Project coverage is 67.35%. Comparing base (912767b) to head (c14b845).
⚠️ Report is 4 commits behind head on master.

Files with missing lines Patch % Lines
...tacollection/tasks/polygon/DrawAreaTaskFragment.kt 13.04% 18 Missing and 2 partials ⚠️
...datacollection/tasks/point/DropPinTaskViewModel.kt 52.50% 14 Missing and 5 partials ⚠️
...id/data/local/room/converter/ValueJsonConverter.kt 19.04% 15 Missing and 2 partials ⚠️
.../datacollection/tasks/point/DropPinTaskFragment.kt 50.00% 14 Missing and 3 partials ⚠️
...acollection/tasks/polygon/DrawAreaTaskViewModel.kt 15.00% 16 Missing and 1 partial ⚠️
...ollection/tasks/polygon/DrawAreaTaskMapFragment.kt 0.00% 10 Missing and 1 partial ⚠️
...tacollection/tasks/point/DropPinTaskMapFragment.kt 46.15% 7 Missing ⚠️
...m/android/usecases/submission/SubmitDataUseCase.kt 33.33% 5 Missing and 1 partial ⚠️
Additional details and impacted files
@@             Coverage Diff              @@
##             master    #3341      +/-   ##
============================================
- Coverage     67.94%   67.35%   -0.59%     
- Complexity     1518     1523       +5     
============================================
  Files           308      305       -3     
  Lines          8308     8382      +74     
  Branches        921      947      +26     
============================================
+ Hits           5645     5646       +1     
- Misses         2121     2187      +66     
- Partials        542      549       +7     
Files with missing lines Coverage Δ
...droid/data/remote/firebase/schema/TaskConverter.kt 84.90% <100.00%> (+3.51%) ⬆️
...java/org/groundplatform/android/model/task/Task.kt 100.00% <100.00%> (ø)
...droid/ui/datacollection/DataCollectionViewModel.kt 79.04% <100.00%> (ø)
...m/android/usecases/submission/SubmitDataUseCase.kt 66.66% <33.33%> (-19.05%) ⬇️
...tacollection/tasks/point/DropPinTaskMapFragment.kt 27.58% <46.15%> (+15.82%) ⬆️
...ollection/tasks/polygon/DrawAreaTaskMapFragment.kt 28.20% <0.00%> (-11.09%) ⬇️
...id/data/local/room/converter/ValueJsonConverter.kt 50.74% <19.04%> (-13.41%) ⬇️
.../datacollection/tasks/point/DropPinTaskFragment.kt 67.24% <50.00%> (-29.32%) ⬇️
...acollection/tasks/polygon/DrawAreaTaskViewModel.kt 74.11% <15.00%> (-7.89%) ⬇️
...datacollection/tasks/point/DropPinTaskViewModel.kt 73.23% <52.50%> (-20.70%) ⬇️
... and 1 more
🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

…-location

# Conflicts:
#	gradle/libs.versions.toml
Copy link
Copy Markdown
Member

@shobhitagarwal1612 shobhitagarwal1612 left a comment

Choose a reason for hiding this comment

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

Can you please attach screen recordings?

  • Legacy survey, once with capture location, then with drop a pin
  • New survey, all combinations of alllowMovingPoint and allowManualOverride with drop pin task

@shobhitagarwal1612
Copy link
Copy Markdown
Member

Can you please attach the screen recordings as requested in previous comment?

@shobhitagarwal1612
Copy link
Copy Markdown
Member

@gino-m Can you please take a pass at this PR too?

@gino-m gino-m removed the request for review from scolsen November 24, 2025 15:22
Copy link
Copy Markdown
Collaborator

@gino-m gino-m left a comment

Choose a reason for hiding this comment

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

I made it half way through, but overall looking at the PR description I think it's clear this PR is trying to do too many things. Can it be split int two or three smaller targeted PRs please?

val allowMovingPoint = getAllowMovingPoint(taskType, task)

// Determine if user can manually override location lock for draw area tasks
val allowManualOverride = getAllowManualOverride(taskType, task)
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Iiuc, this splits the condition into two, allowManualOverride for area, allowMovingPoint for point. Since we're calling both cases "manual location override", can we merge these into one condition, allowManualOverride?

* Whether the user can pan/zoom the map to place a point anywhere (true), or can only capture
* their GPS location (false). Only applies to DROP_PIN tasks.
*/
val allowMovingPoint: Boolean = true,
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

And here.

* - For other tasks: Defaults to true (allow moving).
*/
@Suppress("UnusedParameter")
private fun getAllowMovingPoint(taskType: Task.Type, task: TaskProto): Boolean =
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Same here.

} else {
// Mode: GPS location only
addButton(ButtonAction.CAPTURE_LOCATION)
.setOnClickListener { viewModel.captureLocation() }
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

The viewModel entry point and button label can be the same ("Add point" --> addPoint())

}

if (!viewModel.task.allowMovingPoint) {
viewModel.enableLocationLock()
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

We always want to enable location lock to its previous state, even when manual override is allowed.

/** The location lock was not already enabled. */
NEEDS_ENABLE,

/** Trigger to enable the location lock. */
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Is this a state or an event? From the ktdoc comments here and above it seems like it might be mixing both?

import org.groundplatform.android.ui.map.gms.getAltitudeOrNull
import org.groundplatform.android.ui.map.gms.toCoordinates

/** Location lock states relevant for attempting to enable it or not. */
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Can you please clarify what you mean here?

when (taskData) {
is DropPinTaskData -> dropMarker(taskData.location)
is CaptureLocationTaskData -> dropMarker(taskData.location)
else -> {}
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Does this represent an illegal state? If so should we log an error and exit?

@shobhitagarwal1612
Copy link
Copy Markdown
Member

shobhitagarwal1612 commented Nov 27, 2025

Given the complexity and the number of touched files, I agree with the recommendation that we split this into smaller, incremental PRs to de-risk regressions.

This PR currently covers a lot of ground, including:

  • JSON to TaskData conversion.
  • Schema updates for the Task model.
  • Merging logic across CaptureLocationTaskFragment, DropPinTaskFragment, and DrawAreaTaskFragment.
  • Updating TaskType mappings and SubmitDataUseCase logic.

Proposed Strategy: We can introduce a temporary config flag (e.g., unify_capture_location_task) to implement the new logic alongside the old logic without breaking current functionality.

Suggested Rollout Plan:

  • PR 1: Introduce the unify_capture_location_task boolean and the new bit in the Task model. Introduce unify_capture_location_task and a task bit #3374
  • PR 2: Implement the merged logic in the Fragments/VMs, guarded by the boolean flag (keeping the old path active).
  • PR 3: Update SubmitDataUseCase and DataCollection mappings, still respecting the flag.
  • PR 4: Toggle the flag to true for QA/Verification.
  • PR 5: (Post-verification) Remove the flag and delete the legacy code/logic.

This allows us to review the logic changes in isolation without worrying about breaking the existing user flow immediately. WDYT?

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.

Combine "capture location" and "drop pin" tasks

3 participants