Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for moko-permissions 0.18.0 and update libraries #50

Merged
merged 14 commits into from
Sep 22, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions .github/workflows/compilation-check.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,10 @@ jobs:

steps:
- uses: actions/checkout@v1
- name: Set up JDK 11
- name: Set up JDK 17
uses: actions/setup-java@v1
with:
java-version: 11
java-version: 17
- name: Check runtime
run: ./gradlew build publishToMavenLocal syncMultiPlatformLibraryDebugFrameworkIosX64
- name: Install pods
Expand Down
6 changes: 3 additions & 3 deletions .github/workflows/publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,10 @@ jobs:
SIGNING_KEY: ${{ secrets.GPG_KEY_CONTENTS }}
steps:
- uses: actions/checkout@v1
- name: Set up JDK 11
- name: Set up JDK 17
uses: actions/setup-java@v1
with:
java-version: 11
java-version: 17
- name: Publish
run: ./gradlew publish
release:
Expand All @@ -41,4 +41,4 @@ jobs:
tag_name: release/${{ github.event.inputs.version }}
release_name: ${{ github.event.inputs.version }}
body: "Will be filled later"
draft: true
draft: true
15 changes: 15 additions & 0 deletions geo-compose/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,21 @@ android {
defaultConfig {
minSdk = 21
}

compileOptions {
sourceCompatibility(JavaVersion.VERSION_17)
targetCompatibility(JavaVersion.VERSION_17)
}
}

kotlin {
androidTarget {
compilations.all {
kotlinOptions {
jvmTarget = JavaVersion.VERSION_17.majorVersion
}
}
}
}

