Skip to content

Commit

Permalink
🔀 Merge pull request #3 from vinceglb/initialization-exception-on-and…
Browse files Browse the repository at this point in the history
…roid

🧑‍💻 Create PickerNotInitializedException
  • Loading branch information
vinceglb authored Apr 9, 2024
2 parents defb48f + afd9e1e commit dfb13e7
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
Original file line number Diff line number Diff line change
@@ -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.")
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ public actual sealed class PickerSelectionMode<Out> {
) : PickerSelectionMode<PlatformFile>() {
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()
Expand All @@ -27,7 +27,7 @@ public actual sealed class PickerSelectionMode<Out> {
) : PickerSelectionMode<PlatformFiles>() {
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() }
Expand Down
1 change: 1 addition & 0 deletions samples/sample-core/composeApp/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,7 @@ android {

defaultConfig {
minSdk = 24
targetSdk = 34
}

compileOptions {
Expand Down

0 comments on commit dfb13e7

Please sign in to comment.