Skip to content

Commit df3d358

Browse files
committed
refactor: 하드코딩된 변수 상수화
1 parent ca130c2 commit df3d358

File tree

2 files changed

+12
-32
lines changed

2 files changed

+12
-32
lines changed

app/src/main/java/com/into/websoso/core/common/util/DynamicLimitPhotoPicker.kt

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -41,28 +41,22 @@ class DynamicLimitPhotoPicker : ActivityResultContract<Input, List<Uri>>() {
4141
override fun createIntent(
4242
context: Context,
4343
input: Input,
44-
): Intent {
45-
val mimeType = "image/*"
46-
val intent: Intent
47-
44+
): Intent =
4845
if (Build.VERSION.SDK_INT >= 33) {
49-
intent = Intent(MediaStore.ACTION_PICK_IMAGES).apply {
50-
type = mimeType
46+
Intent(MediaStore.ACTION_PICK_IMAGES).apply {
47+
type = MINE_TYPE
5148
putExtra(MediaStore.EXTRA_PICK_IMAGES_MAX, input.maxSelectable)
5249
}
5350
} else {
54-
intent = Intent(Intent.ACTION_OPEN_DOCUMENT).apply {
55-
type = mimeType
51+
Intent(Intent.ACTION_OPEN_DOCUMENT).apply {
52+
type = MINE_TYPE
5653
addCategory(Intent.CATEGORY_OPENABLE)
5754
addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION)
5855
addFlags(Intent.FLAG_GRANT_PERSISTABLE_URI_PERMISSION)
5956
putExtra(Intent.EXTRA_ALLOW_MULTIPLE, true)
6057
}
6158
}
6259

63-
return intent
64-
}
65-
6660
override fun parseResult(
6761
resultCode: Int,
6862
intent: Intent?,
@@ -81,4 +75,8 @@ class DynamicLimitPhotoPicker : ActivityResultContract<Input, List<Uri>>() {
8175

8276
return uris
8377
}
78+
79+
companion object {
80+
private const val MINE_TYPE: String = "image/*"
81+
}
8482
}

app/src/main/java/com/into/websoso/ui/createFeed/CreateFeedViewModel.kt

Lines changed: 3 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -284,7 +284,7 @@ class CreateFeedViewModel
284284
newImages: List<Uri>,
285285
retryCount: Int = 0,
286286
) {
287-
if (retryCount > 3) return
287+
if (retryCount > MAX_RETRY_COUNT) return
288288

289289
viewModelScope.launch {
290290
runCatching {
@@ -304,26 +304,8 @@ class CreateFeedViewModel
304304
_attachedImages.value = currentImages
305305
}
306306

307-
private fun downloadImage(
308-
url: String,
309-
retryCount: Int = 0,
310-
) {
311-
if (retryCount > 3) return
312-
313-
viewModelScope.launch {
314-
runCatching {
315-
feedRepository.downloadImage(url)
316-
}.onSuccess { uri ->
317-
uri.getOrNull()?.let {
318-
addCompressedImage(it)
319-
}
320-
}.onFailure {
321-
downloadImage(url, retryCount + 1)
322-
}
323-
}
324-
}
325-
326307
companion object {
327-
const val MAX_IMAGE_COUNT = 5
308+
const val MAX_IMAGE_COUNT: Int = 5
309+
private const val MAX_RETRY_COUNT: Int = 3
328310
}
329311
}

0 commit comments

Comments
 (0)