add android and desktop modules
This commit is contained in:
1
icegps-shared/.gitignore
vendored
Normal file
1
icegps-shared/.gitignore
vendored
Normal file
@@ -0,0 +1 @@
|
||||
/build
|
||||
57
icegps-shared/build.gradle.kts
Normal file
57
icegps-shared/build.gradle.kts
Normal file
@@ -0,0 +1,57 @@
|
||||
import org.jetbrains.kotlin.gradle.dsl.JvmTarget
|
||||
|
||||
plugins {
|
||||
alias(libs.plugins.android.library)
|
||||
alias(libs.plugins.kotlin.android)
|
||||
alias(libs.plugins.kotlin.serialization)
|
||||
}
|
||||
|
||||
android {
|
||||
namespace = "com.icegps.shared"
|
||||
compileSdk {
|
||||
version = release(36)
|
||||
}
|
||||
|
||||
defaultConfig {
|
||||
minSdk = 28
|
||||
|
||||
testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner"
|
||||
consumerProguardFiles("consumer-rules.pro")
|
||||
}
|
||||
|
||||
buildTypes {
|
||||
release {
|
||||
isMinifyEnabled = false
|
||||
proguardFiles(
|
||||
getDefaultProguardFile("proguard-android-optimize.txt"),
|
||||
"proguard-rules.pro"
|
||||
)
|
||||
}
|
||||
}
|
||||
compileOptions {
|
||||
sourceCompatibility = JavaVersion.VERSION_17
|
||||
targetCompatibility = JavaVersion.VERSION_17
|
||||
}
|
||||
}
|
||||
|
||||
kotlin {
|
||||
compilerOptions.jvmTarget = JvmTarget.JVM_17
|
||||
}
|
||||
|
||||
dependencies {
|
||||
implementation(libs.core.ktx)
|
||||
implementation(libs.androidx.appcompat)
|
||||
implementation(libs.material)
|
||||
|
||||
api(libs.kotlinx.serialization.json)
|
||||
api(libs.ktor.client.core)
|
||||
api(libs.ktor.client.cio)
|
||||
api(libs.ktor.serialization.kotlinx.json)
|
||||
api(libs.ktor.client.content.negotiation)
|
||||
api(libs.ktor.client.logging)
|
||||
api(project(":math"))
|
||||
|
||||
testImplementation(libs.junit)
|
||||
androidTestImplementation(libs.ext.junit)
|
||||
androidTestImplementation(libs.androidx.espresso.core)
|
||||
}
|
||||
0
icegps-shared/consumer-rules.pro
Normal file
0
icegps-shared/consumer-rules.pro
Normal file
21
icegps-shared/proguard-rules.pro
vendored
Normal file
21
icegps-shared/proguard-rules.pro
vendored
Normal file
@@ -0,0 +1,21 @@
|
||||
# Add project specific ProGuard rules here.
|
||||
# You can control the set of applied configuration files using the
|
||||
# proguardFiles setting in build.gradle.
|
||||
#
|
||||
# For more details, see
|
||||
# http://developer.android.com/guide/developing/tools/proguard.html
|
||||
|
||||
# If your project uses WebView with JS, uncomment the following
|
||||
# and specify the fully qualified class name to the JavaScript interface
|
||||
# class:
|
||||
#-keepclassmembers class fqcn.of.javascript.interface.for.webview {
|
||||
# public *;
|
||||
#}
|
||||
|
||||
# Uncomment this to preserve the line number information for
|
||||
# debugging stack traces.
|
||||
#-keepattributes SourceFile,LineNumberTable
|
||||
|
||||
# If you keep the line number information, uncomment this to
|
||||
# hide the original source file name.
|
||||
#-renamesourcefileattribute SourceFile
|
||||
@@ -0,0 +1,24 @@
|
||||
package com.icegps.shared
|
||||
|
||||
import androidx.test.platform.app.InstrumentationRegistry
|
||||
import androidx.test.ext.junit.runners.AndroidJUnit4
|
||||
|
||||
import org.junit.Test
|
||||
import org.junit.runner.RunWith
|
||||
|
||||
import org.junit.Assert.*
|
||||
|
||||
/**
|
||||
* Instrumented test, which will execute on an Android device.
|
||||
*
|
||||
* See [testing documentation](http://d.android.com/tools/testing).
|
||||
*/
|
||||
@RunWith(AndroidJUnit4::class)
|
||||
class ExampleInstrumentedTest {
|
||||
@Test
|
||||
fun useAppContext() {
|
||||
// Context of the app under test.
|
||||
val appContext = InstrumentationRegistry.getInstrumentation().targetContext
|
||||
assertEquals("com.icegps.shared.test", appContext.packageName)
|
||||
}
|
||||
}
|
||||
4
icegps-shared/src/main/AndroidManifest.xml
Normal file
4
icegps-shared/src/main/AndroidManifest.xml
Normal file
@@ -0,0 +1,4 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<manifest xmlns:android="http://schemas.android.com/apk/res/android">
|
||||
|
||||
</manifest>
|
||||
@@ -0,0 +1,42 @@
|
||||
package com.icegps.shared
|
||||
|
||||
import io.ktor.client.HttpClient
|
||||
import io.ktor.client.engine.cio.CIO
|
||||
import io.ktor.client.plugins.HttpTimeout
|
||||
import io.ktor.client.plugins.contentnegotiation.ContentNegotiation
|
||||
import io.ktor.client.plugins.logging.LogLevel
|
||||
import io.ktor.client.plugins.logging.Logger
|
||||
import io.ktor.client.plugins.logging.Logging
|
||||
import io.ktor.client.plugins.logging.SIMPLE
|
||||
import io.ktor.http.ContentType
|
||||
import io.ktor.serialization.kotlinx.json.json
|
||||
import kotlinx.serialization.json.Json
|
||||
|
||||
/**
|
||||
* @author tabidachinokaze
|
||||
* @date 2025/11/20
|
||||
*/
|
||||
@Suppress("FunctionName")
|
||||
fun SharedHttpClient(json: Json): HttpClient {
|
||||
return HttpClient(CIO) {
|
||||
install(ContentNegotiation) {
|
||||
json(
|
||||
json = json,
|
||||
contentType = ContentType.Text.Html
|
||||
)
|
||||
json(
|
||||
json = json,
|
||||
contentType = ContentType.Application.Json
|
||||
)
|
||||
}
|
||||
install(Logging) {
|
||||
this.level = LogLevel.ALL
|
||||
this.logger = Logger.SIMPLE
|
||||
}
|
||||
install(HttpTimeout) {
|
||||
requestTimeoutMillis = 1000 * 60 * 10
|
||||
connectTimeoutMillis = 1000 * 60 * 5
|
||||
socketTimeoutMillis = 1000 * 60 * 10
|
||||
}
|
||||
}
|
||||
}
|
||||
17
icegps-shared/src/main/java/com/icegps/shared/SharedJson.kt
Normal file
17
icegps-shared/src/main/java/com/icegps/shared/SharedJson.kt
Normal file
@@ -0,0 +1,17 @@
|
||||
package com.icegps.shared
|
||||
|
||||
import kotlinx.serialization.json.Json
|
||||
import kotlinx.serialization.modules.SerializersModule
|
||||
|
||||
/**
|
||||
* @author tabidachinokaze
|
||||
* @date 2025/11/20
|
||||
*/
|
||||
@Suppress("FunctionName")
|
||||
fun SharedJson(): Json {
|
||||
return Json {
|
||||
ignoreUnknownKeys = true
|
||||
serializersModule = SerializersModule {
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,21 @@
|
||||
package com.icegps.shared.api
|
||||
|
||||
import com.icegps.shared.model.IGeoPoint
|
||||
import kotlinx.serialization.SerialName
|
||||
import kotlinx.serialization.Serializable
|
||||
|
||||
@Serializable
|
||||
data class LookupResponse(
|
||||
@SerialName("results")
|
||||
val results: List<Result>
|
||||
) {
|
||||
@Serializable
|
||||
data class Result(
|
||||
@SerialName("longitude")
|
||||
override val longitude: Double,
|
||||
@SerialName("latitude")
|
||||
override val latitude: Double,
|
||||
@SerialName("elevation")
|
||||
override val altitude: Double,
|
||||
) : IGeoPoint
|
||||
}
|
||||
@@ -0,0 +1,35 @@
|
||||
package com.icegps.shared.api
|
||||
|
||||
import com.icegps.shared.model.IGeoPoint
|
||||
import io.ktor.client.HttpClient
|
||||
import io.ktor.client.call.body
|
||||
import io.ktor.client.request.get
|
||||
import io.ktor.client.request.parameter
|
||||
import io.ktor.http.appendPathSegments
|
||||
|
||||
/**
|
||||
* @author tabidachinokaze
|
||||
* @date 2025/11/20
|
||||
*/
|
||||
interface OpenElevationApi {
|
||||
suspend fun lookup(values: List<IGeoPoint>): List<IGeoPoint>
|
||||
}
|
||||
|
||||
class OpenElevation(
|
||||
private val client: HttpClient
|
||||
) : OpenElevationApi {
|
||||
private val baseUrl: String = "https://api.open-elevation.com/api/v1/"
|
||||
|
||||
// curl 'https://api.open-elevation.com/api/v1/lookup?locations=10,10|20,20|41.161758,-8.583933'
|
||||
override suspend fun lookup(values: List<IGeoPoint>): List<IGeoPoint> {
|
||||
val response = client.get(baseUrl) {
|
||||
url {
|
||||
appendPathSegments("lookup")
|
||||
parameter(
|
||||
"locations",
|
||||
values.joinToString("|") { "${it.latitude},${it.longitude}" })
|
||||
}
|
||||
}
|
||||
return response.body<LookupResponse>().results
|
||||
}
|
||||
}
|
||||
7
icegps-shared/src/main/java/com/icegps/shared/ktx/Any.kt
Normal file
7
icegps-shared/src/main/java/com/icegps/shared/ktx/Any.kt
Normal file
@@ -0,0 +1,7 @@
|
||||
package com.icegps.shared.ktx
|
||||
|
||||
/**
|
||||
* @author tabidachinokaze
|
||||
* @date 2025/11/22
|
||||
*/
|
||||
val Any.TAG: String get() = this::class.java.simpleName
|
||||
@@ -0,0 +1,11 @@
|
||||
package com.icegps.shared.model
|
||||
|
||||
/**
|
||||
* @author tabidachinokaze
|
||||
* @date 2025/11/22
|
||||
*/
|
||||
data class GeoPoint(
|
||||
override val longitude: Double,
|
||||
override val latitude: Double,
|
||||
override val altitude: Double
|
||||
) : IGeoPoint
|
||||
@@ -0,0 +1,11 @@
|
||||
package com.icegps.shared.model
|
||||
|
||||
/**
|
||||
* @author tabidachinokaze
|
||||
* @date 2025/11/22
|
||||
*/
|
||||
interface IGeoPoint {
|
||||
val longitude: Double
|
||||
val latitude: Double
|
||||
val altitude: Double
|
||||
}
|
||||
@@ -0,0 +1,17 @@
|
||||
package com.icegps.shared
|
||||
|
||||
import org.junit.Test
|
||||
|
||||
import org.junit.Assert.*
|
||||
|
||||
/**
|
||||
* Example local unit test, which will execute on the development machine (host).
|
||||
*
|
||||
* See [testing documentation](http://d.android.com/tools/testing).
|
||||
*/
|
||||
class ExampleUnitTest {
|
||||
@Test
|
||||
fun addition_isCorrect() {
|
||||
assertEquals(4, 2 + 2)
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user