diff --git a/build.gradle.kts b/build.gradle.kts index 2ec6513..9c03941 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -2,7 +2,7 @@ import org.jetbrains.kotlin.cli.common.toBooleanLenient import org.jetbrains.kotlin.gradle.plugin.mpp.KotlinNativeTarget val isSnapshotUpload = System.getProperty("snapshot").toBooleanLenient() ?: false -val libVersion = "0.2.4" +val libVersion = "0.2.5" val gitName = "abc-${project.name}" buildscript { diff --git a/kmm_location.podspec b/kmm_location.podspec index 1206250..358e4cf 100644 --- a/kmm_location.podspec +++ b/kmm_location.podspec @@ -1,6 +1,6 @@ Pod::Spec.new do |spec| spec.name = 'kmm_location' - spec.version = '0.2.4' + spec.version = '0.2.5' spec.homepage = '' spec.source = { :git => "Not Published", :tag => "Cocoapods/#{spec.name}/#{spec.version}" } spec.authors = '' diff --git a/src/androidMain/kotlin/com/linecorp/abc/location/ABCLocationRequest.kt b/src/androidMain/kotlin/com/linecorp/abc/location/ABCLocationRequest.kt new file mode 100644 index 0000000..4460c4c --- /dev/null +++ b/src/androidMain/kotlin/com/linecorp/abc/location/ABCLocationRequest.kt @@ -0,0 +1,19 @@ +package com.linecorp.abc.location + +data class ABCLocationRequest( + var priority: Priority = Priority.PRIORITY_BALANCED_POWER_ACCURACY, + var fastestInterval: Long? = null, + var interval: Long? = null, + var maxWaitTime: Long? = null, + var smallestDisplacement: Float? = null, + var isWaitForAccurateLocation: Boolean? = null, + var numUpdates: Int? = null, + var expirationTime: Long? = null, +) { + enum class Priority(val value: Int) { + PRIORITY_HIGH_ACCURACY(100), + PRIORITY_BALANCED_POWER_ACCURACY(102), + PRIORITY_LOW_POWER(104), + PRIORITY_NO_POWER(105) + } +} \ No newline at end of file diff --git a/src/androidMain/kotlin/com/linecorp/abc/location/LocationManager.kt b/src/androidMain/kotlin/com/linecorp/abc/location/LocationManager.kt index 03915a0..a5b75a6 100644 --- a/src/androidMain/kotlin/com/linecorp/abc/location/LocationManager.kt +++ b/src/androidMain/kotlin/com/linecorp/abc/location/LocationManager.kt @@ -93,7 +93,7 @@ internal actual class LocationManager { val settings = LocationSettingsRequest.Builder() .addLocationRequest(locationRequest) .build() - buildLocationRequest() + LocationServices .getSettingsClient(context) .checkLocationSettings(settings) @@ -148,15 +148,22 @@ internal actual class LocationManager { private lateinit var fusedLocationClient: FusedLocationProviderClient private lateinit var locationCallback: LocationCallback - private lateinit var locationRequest: LocationRequest - - private fun buildLocationRequest() { - locationRequest = LocationRequest.create() - locationRequest.run { - priority = LocationRequest.PRIORITY_HIGH_ACCURACY - fastestInterval = 1 * 1000 - interval = 1 * 1000 - smallestDisplacement = 10f + private var locationRequest: LocationRequest = LocationRequest.create().apply { + priority = LocationRequest.PRIORITY_HIGH_ACCURACY + fastestInterval = 1 * 1000L + interval = 10 * 1000L + } + + fun setLocationRequest(abcLocationRequest: ABCLocationRequest) { + locationRequest = LocationRequest.create().apply { + priority = abcLocationRequest.priority.value + abcLocationRequest.fastestInterval?.let { fastestInterval = it } + abcLocationRequest.interval?.let { interval = it } + abcLocationRequest.maxWaitTime?.let { maxWaitTime = it } + abcLocationRequest.smallestDisplacement?.let { smallestDisplacement = it } + abcLocationRequest.isWaitForAccurateLocation?.let { isWaitForAccurateLocation = it } + abcLocationRequest.numUpdates?.let { numUpdates = it } + abcLocationRequest.expirationTime?.let { expirationTime = it } } } } \ No newline at end of file diff --git a/src/androidMain/kotlin/com/linecorp/abc/location/extension/ABCLocationExt.kt b/src/androidMain/kotlin/com/linecorp/abc/location/extension/ABCLocationExt.kt index 5f70e06..f0b9cb1 100644 --- a/src/androidMain/kotlin/com/linecorp/abc/location/extension/ABCLocationExt.kt +++ b/src/androidMain/kotlin/com/linecorp/abc/location/extension/ABCLocationExt.kt @@ -4,6 +4,7 @@ import android.app.Activity import android.app.Application import android.content.Context import com.linecorp.abc.location.ABCLocation +import com.linecorp.abc.location.ABCLocationRequest import com.linecorp.abc.location.observers.ActivityLifecycleObserver fun ABCLocation.Companion.processRequestPermissionsResult( @@ -19,14 +20,17 @@ fun ABCLocation.Companion.processRequestPermissionsResult( fun ABCLocation.Companion.showNotificationSetting() = locationManager.showNotificationSetting() +fun ABCLocation.Companion.setLocationRequest(locationRequest: ABCLocationRequest) = + locationManager.setLocationRequest(locationRequest) + + internal var ABCLocation.Companion.activity: Activity? get() = locationManager.activity set(value) { locationManager.activity = value } internal fun ABCLocation.Companion.configure(context: Context) { - val applicationContext = context.applicationContext - ABCLocation.configure(applicationContext) + locationManager.configure(context) - val application = applicationContext as? Application ?: return + val application = context.applicationContext as? Application ?: return application.registerActivityLifecycleCallbacks(ActivityLifecycleObserver) } \ No newline at end of file