diff --git a/app/src/main/java/com/geeksville/mesh/NodeInfo.kt b/app/src/main/java/com/geeksville/mesh/NodeInfo.kt index f4864dd9..2f31ec07 100644 --- a/app/src/main/java/com/geeksville/mesh/NodeInfo.kt +++ b/app/src/main/java/com/geeksville/mesh/NodeInfo.kt @@ -84,11 +84,13 @@ data class NodeInfo( var user: MeshUser? = null, var position: Position? = null, var snr: Float = Float.MAX_VALUE, - var rssi: Int = Int.MAX_VALUE + var rssi: Int = Int.MAX_VALUE, + var lastHeard: Int = 0 // the last time we've seen this node in secs since 1970 ) : Parcelable { - /// Return the last time we've seen this node in secs since 1970 - val lastSeen get() = position?.time ?: 0 + /** + * Return the last time we've seen this node in secs since 1970 + */ val batteryPctLevel get() = position?.batteryPctLevel @@ -104,7 +106,7 @@ data class NodeInfo( // FIXME - use correct timeout from the device settings val timeout = 15 * 60 // Don't set this timeout too tight, or otherwise we will stop sending GPS helper positions to our device - return (now - lastSeen <= timeout) || lastSeen == 0 + return (now - lastHeard <= timeout) || lastHeard == 0 } /// return the position if it is valid, else null diff --git a/app/src/main/java/com/geeksville/mesh/service/MeshService.kt b/app/src/main/java/com/geeksville/mesh/service/MeshService.kt index 83e616cc..21df092c 100644 --- a/app/src/main/java/com/geeksville/mesh/service/MeshService.kt +++ b/app/src/main/java/com/geeksville/mesh/service/MeshService.kt @@ -831,7 +831,6 @@ class MeshService : Service(), Logging { updateNodeInfo(fromNum) { debug("update ${it.user?.longName} with ${p.toOneLineString()}") it.position = Position(p) - updateNodeInfoTime(it, (defaultTime / 1000).toInt()) } } @@ -959,8 +958,8 @@ class MeshService : Service(), Logging { if (!mi.hasGPS) { var broadcastSecs = prefs.positionBroadcastSecs - desiredInterval = if(broadcastSecs == 0) // unset by device, use default - 15 * 60 * 1000 + desiredInterval = if (broadcastSecs == 0) // unset by device, use default + 15 * 60 * 1000 else broadcastSecs * 1000L } @@ -1821,6 +1820,5 @@ class MeshService : Service(), Logging { } fun updateNodeInfoTime(it: NodeInfo, rxTime: Int) { - if (it.position?.time == null || it.position?.time!! < rxTime) - it.position = it.position?.copy(time = rxTime) + it.lastHeard = rxTime } diff --git a/app/src/main/java/com/geeksville/mesh/ui/UsersFragment.kt b/app/src/main/java/com/geeksville/mesh/ui/UsersFragment.kt index 0649aa42..6f0958f4 100644 --- a/app/src/main/java/com/geeksville/mesh/ui/UsersFragment.kt +++ b/app/src/main/java/com/geeksville/mesh/ui/UsersFragment.kt @@ -141,7 +141,7 @@ class UsersFragment : ScreenFragment("Users"), Logging { } renderBattery(n.batteryPctLevel, holder) - holder.lastTime.text = formatAgo(n.lastSeen); + holder.lastTime.text = formatAgo(n.lastHeard); if ((n.num == ourNodeInfo?.num) || (n.snr > 100f)) { holder.signalView.visibility = View.INVISIBLE diff --git a/app/src/main/proto b/app/src/main/proto index 820fa497..f9c4f875 160000 --- a/app/src/main/proto +++ b/app/src/main/proto @@ -1 +1 @@ -Subproject commit 820fa497dfde07e129cad6955bf2f4b2b9cecebc +Subproject commit f9c4f875818c9aa6995e6e25803d52557a1779c7 diff --git a/app/src/test/java/com/geeksville/mesh/service/MeshServiceTest.kt b/app/src/test/java/com/geeksville/mesh/service/MeshServiceTest.kt index aabea759..40bd2c1c 100644 --- a/app/src/test/java/com/geeksville/mesh/service/MeshServiceTest.kt +++ b/app/src/test/java/com/geeksville/mesh/service/MeshServiceTest.kt @@ -17,15 +17,7 @@ class MeshServiceTest { val newerTime = 20 updateNodeInfoTime(nodeInfo, newerTime) - Assert.assertEquals(newerTime, nodeInfo.position?.time) - } - - @Test - fun givenNodeInfo_whenUpdatingWithOldTime_thenPositionTimeIsNotUpdated() { - val olderTime = 5 - val timeBeforeTryingToUpdate = nodeInfo.position?.time - updateNodeInfoTime(nodeInfo, olderTime) - Assert.assertEquals(timeBeforeTryingToUpdate, nodeInfo.position?.time) + Assert.assertEquals(newerTime, nodeInfo.lastHeard) } }