From 88d1487aa61328fe86e86b7a0c18dc086414d2f1 Mon Sep 17 00:00:00 2001 From: kwakjoohyeong Date: Sun, 29 Sep 2024 19:23:20 +0900 Subject: [PATCH] =?UTF-8?q?feat:=20=ED=95=84=ED=84=B0=20UI=20=EB=B3=80?= =?UTF-8?q?=EA=B2=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../filtersetting/FilterBottomSheet.kt | 282 +++++++++--------- .../filtersetting}/PolicyFiltersUiModel.kt | 2 +- core/ui/src/main/res/drawable/ic_filter.xml | 12 + .../src/main/res/drawable/ic_filter_close.xml | 9 + core/ui/src/main/res/values/strings.xml | 9 + .../withpeace/feature/home/HomeScreen.kt | 110 ++++++- .../withpeace/feature/home/HomeViewModel.kt | 53 ++++ .../uistate/FilterListUiState.kt | 36 --- .../feature/policylist/PolicyListScreen.kt | 5 +- .../feature/policylist/PolicyListViewModel.kt | 5 +- .../filtersetting/FilterBottomSheet.kt | 273 +++++++++-------- .../filtersetting}/PolicyFiltersUiModel.kt | 3 +- .../uistate/FilterListUiState.kt | 36 --- 13 files changed, 480 insertions(+), 355 deletions(-) rename {feature/home/src/main/java/com/withpeace/withpeace/feature/home => core/ui/src/main/java/com/withpeace/withpeace/core/ui/policy}/filtersetting/FilterBottomSheet.kt (50%) rename {feature/policylist/src/main/java/com/withpeace/withpeace/feature/policylist/uistate => core/ui/src/main/java/com/withpeace/withpeace/core/ui/policy/filtersetting}/PolicyFiltersUiModel.kt (93%) create mode 100644 core/ui/src/main/res/drawable/ic_filter.xml create mode 100644 core/ui/src/main/res/drawable/ic_filter_close.xml delete mode 100644 feature/home/src/main/java/com/withpeace/withpeace/feature/home/filtersetting/uistate/FilterListUiState.kt rename feature/{home/src/main/java/com/withpeace/withpeace/feature/home/uistate => policylist/src/main/java/com/withpeace/withpeace/feature/policylist/filtersetting}/PolicyFiltersUiModel.kt (85%) delete mode 100644 feature/policylist/src/main/java/com/withpeace/withpeace/feature/policylist/filtersetting/uistate/FilterListUiState.kt diff --git a/feature/home/src/main/java/com/withpeace/withpeace/feature/home/filtersetting/FilterBottomSheet.kt b/core/ui/src/main/java/com/withpeace/withpeace/core/ui/policy/filtersetting/FilterBottomSheet.kt similarity index 50% rename from feature/home/src/main/java/com/withpeace/withpeace/feature/home/filtersetting/FilterBottomSheet.kt rename to core/ui/src/main/java/com/withpeace/withpeace/core/ui/policy/filtersetting/FilterBottomSheet.kt index 3f02e149..d6173e88 100644 --- a/feature/home/src/main/java/com/withpeace/withpeace/feature/home/filtersetting/FilterBottomSheet.kt +++ b/core/ui/src/main/java/com/withpeace/withpeace/core/ui/policy/filtersetting/FilterBottomSheet.kt @@ -1,8 +1,6 @@ -package com.withpeace.withpeace.feature.home.filtersetting +package com.withpeace.withpeace.core.ui.policy.filtersetting -import androidx.compose.animation.animateContentSize -import androidx.compose.animation.core.Spring -import androidx.compose.animation.core.spring +import androidx.compose.foundation.BorderStroke import androidx.compose.foundation.Image import androidx.compose.foundation.ScrollState import androidx.compose.foundation.background @@ -10,6 +8,8 @@ import androidx.compose.foundation.clickable import androidx.compose.foundation.layout.Arrangement import androidx.compose.foundation.layout.Box import androidx.compose.foundation.layout.Column +import androidx.compose.foundation.layout.ExperimentalLayoutApi +import androidx.compose.foundation.layout.FlowRow import androidx.compose.foundation.layout.PaddingValues import androidx.compose.foundation.layout.Row import androidx.compose.foundation.layout.Spacer @@ -18,11 +18,10 @@ import androidx.compose.foundation.layout.height import androidx.compose.foundation.layout.heightIn import androidx.compose.foundation.layout.padding import androidx.compose.foundation.layout.wrapContentHeight +import androidx.compose.foundation.lazy.LazyRow import androidx.compose.foundation.shape.RoundedCornerShape import androidx.compose.foundation.verticalScroll import androidx.compose.material3.ButtonColors -import androidx.compose.material3.Checkbox -import androidx.compose.material3.CheckboxDefaults import androidx.compose.material3.HorizontalDivider import androidx.compose.material3.Text import androidx.compose.material3.TextButton @@ -31,6 +30,7 @@ import androidx.compose.runtime.mutableStateOf import androidx.compose.runtime.remember import androidx.compose.ui.Alignment import androidx.compose.ui.Modifier +import androidx.compose.ui.graphics.Color import androidx.compose.ui.layout.onSizeChanged import androidx.compose.ui.platform.LocalConfiguration import androidx.compose.ui.platform.LocalDensity @@ -38,11 +38,9 @@ import androidx.compose.ui.res.painterResource import androidx.compose.ui.res.stringResource import androidx.compose.ui.unit.dp import com.withpeace.withpeace.core.designsystem.theme.WithpeaceTheme +import com.withpeace.withpeace.core.ui.R import com.withpeace.withpeace.core.ui.policy.ClassificationUiModel import com.withpeace.withpeace.core.ui.policy.RegionUiModel -import com.withpeace.withpeace.feature.home.R -import com.withpeace.withpeace.feature.home.filtersetting.uistate.FilterListUiState -import com.withpeace.withpeace.feature.home.uistate.PolicyFiltersUiModel @Composable fun FilterBottomSheet( @@ -56,7 +54,14 @@ fun FilterBottomSheet( onCloseFilter: () -> Unit, ) { val filterListUiState = - remember { mutableStateOf(FilterListUiState().getStateByFilterState(selectedFilterUiState)) } + remember { + mutableStateOf( + PolicyFiltersUiModel( + classifications = ClassificationUiModel.entries, + regions = RegionUiModel.entries, + ), + ) + } val configuration = LocalConfiguration.current val screenHeight = configuration.screenHeightDp.dp val footerHeight = remember { mutableStateOf(0.dp) } @@ -90,14 +95,6 @@ fun FilterBottomSheet( selectedFilterUiState = selectedFilterUiState, onClassificationCheckChanged = onClassificationCheckChanged, onRegionCheckChanged = onRegionCheckChanged, - onClassificationMoreViewClick = { - filterListUiState.value = - filterListUiState.value.copy(isClassificationExpanded = !filterListUiState.value.isClassificationExpanded) - }, - onRegionMoreViewClick = { - filterListUiState.value = - filterListUiState.value.copy(isRegionExpanded = !filterListUiState.value.isRegionExpanded) - }, scrollState = scrollState, ) } @@ -133,93 +130,116 @@ private fun FilterHeader(modifier: Modifier, onCloseFilter: () -> Unit) { ) } +@OptIn(ExperimentalLayoutApi::class) @Composable private fun ScrollableFilterSection( modifier: Modifier, - filterListUiState: FilterListUiState, + filterListUiState: PolicyFiltersUiModel, selectedFilterUiState: PolicyFiltersUiModel, onClassificationCheckChanged: (ClassificationUiModel) -> Unit, onRegionCheckChanged: (RegionUiModel) -> Unit, - onClassificationMoreViewClick: () -> Unit, - onRegionMoreViewClick: () -> Unit, scrollState: ScrollState, ) { - val scrollSectionHeight = remember { mutableStateOf(0.dp) } - val localDensity = LocalDensity.current - val columnModifier = modifier.padding(horizontal = 24.dp) - Column( - modifier = - if (scrollSectionHeight.value == 0.dp) columnModifier - .onSizeChanged { - if (!filterListUiState.isRegionExpanded && !filterListUiState.isClassificationExpanded) { - scrollSectionHeight.value = with(localDensity) { it.height.toDp() } - } - } - .verticalScroll(scrollState) - else columnModifier - .height(scrollSectionHeight.value) + modifier = modifier .verticalScroll(scrollState) + .padding(horizontal = 24.dp), ) { Spacer(modifier = modifier.height(16.dp)) Text( - text = stringResource(R.string.policy_classfication), + text = stringResource(R.string.policy_classification_image), style = WithpeaceTheme.typography.title2, - color = WithpeaceTheme.colors.SystemBlack, + color = WithpeaceTheme.colors.SnackbarBlack, ) Spacer(modifier = modifier.height(16.dp)) - Column( - modifier = modifier.animateContentSize( - animationSpec = spring( - dampingRatio = Spring.DampingRatioNoBouncy, - stiffness = Spring.StiffnessMedium, - ), - ), - ) { - filterListUiState.getClassifications().forEach { - Row( - modifier = modifier.fillMaxWidth(), - horizontalArrangement = - Arrangement.SpaceBetween, - verticalAlignment = Alignment.CenterVertically, - ) { - Text( - text = stringResource(id = it.stringResId), - style = WithpeaceTheme.typography.body, - color = WithpeaceTheme.colors.SystemBlack, - ) - Checkbox( - colors = CheckboxDefaults.colors( - checkedColor = WithpeaceTheme.colors.MainPurple, - uncheckedColor = WithpeaceTheme.colors.SystemGray2, - checkmarkColor = WithpeaceTheme.colors.SystemWhite, + LazyRow { + items(3) { + val filterItem = filterListUiState.classifications[it] + if (selectedFilterUiState.classifications.contains(filterItem)) { + TextButton( + colors = ButtonColors( + containerColor = WithpeaceTheme.colors.MainPurple, + contentColor = WithpeaceTheme.colors.SystemWhite, + disabledContainerColor = Color.Transparent, + disabledContentColor = WithpeaceTheme.colors.SystemWhite, ), - checked = selectedFilterUiState.classifications.contains(it), - onCheckedChange = { _ -> onClassificationCheckChanged(it) }, - ) + onClick = { onClassificationCheckChanged(filterItem) }, + modifier = modifier + .padding(end = 8.dp), + ) { + Text( + style = WithpeaceTheme.typography.body, + text = stringResource(id = filterItem.stringResId), + ) + } + } else { + TextButton( + colors = ButtonColors( + containerColor = WithpeaceTheme.colors.SystemWhite, + contentColor = WithpeaceTheme.colors.SystemBlack, + disabledContainerColor = Color.Transparent, + disabledContentColor = WithpeaceTheme.colors.SystemBlack, + ), + onClick = { onClassificationCheckChanged(filterItem) }, + border = BorderStroke( + width = 1.dp, + color = WithpeaceTheme.colors.SystemGray2, + ), + modifier = modifier.padding(end = 8.dp), + ) { + Text( + style = WithpeaceTheme.typography.body, + text = stringResource(id = filterItem.stringResId), + color = WithpeaceTheme.colors.SystemBlack, + ) + } } } } - - Spacer(modifier = Modifier.height(16.dp)) - Row( - modifier = modifier - .fillMaxWidth() - .clickable { - onClassificationMoreViewClick() - }, - horizontalArrangement = Arrangement.Center, - ) { - Text( - text = stringResource(id = if (filterListUiState.isClassificationExpanded) R.string.filter_fold else R.string.filter_expanded), - color = WithpeaceTheme.colors.SystemGray1, - style = WithpeaceTheme.typography.caption, - modifier = modifier.padding(end = 4.dp), - ) - Image( - painterResource(id = if (filterListUiState.isClassificationExpanded) R.drawable.ic_filter_fold else R.drawable.ic_filter_expanded), - contentDescription = stringResource(id = R.string.filter_expanded), - ) + Spacer(modifier = modifier.height(8.dp)) + LazyRow { + items(2) { + val filterItem = filterListUiState.classifications[it + 3] + if (selectedFilterUiState.classifications.contains(filterItem)) { + TextButton( + colors = ButtonColors( + containerColor = WithpeaceTheme.colors.MainPurple, + contentColor = WithpeaceTheme.colors.SystemWhite, + disabledContainerColor = Color.Transparent, + disabledContentColor = WithpeaceTheme.colors.SystemWhite, + ), + onClick = { onClassificationCheckChanged(filterItem) }, + modifier = modifier + .padding(end = 8.dp), + ) { + Text( + style = WithpeaceTheme.typography.body, + text = stringResource(id = filterItem.stringResId), + ) + } + } else { + TextButton( + colors = ButtonColors( + containerColor = WithpeaceTheme.colors.SystemWhite, + contentColor = WithpeaceTheme.colors.SystemBlack, + disabledContainerColor = Color.Transparent, + disabledContentColor = WithpeaceTheme.colors.SystemBlack, + ), + onClick = { onClassificationCheckChanged(filterItem) }, + border = BorderStroke( + width = 1.dp, + color = WithpeaceTheme.colors.SystemGray2, + ), + modifier = modifier.padding(end = 8.dp), + ) { + Text( + style = WithpeaceTheme.typography.body, + text = stringResource(id = filterItem.stringResId), + color = WithpeaceTheme.colors.SystemBlack, + ) + } + } + } } Spacer(modifier = modifier.height(16.dp)) HorizontalDivider( @@ -230,66 +250,54 @@ private fun ScrollableFilterSection( Text( text = stringResource(id = R.string.region), style = WithpeaceTheme.typography.title2, - color = WithpeaceTheme.colors.SystemBlack, + color = WithpeaceTheme.colors.SnackbarBlack, ) Spacer(modifier = modifier.height(16.dp)) - Column( - modifier = modifier.animateContentSize( - animationSpec = spring( - dampingRatio = Spring.DampingRatioNoBouncy, - stiffness = Spring.StiffnessMedium, - ), - ), - ) { - filterListUiState.getRegions().forEach { filterItem -> - Row( - modifier = modifier.fillMaxWidth(), - horizontalArrangement = - Arrangement.SpaceBetween, - verticalAlignment = Alignment.CenterVertically, - ) { - Text( - text = filterItem.name, - style = WithpeaceTheme.typography.body, - color = WithpeaceTheme.colors.SystemBlack, - ) - Checkbox( - colors = CheckboxDefaults.colors( - checkedColor = WithpeaceTheme.colors.MainPurple, - uncheckedColor = WithpeaceTheme.colors.SystemGray2, - checkmarkColor = WithpeaceTheme.colors.SystemWhite, + FlowRow { + filterListUiState.regions.dropLast(1).forEach { filterItem -> + if (selectedFilterUiState.regions.contains(filterItem)) { + TextButton( + colors = ButtonColors( + containerColor = WithpeaceTheme.colors.MainPurple, + contentColor = WithpeaceTheme.colors.SystemWhite, + disabledContainerColor = Color.Transparent, + disabledContentColor = WithpeaceTheme.colors.SystemWhite, ), - checked = selectedFilterUiState.regions.contains(filterItem), - onCheckedChange = { onRegionCheckChanged(filterItem) }, - ) + onClick = { onRegionCheckChanged(filterItem) }, + modifier = modifier + .padding(end = 8.dp), + ) { + Text( + style = WithpeaceTheme.typography.body, + text = filterItem.name, + ) + } + } else { + TextButton( + colors = ButtonColors( + containerColor = WithpeaceTheme.colors.SystemWhite, + contentColor = WithpeaceTheme.colors.SystemBlack, + disabledContainerColor = Color.Transparent, + disabledContentColor = WithpeaceTheme.colors.SystemBlack, + ), + onClick = { onRegionCheckChanged(filterItem) }, + border = BorderStroke( + width = 1.dp, + color = WithpeaceTheme.colors.SystemGray2, + ), + modifier = modifier.padding(end = 8.dp), + ) { + Text( + style = WithpeaceTheme.typography.body, + text = filterItem.name, + color = WithpeaceTheme.colors.SystemBlack, + ) + } } } } - Spacer(modifier = Modifier.height(16.dp)) - Row( - modifier = modifier - .fillMaxWidth() - .clickable { - onRegionMoreViewClick() - }, - horizontalArrangement = Arrangement.Center, - ) { - Text( - text = stringResource( - if (filterListUiState.isRegionExpanded) R.string.filter_fold else R.string.filter_expanded, - ), - color = WithpeaceTheme.colors.SystemGray1, - style = WithpeaceTheme.typography.caption, - modifier = modifier.padding(end = 4.dp), - ) - Image( - painterResource(id = if (filterListUiState.isRegionExpanded) R.drawable.ic_filter_fold else R.drawable.ic_filter_expanded), - contentDescription = stringResource(id = R.string.filter_expanded), - ) - } - Spacer(modifier = Modifier.height(24.dp)) } } diff --git a/feature/policylist/src/main/java/com/withpeace/withpeace/feature/policylist/uistate/PolicyFiltersUiModel.kt b/core/ui/src/main/java/com/withpeace/withpeace/core/ui/policy/filtersetting/PolicyFiltersUiModel.kt similarity index 93% rename from feature/policylist/src/main/java/com/withpeace/withpeace/feature/policylist/uistate/PolicyFiltersUiModel.kt rename to core/ui/src/main/java/com/withpeace/withpeace/core/ui/policy/filtersetting/PolicyFiltersUiModel.kt index 957a5139..e2ad44f5 100644 --- a/feature/policylist/src/main/java/com/withpeace/withpeace/feature/policylist/uistate/PolicyFiltersUiModel.kt +++ b/core/ui/src/main/java/com/withpeace/withpeace/core/ui/policy/filtersetting/PolicyFiltersUiModel.kt @@ -1,4 +1,4 @@ -package com.withpeace.withpeace.feature.policylist.uistate +package com.withpeace.withpeace.core.ui.policy.filtersetting import com.withpeace.withpeace.core.domain.model.policy.PolicyFilters import com.withpeace.withpeace.core.ui.policy.ClassificationUiModel diff --git a/core/ui/src/main/res/drawable/ic_filter.xml b/core/ui/src/main/res/drawable/ic_filter.xml new file mode 100644 index 00000000..e8ad2a36 --- /dev/null +++ b/core/ui/src/main/res/drawable/ic_filter.xml @@ -0,0 +1,12 @@ + + + diff --git a/core/ui/src/main/res/drawable/ic_filter_close.xml b/core/ui/src/main/res/drawable/ic_filter_close.xml new file mode 100644 index 00000000..3b9176a8 --- /dev/null +++ b/core/ui/src/main/res/drawable/ic_filter_close.xml @@ -0,0 +1,9 @@ + + + diff --git a/core/ui/src/main/res/values/strings.xml b/core/ui/src/main/res/values/strings.xml index 9c31af9b..f0ff3d48 100644 --- a/core/ui/src/main/res/values/strings.xml +++ b/core/ui/src/main/res/values/strings.xml @@ -30,4 +30,13 @@ 복지,문화 참여,권리 기타 + + + 필터 + 필터 닫기 + 더보기 + 정책 분류 이미지 + 지역 + 전체 해제 + 검색하기 diff --git a/feature/home/src/main/java/com/withpeace/withpeace/feature/home/HomeScreen.kt b/feature/home/src/main/java/com/withpeace/withpeace/feature/home/HomeScreen.kt index 1e26ed04..e6cb6ab2 100644 --- a/feature/home/src/main/java/com/withpeace/withpeace/feature/home/HomeScreen.kt +++ b/feature/home/src/main/java/com/withpeace/withpeace/feature/home/HomeScreen.kt @@ -1,8 +1,10 @@ package com.withpeace.withpeace.feature.home import androidx.compose.foundation.Image +import androidx.compose.foundation.MutatePriority import androidx.compose.foundation.background import androidx.compose.foundation.clickable +import androidx.compose.foundation.gestures.stopScroll import androidx.compose.foundation.layout.Arrangement import androidx.compose.foundation.layout.Box import androidx.compose.foundation.layout.Column @@ -19,13 +21,21 @@ import androidx.compose.foundation.layout.size import androidx.compose.foundation.layout.width import androidx.compose.foundation.lazy.LazyColumn import androidx.compose.foundation.lazy.LazyRow +import androidx.compose.foundation.rememberScrollState import androidx.compose.foundation.shape.CircleShape import androidx.compose.foundation.shape.RoundedCornerShape +import androidx.compose.material3.ExperimentalMaterial3Api import androidx.compose.material3.HorizontalDivider +import androidx.compose.material3.ModalBottomSheet import androidx.compose.material3.Text +import androidx.compose.material3.rememberModalBottomSheetState import androidx.compose.runtime.Composable +import androidx.compose.runtime.LaunchedEffect +import androidx.compose.runtime.getValue import androidx.compose.runtime.mutableStateOf import androidx.compose.runtime.remember +import androidx.compose.runtime.rememberCoroutineScope +import androidx.compose.runtime.setValue import androidx.compose.ui.Alignment import androidx.compose.ui.Modifier import androidx.compose.ui.draw.clip @@ -35,6 +45,7 @@ import androidx.compose.ui.res.stringResource import androidx.compose.ui.text.style.TextOverflow import androidx.compose.ui.unit.dp import androidx.hilt.navigation.compose.hiltViewModel +import androidx.lifecycle.compose.collectAsStateWithLifecycle import com.skydoves.balloon.BalloonAnimation import com.skydoves.balloon.BalloonSizeSpec import com.skydoves.balloon.compose.Balloon @@ -42,20 +53,41 @@ import com.skydoves.balloon.compose.rememberBalloonBuilder import com.skydoves.balloon.compose.setBackgroundColor import com.withpeace.withpeace.core.designsystem.theme.WithpeaceTheme import com.withpeace.withpeace.core.ui.analytics.TrackScreenViewEvent +import com.withpeace.withpeace.core.ui.policy.ClassificationUiModel +import com.withpeace.withpeace.core.ui.policy.RegionUiModel +import com.withpeace.withpeace.core.ui.policy.filtersetting.FilterBottomSheet +import com.withpeace.withpeace.core.ui.policy.filtersetting.PolicyFiltersUiModel +import kotlinx.coroutines.launch @Composable fun HomeRoute( onShowSnackBar: (message: String) -> Unit = {}, - onNavigationSnackBar: (message: String) -> Unit = {}, viewModel: HomeViewModel = hiltViewModel(), + onNavigationSnackBar: (message: String) -> Unit = {}, onPolicyClick: (String) -> Unit, ) { - HomeScreen() + val selectedFilterUiState = viewModel.selectingFilters.collectAsStateWithLifecycle() + HomeScreen( + selectedFilterUiState = selectedFilterUiState.value, + onClassificationCheckChanged = viewModel::onCheckClassification, + onRegionCheckChanged = viewModel::onCheckRegion, + onFilterAllOff = viewModel::onFilterAllOff, + onSearchWithFilter = viewModel::onCompleteFilter, + onCloseFilter = viewModel::onCancelFilter, + onDismissRequest = viewModel::onCancelFilter, + ) } @Composable fun HomeScreen( modifier: Modifier = Modifier, + selectedFilterUiState: PolicyFiltersUiModel, + onDismissRequest: () -> Unit, + onClassificationCheckChanged: (ClassificationUiModel) -> Unit, + onRegionCheckChanged: (RegionUiModel) -> Unit, + onFilterAllOff: () -> Unit, + onSearchWithFilter: () -> Unit, + onCloseFilter: () -> Unit, ) { Column(modifier = modifier.fillMaxSize()) { HomeHeader( @@ -65,16 +97,32 @@ fun HomeScreen( modifier = modifier.height(1.dp), color = WithpeaceTheme.colors.SystemGray3, ) - - ScrollSection(modifier) + ScrollSection( + selectedFilterUiState = selectedFilterUiState, + onDismissRequest = onDismissRequest, + onClassificationCheckChanged = onClassificationCheckChanged, + onRegionCheckChanged = onRegionCheckChanged, + onFilterAllOff = onFilterAllOff, + onSearchWithFilter = onSearchWithFilter, + onCloseFilter = onCloseFilter, + ) } TrackScreenViewEvent(screenName = "home") } -@OptIn(ExperimentalLayoutApi::class) +@OptIn(ExperimentalLayoutApi::class, ExperimentalMaterial3Api::class) @Composable -private fun ScrollSection(modifier: Modifier) { +private fun ScrollSection( + modifier: Modifier = Modifier, + selectedFilterUiState: PolicyFiltersUiModel, + onDismissRequest: () -> Unit, + onClassificationCheckChanged: (ClassificationUiModel) -> Unit, + onRegionCheckChanged: (RegionUiModel) -> Unit, + onFilterAllOff: () -> Unit, + onSearchWithFilter: () -> Unit, + onCloseFilter: () -> Unit, +) { val builder = rememberBalloonBuilder { setIsVisibleArrow(false) setWidth(BalloonSizeSpec.WRAP) @@ -85,7 +133,52 @@ private fun ScrollSection(modifier: Modifier) { setBalloonAnimation(BalloonAnimation.FADE) setArrowSize(0) } + var showBottomSheet by remember { mutableStateOf(false) } + val bottomSheetChildScrollState = rememberScrollState() + + val sheetState = rememberModalBottomSheetState( + skipPartiallyExpanded = true, + ) + val scope = rememberCoroutineScope() + LaunchedEffect(bottomSheetChildScrollState.canScrollBackward) { + if (bottomSheetChildScrollState.value == 0) { + bottomSheetChildScrollState.stopScroll(MutatePriority.PreventUserInput) + } + } + + if (showBottomSheet) { + ModalBottomSheet( + modifier = modifier, + dragHandle = null, + onDismissRequest = { + onDismissRequest() + showBottomSheet = false + }, + sheetState = sheetState, + ) { + FilterBottomSheet( + modifier = modifier, + scrollState = bottomSheetChildScrollState, + selectedFilterUiState = selectedFilterUiState, + onClassificationCheckChanged = onClassificationCheckChanged, + onRegionCheckChanged = onRegionCheckChanged, + onFilterAllOff = onFilterAllOff, + onSearchWithFilter = { + scope.launch { sheetState.hide() }.invokeOnCompletion { + showBottomSheet = false + onSearchWithFilter() + } + }, + onCloseFilter = { + scope.launch { sheetState.hide() }.invokeOnCompletion { + showBottomSheet = false + onCloseFilter() + } + }, + ) + } + } LazyColumn( verticalArrangement = Arrangement.spacedBy(8.dp), @@ -136,7 +229,10 @@ private fun ScrollSection(modifier: Modifier) { shape = CircleShape, ) .padding(4.dp) - .size(16.dp), + .size(16.dp) + .clickable { + showBottomSheet = true + }, contentDescription = "", ) List(5) { //TODO("데이터 변경") diff --git a/feature/home/src/main/java/com/withpeace/withpeace/feature/home/HomeViewModel.kt b/feature/home/src/main/java/com/withpeace/withpeace/feature/home/HomeViewModel.kt index 39209a15..82ae027d 100644 --- a/feature/home/src/main/java/com/withpeace/withpeace/feature/home/HomeViewModel.kt +++ b/feature/home/src/main/java/com/withpeace/withpeace/feature/home/HomeViewModel.kt @@ -1,10 +1,63 @@ package com.withpeace.withpeace.feature.home import androidx.lifecycle.ViewModel +import androidx.lifecycle.viewModelScope +import com.withpeace.withpeace.core.domain.model.policy.PolicyFilters +import com.withpeace.withpeace.core.ui.policy.ClassificationUiModel +import com.withpeace.withpeace.core.ui.policy.RegionUiModel +import com.withpeace.withpeace.core.ui.policy.filtersetting.PolicyFiltersUiModel +import com.withpeace.withpeace.core.ui.policy.filtersetting.toDomain +import com.withpeace.withpeace.core.ui.policy.filtersetting.toUiModel +import com.withpeace.withpeace.core.ui.policy.toDomain import dagger.hilt.android.lifecycle.HiltViewModel +import kotlinx.coroutines.flow.MutableStateFlow +import kotlinx.coroutines.flow.SharingStarted +import kotlinx.coroutines.flow.StateFlow +import kotlinx.coroutines.flow.map +import kotlinx.coroutines.flow.stateIn +import kotlinx.coroutines.flow.update import javax.inject.Inject @HiltViewModel class HomeViewModel @Inject constructor( ) : ViewModel() { + private val _selectingFilters = MutableStateFlow(PolicyFilters()) + val selectingFilters: StateFlow = + _selectingFilters.map { it.toUiModel() }.stateIn( + scope = viewModelScope, + SharingStarted.WhileSubscribed(), + PolicyFiltersUiModel(), + ) + + private var completedFilters = PolicyFilters() + + init { + } + + fun onCheckClassification(classification: ClassificationUiModel) { + _selectingFilters.update { + it.updateClassification(classification.toDomain()) + } + } + + fun onCheckRegion(region: RegionUiModel) { + _selectingFilters.update { + it.updateRegion(region.toDomain()) + } + } + + fun onCompleteFilter() { + completedFilters = selectingFilters.value.toDomain() + // api + } + + fun onCancelFilter() { + _selectingFilters.update { completedFilters } + } + + fun onFilterAllOff() { + _selectingFilters.update { + it.removeAll() + } + } } diff --git a/feature/home/src/main/java/com/withpeace/withpeace/feature/home/filtersetting/uistate/FilterListUiState.kt b/feature/home/src/main/java/com/withpeace/withpeace/feature/home/filtersetting/uistate/FilterListUiState.kt deleted file mode 100644 index 50e7e366..00000000 --- a/feature/home/src/main/java/com/withpeace/withpeace/feature/home/filtersetting/uistate/FilterListUiState.kt +++ /dev/null @@ -1,36 +0,0 @@ -package com.withpeace.withpeace.feature.home.filtersetting.uistate - -import com.withpeace.withpeace.core.ui.policy.ClassificationUiModel -import com.withpeace.withpeace.core.ui.policy.RegionUiModel -import com.withpeace.withpeace.feature.home.uistate.PolicyFiltersUiModel - -data class FilterListUiState( - val isClassificationExpanded: Boolean = false, - val isRegionExpanded: Boolean = false, -) { - private val allClassifications: List = ClassificationUiModel.entries - private val allRegions: List = RegionUiModel.entries - - fun getStateByFilterState(filtersUiModel: PolicyFiltersUiModel): FilterListUiState { - return this.copy( - isClassificationExpanded = allClassifications.indexOf(filtersUiModel.classifications.lastOrNull()) >= FOLDED_CLASSIFICATION_ITEM_COUNT, - isRegionExpanded = allRegions.indexOf(filtersUiModel.regions.lastOrNull()) >= FOLDED_REGION_ITEM_COUNT, - ) - } - - fun getClassifications(): List { - return if (isClassificationExpanded) allClassifications.dropLast(ETC_COUNT) - else allClassifications.subList(0, FOLDED_CLASSIFICATION_ITEM_COUNT) - } - - fun getRegions(): List { - return if (isRegionExpanded) allRegions.dropLast(ETC_COUNT) - else allRegions.subList(0, FOLDED_REGION_ITEM_COUNT) - } - - companion object { - private const val FOLDED_CLASSIFICATION_ITEM_COUNT = 3 - private const val FOLDED_REGION_ITEM_COUNT = 7 - private const val ETC_COUNT = 1 - } -} \ No newline at end of file diff --git a/feature/policylist/src/main/java/com/withpeace/withpeace/feature/policylist/PolicyListScreen.kt b/feature/policylist/src/main/java/com/withpeace/withpeace/feature/policylist/PolicyListScreen.kt index 7e29fddb..c7eeba42 100644 --- a/feature/policylist/src/main/java/com/withpeace/withpeace/feature/policylist/PolicyListScreen.kt +++ b/feature/policylist/src/main/java/com/withpeace/withpeace/feature/policylist/PolicyListScreen.kt @@ -57,9 +57,9 @@ import com.withpeace.withpeace.core.ui.analytics.TrackScreenViewEvent import com.withpeace.withpeace.core.ui.bookmark.BookmarkButton import com.withpeace.withpeace.core.ui.policy.ClassificationUiModel import com.withpeace.withpeace.core.ui.policy.RegionUiModel -import com.withpeace.withpeace.feature.policylist.filtersetting.FilterBottomSheet +import com.withpeace.withpeace.core.ui.policy.filtersetting.FilterBottomSheet import com.withpeace.withpeace.feature.policylist.uistate.PolicyListUiEvent -import com.withpeace.withpeace.feature.policylist.uistate.PolicyFiltersUiModel +import com.withpeace.withpeace.core.ui.policy.filtersetting.PolicyFiltersUiModel import com.withpeace.withpeace.feature.policylist.uistate.YouthPolicyUiModel import kotlinx.coroutines.flow.flowOf import kotlinx.coroutines.launch @@ -457,7 +457,6 @@ private fun YouthPolicyCard( style = WithpeaceTheme.typography.Tag, ) - Image( modifier = modifier .size(57.dp) diff --git a/feature/policylist/src/main/java/com/withpeace/withpeace/feature/policylist/PolicyListViewModel.kt b/feature/policylist/src/main/java/com/withpeace/withpeace/feature/policylist/PolicyListViewModel.kt index 5e4275ff..12bec2da 100644 --- a/feature/policylist/src/main/java/com/withpeace/withpeace/feature/policylist/PolicyListViewModel.kt +++ b/feature/policylist/src/main/java/com/withpeace/withpeace/feature/policylist/PolicyListViewModel.kt @@ -14,10 +14,11 @@ import com.withpeace.withpeace.core.domain.usecase.GetYouthPoliciesUseCase import com.withpeace.withpeace.core.ui.policy.ClassificationUiModel import com.withpeace.withpeace.core.ui.policy.RegionUiModel import com.withpeace.withpeace.core.ui.policy.toDomain +import com.withpeace.withpeace.core.ui.policy.filtersetting.PolicyFiltersUiModel +import com.withpeace.withpeace.core.ui.policy.filtersetting.toDomain +import com.withpeace.withpeace.core.ui.policy.filtersetting.toUiModel import com.withpeace.withpeace.feature.policylist.uistate.PolicyListUiEvent -import com.withpeace.withpeace.feature.policylist.uistate.PolicyFiltersUiModel import com.withpeace.withpeace.feature.policylist.uistate.YouthPolicyUiModel -import com.withpeace.withpeace.feature.policylist.uistate.toDomain import com.withpeace.withpeace.feature.policylist.uistate.toUiModel import dagger.hilt.android.lifecycle.HiltViewModel import kotlinx.coroutines.ExperimentalCoroutinesApi diff --git a/feature/policylist/src/main/java/com/withpeace/withpeace/feature/policylist/filtersetting/FilterBottomSheet.kt b/feature/policylist/src/main/java/com/withpeace/withpeace/feature/policylist/filtersetting/FilterBottomSheet.kt index e5d25e69..7b45d93f 100644 --- a/feature/policylist/src/main/java/com/withpeace/withpeace/feature/policylist/filtersetting/FilterBottomSheet.kt +++ b/feature/policylist/src/main/java/com/withpeace/withpeace/feature/policylist/filtersetting/FilterBottomSheet.kt @@ -1,8 +1,6 @@ package com.withpeace.withpeace.feature.policylist.filtersetting -import androidx.compose.animation.animateContentSize -import androidx.compose.animation.core.Spring -import androidx.compose.animation.core.spring +import androidx.compose.foundation.BorderStroke import androidx.compose.foundation.Image import androidx.compose.foundation.ScrollState import androidx.compose.foundation.background @@ -10,6 +8,8 @@ import androidx.compose.foundation.clickable import androidx.compose.foundation.layout.Arrangement import androidx.compose.foundation.layout.Box import androidx.compose.foundation.layout.Column +import androidx.compose.foundation.layout.ExperimentalLayoutApi +import androidx.compose.foundation.layout.FlowRow import androidx.compose.foundation.layout.PaddingValues import androidx.compose.foundation.layout.Row import androidx.compose.foundation.layout.Spacer @@ -18,11 +18,10 @@ import androidx.compose.foundation.layout.height import androidx.compose.foundation.layout.heightIn import androidx.compose.foundation.layout.padding import androidx.compose.foundation.layout.wrapContentHeight +import androidx.compose.foundation.lazy.LazyRow import androidx.compose.foundation.shape.RoundedCornerShape import androidx.compose.foundation.verticalScroll import androidx.compose.material3.ButtonColors -import androidx.compose.material3.Checkbox -import androidx.compose.material3.CheckboxDefaults import androidx.compose.material3.HorizontalDivider import androidx.compose.material3.Text import androidx.compose.material3.TextButton @@ -31,6 +30,7 @@ import androidx.compose.runtime.mutableStateOf import androidx.compose.runtime.remember import androidx.compose.ui.Alignment import androidx.compose.ui.Modifier +import androidx.compose.ui.graphics.Color import androidx.compose.ui.layout.onSizeChanged import androidx.compose.ui.platform.LocalConfiguration import androidx.compose.ui.platform.LocalDensity @@ -40,8 +40,7 @@ import androidx.compose.ui.unit.dp import com.withpeace.withpeace.core.designsystem.theme.WithpeaceTheme import com.withpeace.withpeace.core.ui.policy.ClassificationUiModel import com.withpeace.withpeace.core.ui.policy.RegionUiModel -import com.withpeace.withpeace.feature.policylist.filtersetting.uistate.FilterListUiState -import com.withpeace.withpeace.feature.policylist.uistate.PolicyFiltersUiModel +import com.withpeace.withpeace.core.ui.policy.filtersetting.PolicyFiltersUiModel import com.withpeace.withpeace.feature.policylist.R @Composable @@ -56,7 +55,14 @@ fun FilterBottomSheet( onCloseFilter: () -> Unit, ) { val filterListUiState = - remember { mutableStateOf(FilterListUiState().getStateByFilterState(selectedFilterUiState)) } + remember { + mutableStateOf( + PolicyFiltersUiModel( + classifications = ClassificationUiModel.entries, + regions = RegionUiModel.entries, + ), + ) + } val configuration = LocalConfiguration.current val screenHeight = configuration.screenHeightDp.dp val footerHeight = remember { mutableStateOf(0.dp) } @@ -90,14 +96,6 @@ fun FilterBottomSheet( selectedFilterUiState = selectedFilterUiState, onClassificationCheckChanged = onClassificationCheckChanged, onRegionCheckChanged = onRegionCheckChanged, - onClassificationMoreViewClick = { - filterListUiState.value = - filterListUiState.value.copy(isClassificationExpanded = !filterListUiState.value.isClassificationExpanded) - }, - onRegionMoreViewClick = { - filterListUiState.value = - filterListUiState.value.copy(isRegionExpanded = !filterListUiState.value.isRegionExpanded) - }, scrollState = scrollState, ) } @@ -133,33 +131,20 @@ private fun FilterHeader(modifier: Modifier, onCloseFilter: () -> Unit) { ) } +@OptIn(ExperimentalLayoutApi::class) @Composable private fun ScrollableFilterSection( modifier: Modifier, - filterListUiState: FilterListUiState, + filterListUiState: PolicyFiltersUiModel, selectedFilterUiState: PolicyFiltersUiModel, onClassificationCheckChanged: (ClassificationUiModel) -> Unit, onRegionCheckChanged: (RegionUiModel) -> Unit, - onClassificationMoreViewClick: () -> Unit, - onRegionMoreViewClick: () -> Unit, scrollState: ScrollState, ) { - val scrollSectionHeight = remember { mutableStateOf(0.dp) } - val localDensity = LocalDensity.current - val columnModifier = modifier.padding(horizontal = 24.dp) - Column( - modifier = - if (scrollSectionHeight.value == 0.dp) columnModifier - .onSizeChanged { - if (!filterListUiState.isRegionExpanded && !filterListUiState.isClassificationExpanded) { - scrollSectionHeight.value = with(localDensity) { it.height.toDp() } - } - } - .verticalScroll(scrollState) - else columnModifier - .height(scrollSectionHeight.value) + modifier = modifier .verticalScroll(scrollState) + .padding(horizontal = 24.dp), ) { Spacer(modifier = modifier.height(16.dp)) Text( @@ -168,58 +153,94 @@ private fun ScrollableFilterSection( color = WithpeaceTheme.colors.SnackbarBlack, ) Spacer(modifier = modifier.height(16.dp)) - Column( - modifier = modifier.animateContentSize( - animationSpec = spring( - dampingRatio = Spring.DampingRatioNoBouncy, - stiffness = Spring.StiffnessMedium, - ), - ), - ) { - filterListUiState.getClassifications().forEach { - Row( - modifier = modifier.fillMaxWidth(), - horizontalArrangement = - Arrangement.SpaceBetween, - verticalAlignment = Alignment.CenterVertically, - ) { - Text( - text = stringResource(id = it.stringResId), - style = WithpeaceTheme.typography.body, - color = WithpeaceTheme.colors.SystemBlack, - ) - Checkbox( - colors = CheckboxDefaults.colors( - checkedColor = WithpeaceTheme.colors.MainPurple, - uncheckedColor = WithpeaceTheme.colors.SystemGray2, - checkmarkColor = WithpeaceTheme.colors.SystemWhite, + LazyRow { + items(3) { + val filterItem = filterListUiState.classifications[it] + if (selectedFilterUiState.classifications.contains(filterItem)) { + TextButton( + colors = ButtonColors( + containerColor = WithpeaceTheme.colors.MainPurple, + contentColor = WithpeaceTheme.colors.SystemWhite, + disabledContainerColor = Color.Transparent, + disabledContentColor = WithpeaceTheme.colors.SystemWhite, ), - checked = selectedFilterUiState.classifications.contains(it), - onCheckedChange = { _ -> onClassificationCheckChanged(it) }, - ) + onClick = { onClassificationCheckChanged(filterItem) }, + modifier = modifier + .padding(end = 8.dp), + ) { + Text( + style = WithpeaceTheme.typography.body, + text = stringResource(id = filterItem.stringResId), + ) + } + } else { + TextButton( + colors = ButtonColors( + containerColor = WithpeaceTheme.colors.SystemWhite, + contentColor = WithpeaceTheme.colors.SystemBlack, + disabledContainerColor = Color.Transparent, + disabledContentColor = WithpeaceTheme.colors.SystemBlack, + ), + onClick = { onClassificationCheckChanged(filterItem) }, + border = BorderStroke( + width = 1.dp, + color = WithpeaceTheme.colors.SystemGray2, + ), + modifier = modifier.padding(end = 8.dp), + ) { + Text( + style = WithpeaceTheme.typography.body, + text = stringResource(id = filterItem.stringResId), + color = WithpeaceTheme.colors.SystemBlack, + ) + } } } } - - Spacer(modifier = Modifier.height(16.dp)) - Row( - modifier = modifier - .fillMaxWidth() - .clickable { - onClassificationMoreViewClick() - }, - horizontalArrangement = Arrangement.Center, - ) { - Text( - text = stringResource(id = if (filterListUiState.isClassificationExpanded) R.string.filter_fold else R.string.filter_expanded), - color = WithpeaceTheme.colors.SystemGray1, - style = WithpeaceTheme.typography.caption, - modifier = modifier.padding(end = 4.dp), - ) - Image( - painterResource(id = if (filterListUiState.isClassificationExpanded) R.drawable.ic_filter_fold else R.drawable.ic_filter_expanded), - contentDescription = stringResource(id = R.string.filter_expanded), - ) + Spacer(modifier = modifier.height(8.dp)) + LazyRow { + items(2) { + val filterItem = filterListUiState.classifications[it + 3] + if (selectedFilterUiState.classifications.contains(filterItem)) { + TextButton( + colors = ButtonColors( + containerColor = WithpeaceTheme.colors.MainPurple, + contentColor = WithpeaceTheme.colors.SystemWhite, + disabledContainerColor = Color.Transparent, + disabledContentColor = WithpeaceTheme.colors.SystemWhite, + ), + onClick = { onClassificationCheckChanged(filterItem) }, + modifier = modifier + .padding(end = 8.dp), + ) { + Text( + style = WithpeaceTheme.typography.body, + text = stringResource(id = filterItem.stringResId), + ) + } + } else { + TextButton( + colors = ButtonColors( + containerColor = WithpeaceTheme.colors.SystemWhite, + contentColor = WithpeaceTheme.colors.SystemBlack, + disabledContainerColor = Color.Transparent, + disabledContentColor = WithpeaceTheme.colors.SystemBlack, + ), + onClick = { onClassificationCheckChanged(filterItem) }, + border = BorderStroke( + width = 1.dp, + color = WithpeaceTheme.colors.SystemGray2, + ), + modifier = modifier.padding(end = 8.dp), + ) { + Text( + style = WithpeaceTheme.typography.body, + text = stringResource(id = filterItem.stringResId), + color = WithpeaceTheme.colors.SystemBlack, + ) + } + } + } } Spacer(modifier = modifier.height(16.dp)) HorizontalDivider( @@ -234,62 +255,50 @@ private fun ScrollableFilterSection( ) Spacer(modifier = modifier.height(16.dp)) - Column( - modifier = modifier.animateContentSize( - animationSpec = spring( - dampingRatio = Spring.DampingRatioNoBouncy, - stiffness = Spring.StiffnessMedium, - ), - ), - ) { - filterListUiState.getRegions().forEach { filterItem -> - Row( - modifier = modifier.fillMaxWidth(), - horizontalArrangement = - Arrangement.SpaceBetween, - verticalAlignment = Alignment.CenterVertically, - ) { - Text( - text = filterItem.name, - style = WithpeaceTheme.typography.body, - color = WithpeaceTheme.colors.SystemBlack, - ) - Checkbox( - colors = CheckboxDefaults.colors( - checkedColor = WithpeaceTheme.colors.MainPurple, - uncheckedColor = WithpeaceTheme.colors.SystemGray2, - checkmarkColor = WithpeaceTheme.colors.SystemWhite, + FlowRow { + filterListUiState.regions.dropLast(1).forEach { filterItem -> + if (selectedFilterUiState.regions.contains(filterItem)) { + TextButton( + colors = ButtonColors( + containerColor = WithpeaceTheme.colors.MainPurple, + contentColor = WithpeaceTheme.colors.SystemWhite, + disabledContainerColor = Color.Transparent, + disabledContentColor = WithpeaceTheme.colors.SystemWhite, + ), + onClick = { onRegionCheckChanged(filterItem) }, + modifier = modifier + .padding(end = 8.dp), + ) { + Text( + style = WithpeaceTheme.typography.body, + text = filterItem.name, + ) + } + } else { + TextButton( + colors = ButtonColors( + containerColor = WithpeaceTheme.colors.SystemWhite, + contentColor = WithpeaceTheme.colors.SystemBlack, + disabledContainerColor = Color.Transparent, + disabledContentColor = WithpeaceTheme.colors.SystemBlack, ), - checked = selectedFilterUiState.regions.contains(filterItem), - onCheckedChange = { onRegionCheckChanged(filterItem) }, - ) + onClick = { onRegionCheckChanged(filterItem) }, + border = BorderStroke( + width = 1.dp, + color = WithpeaceTheme.colors.SystemGray2, + ), + modifier = modifier.padding(end = 8.dp), + ) { + Text( + style = WithpeaceTheme.typography.body, + text = filterItem.name, + color = WithpeaceTheme.colors.SystemBlack, + ) + } } } } - Spacer(modifier = Modifier.height(16.dp)) - Row( - modifier = modifier - .fillMaxWidth() - .clickable { - onRegionMoreViewClick() - }, - horizontalArrangement = Arrangement.Center, - ) { - Text( - text = stringResource( - if (filterListUiState.isRegionExpanded) R.string.filter_fold else R.string.filter_expanded, - ), - color = WithpeaceTheme.colors.SystemGray1, - style = WithpeaceTheme.typography.caption, - modifier = modifier.padding(end = 4.dp), - ) - Image( - painterResource(id = if (filterListUiState.isRegionExpanded) R.drawable.ic_filter_fold else R.drawable.ic_filter_expanded), - contentDescription = stringResource(id = R.string.filter_expanded), - ) - } - Spacer(modifier = Modifier.height(24.dp)) } } diff --git a/feature/home/src/main/java/com/withpeace/withpeace/feature/home/uistate/PolicyFiltersUiModel.kt b/feature/policylist/src/main/java/com/withpeace/withpeace/feature/policylist/filtersetting/PolicyFiltersUiModel.kt similarity index 85% rename from feature/home/src/main/java/com/withpeace/withpeace/feature/home/uistate/PolicyFiltersUiModel.kt rename to feature/policylist/src/main/java/com/withpeace/withpeace/feature/policylist/filtersetting/PolicyFiltersUiModel.kt index 88c35818..d79b7c29 100644 --- a/feature/home/src/main/java/com/withpeace/withpeace/feature/home/uistate/PolicyFiltersUiModel.kt +++ b/feature/policylist/src/main/java/com/withpeace/withpeace/feature/policylist/filtersetting/PolicyFiltersUiModel.kt @@ -1,8 +1,9 @@ -package com.withpeace.withpeace.feature.home.uistate +package com.withpeace.withpeace.feature.policylist.filtersetting import com.withpeace.withpeace.core.domain.model.policy.PolicyFilters import com.withpeace.withpeace.core.ui.policy.ClassificationUiModel import com.withpeace.withpeace.core.ui.policy.RegionUiModel +import com.withpeace.withpeace.core.ui.policy.filtersetting.PolicyFiltersUiModel import com.withpeace.withpeace.core.ui.policy.toDomain import com.withpeace.withpeace.core.ui.policy.toUiModel diff --git a/feature/policylist/src/main/java/com/withpeace/withpeace/feature/policylist/filtersetting/uistate/FilterListUiState.kt b/feature/policylist/src/main/java/com/withpeace/withpeace/feature/policylist/filtersetting/uistate/FilterListUiState.kt deleted file mode 100644 index 4598fa13..00000000 --- a/feature/policylist/src/main/java/com/withpeace/withpeace/feature/policylist/filtersetting/uistate/FilterListUiState.kt +++ /dev/null @@ -1,36 +0,0 @@ -package com.withpeace.withpeace.feature.policylist.filtersetting.uistate - -import com.withpeace.withpeace.core.ui.policy.ClassificationUiModel -import com.withpeace.withpeace.core.ui.policy.RegionUiModel -import com.withpeace.withpeace.feature.policylist.uistate.PolicyFiltersUiModel - -data class FilterListUiState( - val isClassificationExpanded: Boolean = false, - val isRegionExpanded: Boolean = false, -) { - private val allClassifications: List = ClassificationUiModel.entries - private val allRegions: List = RegionUiModel.entries - - fun getStateByFilterState(filtersUiModel: PolicyFiltersUiModel): FilterListUiState { - return this.copy( - isClassificationExpanded = allClassifications.indexOf(filtersUiModel.classifications.lastOrNull()) >= FOLDED_CLASSIFICATION_ITEM_COUNT, - isRegionExpanded = allRegions.indexOf(filtersUiModel.regions.lastOrNull()) >= FOLDED_REGION_ITEM_COUNT, - ) - } - - fun getClassifications(): List { - return if (isClassificationExpanded) allClassifications.dropLast(ETC_COUNT) - else allClassifications.subList(0, FOLDED_CLASSIFICATION_ITEM_COUNT) - } - - fun getRegions(): List { - return if (isRegionExpanded) allRegions.dropLast(ETC_COUNT) - else allRegions.subList(0, FOLDED_REGION_ITEM_COUNT) - } - - companion object { - private const val FOLDED_CLASSIFICATION_ITEM_COUNT = 3 - private const val FOLDED_REGION_ITEM_COUNT = 7 - private const val ETC_COUNT = 1 - } -} \ No newline at end of file