Skip to content

Commit

Permalink
perf : [선물하기] ImmutableList 시험 적용
Browse files Browse the repository at this point in the history
  • Loading branch information
HamBP committed Jul 24, 2024
1 parent 5147af3 commit 76d0583
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 9 deletions.
2 changes: 2 additions & 0 deletions gradle/libs.versions.toml
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ kakao = "2.19.0"
timber = "5.0.1"
mockk = "1.13.8"
tosspayments = "0.1.15"
immutable = "0.3.7"

[libraries]
androidx-activity-compose = { module = "androidx.activity:activity-compose", version.ref = "activity-ktx" }
Expand Down Expand Up @@ -113,6 +114,7 @@ kakao-share = { group = "com.kakao.sdk", name = "v2-share", version.ref = "kakao
retrofit2-kotlinx-serialization-converter = { module = "com.jakewharton.retrofit:retrofit2-kotlinx-serialization-converter", version.ref = "serializationConverter" }
timber = { module = "com.jakewharton.timber:timber", version.ref = "timber" }
mockk = { group = "io.mockk", name = "mockk", version.ref = "mockk" }
immutable = { group = "org.jetbrains.kotlinx", name = "kotlinx-collections-immutable", version.ref = "immutable" }

[plugins]
android-application = { id = "com.android.application", version.ref = "android" }
Expand Down
1 change: 1 addition & 0 deletions presentation/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ dependencies {
implementation(libs.material)
implementation(libs.bundles.lifecycle)
implementation(libs.bundles.compose)
implementation(libs.immutable)
implementation(platform(libs.andoridx.compose.compose.bom))
implementation(libs.bundles.coroutines)
implementation(libs.bundles.firebase)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,13 +34,15 @@ import com.nexters.boolti.domain.model.ImagePair
import com.nexters.boolti.presentation.R
import com.nexters.boolti.presentation.theme.BooltiTheme
import com.nexters.boolti.presentation.theme.Grey10
import kotlinx.collections.immutable.ImmutableList
import kotlinx.collections.immutable.toPersistentList


@Composable
fun CardSelection(
message: String,
onMessageChanged: (String) -> Unit,
images: List<ImagePair>,
images: ImmutableList<ImagePair>,
selectedImage: ImagePair?,
onImageSelected: (ImagePair) -> Unit,
) {
Expand Down Expand Up @@ -115,7 +117,7 @@ fun CardSelection(

@Composable
private fun CardCarousel(
images: List<ImagePair>,
images: ImmutableList<ImagePair>,
selectedImage: ImagePair?,
onImageSelected: (ImagePair) -> Unit,
modifier: Modifier = Modifier,
Expand Down Expand Up @@ -164,7 +166,7 @@ private fun CardSelectionPreview() {
"https://picsum.photos/200",
"https://picsum.photos/200"
)
},
}.toPersistentList(),
selectedImage = ImagePair("", "", ""),
onImageSelected = {}
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,20 +3,23 @@ package com.nexters.boolti.presentation.screen.gift
import androidx.compose.runtime.Stable
import com.nexters.boolti.domain.model.ImagePair
import com.nexters.boolti.presentation.R
import kotlinx.collections.immutable.ImmutableList
import kotlinx.collections.immutable.persistentListOf
import kotlinx.collections.immutable.toPersistentList
import java.time.LocalDateTime

@Stable
data class GiftUiState(
val loading: Boolean = true,
val giftImages: List<ImagePair> = emptyList(),
val giftImages: ImmutableList<ImagePair> = persistentListOf(),
val poster: String = "",
val showDate: LocalDateTime = LocalDateTime.now(),
val showName: String = "",
val ticketName: String = "",
val ticketCount: Int = 1,
val totalPrice: Int = 0,
val refundPolicy: List<String> = emptyList(),
val orderAgreement: List<Pair<Int, Boolean>> = listOf(
val refundPolicy: ImmutableList<String> = persistentListOf(),
val orderAgreement: ImmutableList<Pair<Int, Boolean>> = persistentListOf(
Pair(R.string.order_agreement_privacy_collection, false),
Pair(R.string.order_agreement_privacy_offer, false),
),
Expand All @@ -35,5 +38,9 @@ data class GiftUiState(
receiverName.isNotBlank() && receiverContact.isNotBlank()

fun toggleAgreement(): GiftUiState =
copy(orderAgreement = orderAgreement.map { it.copy(second = !orderAgreed) })
copy(
orderAgreement = orderAgreement.map {
it.copy(second = !orderAgreed)
}.toPersistentList()
)
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import com.nexters.boolti.domain.usecase.GetRefundPolicyUsecase
import com.nexters.boolti.domain.usecase.GetUserUsecase
import com.nexters.boolti.presentation.base.BaseViewModel
import dagger.hilt.android.lifecycle.HiltViewModel
import kotlinx.collections.immutable.toPersistentList
import kotlinx.coroutines.channels.Channel
import kotlinx.coroutines.flow.MutableStateFlow
import kotlinx.coroutines.flow.StateFlow
Expand Down Expand Up @@ -56,15 +57,15 @@ class GiftViewModel @Inject constructor(
private fun load() {
getRefundPolicyUseCase().onEach { refundPolicy ->
_uiState.update {
it.copy(refundPolicy = refundPolicy)
it.copy(refundPolicy = refundPolicy.toPersistentList())
}
}.launchIn(viewModelScope + recordExceptionHandler)

giftRepository.getGiftImages()
.onEach { images ->
_uiState.update {
it.copy(
giftImages = images,
giftImages = images.toPersistentList(),
selectedImage = images.first()
)
}
Expand Down

0 comments on commit 76d0583

Please sign in to comment.