dependencies {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,25 +4,18 @@

package dev.icerock.moko.geo.compose

import android.content.Context
import androidx.activity.ComponentActivity
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
val activity: ComponentActivity = LocalContext.current as ComponentActivity

LaunchedEffect(locationTracker, lifecycleOwner, context) {
val fragmentManager: FragmentManager = (context as FragmentActivity).supportFragmentManager

locationTracker.bind(lifecycleOwner.lifecycle, context, fragmentManager)
LaunchedEffect(activity) {
locationTracker.bind(activity)
}
}
19 changes: 19 additions & 0 deletions geo/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,25 @@ plugins {
id("kotlin-parcelize")
}

android {
namespace = "dev.icerock.moko.geo"

compileOptions {
sourceCompatibility(JavaVersion.VERSION_17)
targetCompatibility(JavaVersion.VERSION_17)
}
}

kotlin {
androidTarget {
compilations.all {
kotlinOptions {
jvmTarget = JavaVersion.VERSION_17.majorVersion
}
}
}
}

dependencies {
commonMainImplementation(libs.coroutines)

Expand Down
5 changes: 2 additions & 3 deletions geo/src/androidMain/AndroidManifest.xml
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="dev.icerock.moko.geo">
<manifest xmlns:android="http://schemas.android.com/apk/res/android">

<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
</manifest>
</manifest>
34 changes: 21 additions & 13 deletions geo/src/androidMain/kotlin/dev/icerock/moko/geo/LocationTracker.kt
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,8 @@
package dev.icerock.moko.geo

import android.annotation.SuppressLint
import android.content.Context
import android.os.Build
import androidx.fragment.app.FragmentManager
import androidx.activity.ComponentActivity
import androidx.lifecycle.Lifecycle
import androidx.lifecycle.LifecycleObserver
import androidx.lifecycle.OnLifecycleEvent
Expand All @@ -30,7 +29,7 @@ import kotlinx.coroutines.launch
actual class LocationTracker(
actual val permissionsController: PermissionsController,
interval: Long = 1000,
priority: Int = LocationRequest.PRIORITY_HIGH_ACCURACY
priority: Int = LocationRequest.PRIORITY_HIGH_ACCURACY,
) : LocationCallback() {
private var locationProviderClient: FusedLocationProviderClient? = null
private var isStarted: Boolean = false
Expand All @@ -42,17 +41,17 @@ actual class LocationTracker(
private val extendedLocationsChannel = Channel<ExtendedLocation>(Channel.CONFLATED)
private val trackerScope = CoroutineScope(Dispatchers.Main)

fun bind(lifecycle: Lifecycle, context: Context, fragmentManager: FragmentManager) {
permissionsController.bind(lifecycle, fragmentManager)
fun bind(activity: ComponentActivity) {
permissionsController.bind(activity)

locationProviderClient = LocationServices.getFusedLocationProviderClient(context)
locationProviderClient = LocationServices.getFusedLocationProviderClient(activity)

@SuppressLint("MissingPermission")
if (isStarted) {
locationProviderClient?.requestLocationUpdates(locationRequest, this, null)
}

lifecycle.addObserver(object : LifecycleObserver {
activity.lifecycle.addObserver(object : LifecycleObserver {
@OnLifecycleEvent(Lifecycle.Event.ON_DESTROY)
fun onDestroy() {
locationProviderClient?.removeLocationUpdates(this@LocationTracker)
Expand All @@ -66,14 +65,23 @@ actual class LocationTracker(

val lastLocation = locationResult.lastLocation ?: return

val speedAccuracy = if (Build.VERSION.SDK_INT < Build.VERSION_CODES.O) null
else lastLocation.speedAccuracyMetersPerSecond.toDouble()
val speedAccuracy = if (Build.VERSION.SDK_INT < Build.VERSION_CODES.O) {
null
} else {
lastLocation.speedAccuracyMetersPerSecond.toDouble()
}

val bearingAccuracy = if (Build.VERSION.SDK_INT < Build.VERSION_CODES.O) null
else lastLocation.bearingAccuracyDegrees.toDouble()
val bearingAccuracy = if (Build.VERSION.SDK_INT < Build.VERSION_CODES.O) {
null
} else {
lastLocation.bearingAccuracyDegrees.toDouble()
}

val verticalAccuracy = if (Build.VERSION.SDK_INT < Build.VERSION_CODES.O) null
else lastLocation.verticalAccuracyMeters.toDouble()
val verticalAccuracy = if (Build.VERSION.SDK_INT < Build.VERSION_CODES.O) {
null
} else {
lastLocation.verticalAccuracyMeters.toDouble()
}

val latLng = LatLng(
lastLocation.latitude,
Expand Down
10 changes: 8 additions & 2 deletions geo/src/iosX64Main/kotlin/dev/icerock/moko/geo/Tracker.kt
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

package dev.icerock.moko.geo

import kotlinx.cinterop.ExperimentalForeignApi
import kotlinx.cinterop.useContents
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.channels.Channel
Expand All @@ -16,9 +17,11 @@ import platform.Foundation.NSLog
import platform.Foundation.timeIntervalSince1970
import platform.UIKit.UIDevice
import platform.darwin.NSObject
import kotlin.experimental.ExperimentalNativeApi
import kotlin.native.ref.WeakReference
import kotlin.time.Duration.Companion.seconds

@OptIn(ExperimentalNativeApi::class, ExperimentalForeignApi::class)
internal actual class Tracker actual constructor(
locationsChannel: Channel<LatLng>,
extendedLocationsChannel: Channel<ExtendedLocation>,
Expand All @@ -37,8 +40,11 @@ internal actual class Tracker actual constructor(

locations.forEach { location ->
val courseAccuracy =
if (UIDevice.currentDevice.systemVersion.compareTo("13.4") < 0) null
else location.courseAccuracy
if (UIDevice.currentDevice.systemVersion.compareTo("13.4") < 0) {
null
} else {
location.courseAccuracy
}

val latLng = location.coordinate().useContents {
LatLng(
Expand Down
9 changes: 6 additions & 3 deletions gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,16 @@ kotlin.mpp.androidSourceSetLayoutVersion=2

android.useAndroidX=true

moko.android.targetSdk=33
moko.android.compileSdk=33
moko.android.minSdk=16
moko.android.targetSdk=34
moko.android.compileSdk=34
moko.android.minSdk=21
Alex009 marked this conversation as resolved.
Show resolved Hide resolved

moko.publish.name=MOKO geo
moko.publish.description=Geolocation access for mobile (android & ios) Kotlin Multiplatform development
moko.publish.repo.org=icerockdev
moko.publish.repo.name=moko-geo
moko.publish.license=Apache-2.0
moko.publish.developers=alex009|Aleksey Mikhailov|[email protected]
android.defaults.buildfeatures.buildconfig=true
android.nonTransitiveRClass=false
android.nonFinalResIds=false
burnoo marked this conversation as resolved.
Show resolved Hide resolved
23 changes: 11 additions & 12 deletions gradle/libs.versions.toml
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
[versions]
kotlinVersion = "1.8.10"
kotlinVersion = "1.9.24"
androidAppCompatVersion = "1.6.1"
androidLifecycleVersion = "2.2.0"
playServicesLocationVersion = "21.0.1"
coroutinesVersion = "1.6.4"
composeJetBrainsVersion = "1.3.1"
mokoParcelizeVersion = "0.8.0"
mokoPermissionsVersion = "0.15.0"
mokoMvvmVersion = "0.16.0"
playServicesLocationVersion = "21.3.0"
coroutinesVersion = "1.9.0-RC"
burnoo marked this conversation as resolved.
Show resolved Hide resolved
composeJetBrainsVersion = "1.6.11"
mokoParcelizeVersion = "0.9.0"
mokoPermissionsVersion = "0.18.0"
mokoMvvmVersion = "0.16.1"
mokoGeoVersion = "0.6.0"
mokoResourcesVersion = "0.21.1"
mokoResourcesVersion = "0.24.1"

[libraries]
appCompat = { module = "androidx.appcompat:appcompat", version.ref = "androidAppCompatVersion" }
Expand All @@ -26,10 +26,9 @@ mokoResources = { module = "dev.icerock.moko:resources", version.ref = "mokoReso

kotlinGradlePlugin = { module = "org.jetbrains.kotlin:kotlin-gradle-plugin", version.ref = "kotlinVersion" }
androidGradlePlugin = { module = "com.android.tools.build:gradle", version = "7.4.2" }
googleServicesGradlePlugin = { module = "com.google.gms:google-services", version = "4.3.15" }
firebaseGradlePlugin = { module = "com.google.firebase:firebase-crashlytics-gradle", version = "2.9.4" }
mokoGradlePlugin = { module = "dev.icerock.moko:moko-gradle-plugin", version = "0.2.0" }
googleServicesGradlePlugin = { module = "com.google.gms:google-services", version = "4.4.2" }
mokoGradlePlugin = { module = "dev.icerock.moko:moko-gradle-plugin", version = "0.3.0" }
mobileMultiplatformGradlePlugin = { module = "dev.icerock:mobile-multiplatform", version = "0.14.2" }
kotlinSerializationGradlePlugin = { module = "org.jetbrains.kotlin:kotlin-serialization", version.ref = "kotlinVersion" }
composeJetBrainsGradlePlugin = { module = "org.jetbrains.compose:compose-gradle-plugin", version.ref = "composeJetBrainsVersion" }
detektGradlePlugin = { module = "io.gitlab.arturbosch.detekt:detekt-gradle-plugin", version = "1.22.0" }
detektGradlePlugin = { module = "io.gitlab.arturbosch.detekt:detekt-gradle-plugin", version = "1.23.6" }
Binary file modified gradle/wrapper/gradle-wrapper.jar
Binary file not shown.
2 changes: 1 addition & 1 deletion gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-7.6.1-bin.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-8.8-bin.zip
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
Loading
Loading