-
Notifications
You must be signed in to change notification settings - Fork 15
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #37 from icerockdev/develop
Release 0.6.0
- Loading branch information
Showing
16 changed files
with
229 additions
and
97 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
/* | ||
* Copyright 2023 IceRock MAG Inc. Use of this source code is governed by the Apache 2.0 license. | ||
*/ | ||
|
||
plugins { | ||
id("dev.icerock.moko.gradle.multiplatform.mobile") | ||
id("dev.icerock.moko.gradle.publication") | ||
id("dev.icerock.moko.gradle.stub.javadoc") | ||
id("dev.icerock.moko.gradle.detekt") | ||
id("org.jetbrains.compose") | ||
} | ||
|
||
android { | ||
namespace = "dev.icerock.moko.geo.compose" | ||
|
||
defaultConfig { | ||
minSdk = 21 | ||
} | ||
} | ||
|
||
dependencies { | ||
commonMainApi(projects.geo) | ||
commonMainApi(compose.runtime) | ||
|
||
androidMainImplementation(libs.appCompat) | ||
androidMainImplementation(compose.foundation) | ||
} |
28 changes: 28 additions & 0 deletions
28
.../src/androidMain/kotlin/dev/icerock/moko/geo/compose/BindLocationTrackerEffect.android.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
/* | ||
* Copyright 2023 IceRock MAG Inc. Use of this source code is governed by the Apache 2.0 license. | ||
*/ | ||
|
||
package dev.icerock.moko.geo.compose | ||
|
||
import android.content.Context | ||
import androidx.compose.runtime.Composable | ||
import androidx.compose.runtime.LaunchedEffect | ||
import androidx.compose.ui.platform.LocalContext | ||
import androidx.compose.ui.platform.LocalLifecycleOwner | ||
import androidx.fragment.app.FragmentActivity | ||
import androidx.fragment.app.FragmentManager | ||
import androidx.lifecycle.LifecycleOwner | ||
import dev.icerock.moko.geo.LocationTracker | ||
|
||
@Suppress("FunctionNaming") | ||
@Composable | ||
actual fun BindLocationTrackerEffect(locationTracker: LocationTracker) { | ||
val lifecycleOwner: LifecycleOwner = LocalLifecycleOwner.current | ||
val context: Context = LocalContext.current | ||
|
||
LaunchedEffect(locationTracker, lifecycleOwner, context) { | ||
val fragmentManager: FragmentManager = (context as FragmentActivity).supportFragmentManager | ||
|
||
locationTracker.bind(lifecycleOwner.lifecycle, context, fragmentManager) | ||
} | ||
} |
47 changes: 47 additions & 0 deletions
47
...ose/src/androidMain/kotlin/dev/icerock/moko/geo/compose/LocationTrackerFactory.android.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
/* | ||
* Copyright 2023 IceRock MAG Inc. Use of this source code is governed by the Apache 2.0 license. | ||
*/ | ||
|
||
package dev.icerock.moko.geo.compose | ||
|
||
import android.content.Context | ||
import androidx.compose.runtime.Composable | ||
import androidx.compose.runtime.remember | ||
import androidx.compose.ui.platform.LocalContext | ||
import com.google.android.gms.location.LocationRequest | ||
import dev.icerock.moko.geo.LocationTracker | ||
import dev.icerock.moko.permissions.PermissionsController | ||
|
||
@Composable | ||
actual fun rememberLocationTrackerFactory(accuracy: LocationTrackerAccuracy): LocationTrackerFactory { | ||
val context: Context = LocalContext.current | ||
return remember(context) { | ||
object : LocationTrackerFactory { | ||
override fun createLocationTracker(): LocationTracker { | ||
return LocationTracker( | ||
permissionsController = PermissionsController( | ||
applicationContext = context.applicationContext | ||
), | ||
priority = accuracy.toPriority() | ||
) | ||
} | ||
|
||
override fun createLocationTracker( | ||
permissionsController: PermissionsController | ||
): LocationTracker { | ||
return LocationTracker( | ||
permissionsController = permissionsController, | ||
priority = accuracy.toPriority() | ||
) | ||
} | ||
} | ||
} | ||
} | ||
|
||
private fun LocationTrackerAccuracy.toPriority(): Int { | ||
return when (this) { | ||
LocationTrackerAccuracy.Best -> LocationRequest.PRIORITY_HIGH_ACCURACY | ||
LocationTrackerAccuracy.Medium -> LocationRequest.PRIORITY_BALANCED_POWER_ACCURACY | ||
LocationTrackerAccuracy.LowPower -> LocationRequest.PRIORITY_LOW_POWER | ||
} | ||
} |
12 changes: 12 additions & 0 deletions
12
geo-compose/src/commonMain/kotlin/dev/icerock/moko/geo/compose/BindLocationTrackerEffect.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
/* | ||
* Copyright 2023 IceRock MAG Inc. Use of this source code is governed by the Apache 2.0 license. | ||
*/ | ||
|
||
package dev.icerock.moko.geo.compose | ||
|
||
import androidx.compose.runtime.Composable | ||
import dev.icerock.moko.geo.LocationTracker | ||
|
||
@Suppress("FunctionNaming") | ||
@Composable | ||
expect fun BindLocationTrackerEffect(locationTracker: LocationTracker) |
23 changes: 23 additions & 0 deletions
23
geo-compose/src/commonMain/kotlin/dev/icerock/moko/geo/compose/LocationTrackerFactory.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
/* | ||
* Copyright 2023 IceRock MAG Inc. Use of this source code is governed by the Apache 2.0 license. | ||
*/ | ||
|
||
package dev.icerock.moko.geo.compose | ||
|
||
import androidx.compose.runtime.Composable | ||
import dev.icerock.moko.geo.LocationTracker | ||
import dev.icerock.moko.permissions.PermissionsController | ||
|
||
interface LocationTrackerFactory { | ||
fun createLocationTracker(): LocationTracker | ||
fun createLocationTracker(permissionsController: PermissionsController): LocationTracker | ||
} | ||
|
||
enum class LocationTrackerAccuracy { | ||
Best, | ||
Medium, | ||
LowPower | ||
} | ||
|
||
@Composable | ||
expect fun rememberLocationTrackerFactory(accuracy: LocationTrackerAccuracy): LocationTrackerFactory |
13 changes: 13 additions & 0 deletions
13
geo-compose/src/iosMain/kotlin/dev/icerock/moko/geo/compose/BindLocationTrackerEffect.ios.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
/* | ||
* Copyright 2023 IceRock MAG Inc. Use of this source code is governed by the Apache 2.0 license. | ||
*/ | ||
|
||
package dev.icerock.moko.geo.compose | ||
|
||
import androidx.compose.runtime.Composable | ||
import dev.icerock.moko.geo.LocationTracker | ||
|
||
// on iOS side we should not do anything to prepare LocationTracker to work | ||
@Suppress("FunctionNaming") | ||
@Composable | ||
actual fun BindLocationTrackerEffect(locationTracker: LocationTracker) = Unit |
45 changes: 45 additions & 0 deletions
45
geo-compose/src/iosMain/kotlin/dev/icerock/moko/geo/compose/LocationTrackerFactory.ios.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
/* | ||
* Copyright 2023 IceRock MAG Inc. Use of this source code is governed by the Apache 2.0 license. | ||
*/ | ||
|
||
package dev.icerock.moko.geo.compose | ||
|
||
import androidx.compose.runtime.Composable | ||
import androidx.compose.runtime.remember | ||
import dev.icerock.moko.geo.LocationTracker | ||
import dev.icerock.moko.permissions.PermissionsController | ||
import platform.CoreLocation.CLLocationAccuracy | ||
import platform.CoreLocation.kCLLocationAccuracyBest | ||
import platform.CoreLocation.kCLLocationAccuracyKilometer | ||
import platform.CoreLocation.kCLLocationAccuracyReduced | ||
|
||
@Composable | ||
actual fun rememberLocationTrackerFactory(accuracy: LocationTrackerAccuracy): LocationTrackerFactory { | ||
return remember { | ||
object : LocationTrackerFactory { | ||
override fun createLocationTracker(): LocationTracker { | ||
return LocationTracker( | ||
permissionsController = dev.icerock.moko.permissions.ios.PermissionsController(), | ||
accuracy = accuracy.toIosAccuracy() | ||
) | ||
} | ||
|
||
override fun createLocationTracker( | ||
permissionsController: PermissionsController | ||
): LocationTracker { | ||
return LocationTracker( | ||
permissionsController = permissionsController, | ||
accuracy = accuracy.toIosAccuracy() | ||
) | ||
} | ||
} | ||
} | ||
} | ||
|
||
private fun LocationTrackerAccuracy.toIosAccuracy(): CLLocationAccuracy { | ||
return when (this) { | ||
LocationTrackerAccuracy.Best -> kCLLocationAccuracyBest | ||
LocationTrackerAccuracy.Medium -> kCLLocationAccuracyKilometer | ||
LocationTrackerAccuracy.LowPower -> kCLLocationAccuracyReduced | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
73 changes: 0 additions & 73 deletions
73
geo/src/iosMain/kotlin/dev/icerock/moko/geo/UIDispatcher.kt
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.