Skip to content

Commit

Permalink
Merge pull request #1007 from PhenoApps/v5_587_geo_coordinate_warning
Browse files Browse the repository at this point in the history
v5 geo coordinate warning update
  • Loading branch information
trife authored Aug 3, 2024
2 parents 699cec4 + 0305ae3 commit 454f1cf
Showing 1 changed file with 51 additions and 3 deletions.
54 changes: 51 additions & 3 deletions app/src/main/java/com/fieldbook/tracker/traits/GNSSTraitLayout.kt
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import android.bluetooth.BluetoothDevice
import android.content.Context
import android.content.Intent
import android.content.IntentFilter
import android.database.sqlite.SQLiteException
import android.location.Location
import android.os.Handler
import android.os.Looper
Expand Down Expand Up @@ -76,6 +77,9 @@ class GNSSTraitLayout : BaseTraitLayout, GPSTracker.GPSTrackerListener {
//flag to track when collect button is disabled
private var isCollectEnabled = false

//flag to track if this is the first time user is collecting a location before leaving the entry
private var isFirstCollect = true

private lateinit var chipGroup: ChipGroup
private lateinit var averageSwitch: SwitchCompat
private lateinit var utcTextView: TextView
Expand Down Expand Up @@ -223,6 +227,39 @@ class GNSSTraitLayout : BaseTraitLayout, GPSTracker.GPSTrackerListener {

setupChooseBluetoothDevice()

checkIfFirstConnect()
}

//updates the average warning flag everytime the layout is loaded
//if a geo coordinate already exists, we warn the user before they try to update it
private fun checkIfFirstConnect() {

try {

val studyDbId = (context as CollectActivity).studyId

val units = database.getAllObservationUnits(studyDbId.toInt())
.filter { it.observation_unit_db_id == currentRange.plot_id }

if (units.isNotEmpty()) {

val unit = units.first()

//the saved geo coordinate location
val location = GeodeticUtils.parseGeoCoordinate(unit.geo_coordinates)

isFirstCollect = location == null
}

} catch (e: SQLiteException) {

isFirstCollect = true

} catch (e: NoSuchElementException) {

isFirstCollect = true

}
}

/**
Expand Down Expand Up @@ -359,7 +396,7 @@ class GNSSTraitLayout : BaseTraitLayout, GPSTracker.GPSTrackerListener {
val info = AverageInfo(unit, location, pointsToAverage, latLength, lngLength, precision)
if (avgDuration > -1L) {

if (location != null) {
if (!isFirstCollect) {

//averaging is updating the location, so ask the user
alertLocationUpdate {
Expand All @@ -378,8 +415,19 @@ class GNSSTraitLayout : BaseTraitLayout, GPSTracker.GPSTrackerListener {

if (location != null) {

//averaging is updating the location, so ask the user
alertLocationUpdate {
if (!isFirstCollect) {

//averaging is updating the location, so ask the user
alertLocationUpdate {
val original = (location.latitude) to (location.longitude)
val current = newLat to newLng
pointsToAverage.add(original)
pointsToAverage.add(current)
averagePoints(info)
}

} else {

val original = (location.latitude) to (location.longitude)
val current = newLat to newLng
pointsToAverage.add(original)
Expand Down

0 comments on commit 454f1cf

Please sign in to comment.