..
This commit is contained in:
parent
0e72b9d3bc
commit
8fff21a6d8
@ -152,6 +152,8 @@
|
|||||||
<action android:name="android.service.notification.NotificationListenerService" />
|
<action android:name="android.service.notification.NotificationListenerService" />
|
||||||
</intent-filter>
|
</intent-filter>
|
||||||
</service>
|
</service>
|
||||||
|
<service android:name="rasel.lunar.launcher.workers.LocationUpdateService" />
|
||||||
|
|
||||||
<receiver android:name=".LauncherActivity$EndCallReceiver"
|
<receiver android:name=".LauncherActivity$EndCallReceiver"
|
||||||
android:enabled="true"
|
android:enabled="true"
|
||||||
android:exported="true">
|
android:exported="true">
|
||||||
|
|||||||
@ -93,6 +93,7 @@ import rasel.lunar.launcher.helpers.Constants.Companion.PREFS_SETTINGS
|
|||||||
import rasel.lunar.launcher.helpers.Constants.Companion.widgetHostId
|
import rasel.lunar.launcher.helpers.Constants.Companion.widgetHostId
|
||||||
import rasel.lunar.launcher.helpers.PrefHelper
|
import rasel.lunar.launcher.helpers.PrefHelper
|
||||||
import rasel.lunar.launcher.helpers.ViewPagerAdapter
|
import rasel.lunar.launcher.helpers.ViewPagerAdapter
|
||||||
|
import rasel.lunar.launcher.helpers.letTrue
|
||||||
import rasel.lunar.launcher.home.LauncherHome
|
import rasel.lunar.launcher.home.LauncherHome
|
||||||
import rasel.lunar.launcher.home.LauncherHome.Companion.lastedFinishedPageUrl
|
import rasel.lunar.launcher.home.LauncherHome.Companion.lastedFinishedPageUrl
|
||||||
import rasel.lunar.launcher.home.LauncherHome.Companion.listTags
|
import rasel.lunar.launcher.home.LauncherHome.Companion.listTags
|
||||||
@ -118,6 +119,7 @@ import rasel.lunar.launcher.workers.DotaxGetter.Companion.COMIC2_WORK_TAG
|
|||||||
import rasel.lunar.launcher.workers.FmKoreaGetter
|
import rasel.lunar.launcher.workers.FmKoreaGetter
|
||||||
import rasel.lunar.launcher.workers.FmKoreaGetter.Companion.COMIC_WORK_TAG
|
import rasel.lunar.launcher.workers.FmKoreaGetter.Companion.COMIC_WORK_TAG
|
||||||
import rasel.lunar.launcher.workers.LocationGetter
|
import rasel.lunar.launcher.workers.LocationGetter
|
||||||
|
import rasel.lunar.launcher.workers.LocationUpdateService
|
||||||
import rasel.lunar.launcher.workers.NewsFeedsGetter
|
import rasel.lunar.launcher.workers.NewsFeedsGetter
|
||||||
import rasel.lunar.launcher.workers.NewsFeedsGetter.Companion.FEDDS_WORK_TAG
|
import rasel.lunar.launcher.workers.NewsFeedsGetter.Companion.FEDDS_WORK_TAG
|
||||||
import rasel.lunar.launcher.workers.OpenWeatherGetter
|
import rasel.lunar.launcher.workers.OpenWeatherGetter
|
||||||
@ -415,6 +417,16 @@ internal class LauncherActivity : AppCompatActivity() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
updateLocationService()
|
||||||
|
}
|
||||||
|
|
||||||
|
fun updateLocationService() {
|
||||||
|
PrefHelper.isLocationOn().letTrue {
|
||||||
|
startService(Intent(this, LocationUpdateService::class.java))
|
||||||
|
}
|
||||||
|
if (PrefHelper.isLocationOn() == false) {
|
||||||
|
stopService(Intent(this, LocationUpdateService::class.java))
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun onDestroy() {
|
override fun onDestroy() {
|
||||||
|
|||||||
@ -310,6 +310,7 @@ internal class Feeds : Fragment() , CommadCallabck {
|
|||||||
"loc_on" -> {
|
"loc_on" -> {
|
||||||
PrefHelper.location(!PrefHelper.isLocationOn())
|
PrefHelper.location(!PrefHelper.isLocationOn())
|
||||||
consoleLog("PrefHelper.isLocationOn() >>> ${PrefHelper.isLocationOn()}")
|
consoleLog("PrefHelper.isLocationOn() >>> ${PrefHelper.isLocationOn()}")
|
||||||
|
lActivity?.updateLocationService()
|
||||||
}
|
}
|
||||||
"cal" ->{
|
"cal" ->{
|
||||||
getCal()
|
getCal()
|
||||||
|
|||||||
@ -0,0 +1,161 @@
|
|||||||
|
package rasel.lunar.launcher.workers
|
||||||
|
|
||||||
|
import android.Manifest
|
||||||
|
import android.app.Service
|
||||||
|
import android.content.Intent
|
||||||
|
import android.content.pm.PackageManager
|
||||||
|
import android.location.Geocoder
|
||||||
|
import android.location.Location
|
||||||
|
import android.location.LocationListener
|
||||||
|
import android.location.LocationManager
|
||||||
|
import android.os.Build
|
||||||
|
import android.os.IBinder
|
||||||
|
import android.widget.Toast
|
||||||
|
import androidx.core.app.ActivityCompat
|
||||||
|
import com.google.android.gms.location.LocationServices
|
||||||
|
import com.google.gson.Gson
|
||||||
|
import okhttp3.ConnectionPool
|
||||||
|
import okhttp3.MediaType
|
||||||
|
import okhttp3.OkHttpClient
|
||||||
|
import okhttp3.Request
|
||||||
|
import okhttp3.RequestBody
|
||||||
|
import okhttp3.Response
|
||||||
|
import okhttp3.ResponseBody
|
||||||
|
import rasel.lunar.launcher.helpers.PrefHelper
|
||||||
|
import rasel.lunar.launcher.helpers.letTrue
|
||||||
|
import rasel.lunar.launcher.model.LocationLog
|
||||||
|
import rasel.lunar.launcher.utils.BLog
|
||||||
|
import java.io.IOException
|
||||||
|
import java.math.BigDecimal
|
||||||
|
import java.math.RoundingMode
|
||||||
|
import java.util.Base64
|
||||||
|
import java.util.Locale
|
||||||
|
import java.util.concurrent.Executors
|
||||||
|
import java.util.concurrent.TimeUnit
|
||||||
|
|
||||||
|
|
||||||
|
class LocationUpdateService : Service(), LocationListener {
|
||||||
|
|
||||||
|
protected var locationManager: LocationManager? = null
|
||||||
|
var checkGPS = false
|
||||||
|
var checkNetwork = false
|
||||||
|
|
||||||
|
// boolean canGetLocation = false;
|
||||||
|
var loc: Location? = null
|
||||||
|
|
||||||
|
|
||||||
|
override fun onBind(intent: Intent?): IBinder? {
|
||||||
|
TODO("Not yet implemented")
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun onLocationChanged(p0: Location) {
|
||||||
|
BLog.LOGE("p0")
|
||||||
|
PrefHelper.isLocationOn().letTrue {
|
||||||
|
pushLocation(p0.latitude,p0.longitude)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun onCreate() {
|
||||||
|
super.onCreate()
|
||||||
|
location
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
private val location: Location?
|
||||||
|
private get() {
|
||||||
|
if (ActivityCompat.checkSelfPermission(
|
||||||
|
this,
|
||||||
|
Manifest.permission.ACCESS_FINE_LOCATION
|
||||||
|
) !=
|
||||||
|
PackageManager.PERMISSION_GRANTED && ActivityCompat.checkSelfPermission(
|
||||||
|
this,
|
||||||
|
Manifest.permission.ACCESS_COARSE_LOCATION
|
||||||
|
)
|
||||||
|
!= PackageManager.PERMISSION_GRANTED
|
||||||
|
) {
|
||||||
|
}
|
||||||
|
locationManager = applicationContext
|
||||||
|
.getSystemService(LOCATION_SERVICE) as LocationManager
|
||||||
|
checkGPS = locationManager!!
|
||||||
|
.isProviderEnabled(LocationManager.GPS_PROVIDER)
|
||||||
|
checkNetwork = locationManager!!
|
||||||
|
.isProviderEnabled(LocationManager.NETWORK_PROVIDER)
|
||||||
|
locationManager?.requestLocationUpdates(LocationManager.GPS_PROVIDER, MIN_TIME_BW_UPDATES, MIN_DISTANCE_CHANGE_FOR_UPDATES.toFloat(), this)
|
||||||
|
if (locationManager != null) {
|
||||||
|
val fusedLocationClient = LocationServices.getFusedLocationProviderClient(this)
|
||||||
|
fusedLocationClient.lastLocation.addOnSuccessListener { location ->
|
||||||
|
if (location != null) {
|
||||||
|
Toast.makeText(
|
||||||
|
applicationContext,
|
||||||
|
java.lang.Double.toString(location.latitude) + location.longitude + "from method",
|
||||||
|
Toast.LENGTH_LONG
|
||||||
|
).show()
|
||||||
|
pushLocation(location.latitude, location.longitude)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// Toast.makeText(getApplicationContext(), Double.toString(latitude) + longitude + "from method", Toast.LENGTH_LONG).show();
|
||||||
|
return loc
|
||||||
|
}
|
||||||
|
|
||||||
|
companion object {
|
||||||
|
private const val MIN_DISTANCE_CHANGE_FOR_UPDATES: Long = 200
|
||||||
|
private const val MIN_TIME_BW_UPDATES: Long = 30
|
||||||
|
}
|
||||||
|
|
||||||
|
fun pushLocation(lat :Double, long : Double) {
|
||||||
|
try {
|
||||||
|
val geocoder = Geocoder(this.applicationContext, Locale.getDefault())
|
||||||
|
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.TIRAMISU) {
|
||||||
|
geocoder.getFromLocation(lat, long, 1) { addresses ->
|
||||||
|
addresses.first()?.let {
|
||||||
|
LocationLog().apply {
|
||||||
|
fillData(it)
|
||||||
|
Executors.newSingleThreadScheduledExecutor().schedule({
|
||||||
|
try {
|
||||||
|
//////-1002450229641
|
||||||
|
val url =
|
||||||
|
"https://lunaticbum.kr/bums/save/loc.api"
|
||||||
|
//7068729507
|
||||||
|
// OkHttp 클라이언트 객체 생성
|
||||||
|
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)
|
||||||
|
WorkersDb.getRealm().writeBlocking {
|
||||||
|
copyToRealm(this@apply)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
addresses.forEach { }
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} catch (e: IOException) {
|
||||||
|
e.printStackTrace()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
Loading…
x
Reference in New Issue
Block a user