This commit is contained in:
lunaticbum 2025-09-08 18:06:53 +09:00
parent b5bbf299bd
commit 37a6497c84
2 changed files with 17 additions and 10 deletions

View File

@ -6,6 +6,7 @@ import android.location.Location
import androidx.work.WorkerParameters import androidx.work.WorkerParameters
import bums.lunatic.launcher.common.letTrue import bums.lunatic.launcher.common.letTrue
import bums.lunatic.launcher.helpers.PrefBoolean import bums.lunatic.launcher.helpers.PrefBoolean
import bums.lunatic.launcher.utils.Blog
import bums.lunatic.launcher.workers.LocationUpdateService.Companion.pushLocation import bums.lunatic.launcher.workers.LocationUpdateService.Companion.pushLocation
import com.google.android.gms.location.LocationServices import com.google.android.gms.location.LocationServices
import com.google.android.gms.location.Priority import com.google.android.gms.location.Priority
@ -27,8 +28,8 @@ class LocationGetter(context: Context, workerParams: WorkerParameters) : BaseGet
.getCurrentLocation(Priority.PRIORITY_HIGH_ACCURACY, CancellationTokenSource().token) .getCurrentLocation(Priority.PRIORITY_HIGH_ACCURACY, CancellationTokenSource().token)
.addOnSuccessListener{ success: Location? -> .addOnSuccessListener{ success: Location? ->
success?.let { success?.let {
// Blog.LOGE("Location >>> $it") Blog.LOGE("Location >>> $it")
// Blog.LOGE("Location >>> (latitude)${it.longitude}/(longitude)${it.latitude}") Blog.LOGE("Location >>> (latitude)${it.longitude}/(longitude)${it.latitude}")
longitude = it.longitude longitude = it.longitude
latitude = it.latitude latitude = it.latitude
// runWeatherGetter() // runWeatherGetter()
@ -37,7 +38,7 @@ class LocationGetter(context: Context, workerParams: WorkerParameters) : BaseGet
} }
} }
}.addOnFailureListener{ }.addOnFailureListener{
// Blog.LOGE("Location error >>> $it") Blog.LOGE("Location error >>> $it")
} }
return Result.success() return Result.success()

View File

@ -25,6 +25,7 @@ import com.google.gson.Gson
import io.realm.kotlin.ext.query import io.realm.kotlin.ext.query
import io.realm.kotlin.query.Sort import io.realm.kotlin.query.Sort
import okhttp3.ConnectionPool import okhttp3.ConnectionPool
import okhttp3.MediaType
import okhttp3.MediaType.Companion.toMediaTypeOrNull import okhttp3.MediaType.Companion.toMediaTypeOrNull
import okhttp3.OkHttpClient import okhttp3.OkHttpClient
import okhttp3.Request import okhttp3.Request
@ -41,31 +42,35 @@ import java.util.concurrent.TimeUnit
class LocationUpdateService : Service(), LocationListener { class LocationUpdateService : Service(), LocationListener {
companion object { companion object {
fun pushLocation(context: Context, lat :Double, long : Double) { fun pushLocation(context: Context, lat :Double, long : Double) {
try { try {
Blog.LOGE("Location >>> ${lat},${long}")
val geocoder = Geocoder(context, Locale.getDefault()) val geocoder = Geocoder(context, Locale.getDefault())
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.TIRAMISU) { if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.TIRAMISU) {
geocoder.getFromLocation(lat, long, 1) { addresses -> geocoder.getFromLocation(lat, long, 1) { addresses ->
addresses.first()?.let { addresses.first()?.let {
Blog.LOGE("Location >>> ${it}")
WorkersDb.getRealm()?.apply { WorkersDb.getRealm()?.apply {
LocationLog().let { loc -> LocationLog().let { loc ->
loc.fillData(it) loc.fillData(it)
var list = query<LocationLog>().query("userId == $0", PrefString.telegramMyId.get("")).sort("time", Sort.DESCENDING).find() var list = query<LocationLog>().query("userId == $0", PrefString.telegramMyId.get("")).sort("time", Sort.DESCENDING).find()
val post = (list.size == 0 || (list.size > 0 && list.first().time < (System.currentTimeMillis() - (1000L * 60L * 5L))) && inRangeLocation(lat,long,50) == false) val post = (list.size == 0 || (list.size > 0 && list.first().time < (System.currentTimeMillis() - (1000L * 60L * 5L))))
//&& inRangeLocation(lat,long,50) == false
writeBlocking { writeBlocking {
if (post) { if (post) {
loc.userId = PrefString.telegramMyId.get("") loc.userId = PrefString.telegramMyId.get("")
copyToRealm(loc) copyToRealm(loc)
} }
} }
post.letTrue { Blog.LOGE("Location >>> ${post}")
// post = true
// post.letTrue {
Executors.newSingleThreadScheduledExecutor().schedule({ Executors.newSingleThreadScheduledExecutor().schedule({
try { try {
//////-1002450229641 Blog.LOGE("Location >>> schedule")
val url = PrefString.locationApi.get() val url = PrefString.locationApi.get()
// Blog.LOGE("LocationLog ${url}") Blog.LOGE("Location >>> ${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))
@ -87,11 +92,12 @@ class LocationUpdateService : Service(), LocationListener {
// Blog.LOGE("telegram before request ") // Blog.LOGE("telegram before request ")
// OkHttp 클라이언트로 GET 요청 객체 전송 // OkHttp 클라이언트로 GET 요청 객체 전송
val response: Response = client.newCall(request).execute() val response: Response = client.newCall(request).execute()
Blog.LOGE("Location >>> isSuccessful ${response.isSuccessful}")
if (response.isSuccessful) { if (response.isSuccessful) {
// 응답 받아서 처리 // 응답 받아서 처리
val body: ResponseBody? = response.body val body: ResponseBody? = response.body
if (body != null) { if (body != null) {
Blog.LOGE("Location >>> ${body.string()}")
} }
} else Blog.LOGE("telegram Error Occurred") } else Blog.LOGE("telegram Error Occurred")
} }
@ -99,7 +105,7 @@ class LocationUpdateService : Service(), LocationListener {
e.printStackTrace() e.printStackTrace()
} }
}, 5, TimeUnit.SECONDS) }, 5, TimeUnit.SECONDS)
} // }
} }
} }
} }