aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorIván Ávalos <avalos@disroot.org>2021-12-04 14:08:43 -0600
committerIván Ávalos <avalos@disroot.org>2021-12-04 14:08:43 -0600
commit707250d85de9459fac363bb31562a812cd095769 (patch)
treefdec150435fe1bbeb9e8583864d442ea30861d31
parent3d1d65282ac4159a539c1158e6d0ec74f971e177 (diff)
downloadetbsa-trackermap-mobile-707250d85de9459fac363bb31562a812cd095769.tar.gz
etbsa-trackermap-mobile-707250d85de9459fac363bb31562a812cd095769.tar.bz2
etbsa-trackermap-mobile-707250d85de9459fac363bb31562a812cd095769.zip
Replaced Java stuff with Kotlin native stuff, and deleted ApplicationDelegates (probably useless)
-rw-r--r--shared/build.gradle.kts1
-rw-r--r--shared/src/commonMain/kotlin/mx/trackermap/TrackerMap/client/infrastructure/ApiClient.kt2
-rw-r--r--shared/src/commonMain/kotlin/mx/trackermap/TrackerMap/client/infrastructure/ApplicationDelegates.kt29
-rw-r--r--shared/src/commonMain/kotlin/mx/trackermap/TrackerMap/client/infrastructure/Errors.kt3
-rw-r--r--shared/src/commonMain/kotlin/mx/trackermap/TrackerMap/client/infrastructure/LocalDateAdapter.kt8
-rw-r--r--shared/src/commonMain/kotlin/mx/trackermap/TrackerMap/client/infrastructure/LocalDateTimeAdapter.kt8
6 files changed, 9 insertions, 42 deletions
diff --git a/shared/build.gradle.kts b/shared/build.gradle.kts
index 49f718d..4a6cd59 100644
--- a/shared/build.gradle.kts
+++ b/shared/build.gradle.kts
@@ -22,6 +22,7 @@ kotlin {
implementation("io.ktor:ktor-client-core:1.6.6")
implementation("io.ktor:ktor-client-cio:1.6.6")
implementation("io.ktor:ktor-client-serialization:1.6.6")
+ implementation("org.jetbrains.kotlinx:kotlinx-datetime:0.3.1")
}
}
val commonTest by getting {
diff --git a/shared/src/commonMain/kotlin/mx/trackermap/TrackerMap/client/infrastructure/ApiClient.kt b/shared/src/commonMain/kotlin/mx/trackermap/TrackerMap/client/infrastructure/ApiClient.kt
index 0f1d7da..c44d473 100644
--- a/shared/src/commonMain/kotlin/mx/trackermap/TrackerMap/client/infrastructure/ApiClient.kt
+++ b/shared/src/commonMain/kotlin/mx/trackermap/TrackerMap/client/infrastructure/ApiClient.kt
@@ -8,7 +8,6 @@ import io.ktor.client.request.*
import io.ktor.client.statement.*
import io.ktor.http.*
import io.ktor.util.*
-import java.io.File
open class ApiClient(val baseUrl: String) {
companion object {
@@ -35,7 +34,6 @@ open class ApiClient(val baseUrl: String) {
protected inline fun <reified T> fillRequest(requestBuilder: HttpRequestBuilder, content: T, mediaType: String = ApiJsonMediaType) {
when {
- content is File -> TODO("i don't know what to do here.")
mediaType == ApiFormDataMediaType && content is Map<*, *> -> {
val parametersBuilder = ParametersBuilder()
content.forEach { map ->
diff --git a/shared/src/commonMain/kotlin/mx/trackermap/TrackerMap/client/infrastructure/ApplicationDelegates.kt b/shared/src/commonMain/kotlin/mx/trackermap/TrackerMap/client/infrastructure/ApplicationDelegates.kt
deleted file mode 100644
index 7b91344..0000000
--- a/shared/src/commonMain/kotlin/mx/trackermap/TrackerMap/client/infrastructure/ApplicationDelegates.kt
+++ /dev/null
@@ -1,29 +0,0 @@
-package mx.trackermap.TrackerMap.client.infrastructure
-
-import kotlin.properties.ReadWriteProperty
-import kotlin.reflect.KProperty
-
-object ApplicationDelegates {
- /**
- * Provides a property delegate, allowing the property to be set once and only once.
- *
- * If unset (no default value), a get on the property will throw [IllegalStateException].
- */
- fun <T> setOnce(defaultValue: T? = null): ReadWriteProperty<Any?, T> = SetOnce(defaultValue)
-
- private class SetOnce<T>(defaultValue: T? = null) : ReadWriteProperty<Any?, T> {
- private var isSet = false
- private var value: T? = defaultValue
-
- override fun getValue(thisRef: Any?, property: KProperty<*>): T {
- return value ?: throw IllegalStateException("${property.name} not initialized")
- }
-
- override fun setValue(thisRef: Any?, property: KProperty<*>, value: T) = synchronized(this) {
- if (!isSet) {
- this.value = value
- isSet = true
- }
- }
- }
-} \ No newline at end of file
diff --git a/shared/src/commonMain/kotlin/mx/trackermap/TrackerMap/client/infrastructure/Errors.kt b/shared/src/commonMain/kotlin/mx/trackermap/TrackerMap/client/infrastructure/Errors.kt
index 8932856..3c44140 100644
--- a/shared/src/commonMain/kotlin/mx/trackermap/TrackerMap/client/infrastructure/Errors.kt
+++ b/shared/src/commonMain/kotlin/mx/trackermap/TrackerMap/client/infrastructure/Errors.kt
@@ -1,8 +1,5 @@
-@file:Suppress("unused")
package mx.trackermap.TrackerMap.client.infrastructure
-import java.lang.RuntimeException
-
open class ClientException : RuntimeException {
/**
diff --git a/shared/src/commonMain/kotlin/mx/trackermap/TrackerMap/client/infrastructure/LocalDateAdapter.kt b/shared/src/commonMain/kotlin/mx/trackermap/TrackerMap/client/infrastructure/LocalDateAdapter.kt
index 6b73b60..7142665 100644
--- a/shared/src/commonMain/kotlin/mx/trackermap/TrackerMap/client/infrastructure/LocalDateAdapter.kt
+++ b/shared/src/commonMain/kotlin/mx/trackermap/TrackerMap/client/infrastructure/LocalDateAdapter.kt
@@ -1,14 +1,14 @@
package mx.trackermap.TrackerMap.client.infrastructure
-import java.time.LocalDate
-import java.time.format.DateTimeFormatter
+import kotlinx.datetime.LocalDate
+
class LocalDateAdapter {
fun toJson(value: LocalDate): String {
- return DateTimeFormatter.ISO_LOCAL_DATE.format(value)
+ return value.toString()
}
fun fromJson(value: String): LocalDate {
- return LocalDate.parse(value, DateTimeFormatter.ISO_LOCAL_DATE_TIME)
+ return LocalDate.parse(value)
}
} \ No newline at end of file
diff --git a/shared/src/commonMain/kotlin/mx/trackermap/TrackerMap/client/infrastructure/LocalDateTimeAdapter.kt b/shared/src/commonMain/kotlin/mx/trackermap/TrackerMap/client/infrastructure/LocalDateTimeAdapter.kt
index 1534448..d073ff4 100644
--- a/shared/src/commonMain/kotlin/mx/trackermap/TrackerMap/client/infrastructure/LocalDateTimeAdapter.kt
+++ b/shared/src/commonMain/kotlin/mx/trackermap/TrackerMap/client/infrastructure/LocalDateTimeAdapter.kt
@@ -1,15 +1,15 @@
package mx.trackermap.TrackerMap.client.infrastructure
-import java.time.LocalDateTime
-import java.time.format.DateTimeFormatter
+import kotlinx.datetime.LocalDateTime
+
class LocalDateTimeAdapter {
fun toJson(value: LocalDateTime): String {
- return DateTimeFormatter.ISO_LOCAL_DATE_TIME.format(value)
+ return value.toString()
}
fun fromJson(value: String): LocalDateTime {
- return LocalDateTime.parse(value, DateTimeFormatter.ISO_LOCAL_DATE_TIME)
+ return LocalDateTime.parse(value)
}
} \ No newline at end of file