Skip to content

Commit

Permalink
#80 [mod] fix gradlew lint debug
Browse files Browse the repository at this point in the history
  • Loading branch information
wnehdals committed Jul 26, 2023
1 parent b96cd99 commit b2c10e2
Showing 1 changed file with 24 additions and 3 deletions.
27 changes: 24 additions & 3 deletions app/src/main/java/com/jjbaksa/jjbaksa/util/FusedLocationUtil.kt
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
package com.jjbaksa.jjbaksa.util

import android.Manifest
import android.content.Context
import android.content.pm.PackageManager
import android.os.Looper
import android.util.Log
import androidx.core.app.ActivityCompat
import com.google.android.gms.location.LocationCallback
import com.google.android.gms.location.LocationRequest
import com.google.android.gms.location.LocationResult
Expand All @@ -12,7 +15,11 @@ class FusedLocationUtil(
private val context: Context,
private val callBackLocation: (Double, Double) -> Unit
) {
private val fusedLocationClient by lazy { LocationServices.getFusedLocationProviderClient(context) }
private val fusedLocationClient by lazy {
LocationServices.getFusedLocationProviderClient(
context
)
}
private val permissions = arrayOf(
android.Manifest.permission.ACCESS_FINE_LOCATION,
android.Manifest.permission.ACCESS_COARSE_LOCATION,
Expand All @@ -32,19 +39,33 @@ class FusedLocationUtil(
}
}
}

fun startLocationUpdate() {
if (context.hasPermission(permissions)) {
fusedLocationClient.requestLocationUpdates(createLocationRequest(), locationCallback, Looper.getMainLooper())
if (ActivityCompat.checkSelfPermission(
context,
Manifest.permission.ACCESS_FINE_LOCATION
) == PackageManager.PERMISSION_GRANTED && ActivityCompat.checkSelfPermission(
context,
Manifest.permission.ACCESS_COARSE_LOCATION
) == PackageManager.PERMISSION_GRANTED
) {
fusedLocationClient.requestLocationUpdates(
createLocationRequest(),
locationCallback,
Looper.getMainLooper()
)
} else {
}
}

private fun createLocationRequest(): LocationRequest {
return LocationRequest.create().apply {
interval = 10 * 1000
fastestInterval = 5 * 1000
priority = LocationRequest.PRIORITY_HIGH_ACCURACY
}
}

fun stopLocationUpdates() {
fusedLocationClient.removeLocationUpdates(locationCallback)
}
Expand Down

0 comments on commit b2c10e2

Please sign in to comment.