...
This commit is contained in:
parent
b5bbf299bd
commit
37a6497c84
@ -6,6 +6,7 @@ import android.location.Location
|
||||
import androidx.work.WorkerParameters
|
||||
import bums.lunatic.launcher.common.letTrue
|
||||
import bums.lunatic.launcher.helpers.PrefBoolean
|
||||
import bums.lunatic.launcher.utils.Blog
|
||||
import bums.lunatic.launcher.workers.LocationUpdateService.Companion.pushLocation
|
||||
import com.google.android.gms.location.LocationServices
|
||||
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)
|
||||
.addOnSuccessListener{ success: Location? ->
|
||||
success?.let {
|
||||
// Blog.LOGE("Location >>> $it")
|
||||
// Blog.LOGE("Location >>> (latitude)${it.longitude}/(longitude)${it.latitude}")
|
||||
Blog.LOGE("Location >>> $it")
|
||||
Blog.LOGE("Location >>> (latitude)${it.longitude}/(longitude)${it.latitude}")
|
||||
longitude = it.longitude
|
||||
latitude = it.latitude
|
||||
// runWeatherGetter()
|
||||
@ -37,7 +38,7 @@ class LocationGetter(context: Context, workerParams: WorkerParameters) : BaseGet
|
||||
}
|
||||
}
|
||||
}.addOnFailureListener{
|
||||
// Blog.LOGE("Location error >>> $it")
|
||||
Blog.LOGE("Location error >>> $it")
|
||||
}
|
||||
|
||||
return Result.success()
|
||||
|
||||
@ -25,6 +25,7 @@ import com.google.gson.Gson
|
||||
import io.realm.kotlin.ext.query
|
||||
import io.realm.kotlin.query.Sort
|
||||
import okhttp3.ConnectionPool
|
||||
import okhttp3.MediaType
|
||||
import okhttp3.MediaType.Companion.toMediaTypeOrNull
|
||||
import okhttp3.OkHttpClient
|
||||
import okhttp3.Request
|
||||
@ -41,31 +42,35 @@ import java.util.concurrent.TimeUnit
|
||||
class LocationUpdateService : Service(), LocationListener {
|
||||
|
||||
companion object {
|
||||
|
||||
fun pushLocation(context: Context, lat :Double, long : Double) {
|
||||
try {
|
||||
Blog.LOGE("Location >>> ${lat},${long}")
|
||||
val geocoder = Geocoder(context, Locale.getDefault())
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.TIRAMISU) {
|
||||
geocoder.getFromLocation(lat, long, 1) { addresses ->
|
||||
addresses.first()?.let {
|
||||
Blog.LOGE("Location >>> ${it}")
|
||||
WorkersDb.getRealm()?.apply {
|
||||
LocationLog().let { loc ->
|
||||
loc.fillData(it)
|
||||
|
||||
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 {
|
||||
if (post) {
|
||||
loc.userId = PrefString.telegramMyId.get("")
|
||||
copyToRealm(loc)
|
||||
}
|
||||
}
|
||||
post.letTrue {
|
||||
Blog.LOGE("Location >>> ${post}")
|
||||
// post = true
|
||||
// post.letTrue {
|
||||
Executors.newSingleThreadScheduledExecutor().schedule({
|
||||
try {
|
||||
//////-1002450229641
|
||||
Blog.LOGE("Location >>> schedule")
|
||||
val url = PrefString.locationApi.get()
|
||||
// Blog.LOGE("LocationLog ${url}")
|
||||
Blog.LOGE("Location >>> ${url}")
|
||||
if (url.length > 10) {
|
||||
val client = OkHttpClient.Builder()
|
||||
.connectionPool(ConnectionPool(5, 60, TimeUnit.SECONDS))
|
||||
@ -87,11 +92,12 @@ class LocationUpdateService : Service(), LocationListener {
|
||||
// Blog.LOGE("telegram before request ")
|
||||
// OkHttp 클라이언트로 GET 요청 객체 전송
|
||||
val response: Response = client.newCall(request).execute()
|
||||
Blog.LOGE("Location >>> isSuccessful ${response.isSuccessful}")
|
||||
if (response.isSuccessful) {
|
||||
// 응답 받아서 처리
|
||||
val body: ResponseBody? = response.body
|
||||
if (body != null) {
|
||||
|
||||
Blog.LOGE("Location >>> ${body.string()}")
|
||||
}
|
||||
} else Blog.LOGE("telegram Error Occurred")
|
||||
}
|
||||
@ -99,7 +105,7 @@ class LocationUpdateService : Service(), LocationListener {
|
||||
e.printStackTrace()
|
||||
}
|
||||
}, 5, TimeUnit.SECONDS)
|
||||
}
|
||||
// }
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user