|
@@ -14,6 +14,7 @@ import org.json.JSONArray
|
|
import org.json.JSONObject
|
|
import org.json.JSONObject
|
|
import retrofit2.Retrofit
|
|
import retrofit2.Retrofit
|
|
import java.text.SimpleDateFormat
|
|
import java.text.SimpleDateFormat
|
|
|
|
+import java.util.concurrent.TimeUnit
|
|
import kotlin.concurrent.fixedRateTimer
|
|
import kotlin.concurrent.fixedRateTimer
|
|
|
|
|
|
|
|
|
|
@@ -30,14 +31,14 @@ class BackendClient {
|
|
}
|
|
}
|
|
|
|
|
|
private fun startTimer() {
|
|
private fun startTimer() {
|
|
- fixedRateTimer(name = "hello-timer",
|
|
|
|
|
|
+ val fixedRateTimer = fixedRateTimer(name = "hello-timer",
|
|
initialDelay = 10000, period = 60000) {
|
|
initialDelay = 10000, period = 60000) {
|
|
|
|
|
|
- val dao :GpsDataDao = trackApp.database.gpsDataDao()
|
|
|
|
|
|
+ val dao: GpsDataDao = trackApp.database.gpsDataDao()
|
|
|
|
|
|
- Log.i(mTag,"Sending data....")
|
|
|
|
- val pos : List<GpsData> = dao.getUnsentGpsPositions()
|
|
|
|
- if( pos.isNotEmpty() ) {
|
|
|
|
|
|
+ Log.i(mTag, "Sending data....")
|
|
|
|
+ val pos: List<GpsData> = dao.getUnsentGpsPositions()
|
|
|
|
+ if (pos.isNotEmpty()) {
|
|
val rawJson: String = convertPosListToRawJson(pos)
|
|
val rawJson: String = convertPosListToRawJson(pos)
|
|
val retVal: Boolean = sendGpsPosDataToBackendServer(rawJson)
|
|
val retVal: Boolean = sendGpsPosDataToBackendServer(rawJson)
|
|
if (retVal) {
|
|
if (retVal) {
|
|
@@ -47,6 +48,9 @@ class BackendClient {
|
|
dao.setAsUploaded(first, last)
|
|
dao.setAsUploaded(first, last)
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
+
|
|
|
|
+ // Delete of older data more than 1h old and already uploaded to server
|
|
|
|
+ dao.deleteOldAndUploaded(System.currentTimeMillis().minus(60L * 60L * 1000L))
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|