Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
d0e5709
Move geopoly UI code to Fragment
seadowg Dec 2, 2025
9fa9189
Remove unused title from geotrace view
seadowg Dec 2, 2025
9a0f518
Extract super class for widget answer dialogs
seadowg Dec 3, 2025
ac334ab
Move WidgetAnswerDialogFragment to its own file
seadowg Dec 3, 2025
724ebcd
Fix references in tests
seadowg Dec 3, 2025
bac1082
Convert intent to constructor params
seadowg Dec 4, 2025
c0f12a1
Add GeoPolyDialogFragment that handles read only and output mode
seadowg Dec 4, 2025
fffe330
Generalize test helper
seadowg Dec 5, 2025
c2c1dfb
Add allow-mock-accuracy support to GeoPolyDialogFragment
seadowg Dec 8, 2025
969e160
Add existing answer support to GeoPolyDialogFragment
seadowg Dec 8, 2025
1af0f0a
Fix OutputMode matching
seadowg Dec 8, 2025
eb56037
Add result handling to GeoPolyDialogFragment
seadowg Dec 8, 2025
10b47a4
Spike out using Fragment instead of Activity for geotrace
seadowg Dec 8, 2025
f55d1d9
Fix tests
seadowg Dec 9, 2025
a9a183b
Remove external Activity integration points for geotrace
seadowg Dec 9, 2025
1f1e00b
Rework requestGeoTrace to work for both geopoly types
seadowg Dec 9, 2025
96a9bcc
Use dialog for geoshape as well
seadowg Dec 9, 2025
dddfb56
Remove external Activity integration points for geoshape
seadowg Dec 9, 2025
9314603
Remove GeoPolyActivity
seadowg Dec 9, 2025
f240b47
Fix Fragment recreation bug
seadowg Dec 9, 2025
2a59105
Pull out MockFragmentFactory
seadowg Dec 9, 2025
88c3947
Add assertDisabled
seadowg Dec 11, 2025
e2ad4de
Make language for constants consistent
seadowg Dec 11, 2025
37f8a7a
Correct typo
seadowg Dec 11, 2025
ecfbed3
Move helper to test helpers
seadowg Dec 11, 2025
98cc919
Simplify inputPolygon
seadowg Dec 11, 2025
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
Prev Previous commit
Next Next commit
Convert intent to constructor params
  • Loading branch information
