-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
* refactor: image 정보로 mimeType, size 추가 * feat: 타입, 사이즈 검증 로직 추가 * refactor: 리뷰반영
- Loading branch information
1 parent
d5453f0
commit de1a3e7
Showing
13 changed files
with
126 additions
and
38 deletions.
There are no files selected for viewing
12 changes: 12 additions & 0 deletions
12
core/data/src/main/kotlin/com/withpeace/withpeace/core/data/mapper/ImageInfoMapper.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
package com.withpeace.withpeace.core.data.mapper | ||
|
||
import com.withpeace.withpeace.core.domain.model.image.ImageInfo | ||
import com.withpeace.withpeace.core.imagestorage.ImageInfoEntity | ||
|
||
fun ImageInfoEntity.toDomain(): ImageInfo { | ||
return ImageInfo( | ||
uri = imageUri.toString(), | ||
mimeType = mimeType, | ||
byteSize = byteSize, | ||
) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
29 changes: 29 additions & 0 deletions
29
core/domain/src/main/java/com/withpeace/withpeace/core/domain/model/image/ImageInfo.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
package com.withpeace.withpeace.core.domain.model.image | ||
|
||
data class ImageInfo( | ||
val uri: String, | ||
val mimeType: String, | ||
val byteSize: Long, | ||
) { | ||
fun isUploadType(): Boolean { | ||
val imageMimeType = mimeType.split("/").last().lowercase() // image/png | ||
return uploadType.contains(imageMimeType) | ||
} | ||
|
||
fun isSizeOver(): Boolean { | ||
return byteSize.bytesToMegabytes() > MAX_MEGA_BYTE_SIZE | ||
} | ||
|
||
private fun Long.bytesToMegabytes(): Double { | ||
return this / (BYTE_TO_KB_UNIT * KB_TO_MB_UNIT) | ||
} | ||
|
||
companion object { | ||
private val uploadType = arrayOf( | ||
"jpg", "png", "webp", "jpeg", | ||
) | ||
private const val BYTE_TO_KB_UNIT = 1024.0 | ||
private const val KB_TO_MB_UNIT = 1024.0 | ||
private const val MAX_MEGA_BYTE_SIZE = 10 | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
9 changes: 9 additions & 0 deletions
9
core/imagestorage/src/main/java/com/withpeace/withpeace/core/imagestorage/ImageInfoEntity.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
package com.withpeace.withpeace.core.imagestorage | ||
|
||
import android.net.Uri | ||
|
||
data class ImageInfoEntity( | ||
val imageUri: Uri, | ||
val mimeType: String, | ||
val byteSize: Long, | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
4 changes: 3 additions & 1 deletion
4
feature/gallery/src/main/java/com/withpeace/withpeace/feature/gallery/GallerySideEffect.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,7 @@ | ||
package com.withpeace.withpeace.feature.gallery | ||
|
||
sealed interface GallerySideEffect { | ||
data object SelectImageFail : GallerySideEffect | ||
data object SelectImageNoMore : GallerySideEffect | ||
data object SelectImageNoApplyType : GallerySideEffect | ||
data object SelectImageOverSize : GallerySideEffect | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters