-
Notifications
You must be signed in to change notification settings - Fork 1.4k
Restyle geoshape/geotrace #7017
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
Changes from 1 commit
736ef94
36fad66
ecd7772
c825cc2
12b6cd8
b05cc7a
98c9d9b
71dc983
cdc6503
6a76557
dff3c30
2b6491d
be829c4
b6c1276
29b7bb3
8415fc2
7e585a2
d5f30e7
3d90579
b45e310
7d09ee0
0f8d2f2
e576fa6
91b0bea
6ae1adb
d0281d4
2774e36
055f227
f3147e3
3e07038
d508feb
974898f
a63222a
f3c1845
46f0155
16eabc9
2164907
72a978f
f6ded2d
35ae10e
e6d579d
0b63d63
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
- Loading branch information
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,13 +1,19 @@ | ||
| package org.odk.collect.geo.geopoly | ||
|
|
||
| import androidx.lifecycle.ViewModel | ||
| import androidx.lifecycle.viewModelScope | ||
| import kotlinx.coroutines.flow.MutableStateFlow | ||
| import kotlinx.coroutines.flow.StateFlow | ||
| import kotlinx.coroutines.launch | ||
| import org.odk.collect.geo.geopoly.GeoPolyFragment.OutputMode | ||
| import org.odk.collect.location.tracker.LocationTracker | ||
| import org.odk.collect.maps.MapPoint | ||
| import kotlin.collections.plus | ||
|
|
||
| class GeoPolyViewModel(outputMode: OutputMode, points: List<MapPoint>) : | ||
| class GeoPolyViewModel( | ||
| outputMode: OutputMode, | ||
| points: List<MapPoint>, | ||
| private val locationTracker: LocationTracker | ||
| ) : | ||
| ViewModel() { | ||
seadowg marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| private val _points = MutableStateFlow( | ||
|
|
@@ -22,6 +28,29 @@ class GeoPolyViewModel(outputMode: OutputMode, points: List<MapPoint>) : | |
| } | ||
| ) | ||
| val points: StateFlow<List<MapPoint>> = _points | ||
| private var accuracyThreshold: Int = 0 | ||
|
|
||
| init { | ||
| viewModelScope.launch { | ||
|
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We've talked off and on about whether to use coroutines directly like this (as opposed to through our Scheduler interface) - especially with ViewModels as it gives us |
||
| locationTracker.getLocation().collect { | ||
| if (it != null) { | ||
| accuracyThreshold.let { threshold -> | ||
seadowg marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| if (threshold == 0 || it.accuracy <= threshold) { | ||
| add( | ||
| MapPoint( | ||
| it.latitude, | ||
| it.longitude, | ||
| it.altitude, | ||
| it.accuracy.toDouble() | ||
| ) | ||
| ) | ||
| } | ||
| } | ||
|
|
||
| } | ||
| } | ||
| } | ||
| } | ||
|
|
||
| fun add(point: MapPoint) { | ||
| val points = _points.value | ||
|
|
@@ -37,4 +66,17 @@ class GeoPolyViewModel(outputMode: OutputMode, points: List<MapPoint>) : | |
| fun update(points: List<MapPoint>) { | ||
| _points.value = points | ||
| } | ||
|
|
||
| fun startRecording(retainMockAccuracy: Boolean, accuracyThreshold: Int, interval: Long) { | ||
| this.accuracyThreshold = accuracyThreshold | ||
| locationTracker.start(retainMockAccuracy, interval) | ||
| } | ||
|
|
||
| fun stopRecording() { | ||
| locationTracker.stop() | ||
| } | ||
|
|
||
| override fun onCleared() { | ||
| locationTracker.stop() | ||
| } | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -86,7 +86,7 @@ class LocationTrackerService : Service(), LocationClient.LocationClientListener | |
| val interval = intent.getLongExtra(EXTRA_UPDATE_INTERVAL, -1) | ||
| locationClient.setUpdateIntervals( | ||
| interval, | ||
| interval / 2 | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Should we simplify
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I can follow up with that as I'd like to investigate white it was the way it was. |
||
| interval | ||
| ) | ||
| } | ||
|
|
||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We can probably move a bunch more of the Fragment's state in to this (or another) ViewModel, but I think this is a good start for now: we can continue improving this as part of #6970.