Skip to content

Commit

Permalink
Merge pull request #180 from jkwiecien/kotlin
Browse files Browse the repository at this point in the history
Fix: makes sure cleanup is done before starting new operation
  • Loading branch information
jkwiecien committed Apr 1, 2019
2 parents 45ae226 + d10a7b8 commit f54047f
Showing 1 changed file with 6 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ class EasyImage private constructor(
}

private fun startChooser(caller: Any) {
cleanup()
getCallerActivity(caller)?.let { activity ->
try {
lastCameraFile = Files.createCameraPictureFile(context)
Expand All @@ -54,20 +55,23 @@ class EasyImage private constructor(
}

private fun startDocuments(caller: Any) {
cleanup()
getCallerActivity(caller)?.let { activity ->
val intent = Intents.createDocumentsIntent()
activity.startActivityForResult(intent, RequestCodes.PICK_PICTURE_FROM_DOCUMENTS)
}
}

private fun startGallery(caller: Any) {
cleanup()
getCallerActivity(caller)?.let { activity ->
val intent = Intents.createGalleryIntent(allowMultiple)
activity.startActivityForResult(intent, RequestCodes.PICK_PICTURE_FROM_GALLERY)
}
}

private fun startCameraForImage(caller: Any) {
cleanup()
getCallerActivity(caller)?.let { activity ->
lastCameraFile = Files.createCameraPictureFile(context)
val takePictureIntent = Intents.createCameraForImageIntent(activity, lastCameraFile!!.uri)
Expand All @@ -84,6 +88,7 @@ class EasyImage private constructor(
}

private fun startCameraForVideo(caller: Any) {
cleanup()
getCallerActivity(caller)?.let { activity ->
lastCameraFile = Files.createCameraVideoFile(context)
val recordVideoIntent = Intents.createCameraForVideoIntent(activity, lastCameraFile!!.uri)
Expand Down Expand Up @@ -183,6 +188,7 @@ class EasyImage private constructor(
onPickedExistingPicturesFromLocalStorage(resultIntent, activity, callbacks)
}
} catch (error: Throwable) {
cleanup()
error.printStackTrace()
callbacks.onImagePickerError(error, MediaSource.GALLERY)
}
Expand Down

0 comments on commit f54047f

Please sign in to comment.