From d6f550d4fe96b9dce52f021c60c2463b32f98029 Mon Sep 17 00:00:00 2001 From: lunaticbum <> Date: Mon, 21 Oct 2024 17:24:48 +0900 Subject: [PATCH] ... --- .../launcher/workers/LocationUpdateService.kt | 83 ++++++++++--------- 1 file changed, 42 insertions(+), 41 deletions(-) diff --git a/app/src/main/kotlin/bums/lunatic/launcher/workers/LocationUpdateService.kt b/app/src/main/kotlin/bums/lunatic/launcher/workers/LocationUpdateService.kt index b1cf7944..12555dd4 100644 --- a/app/src/main/kotlin/bums/lunatic/launcher/workers/LocationUpdateService.kt +++ b/app/src/main/kotlin/bums/lunatic/launcher/workers/LocationUpdateService.kt @@ -51,53 +51,54 @@ class LocationUpdateService : Service(), LocationListener { WorkersDb.getRealm()?.apply { LocationLog().let { loc -> loc.fillData(it) -// var list = query().sort("time", Sort.DESCENDING).find() -// (list.size == 0 || (list.size > 0 && list.first().time < (System.currentTimeMillis() - (1000L * 60L * 10L)) && list.first().mLatitude )).letTrue { - Executors.newSingleThreadScheduledExecutor().schedule({ - try { - //////-1002450229641 - val url = PrefString.locationApi.get() - if (url.length > 10) { - val client = OkHttpClient.Builder() - .connectionPool(ConnectionPool(5, 60, TimeUnit.SECONDS)) - .build() - - // GET 요청 객체 생성 - val builder: Request.Builder = Request.Builder().url(url) - .addHeader("Content-Type", "application/json").get() - builder.method( - "POST", RequestBody.create( - MediaType.parse("application/text"), - Base64.getEncoder().encode( - Gson().toJson(this@apply).toByteArray() - ) - ) - ) - val request: Request = builder.build() - - BLog.LOGE("telegram before request ") - // OkHttp 클라이언트로 GET 요청 객체 전송 - val response: Response = client.newCall(request).execute() - if (response.isSuccessful()) { - // 응답 받아서 처리 - val body: ResponseBody? = response.body() - if (body != null) { - - } - } else BLog.LOGE("telegram Error Occurred") - } - } catch (e: java.lang.Exception) { - e.printStackTrace() - } - }, 5, TimeUnit.SECONDS) -// } + var list = query().sort("time", Sort.DESCENDING).find() writeBlocking { copyToRealm(loc) } + (list.size == 0 || (list.size > 0 && list.first().time < (System.currentTimeMillis() - (1000L * 60L * 5L)) )).letTrue { + Executors.newSingleThreadScheduledExecutor().schedule({ + try { + //////-1002450229641 + val url = PrefString.locationApi.get() + BLog.LOGE("LocationLog ${url}") + if (url.length > 10) { + val client = OkHttpClient.Builder() + .connectionPool(ConnectionPool(5, 60, TimeUnit.SECONDS)) + .build() + + // GET 요청 객체 생성 + val builder: Request.Builder = Request.Builder().url(url) + .addHeader("Content-Type", "application/json").get() + builder.method( + "POST", RequestBody.create( + MediaType.parse("application/text"), + Base64.getEncoder().encode( + Gson().toJson(loc).toByteArray() + ) + ) + ) + val request: Request = builder.build() + + BLog.LOGE("telegram before request ") + // OkHttp 클라이언트로 GET 요청 객체 전송 + val response: Response = client.newCall(request).execute() + if (response.isSuccessful()) { + // 응답 받아서 처리 + val body: ResponseBody? = response.body() + if (body != null) { + + } + } else BLog.LOGE("telegram Error Occurred") + } + } catch (e: java.lang.Exception) { + e.printStackTrace() + } + }, 5, TimeUnit.SECONDS) + } } } } - addresses.forEach { } +// addresses.forEach { } } } } catch (e: IOException) {