diff --git a/app/src/main/java/app/klottr/KlottrAppShell.kt b/app/src/main/java/app/klottr/KlottrAppShell.kt index c5b00d3..9fbf89e 100644 --- a/app/src/main/java/app/klottr/KlottrAppShell.kt +++ b/app/src/main/java/app/klottr/KlottrAppShell.kt @@ -84,6 +84,7 @@ import app.klottr.util.KLog import app.klottr.util.NoteDetailCache import app.klottr.util.OutboxStore import app.klottr.util.SettingsStore +import app.klottr.util.UUID import app.klottr.util.formatCoords import app.klottr.util.formatDistance import coil3.ImageLoader @@ -95,7 +96,6 @@ import kotlinx.coroutines.IO import kotlinx.coroutines.launch import kotlinx.coroutines.withContext import java.io.File -import java.util.UUID import kotlin.collections.component1 import kotlin.collections.component2 import kotlin.collections.iterator @@ -680,7 +680,7 @@ fun KlottrAppShell( return@WriteDocDialog } val created = Clock.System.now().toEpochMilliseconds() - val requestId = UUID.randomUUID().toString() + val requestId = UUID.randomUUID() if (isSavingDoc) return@WriteDocDialog isSavingDoc = true diff --git a/shared/src/commonMain/kotlin/app/klottr/util/UUID.kt b/shared/src/commonMain/kotlin/app/klottr/util/UUID.kt new file mode 100644 index 0000000..8864c12 --- /dev/null +++ b/shared/src/commonMain/kotlin/app/klottr/util/UUID.kt @@ -0,0 +1,13 @@ +package app.klottr.util + +import kotlin.random.Random + +object UUID { + fun randomUUID(): String { + val b = Random.nextBytes(16) + b[6] = ((b[6].toInt() and 0x0f) or 0x40).toByte() // version 4 + b[8] = ((b[8].toInt() and 0x3f) or 0x80).toByte() // variant 10 + val h = b.joinToString("") { (it.toInt() and 0xff).toString(16).padStart(2, '0') } + return "${h.substring(0, 8)}-${h.substring(8, 12)}-${h.substring(12, 16)}-${h.substring(16, 20)}-${h.substring(20)}" + } +} diff --git a/shared/src/commonMain/kotlin/app/klottr/util/UserId.kt b/shared/src/commonMain/kotlin/app/klottr/util/UserId.kt index 53299d0..35f1933 100644 --- a/shared/src/commonMain/kotlin/app/klottr/util/UserId.kt +++ b/shared/src/commonMain/kotlin/app/klottr/util/UserId.kt @@ -11,16 +11,8 @@ object UserId { if (KvPrefs.contains(KEY)) { KvPrefs.getString(KEY, null)?.let { return it } } - val fresh = randomUuidV4() + val fresh = UUID.randomUUID() KvPrefs.putString(KEY, fresh) return fresh } - - private fun randomUuidV4(): String { - val b = Random.nextBytes(16) - b[6] = ((b[6].toInt() and 0x0f) or 0x40).toByte() // version 4 - b[8] = ((b[8].toInt() and 0x3f) or 0x80).toByte() // variant 10 - val h = b.joinToString("") { (it.toInt() and 0xff).toString(16).padStart(2, '0') } - return "${h.substring(0,8)}-${h.substring(8,12)}-${h.substring(12,16)}-${h.substring(16,20)}-${h.substring(20)}" - } }