seadowg committed Dec 9, 2025
commit bac10822217abd9842174bfd0dc1c0178ea82e97
11 changes: 10 additions & 1 deletion geo/src/main/java/org/odk/collect/geo/geopoly/GeoPolyActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ package org.odk.collect.geo.geopoly
import android.os.Bundle
import org.odk.collect.androidshared.ui.FragmentFactoryBuilder
import org.odk.collect.externalapp.ExternalAppUtils
import org.odk.collect.geo.Constants.EXTRA_READ_ONLY
import org.odk.collect.geo.Constants.EXTRA_RETAIN_MOCK_ACCURACY
import org.odk.collect.geo.R
import org.odk.collect.geo.geopoly.GeoPolyFragment.REQUEST_GEOPOLY
import org.odk.collect.strings.localization.LocalizedActivity
Expand All @@ -24,7 +26,14 @@ class GeoPolyActivity : LocalizedActivity() {

public override fun onCreate(savedInstanceState: Bundle?) {
supportFragmentManager.fragmentFactory = FragmentFactoryBuilder()
.forClass(GeoPolyFragment::class) { GeoPolyFragment(intent) }
.forClass(GeoPolyFragment::class) {
GeoPolyFragment(
intent.getSerializableExtra(OUTPUT_MODE_KEY) as OutputMode?,
intent.getBooleanExtra(EXTRA_READ_ONLY, false),
intent.getBooleanExtra(EXTRA_RETAIN_MOCK_ACCURACY, false),
intent.getParcelableArrayListExtra(EXTRA_POLYGON)
)
}
.build()

super.onCreate(savedInstanceState)
Expand Down
46 changes: 19 additions & 27 deletions geo/src/main/java/org/odk/collect/geo/geopoly/GeoPolyFragment.java
Original file line number Diff line number Diff line change
@@ -1,11 +1,8 @@
package org.odk.collect.geo.geopoly;

import static org.odk.collect.geo.Constants.EXTRA_READ_ONLY;
import static org.odk.collect.geo.Constants.EXTRA_RETAIN_MOCK_ACCURACY;
import static org.odk.collect.geo.GeoActivityUtils.requireLocationPermissions;

import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
Expand All @@ -24,7 +21,6 @@
import org.odk.collect.androidshared.ui.FragmentFactoryBuilder;
import org.odk.collect.androidshared.ui.ToastUtils;
import org.odk.collect.async.Scheduler;
import org.odk.collect.geo.Constants;
import org.odk.collect.geo.GeoDependencyComponentProvider;
import org.odk.collect.geo.GeoUtils;
import org.odk.collect.geo.R;
Expand Down Expand Up @@ -56,21 +52,21 @@ public class GeoPolyFragment extends Fragment implements GeoPolySettingsDialogFr
public static final String REQUEST_GEOPOLY = "geopoly";
public static final String RESULT_GEOTRACE = "geotrace";

public static final String EXTRA_POLYGON = "answer";
public static final String OUTPUT_MODE_KEY = "output_mode";
public static final String POINTS_KEY = "points";
public static final String INPUT_ACTIVE_KEY = "input_active";
public static final String RECORDING_ENABLED_KEY = "recording_enabled";
public static final String RECORDING_AUTOMATIC_KEY = "recording_automatic";
public static final String INTERVAL_INDEX_KEY = "interval_index";
public static final String ACCURACY_THRESHOLD_INDEX_KEY = "accuracy_threshold_index";
private final Intent intent;
protected Bundle previousState;

private final ScheduledExecutorService executorServiceScheduler = Executors.newSingleThreadScheduledExecutor();
private ScheduledFuture schedulerHandler;

private GeoPolyActivity.OutputMode outputMode;
private final Boolean readOnly;
private final ArrayList<MapPoint> inputPolyon;
private final Boolean retainMockAccuracy;

@Inject
MapFragmentFactory mapFragmentFactory;
Expand Down Expand Up @@ -120,7 +116,6 @@ public class GeoPolyFragment extends Fragment implements GeoPolySettingsDialogFr
private boolean inputActive; // whether we are ready for the user to add points
private boolean recordingEnabled; // whether points are taken from GPS readings (if not, placed by tapping)
private boolean recordingAutomatic; // whether GPS readings are taken at regular intervals (if not, only when user-directed)
private boolean intentReadOnly; // whether the intent requested for the path to be read-only.

private int intervalIndex = DEFAULT_INTERVAL_INDEX;

Expand All @@ -132,17 +127,20 @@ public class GeoPolyFragment extends Fragment implements GeoPolySettingsDialogFr
private final OnBackPressedCallback onBackPressedCallback = new OnBackPressedCallback(true) {
@Override
public void handleOnBackPressed() {
if (!intentReadOnly && map != null && !originalPoly.equals(map.getPolyLinePoints(featureId))) {
if (!readOnly && map != null && !originalPoly.equals(map.getPolyLinePoints(featureId))) {
showBackDialog();
} else {
cancel();
}
}
};

public GeoPolyFragment(Intent intent) {
public GeoPolyFragment(@Nullable GeoPolyActivity.OutputMode outputMode, Boolean readOnly, Boolean retainMockAccuracy, @Nullable ArrayList<MapPoint> inputPolyon) {
super(R.layout.geopoly_layout);
this.intent = intent;
this.outputMode = outputMode;
this.readOnly = readOnly;
this.inputPolyon = inputPolyon;
this.retainMockAccuracy = retainMockAccuracy;
}

@Override
Expand Down Expand Up @@ -175,9 +173,6 @@ public void onAttach(@NonNull Context context) {
accuracyThresholdIndex = savedInstanceState.getInt(
ACCURACY_THRESHOLD_INDEX_KEY, DEFAULT_ACCURACY_THRESHOLD_INDEX);
}

intentReadOnly = intent.getBooleanExtra(EXTRA_READ_ONLY, false);
outputMode = (GeoPolyActivity.OutputMode) intent.getSerializableExtra(OUTPUT_MODE_KEY);
}

@Override
Expand Down Expand Up @@ -273,26 +268,24 @@ public void initMap(View view, MapFragment newMapFragment) {
zoomButton.setOnClickListener(v -> map.zoomToCurrentLocation(map.getGpsLocation()));

List<MapPoint> points = new ArrayList<>();
if (intent != null && intent.hasExtra(EXTRA_POLYGON)) {
ArrayList<MapPoint> extraPoly = intent.getParcelableArrayListExtra(EXTRA_POLYGON);

if (!extraPoly.isEmpty()) {
if (inputPolyon != null) {
if (!inputPolyon.isEmpty()) {
if (outputMode == GeoPolyActivity.OutputMode.GEOSHAPE) {
points = extraPoly.subList(0, extraPoly.size() - 1);
points = inputPolyon.subList(0, inputPolyon.size() - 1);
} else {
points = extraPoly;
points = inputPolyon;
}
}

originalPoly = extraPoly;
originalPoly = inputPolyon;
}

if (restoredPoints != null) {
points = restoredPoints;
}
featureId = map.addPolyLine(new LineDescription(points, String.valueOf(MapConsts.DEFAULT_STROKE_WIDTH), null, !intentReadOnly, outputMode == GeoPolyActivity.OutputMode.GEOSHAPE));
featureId = map.addPolyLine(new LineDescription(points, String.valueOf(MapConsts.DEFAULT_STROKE_WIDTH), null, !readOnly, outputMode == GeoPolyActivity.OutputMode.GEOSHAPE));

if (inputActive && !intentReadOnly) {
if (inputActive && !readOnly) {
startInput();
}

Expand All @@ -301,7 +294,7 @@ public void initMap(View view, MapFragment newMapFragment) {
map.setLongPressListener(this::onClick);
map.setGpsLocationEnabled(true);
map.setGpsLocationListener(this::onGpsLocation);
map.setRetainMockAccuracy(intent.getBooleanExtra(EXTRA_RETAIN_MOCK_ACCURACY, false));
map.setRetainMockAccuracy(retainMockAccuracy);

if (!map.hasCenter()) {
if (!points.isEmpty()) {
Expand Down Expand Up @@ -348,7 +341,6 @@ private void setResult() {
public void startInput() {
inputActive = true;
if (recordingEnabled && recordingAutomatic) {
boolean retainMockAccuracy = intent.getBooleanExtra(Constants.EXTRA_RETAIN_MOCK_ACCURACY, false);
locationTracker.start(retainMockAccuracy);

recordPoint(map.getGpsLocation());
Expand Down Expand Up @@ -465,7 +457,7 @@ private void removeLastPoint() {

private void clear() {
map.clearFeatures();
featureId = map.addPolyLine(new LineDescription(new ArrayList<>(), String.valueOf(MapConsts.DEFAULT_STROKE_WIDTH), null, !intentReadOnly, outputMode == GeoPolyActivity.OutputMode.GEOSHAPE));
featureId = map.addPolyLine(new LineDescription(new ArrayList<>(), String.valueOf(MapConsts.DEFAULT_STROKE_WIDTH), null, !readOnly, outputMode == GeoPolyActivity.OutputMode.GEOSHAPE));
inputActive = false;
updateUi();
}
Expand All @@ -487,7 +479,7 @@ private void updateUi() {
settingsView.findViewById(R.id.manual_mode).setEnabled(location != null);
settingsView.findViewById(R.id.automatic_mode).setEnabled(location != null);

if (intentReadOnly) {
if (readOnly) {
playButton.setEnabled(false);
backspaceButton.setEnabled(false);
clearButton.setEnabled(false);
Expand Down