From 290ead1b43d3416ebe19d0ba130b698db8b19fac Mon Sep 17 00:00:00 2001 From: Ash Davies <1892070+ashdavies@users.noreply.github.com> Date: Tue, 17 Dec 2024 16:31:22 +0100 Subject: [PATCH] Move to stdlib Uuid (#1405) Co-authored-by: Ashley Davies --- .../io/ashdavies/party/gallery/StorageManager.android.kt | 6 ++++-- .../kotlin/io/ashdavies/party/gallery/ImageManager.kt | 6 ++++-- .../kotlin/io/ashdavies/gallery/SyncManagerTest.kt | 6 ++++-- .../io/ashdavies/party/gallery/StorageManager.jvm.kt | 6 ++++-- .../io/ashdavies/identity/GoogleIdIdentityService.kt | 6 ++++-- .../kotlin/io/ashdavies/util/PlatformUuid.android.kt | 7 ------- .../commonMain/kotlin/io/ashdavies/util/PlatformUuid.kt | 3 --- .../jvmMain/kotlin/io/ashdavies/util/PlatformUuid.jvm.kt | 7 ------- 8 files changed, 20 insertions(+), 27 deletions(-) delete mode 100644 platform-support/src/androidMain/kotlin/io/ashdavies/util/PlatformUuid.android.kt delete mode 100644 platform-support/src/commonMain/kotlin/io/ashdavies/util/PlatformUuid.kt delete mode 100644 platform-support/src/jvmMain/kotlin/io/ashdavies/util/PlatformUuid.jvm.kt diff --git a/conferences-app/src/androidMain/kotlin/io/ashdavies/party/gallery/StorageManager.android.kt b/conferences-app/src/androidMain/kotlin/io/ashdavies/party/gallery/StorageManager.android.kt index 48f1626ef..ca3d51c62 100644 --- a/conferences-app/src/androidMain/kotlin/io/ashdavies/party/gallery/StorageManager.android.kt +++ b/conferences-app/src/androidMain/kotlin/io/ashdavies/party/gallery/StorageManager.android.kt @@ -1,18 +1,20 @@ package io.ashdavies.party.gallery import io.ashdavies.content.PlatformContext -import io.ashdavies.util.randomUuid import kotlinx.coroutines.withContext import java.io.File import kotlin.coroutines.CoroutineContext +import kotlin.uuid.ExperimentalUuidApi +import kotlin.uuid.Uuid internal actual fun StorageManager( pathProvider: PathProvider, coroutineContext: CoroutineContext, ): StorageManager = object : StorageManager { + @OptIn(ExperimentalUuidApi::class) override suspend fun create(platformContext: PlatformContext): File = withContext(coroutineContext) { - File(pathProvider.getImagesPath(), "${randomUuid()}.jpg").apply { + File(pathProvider.getImagesPath(), "${Uuid.random()}.jpg").apply { require(createNewFile()) { "File already exists" } } } diff --git a/conferences-app/src/commonMain/kotlin/io/ashdavies/party/gallery/ImageManager.kt b/conferences-app/src/commonMain/kotlin/io/ashdavies/party/gallery/ImageManager.kt index dafe66723..3033b0b3a 100644 --- a/conferences-app/src/commonMain/kotlin/io/ashdavies/party/gallery/ImageManager.kt +++ b/conferences-app/src/commonMain/kotlin/io/ashdavies/party/gallery/ImageManager.kt @@ -2,8 +2,9 @@ package io.ashdavies.party.gallery import io.ashdavies.content.PlatformContext import io.ashdavies.sql.mapToList -import io.ashdavies.util.randomUuid import kotlinx.coroutines.flow.Flow +import kotlin.uuid.ExperimentalUuidApi +import kotlin.uuid.Uuid internal interface ImageManager { val list: Flow> @@ -28,9 +29,10 @@ internal fun ImageManager( .selectAll() .mapToList() + @OptIn(ExperimentalUuidApi::class) override fun add(file: File) { val image = Image( - uuid = randomUuid(), + uuid = "${Uuid.random()}", name = file.getName(), path = file.getAbsolutePath(), ) diff --git a/conferences-app/src/commonTest/kotlin/io/ashdavies/gallery/SyncManagerTest.kt b/conferences-app/src/commonTest/kotlin/io/ashdavies/gallery/SyncManagerTest.kt index f970c3224..4c2c49781 100644 --- a/conferences-app/src/commonTest/kotlin/io/ashdavies/gallery/SyncManagerTest.kt +++ b/conferences-app/src/commonTest/kotlin/io/ashdavies/gallery/SyncManagerTest.kt @@ -5,14 +5,16 @@ import io.ashdavies.http.DefaultHttpConfiguration import io.ashdavies.party.gallery.SyncManager import io.ashdavies.party.gallery.SyncState import io.ashdavies.party.gallery.inMemoryHttpClientEngine -import io.ashdavies.util.randomUuid import io.ktor.client.HttpClient import io.ktor.utils.io.ByteReadChannel import kotlinx.coroutines.test.runTest import kotlin.test.Test import kotlin.test.assertEquals +import kotlin.uuid.ExperimentalUuidApi +import kotlin.uuid.Uuid -private val RandomImage = "${randomUuid()}.jpg" +@OptIn(ExperimentalUuidApi::class) +private val RandomImage = "${Uuid.random()}.jpg" internal class SyncManagerTest { diff --git a/conferences-app/src/jvmMain/kotlin/io/ashdavies/party/gallery/StorageManager.jvm.kt b/conferences-app/src/jvmMain/kotlin/io/ashdavies/party/gallery/StorageManager.jvm.kt index 10f637c79..a58595efb 100644 --- a/conferences-app/src/jvmMain/kotlin/io/ashdavies/party/gallery/StorageManager.jvm.kt +++ b/conferences-app/src/jvmMain/kotlin/io/ashdavies/party/gallery/StorageManager.jvm.kt @@ -1,18 +1,20 @@ package io.ashdavies.party.gallery import io.ashdavies.content.PlatformContext -import io.ashdavies.util.randomUuid import kotlinx.coroutines.withContext import java.io.File import kotlin.coroutines.CoroutineContext +import kotlin.uuid.ExperimentalUuidApi +import kotlin.uuid.Uuid internal actual fun StorageManager( pathProvider: PathProvider, coroutineContext: CoroutineContext, ): StorageManager = object : StorageManager { + @OptIn(ExperimentalUuidApi::class) override suspend fun create(platformContext: PlatformContext): File = withContext(coroutineContext) { - File(pathProvider.getImagesPath(), "${randomUuid()}.jpg").apply { + File(pathProvider.getImagesPath(), "${Uuid.random()}.jpg").apply { require(createNewFile()) { "File already exists" } } } diff --git a/identity-manager/src/commonMain/kotlin/io/ashdavies/identity/GoogleIdIdentityService.kt b/identity-manager/src/commonMain/kotlin/io/ashdavies/identity/GoogleIdIdentityService.kt index c6b5f09a1..44c06cc0d 100644 --- a/identity-manager/src/commonMain/kotlin/io/ashdavies/identity/GoogleIdIdentityService.kt +++ b/identity-manager/src/commonMain/kotlin/io/ashdavies/identity/GoogleIdIdentityService.kt @@ -1,14 +1,16 @@ package io.ashdavies.identity import io.ashdavies.content.PlatformContext -import io.ashdavies.util.randomUuid +import kotlin.uuid.ExperimentalUuidApi +import kotlin.uuid.Uuid internal expect class GoogleIdIdentityService( context: PlatformContext, ) : IdentityService +@OptIn(ExperimentalUuidApi::class) internal data class GoogleIdIdentityRequest( val serverClientId: String, val autoSelectEnabled: Boolean = true, - val nonce: String? = randomUuid(), + val nonce: String = "${Uuid.random()}", ) : IdentityRequest diff --git a/platform-support/src/androidMain/kotlin/io/ashdavies/util/PlatformUuid.android.kt b/platform-support/src/androidMain/kotlin/io/ashdavies/util/PlatformUuid.android.kt deleted file mode 100644 index 4a4acf266..000000000 --- a/platform-support/src/androidMain/kotlin/io/ashdavies/util/PlatformUuid.android.kt +++ /dev/null @@ -1,7 +0,0 @@ -package io.ashdavies.util - -import java.util.UUID - -public actual fun randomUuid(): String { - return "${UUID.randomUUID()}" -} diff --git a/platform-support/src/commonMain/kotlin/io/ashdavies/util/PlatformUuid.kt b/platform-support/src/commonMain/kotlin/io/ashdavies/util/PlatformUuid.kt deleted file mode 100644 index fc885627c..000000000 --- a/platform-support/src/commonMain/kotlin/io/ashdavies/util/PlatformUuid.kt +++ /dev/null @@ -1,3 +0,0 @@ -package io.ashdavies.util - -public expect fun randomUuid(): String diff --git a/platform-support/src/jvmMain/kotlin/io/ashdavies/util/PlatformUuid.jvm.kt b/platform-support/src/jvmMain/kotlin/io/ashdavies/util/PlatformUuid.jvm.kt deleted file mode 100644 index 4a4acf266..000000000 --- a/platform-support/src/jvmMain/kotlin/io/ashdavies/util/PlatformUuid.jvm.kt +++ /dev/null @@ -1,7 +0,0 @@ -package io.ashdavies.util - -import java.util.UUID - -public actual fun randomUuid(): String { - return "${UUID.randomUUID()}" -}