Merge pull request #112 from lgoix/timefix

Fix time issue and Toast not showing when notification are disabled
1.2-legacy
Kevin Hester 2020-07-31 09:09:09 -07:00 zatwierdzone przez GitHub
commit 888139d589
Nie znaleziono w bazie danych klucza dla tego podpisu
ID klucza GPG: 4AEE18F83AFDEB23
4 zmienionych plików z 53 dodań i 11 usunięć

Wyświetl plik

@ -858,7 +858,7 @@ class MainActivity : AppCompatActivity(), Logging,
return true
}
R.id.connectStatusImage -> {
Toast.makeText(this, item.title, Toast.LENGTH_SHORT).show()
Toast.makeText(applicationContext, item.title, Toast.LENGTH_SHORT).show()
return true
}
else -> super.onOptionsItemSelected(item)
@ -869,7 +869,7 @@ class MainActivity : AppCompatActivity(), Logging,
try {
val packageInfo: PackageInfo = packageManager.getPackageInfo(packageName, 0)
val versionName = packageInfo.versionName
Toast.makeText(this, versionName, Toast.LENGTH_LONG).show()
Toast.makeText(applicationContext, versionName, Toast.LENGTH_LONG).show()
} catch (e: PackageManager.NameNotFoundException) {
errormsg("Can not find the version: ${e.message}")
}

Wyświetl plik

@ -866,9 +866,10 @@ class MeshService : Service(), Logging {
}
/// Update our DB of users based on someone sending out a Position subpacket
private fun handleReceivedPosition(fromNum: Int, p: MeshProtos.Position) {
private fun handleReceivedPosition(fromNum: Int, p: MeshProtos.Position, defaultTime: Int = Position.currentTime()) {
updateNodeInfo(fromNum) {
it.position = Position(p, it.position?.time ?: 0)
it.position = Position(p)
updateNodeInfoTime(it, defaultTime)
}
}
@ -942,22 +943,22 @@ class MeshService : Service(), Logging {
val p = packet.decoded
// If the rxTime was not set by the device (because device software was old), guess at a time
val rxTime = if (packet.rxTime == 0) packet.rxTime else currentSecond()
val rxTime = if (packet.rxTime != 0) packet.rxTime else currentSecond()
// Update last seen for the node that sent the packet, but also for _our node_ because anytime a packet passes
// through our node on the way to the phone that means that local node is also alive in the mesh
updateNodeInfo(fromNum) {
// Update our last seen based on any valid timestamps. If the device didn't provide a timestamp make one
val lastSeen = rxTime
it.position = it.position?.copy(time = lastSeen)
}
updateNodeInfo(myNodeNum) {
it.position = it.position?.copy(time = currentSecond())
}
if (p.hasPosition())
handleReceivedPosition(fromNum, p.position)
handleReceivedPosition(fromNum, p.position, rxTime)
else
updateNodeInfo(fromNum) {
// Update our last seen based on any valid timestamps. If the device didn't provide a timestamp make one
updateNodeInfoTime(it, rxTime)
}
if (p.hasData())
handleReceivedData(packet)
@ -1620,3 +1621,8 @@ class MeshService : Service(), Logging {
}
}
}
public fun updateNodeInfoTime(it: NodeInfo, rxTime: Int) {
if (it.position?.time == null || it.position?.time!! < rxTime)
it.position = it.position?.copy(time = rxTime)
}

Wyświetl plik

@ -14,5 +14,10 @@ class PositionTest {
Assert.assertEquals(Position.degD(Position.degI(-89.0)), -89.0, 0.01)
}
@Test
fun givenPositionCreatedWithoutTime_thenTimeIsSet() {
val position = Position(37.1, 121.1, 35)
Assert.assertTrue(position.time != 0)
}
}

Wyświetl plik

@ -0,0 +1,31 @@
package com.geeksville.mesh.service
import com.geeksville.mesh.MeshUser
import com.geeksville.mesh.NodeInfo
import com.geeksville.mesh.Position
import org.junit.Assert
import org.junit.Test
class MeshServiceTest {
val nodeInfo = NodeInfo(4, MeshUser("+one", "User One", "U1"), Position(37.1, 121.1, 35, 10))
@Test
fun givenNodeInfo_whenUpdatingWithNewTime_thenPositionTimeIsUpdated() {
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)
}
}