|
@@ -1,9 +1,9 @@
|
|
|
package com.flacksta.chef.journeygpstracker.backend
|
|
|
|
|
|
-import android.os.CountDownTimer
|
|
|
import android.util.Log
|
|
|
import com.flacksta.chef.journeygpstracker.JourneyGpsTrackerApplication
|
|
|
import com.flacksta.chef.journeygpstracker.database.GpsData
|
|
|
+import com.flacksta.chef.journeygpstracker.database.GpsDataDao
|
|
|
import com.google.gson.GsonBuilder
|
|
|
import com.google.gson.JsonParser
|
|
|
import kotlinx.coroutines.*
|
|
@@ -32,13 +32,21 @@ class BackendClient {
|
|
|
val fixedRateTimer = fixedRateTimer(name = "hello-timer",
|
|
|
initialDelay = 10000, period = 30000) {
|
|
|
|
|
|
+ val dao :GpsDataDao = trackApp.database.gpsDataDao()
|
|
|
+
|
|
|
Log.i("Thc","Sending data....")
|
|
|
- val pos : List<GpsData> = trackApp.database.gpsDataDao().getUnsentGpsPositions()
|
|
|
+ val pos : List<GpsData> = dao.getUnsentGpsPositions()
|
|
|
val rawJson:String = convertPosListToRawJson(pos)
|
|
|
Log.i("Thc","Count:" + rawJson)
|
|
|
Log.i("Thc","Thread A:"+Thread.currentThread())
|
|
|
val retVal:Boolean = sendGpsPosDataToBackendServer(rawJson)
|
|
|
Log.i("Thc","retVal post: $retVal")
|
|
|
+ if( retVal == true ) {
|
|
|
+ // Delete the successful ones
|
|
|
+ val first: Long = pos.get(0).ts
|
|
|
+ val last: Long = pos.get(pos.size - 1).ts
|
|
|
+ dao.setAsUploaded(first,last)
|
|
|
+ }
|
|
|
}
|
|
|
}
|
|
|
|