From b609ee1dc0ffe2a4c6acf2d08e13c46a7ded5fe1 Mon Sep 17 00:00:00 2001 From: Iván Ávalos Date: Sat, 4 Dec 2021 14:08:43 -0600 Subject: Replaced Java stuff with Kotlin native stuff, and deleted ApplicationDelegates (probably useless) --- .../TrackerMap/client/infrastructure/ApiClient.kt | 2 -- .../client/infrastructure/ApplicationDelegates.kt | 29 ---------------------- .../TrackerMap/client/infrastructure/Errors.kt | 3 --- .../client/infrastructure/LocalDateAdapter.kt | 8 +++--- .../client/infrastructure/LocalDateTimeAdapter.kt | 8 +++--- 5 files changed, 8 insertions(+), 42 deletions(-) delete mode 100644 shared/src/commonMain/kotlin/mx/trackermap/TrackerMap/client/infrastructure/ApplicationDelegates.kt (limited to 'shared/src') 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 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 setOnce(defaultValue: T? = null): ReadWriteProperty = SetOnce(defaultValue) - - private class SetOnce(defaultValue: T? = null) : ReadWriteProperty { - 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 -- cgit v1.2.3