From 17a6236ae738b6567328709f2b8262fa7d11a46b Mon Sep 17 00:00:00 2001 From: Gino Miceli Date: Sat, 13 Jan 2024 09:58:54 -0500 Subject: [PATCH] Add share multiplatform module scaffolding --- build.gradle | 1 + settings.gradle | 2 +- shared/build.gradle.kts | 41 +++++++++++++++++++ .../google/ground/shared/Platform.android.kt | 23 +++++++++++ .../com/google/ground/shared/Greeting.kt | 25 +++++++++++ .../com/google/ground/shared/Platform.kt | 23 +++++++++++ .../com/google/ground/shared/Platform.ios.kt | 25 +++++++++++ 7 files changed, 139 insertions(+), 1 deletion(-) create mode 100644 shared/build.gradle.kts create mode 100644 shared/src/androidMain/kotlin/com/google/ground/shared/Platform.android.kt create mode 100644 shared/src/commonMain/kotlin/com/google/ground/shared/Greeting.kt create mode 100644 shared/src/commonMain/kotlin/com/google/ground/shared/Platform.kt create mode 100644 shared/src/iosMain/kotlin/com/google/ground/shared/Platform.ios.kt diff --git a/build.gradle b/build.gradle index 6981dd356f..de238e2efd 100644 --- a/build.gradle +++ b/build.gradle @@ -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 { diff --git a/settings.gradle b/settings.gradle index f39e0248e5..54250642cd 100644 --- a/settings.gradle +++ b/settings.gradle @@ -2,5 +2,5 @@ plugins { id 'org.gradle.toolchains.foojay-resolver-convention' version '0.4.0' } -include ':ground', ':sharedTest' +include ':shared', ':ground', ':sharedTest' diff --git a/shared/build.gradle.kts b/shared/build.gradle.kts new file mode 100644 index 0000000000..ad0dbb8e25 --- /dev/null +++ b/shared/build.gradle.kts @@ -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 } +} diff --git a/shared/src/androidMain/kotlin/com/google/ground/shared/Platform.android.kt b/shared/src/androidMain/kotlin/com/google/ground/shared/Platform.android.kt new file mode 100644 index 0000000000..dd900d89be --- /dev/null +++ b/shared/src/androidMain/kotlin/com/google/ground/shared/Platform.android.kt @@ -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() \ No newline at end of file diff --git a/shared/src/commonMain/kotlin/com/google/ground/shared/Greeting.kt b/shared/src/commonMain/kotlin/com/google/ground/shared/Greeting.kt new file mode 100644 index 0000000000..35c83ecd3f --- /dev/null +++ b/shared/src/commonMain/kotlin/com/google/ground/shared/Greeting.kt @@ -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}!" + } +} \ No newline at end of file diff --git a/shared/src/commonMain/kotlin/com/google/ground/shared/Platform.kt b/shared/src/commonMain/kotlin/com/google/ground/shared/Platform.kt new file mode 100644 index 0000000000..25ba5e39a2 --- /dev/null +++ b/shared/src/commonMain/kotlin/com/google/ground/shared/Platform.kt @@ -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 \ No newline at end of file diff --git a/shared/src/iosMain/kotlin/com/google/ground/shared/Platform.ios.kt b/shared/src/iosMain/kotlin/com/google/ground/shared/Platform.ios.kt new file mode 100644 index 0000000000..b3b5ada001 --- /dev/null +++ b/shared/src/iosMain/kotlin/com/google/ground/shared/Platform.ios.kt @@ -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() \ No newline at end of file