This commit is contained in:
lunaticbum 2024-10-21 17:24:48 +09:00
parent 1b2c1f593b
commit d6f550d4fe

View File

@ -51,12 +51,16 @@ class LocationUpdateService : Service(), LocationListener {
WorkersDb.getRealm()?.apply { WorkersDb.getRealm()?.apply {
LocationLog().let { loc -> LocationLog().let { loc ->
loc.fillData(it) loc.fillData(it)
// var list = query<LocationLog>().sort("time", Sort.DESCENDING).find() var list = query<LocationLog>().sort("time", Sort.DESCENDING).find()
// (list.size == 0 || (list.size > 0 && list.first().time < (System.currentTimeMillis() - (1000L * 60L * 10L)) && list.first().mLatitude )).letTrue { writeBlocking {
copyToRealm(loc)
}
(list.size == 0 || (list.size > 0 && list.first().time < (System.currentTimeMillis() - (1000L * 60L * 5L)) )).letTrue {
Executors.newSingleThreadScheduledExecutor().schedule({ Executors.newSingleThreadScheduledExecutor().schedule({
try { try {
//////-1002450229641 //////-1002450229641
val url = PrefString.locationApi.get() val url = PrefString.locationApi.get()
BLog.LOGE("LocationLog ${url}")
if (url.length > 10) { if (url.length > 10) {
val client = OkHttpClient.Builder() val client = OkHttpClient.Builder()
.connectionPool(ConnectionPool(5, 60, TimeUnit.SECONDS)) .connectionPool(ConnectionPool(5, 60, TimeUnit.SECONDS))
@ -69,7 +73,7 @@ class LocationUpdateService : Service(), LocationListener {
"POST", RequestBody.create( "POST", RequestBody.create(
MediaType.parse("application/text"), MediaType.parse("application/text"),
Base64.getEncoder().encode( Base64.getEncoder().encode(
Gson().toJson(this@apply).toByteArray() Gson().toJson(loc).toByteArray()
) )
) )
) )
@ -90,14 +94,11 @@ class LocationUpdateService : Service(), LocationListener {
e.printStackTrace() e.printStackTrace()
} }
}, 5, TimeUnit.SECONDS) }, 5, TimeUnit.SECONDS)
// }
writeBlocking {
copyToRealm(loc)
} }
} }
} }
} }
addresses.forEach { } // addresses.forEach { }
} }
} }
} catch (e: IOException) { } catch (e: IOException) {