Skip to content

Commit

Permalink
Add shared multiplatform module
Browse files Browse the repository at this point in the history
  • Loading branch information
gino-m committed Jan 13, 2024
1 parent 0b66e9d commit bc8bc4c
Show file tree
Hide file tree
Showing 7 changed files with 139 additions and 1 deletion.
1 change: 1 addition & 0 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ plugins {
id "com.ncorti.ktfmt.gradle" version "0.11.0"
id "com.google.dagger.hilt.android" version "$hiltVersion" apply false
id "io.gitlab.arturbosch.detekt" version "1.23.0"
id "org.jetbrains.kotlin.multiplatform" version "1.9.22" apply false
}

allprojects {
Expand Down
2 changes: 1 addition & 1 deletion settings.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,5 @@ plugins {
id 'org.gradle.toolchains.foojay-resolver-convention' version '0.4.0'
}

include ':ground', ':sharedTest'
include ':shared', ':ground', ':sharedTest'

41 changes: 41 additions & 0 deletions shared/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
/*
* Copyright 2024 Google LLC
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

plugins {
kotlin("multiplatform")
id("com.android.library")
}

kotlin {
androidTarget { compilations.all { kotlinOptions { jvmTarget = "1.8" } } }

js(IR) { nodejs() }

sourceSets {
commonMain.dependencies {
// put your multiplatform dependencies here
}
// commonTest.dependencies {
// implementation(libs.kotlin.test)
// }
}
}

android {
namespace = "com.google.ground.shared"
compileSdk = 34
defaultConfig { minSdk = 24 }
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
/*
* Copyright 2024 Google LLC
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package com.google.ground.shared

class AndroidPlatform : Platform {
override val name: String = "Android ${android.os.Build.VERSION.SDK_INT}"
}

actual fun getPlatform(): Platform = AndroidPlatform()
25 changes: 25 additions & 0 deletions shared/src/commonMain/kotlin/com/google/ground/shared/Greeting.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
/*
* Copyright 2024 Google LLC
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package com.google.ground.shared

class Greeting {
private val platform: Platform = getPlatform()

fun greet(): String {
return "Hello, ${platform.name}!"
}
}
23 changes: 23 additions & 0 deletions shared/src/commonMain/kotlin/com/google/ground/shared/Platform.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
/*
* Copyright 2024 Google LLC
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package com.google.ground.shared

interface Platform {
val name: String
}

expect fun getPlatform(): Platform
25 changes: 25 additions & 0 deletions shared/src/iosMain/kotlin/com/google/ground/shared/Platform.ios.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
/*
* Copyright 2024 Google LLC
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package com.google.ground.shared

import platform.UIKit.UIDevice

class IOSPlatform: Platform {
override val name: String = UIDevice.currentDevice.systemName() + " " + UIDevice.currentDevice.systemVersion
}

actual fun getPlatform(): Platform = IOSPlatform()

0 comments on commit bc8bc4c

Please sign in to comment.