Skip to content

Commit

Permalink
Merge pull request #62 from ParkSangGwon/feature/error-listener-strin…
Browse files Browse the repository at this point in the history
…g-to-throwable

Change OnErrorListener's parameter is String to Throwable
  • Loading branch information
ParkSangGwon authored Mar 2, 2021
2 parents 46eb46d + 944e0b5 commit 7e09829
Show file tree
Hide file tree
Showing 5 changed files with 12 additions and 12 deletions.
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ android.enableJetifier=true
# Kotlin code style for this project: "official" or "obsolete":
kotlin.code.style=official
GROUP=gun0912.ted
VERSION_NAME=1.1.8
VERSION_NAME=1.1.9
DEVELOPER_ID='gun0912'
DEVELOPER_NAME='Ted Park'
SITE_URL='https://github.com/ParkSangGwon/TedImagePicker'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,10 @@ class TedImagePicker {
return this
}

fun errorListener(action: (String) -> Unit): Builder {
fun errorListener(action: (Throwable) -> Unit): Builder {
this.onErrorListener = object : OnErrorListener {
override fun onError(message: String) {
action(message)
override fun onError(throwable: Throwable) {
action(throwable)
}
}
return this
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -92,9 +92,9 @@ open class TedImagePickerBaseBuilder<out B : TedImagePickerBaseBuilder<B>>(
if (permissionResult.isGranted) {
startActivity(context)
} else {
onErrorListener?.onError("Permission denied")
onErrorListener?.onError(IllegalAccessException("Permission denied"))
}
}, { throwable -> onErrorListener?.onError(throwable.localizedMessage) })
}, { throwable -> onErrorListener?.onError(throwable) })
}

private fun checkPermission(context: Context) = TedRx2Permission.with(context)
Expand All @@ -110,7 +110,7 @@ open class TedImagePickerBaseBuilder<out B : TedImagePickerBaseBuilder<B>>(
if (activityResult.resultCode == Activity.RESULT_OK) {
onComplete(activityResult.data)
}
}, { throwable -> onErrorListener?.onError(throwable.localizedMessage) })
}, { throwable -> onErrorListener?.onError(throwable) })
}
}

Expand All @@ -122,7 +122,7 @@ open class TedImagePickerBaseBuilder<out B : TedImagePickerBaseBuilder<B>>(
when {
selectedUri != null -> onSelectedListener?.onSelected(selectedUri)
selectedUriList != null -> onMultiSelectedListener?.onSelected(selectedUriList)
else -> IllegalStateException("selectedUri/selectedUriList can not null")
else -> onErrorListener?.onError(IllegalStateException("selectedUri/selectedUriList can not null"))
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,8 @@ class TedRxImagePicker {

private fun start(selectType: SelectType, emitter: SingleEmitter<*>) {
this.onErrorListener = object : OnErrorListener {
override fun onError(message: String) {
emitter.onError(RuntimeException(message))
override fun onError(throwable: Throwable) {
emitter.onError(throwable)
}
}
this.selectType = selectType
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
package gun0912.tedimagepicker.builder.listener

interface OnErrorListener {
fun onError(message: String)
}
fun onError(throwable: Throwable)
}

0 comments on commit 7e09829

Please sign in to comment.