Skip to content

Commit

Permalink
pr improvements
Browse files Browse the repository at this point in the history
  • Loading branch information
Remigiusz Pawłowski authored and Remigiusz Pawłowski committed Mar 31, 2022
1 parent 66cf1a7 commit 0a2a9ba
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 13 deletions.
4 changes: 2 additions & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/)
- `Security` in case of vulnerabilities.

## [x.x.x] - unreleased
### Added
- CropException sealed class with CancellationException [#332](https://github.com/CanHub/Android-Image-Cropper/issues/332)
### Changed
- CropException sealed class with cancellation and Image exceptions [#332](https://github.com/CanHub/Android-Image-Cropper/issues/332)
### Fixed
- Fix disable closing AlertDialog when touching outside the dialog [#334](https://github.com/CanHub/Android-Image-Cropper/issues/334)
## [4.2.0] - 21/03/2022
Expand Down
10 changes: 4 additions & 6 deletions cropper/src/main/java/com/canhub/cropper/BitmapUtils.kt
Original file line number Diff line number Diff line change
Expand Up @@ -132,9 +132,7 @@ internal object BitmapUtils {
val bitmap = decodeImage(resolver, uri, options)
BitmapSampled(bitmap, options.inSampleSize)
} catch (e: Exception) {
throw CropException.FailedToLoadBitmapException(
uri, e.message
)
throw CropException.FailedToLoadBitmap(uri, e.message)
}
}

Expand Down Expand Up @@ -658,7 +656,7 @@ internal object BitmapUtils {
result?.recycle()
throw e
} catch (e: Exception) {
throw CropException.FailedToLoadBitmapException(loadedImageUri, e.message)
throw CropException.FailedToLoadBitmap(loadedImageUri, e.message)
}
return BitmapSampled(result, sampleSize)
}
Expand Down Expand Up @@ -702,7 +700,7 @@ internal object BitmapUtils {
closeSafe(stream)
}
} while (options.inSampleSize <= 512)
throw CropException.FailedToDecodeImageException(uri)
throw CropException.FailedToDecodeImage(uri)
}

/**
Expand Down Expand Up @@ -743,7 +741,7 @@ internal object BitmapUtils {
closeSafe(stream)
decoder?.recycle()
} catch (e: Exception) {
throw CropException.FailedToLoadBitmapException(uri, e.message)
throw CropException.FailedToLoadBitmap(uri, e.message)
}
return BitmapSampled(null, 1)
}
Expand Down
15 changes: 11 additions & 4 deletions cropper/src/main/java/com/canhub/cropper/CropException.kt
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,15 @@ package com.canhub.cropper
import android.net.Uri

sealed class CropException(message: String) : Exception(message) {
class CancellationException : CropException("cropping has been cancelled by the user")
class FailedToLoadBitmapException(uri: Uri, message: String?) :
CropException("Failed to load sampled bitmap: $uri\r\n$message")
class FailedToDecodeImageException(uri: Uri) : CropException("Failed to decode image: $uri")
class Cancellation : CropException("$EXCEPTION_PREFIX cropping has been cancelled by the user")
class FailedToLoadBitmap(uri: Uri, message: String?) :
CropException("$EXCEPTION_PREFIX Failed to load sampled bitmap: $uri\r\n$message")

class FailedToDecodeImage(uri: Uri) :
CropException("$EXCEPTION_PREFIX Failed to decode image: $uri")

companion object {

const val EXCEPTION_PREFIX = "crop:"
}
}
2 changes: 1 addition & 1 deletion cropper/src/main/java/com/canhub/cropper/CropImage.kt
Original file line number Diff line number Diff line change
Expand Up @@ -254,7 +254,7 @@ object CropImage {
originalUri = null,
bitmap = null,
uriContent = null,
error = CropException.CancellationException(),
error = CropException.Cancellation(),
cropPoints = floatArrayOf(),
cropRect = null,
wholeImageRect = null,
Expand Down

0 comments on commit 0a2a9ba

Please sign in to comment.