diff --git a/gradle/libs.versions.toml b/gradle/libs.versions.toml index c4f8259f..fce8bdf9 100644 --- a/gradle/libs.versions.toml +++ b/gradle/libs.versions.toml @@ -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" } @@ -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" } diff --git a/presentation/build.gradle.kts b/presentation/build.gradle.kts index b884ff72..8742510f 100644 --- a/presentation/build.gradle.kts +++ b/presentation/build.gradle.kts @@ -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) diff --git a/presentation/src/main/java/com/nexters/boolti/presentation/screen/gift/CardSelection.kt b/presentation/src/main/java/com/nexters/boolti/presentation/screen/gift/CardSelection.kt index 7bff9226..410c551d 100644 --- a/presentation/src/main/java/com/nexters/boolti/presentation/screen/gift/CardSelection.kt +++ b/presentation/src/main/java/com/nexters/boolti/presentation/screen/gift/CardSelection.kt @@ -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, + images: ImmutableList, selectedImage: ImagePair?, onImageSelected: (ImagePair) -> Unit, ) { @@ -115,7 +117,7 @@ fun CardSelection( @Composable private fun CardCarousel( - images: List, + images: ImmutableList, selectedImage: ImagePair?, onImageSelected: (ImagePair) -> Unit, modifier: Modifier = Modifier, @@ -164,7 +166,7 @@ private fun CardSelectionPreview() { "https://picsum.photos/200", "https://picsum.photos/200" ) - }, + }.toPersistentList(), selectedImage = ImagePair("", "", ""), onImageSelected = {} ) diff --git a/presentation/src/main/java/com/nexters/boolti/presentation/screen/gift/GiftUiState.kt b/presentation/src/main/java/com/nexters/boolti/presentation/screen/gift/GiftUiState.kt index 0ba3accf..d6de7632 100644 --- a/presentation/src/main/java/com/nexters/boolti/presentation/screen/gift/GiftUiState.kt +++ b/presentation/src/main/java/com/nexters/boolti/presentation/screen/gift/GiftUiState.kt @@ -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 = emptyList(), + val giftImages: ImmutableList = 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 = emptyList(), - val orderAgreement: List> = listOf( + val refundPolicy: ImmutableList = persistentListOf(), + val orderAgreement: ImmutableList> = persistentListOf( Pair(R.string.order_agreement_privacy_collection, false), Pair(R.string.order_agreement_privacy_offer, false), ), @@ -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() + ) } diff --git a/presentation/src/main/java/com/nexters/boolti/presentation/screen/gift/GiftViewModel.kt b/presentation/src/main/java/com/nexters/boolti/presentation/screen/gift/GiftViewModel.kt index 5b0089df..610f0301 100644 --- a/presentation/src/main/java/com/nexters/boolti/presentation/screen/gift/GiftViewModel.kt +++ b/presentation/src/main/java/com/nexters/boolti/presentation/screen/gift/GiftViewModel.kt @@ -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 @@ -56,7 +57,7 @@ class GiftViewModel @Inject constructor( private fun load() { getRefundPolicyUseCase().onEach { refundPolicy -> _uiState.update { - it.copy(refundPolicy = refundPolicy) + it.copy(refundPolicy = refundPolicy.toPersistentList()) } }.launchIn(viewModelScope + recordExceptionHandler) @@ -64,7 +65,7 @@ class GiftViewModel @Inject constructor( .onEach { images -> _uiState.update { it.copy( - giftImages = images, + giftImages = images.toPersistentList(), selectedImage = images.first() ) }