Skip to content

Commit

Permalink
Change URI methods - 3.0.0 (#112)
Browse files Browse the repository at this point in the history
* Make the filePath methods explicit for usage with uriFilePath
  • Loading branch information
Canato authored Apr 13, 2021
1 parent 7eb9ffe commit 82c66e7
Show file tree
Hide file tree
Showing 7 changed files with 16 additions and 17 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ class MainActivity {
val result = CropImage.getActivityResult(data)
if (resultCode == Activity.RESULT_OK) {
val resultUri: Uri? = result?.uriContent
val resultFilePath: String? = result?.getFilePath(requireContext())
val resultFilePath: String? = result?.getUriFilePath(requireContext())
} else if (resultCode == CropImage.CROP_IMAGE_ACTIVITY_RESULT_ERROR_CODE) {
val error = result!!.error
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ class BitmapLoadingWorkerJob internal constructor(

/**
* The Android URI of the image to load.
* NOT a file path, for it use [getFilePath]
* NOT a file path, for it use [getUriFilePath]
*/
val uriContent: Uri

Expand All @@ -95,7 +95,7 @@ class BitmapLoadingWorkerJob internal constructor(
val error: Exception?

/** The file path of the image to load */
fun getFilePath(context: Context): String = getFilePathFromUri(context, uriContent)
fun getUriFilePath(context: Context): String = getFilePathFromUri(context, uriContent)

internal constructor(uri: Uri, bitmap: Bitmap?, loadSampleSize: Int, degreesRotated: Int) {
uriContent = uri
Expand Down
8 changes: 4 additions & 4 deletions cropper/src/main/java/com/canhub/cropper/CropImage.kt
Original file line number Diff line number Diff line change
Expand Up @@ -339,7 +339,7 @@ object CropImage {
/**
* Get URI to image received from capture by camera.
*
* This is not the File Path, for it please use [getCaptureImageOutputFilePath]
* This is not the File Path, for it please use [getCaptureImageOutputUriFilePath]
*
* @param context used to access Android APIs, like content resolve, it is your
* activity/fragment/widget.
Expand Down Expand Up @@ -372,14 +372,14 @@ object CropImage {
* @param context used to access Android APIs, like content resolve, it is your
* activity/fragment/widget.
*/
fun getCaptureImageOutputFilePath(context: Context): String =
fun getCaptureImageOutputUriFilePath(context: Context): String =
getFilePathFromUri(context, getCaptureImageOutputUriContent(context))

/**
* Get the URI of the selected image from [getPickImageChooserIntent].
* Will return the correct URI for camera and gallery image.
*
* This is not the File Path, for it please use [getPickImageResultFilePath]
* This is not the File Path, for it please use [getPickImageResultUriFilePath]
*
* @param context used to access Android APIs, like content resolve, it is your
* activity/fragment/widget.
Expand All @@ -402,7 +402,7 @@ object CropImage {
* activity/fragment/widget.
* @param data the returned data of the activity result
*/
fun getPickImageResultFilePath(context: Context, data: Intent?): String =
fun getPickImageResultUriFilePath(context: Context, data: Intent?): String =
getFilePathFromUri(context, getPickImageResultUriContent(context, data))

/**
Expand Down
4 changes: 2 additions & 2 deletions cropper/src/main/java/com/canhub/cropper/CropImageView.kt
Original file line number Diff line number Diff line change
Expand Up @@ -1659,7 +1659,7 @@ class CropImageView @JvmOverloads constructor(context: Context, attrs: Attribute
* The Android uri of the saved cropped image result.<br></br>
* Null if get cropped image was executed, no output requested or failure.
*
* This is NOT the file path, please use [getFilePath]
* This is NOT the file path, please use [getUriFilePath]
*/
val uriContent: Uri?,
/** The error that failed the loading/cropping (null if successful) */
Expand Down Expand Up @@ -1721,7 +1721,7 @@ class CropImageView @JvmOverloads constructor(context: Context, attrs: Attribute
* The file path of the image to load
* Null if get cropped image was executed, no output requested or failure.
*/
fun getFilePath(context: Context): String? =
fun getUriFilePath(context: Context): String? =
uriContent?.let { getFilePathFromUri(context, it) }
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ internal class SCameraPresenter : SCameraContract.Presenter {
Log.v(
"File Path",
context
?.let { CropImage.getActivityResult(data)?.getFilePath(it) }
?.let { CropImage.getActivityResult(data)?.getUriFilePath(it) }
.toString()
)

Expand All @@ -110,16 +110,15 @@ internal class SCameraPresenter : SCameraContract.Presenter {
}
SCameraFragment.CUSTOM_REQUEST_CODE -> {
context?.let {
Log.v("File Path", CropImage.getPickImageResultFilePath(it, data))

CropImage.getPickImageResultFilePath(it, data)
Log.v("File Path", CropImage.getPickImageResultUriFilePath(it, data))
CropImage.getPickImageResultUriFilePath(it, data)
val uri = CropImage.getPickImageResultUriContent(it, data)
view?.handleCropImageResult(uri.toString().replace("file:", ""))
}
}
CropImage.PICK_IMAGE_CHOOSER_REQUEST_CODE -> {
context?.let { ctx ->
Log.v("File Path", CropImage.getPickImageResultFilePath(ctx, data))
Log.v("File Path", CropImage.getPickImageResultUriFilePath(ctx, data))
val uri = CropImage.getPickImageResultUriContent(ctx, data)

view?.handleCropImageResult(uri.toString())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,7 @@ internal class SCropImageViewFragment :
handleCropResult(CropImage.getActivityResult(data))
CropImage.PICK_IMAGE_CHOOSER_REQUEST_CODE -> {
val ctx = context
ctx?.let { Log.v("File Path", CropImage.getPickImageResultFilePath(it, data)) }
ctx?.let { Log.v("File Path", CropImage.getPickImageResultUriFilePath(it, data)) }
val imageUri = ctx?.let { CropImage.getPickImageResultUriContent(it, data) }

if (imageUri != null &&
Expand Down Expand Up @@ -230,7 +230,7 @@ internal class SCropImageViewFragment :
if (binding.cropImageView.cropShape == CropImageView.CropShape.OVAL)
result.bitmap?.let { CropImage.toOvalBitmap(it) }
else result.bitmap
context?.let { Log.v("File Path", result.getFilePath(it).toString()) }
context?.let { Log.v("File Path", result.getUriFilePath(it).toString()) }
SCropResultActivity.start(this, imageBitmap, result.uriContent, result.sampleSize)
} else {
Log.e("AIC", "Failed to crop image", result?.error)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ internal class SExtendActivity : CropImageActivity(), SExtendContract.View {
sampleSize
)

Log.v("File Path", result.getFilePath(this).toString())
Log.v("File Path", result.getUriFilePath(this).toString())
binding.cropImageView.setImageUriAsync(result.uriContent)
}

Expand Down

0 comments on commit 82c66e7

Please sign in to comment.