Skip to content

Commit 16becb7

Browse files
committed
[Refactor] 중복 코드 제거
1 parent 51ff0a4 commit 16becb7

File tree

1 file changed

+15
-21
lines changed

1 file changed

+15
-21
lines changed

app/src/main/java/com/and04/naturealbum/utils/image/ImageConvert.kt

+15-21
Original file line numberDiff line numberDiff line change
@@ -31,30 +31,24 @@ object ImageConvert {
3131
imageFile.createNewFile()
3232

3333
FileOutputStream(imageFile).use { fos ->
34-
if (external) {
35-
BitmapFactory.decodeStream(URL(photoUri).openStream()).apply {
36-
if (Build.VERSION.SDK_INT >= 30) {
37-
compress(Bitmap.CompressFormat.WEBP_LOSSY, COMPRESS_QUALITY, fos)
38-
} else {
39-
compress(Bitmap.CompressFormat.JPEG, COMPRESS_QUALITY, fos)
40-
}
41-
42-
recycle()
34+
val bitmapFactory =
35+
if (external) {
36+
BitmapFactory.decodeStream(URL(photoUri).openStream())
37+
} else {
38+
val bufferedInputStream = BufferedInputStream(
39+
context.contentResolver.openInputStream(photoUri.toUri())
40+
)
41+
BitmapFactory.decodeStream(bufferedInputStream)
4342
}
44-
} else {
45-
val bufferedInputStream = BufferedInputStream(
46-
context.contentResolver.openInputStream(photoUri.toUri())
47-
)
4843

49-
BitmapFactory.decodeStream(bufferedInputStream).apply {
50-
if (Build.VERSION.SDK_INT >= 30) {
51-
compress(Bitmap.CompressFormat.WEBP_LOSSY, COMPRESS_QUALITY, fos)
52-
} else {
53-
compress(Bitmap.CompressFormat.JPEG, COMPRESS_QUALITY, fos)
54-
}
44+
bitmapFactory.apply {
45+
if (Build.VERSION.SDK_INT >= 30) {
46+
compress(Bitmap.CompressFormat.WEBP_LOSSY, COMPRESS_QUALITY, fos)
47+
} else {
48+
compress(Bitmap.CompressFormat.JPEG, COMPRESS_QUALITY, fos)
49+
}
5550

56-
recycle()
57-
} ?: throw NullPointerException()
51+
recycle()
5852
}
5953

6054
fos.flush()

0 commit comments

Comments
 (0)