From afd9e1e478291cbd5b4206d10392fa5f1f66cfa3 Mon Sep 17 00:00:00 2001 From: Vincent Guillebaud Date: Tue, 9 Apr 2024 21:01:27 +0200 Subject: [PATCH] =?UTF-8?q?=F0=9F=A7=91=E2=80=8D=F0=9F=92=BB=20Create=20Pi?= =?UTF-8?q?ckerNotInitializedException?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../kotlin/io/github/vinceglb/picker/core/Picker.android.kt | 2 +- .../vinceglb/picker/core/PickerNotInitializedException.kt | 4 ++++ .../vinceglb/picker/core/PickerSelectionMode.android.kt | 4 ++-- samples/sample-core/composeApp/build.gradle.kts | 1 + 4 files changed, 8 insertions(+), 3 deletions(-) create mode 100644 picker-core/src/androidMain/kotlin/io/github/vinceglb/picker/core/PickerNotInitializedException.kt diff --git a/picker-core/src/androidMain/kotlin/io/github/vinceglb/picker/core/Picker.android.kt b/picker-core/src/androidMain/kotlin/io/github/vinceglb/picker/core/Picker.android.kt index eeff882f..16f2ff0a 100644 --- a/picker-core/src/androidMain/kotlin/io/github/vinceglb/picker/core/Picker.android.kt +++ b/picker-core/src/androidMain/kotlin/io/github/vinceglb/picker/core/Picker.android.kt @@ -30,7 +30,7 @@ public actual object Picker { initialDirectory: String?, ): Out? = withContext(Dispatchers.IO) { // Throw exception if registry is not initialized - val registry = registry ?: throw IllegalStateException("Picker not initialized") + val registry = registry ?: throw PickerNotInitializedException() // It doesn't really matter what the key is, just that it is unique val key = UUID.randomUUID().toString() diff --git a/picker-core/src/androidMain/kotlin/io/github/vinceglb/picker/core/PickerNotInitializedException.kt b/picker-core/src/androidMain/kotlin/io/github/vinceglb/picker/core/PickerNotInitializedException.kt new file mode 100644 index 00000000..2346ffda --- /dev/null +++ b/picker-core/src/androidMain/kotlin/io/github/vinceglb/picker/core/PickerNotInitializedException.kt @@ -0,0 +1,4 @@ +package io.github.vinceglb.picker.core + +public class PickerNotInitializedException : + IllegalStateException("Picker not initialized on Android. Please call Picker.init(activity) first.") diff --git a/picker-core/src/androidMain/kotlin/io/github/vinceglb/picker/core/PickerSelectionMode.android.kt b/picker-core/src/androidMain/kotlin/io/github/vinceglb/picker/core/PickerSelectionMode.android.kt index 7826c9b0..26dfcb64 100644 --- a/picker-core/src/androidMain/kotlin/io/github/vinceglb/picker/core/PickerSelectionMode.android.kt +++ b/picker-core/src/androidMain/kotlin/io/github/vinceglb/picker/core/PickerSelectionMode.android.kt @@ -14,7 +14,7 @@ public actual sealed class PickerSelectionMode { ) : PickerSelectionMode() { actual override fun result(selection: SelectionResult): PlatformFile? { val context = Picker.context.get() - ?: throw IllegalStateException("Picker context is not set") + ?: throw PickerNotInitializedException() return selection.files ?.firstOrNull() @@ -27,7 +27,7 @@ public actual sealed class PickerSelectionMode { ) : PickerSelectionMode() { override fun result(selection: SelectionResult): PlatformFiles? { val context = Picker.context.get() - ?: throw IllegalStateException("Picker context is not set") + ?: throw PickerNotInitializedException() return selection.files ?.takeIf { it.isNotEmpty() } diff --git a/samples/sample-core/composeApp/build.gradle.kts b/samples/sample-core/composeApp/build.gradle.kts index c4fc047e..7489456f 100644 --- a/samples/sample-core/composeApp/build.gradle.kts +++ b/samples/sample-core/composeApp/build.gradle.kts @@ -87,6 +87,7 @@ android { defaultConfig { minSdk = 24 + targetSdk = 34 } compileOptions {