Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[mod] 필터뷰 슈정 #221

Merged
merged 18 commits into from
Feb 14, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
18 commits
Select commit Hold shift + click to select a range
cebc374
[chore] #218 필터뷰 UX Writing 수정 사항 반영 (strings.xml)
jihyunniiii Jan 31, 2024
532c91b
[chore] #218 필터뷰 UX Writing 수정 사항 반영 (Type)
jihyunniiii Jan 31, 2024
f6c330a
[chore] #218 필터뷰 UX Writing 수정 사항 반영 (strings.xml)
jihyunniiii Feb 1, 2024
4a04a48
[chore] #218 필터뷰 xml 수정
jihyunniiii Feb 1, 2024
8f5aa8d
[chore] #218 네이밍 수정
jihyunniiii Feb 1, 2024
c1e2e68
[chore] #218 건너뛰기 위치 변경
jihyunniiii Feb 1, 2024
16e2169
[chore] #218 네이밍 변경
jihyunniiii Feb 2, 2024
a7889dd
[mod] #218 성분공개 필터 중복선택 -> 단일선택 변경
jihyunniiii Feb 2, 2024
e95064a
[chore] #218 BreadFilterType에 id 추가
jihyunniiii Feb 3, 2024
ed1d8c3
[chore] #218 NutrientFilterType에 id 추가
jihyunniiii Feb 3, 2024
31488ba
[chore] #218 breadTypeList를 내려주도록 수정
jihyunniiii Feb 3, 2024
acd3c8e
[chore] #218 회원 필터 정보 변경하기 DTO 수정
jihyunniiii Feb 3, 2024
c8bcfa8
[chore] #218 NutrientFilterType 네이밍 변경
jihyunniiii Feb 4, 2024
58028ed
[mod] #218 필터 관련 Amplitude 수정 사항 반영 및 로직 변경
jihyunniiii Feb 5, 2024
e06d3c0
[chore] #218 유저 필터칩 조회 API 변경사항 반영 (response List 형태로 변경)
jihyunniiii Feb 5, 2024
ec2f607
[chore] #218 RequestSettingFilter DTO 수정
jihyunniiii Feb 5, 2024
7ce74e0
[chore] #218 ktlintFormat
jihyunniiii Feb 5, 2024
6336c2b
Merge branch 'develop' into mod-filter-view
jihyunniiii Feb 14, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -5,21 +5,6 @@ import kotlinx.serialization.Serializable
@Serializable
data class RequestSettingFilter(
val mainPurpose: String,
val breadType: BreadType,
val nutrientType: NutrientType
) {
@Serializable
data class BreadType(
val isGlutenFree: Boolean,
val isVegan: Boolean,
val isNutFree: Boolean,
val isSugarFree: Boolean,
)

@Serializable
data class NutrientType(
val isNutrientOpen: Boolean,
val isIngredientOpen: Boolean,
val isNotOpen: Boolean,
)
}
val breadTypeList: List<Int>,
val nutrientTypeList: List<Int>
)
Original file line number Diff line number Diff line change
Expand Up @@ -11,29 +11,20 @@ data class ResponseGetUserFilter(
) {
@Serializable
data class Data(
val breadType: BreadType,
val breadTypeList: List<BreadTypeId>,
val mainPurpose: String,
val memberId: Int,
val nickname: String,
val nutrientType: NutrientType
val nutrientTypeList: List<NutrientTypeId>
) {
@Serializable
data class BreadType(
val breadTypeId: Int,
val breadTypeName: String,
val isGlutenFree: Boolean,
val isNutFree: Boolean,
val isSugarFree: Boolean,
val isVegan: Boolean
data class BreadTypeId(
val breadTypeId: Int
)

@Serializable
data class NutrientType(
val isIngredientOpen: Boolean,
val isNotOpen: Boolean,
val isNutrientOpen: Boolean,
val nutrientTypeId: Int,
val nutrientTypeName: String
data class NutrientTypeId(
val nutrientTypeId: Int
)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,44 +11,30 @@ data class ResponseSettingFilter(
) {
@Serializable
data class Data(
val breadType: BreadType,
val breadTypeList: List<BreadTypeId>,
val mainPurpose: String,
val memberId: Int,
val nickname: String,
val nutrientType: NutrientType
val nutrientTypeList: List<NutrientTypeId>
)

@Serializable
data class BreadType(
val breadTypeId: Int,
val breadTypeName: String,
val isGlutenFree: Boolean,
val isNutFree: Boolean,
val isSugarFree: Boolean,
val isVegan: Boolean
data class BreadTypeId(
val breadTypeId: Int
)

@Serializable
data class NutrientType(
val isIngredientOpen: Boolean,
val isNotOpen: Boolean,
val isNutrientOpen: Boolean,
val nutrientTypeId: Int,
val nutrientTypeName: String
data class NutrientTypeId(
val nutrientTypeId: Int
)

fun toSelectedFilter() = SelectedFilter(
mainPurpose = data.mainPurpose,
breadType = SelectedFilter.BreadType(
isGlutenFree = data.breadType.isGlutenFree,
isVegan = data.breadType.isVegan,
isNutFree = data.breadType.isNutFree,
isSugarFree = data.breadType.isSugarFree
),
nutrientType = SelectedFilter.NutrientType(
isIngredientOpen = data.nutrientType.isIngredientOpen,
isNotOpen = data.nutrientType.isNotOpen,
isNutrientOpen = data.nutrientType.isNutrientOpen
)
breadTypeList = data.breadTypeList.map { breadType -> SelectedFilter.BreadTypeId(breadTypeId = breadType.breadTypeId) },
nutrientTypeList = data.nutrientTypeList.map { nutrientType ->
SelectedFilter.NutrientTypeId(
nutrientTypeId = nutrientType.nutrientTypeId
)
}
)
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,14 @@ package com.sopt.geonppang.domain.model

data class SelectedFilter(
val mainPurpose: String,
val breadType: BreadType,
val nutrientType: NutrientType
val breadTypeList: List<BreadTypeId>,
val nutrientTypeList: List<NutrientTypeId>
) {
data class BreadType(
val isGlutenFree: Boolean,
val isVegan: Boolean,
val isNutFree: Boolean,
val isSugarFree: Boolean,
data class BreadTypeId(
val breadTypeId: Int
)

data class NutrientType(
val isIngredientOpen: Boolean,
val isNotOpen: Boolean,
val isNutrientOpen: Boolean
data class NutrientTypeId(
val nutrientTypeId: Int
)
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,7 @@ import com.sopt.geonppang.R
import com.sopt.geonppang.databinding.ActivityFilterBinding
import com.sopt.geonppang.presentation.MainActivity
import com.sopt.geonppang.presentation.model.AmplitudeFilterSettingInfo
import com.sopt.geonppang.presentation.type.BreadFilterType
import com.sopt.geonppang.presentation.type.FilterInfoType
import com.sopt.geonppang.presentation.type.NutrientFilterType
import com.sopt.geonppang.util.AmplitudeUtils
import com.sopt.geonppang.util.UiState
import com.sopt.geonppang.util.binding.BindingActivity
Expand Down Expand Up @@ -197,14 +195,16 @@ class FilterSettingActivity : BindingActivity<ActivityFilterBinding>(R.layout.ac
property: UiState.Success<AmplitudeFilterSettingInfo>
) {
property.data.mainPurposeType?.let { mainPurposeType ->
AmplitudeUtils.trackEventWithMapProperties(
eventName,
mapOf(
MAIN_PURPOSE to mainPurposeType,
BREAD_TYPE to getStringBreadType(property.data.breadType),
INGREDIENTS_TYPE to getStringIngredientType(property.data.ingredientType)
property.data.ingredientType?.let { ingredientType ->
AmplitudeUtils.trackEventWithMapProperties(
eventName,
mapOf(
MAIN_PURPOSE to mainPurposeType,
BREAD_TYPE to property.data.breadType,
INGREDIENTS_TYPE to ingredientType
)
)
)
}
}
}

Expand All @@ -226,14 +226,6 @@ class FilterSettingActivity : BindingActivity<ActivityFilterBinding>(R.layout.ac
}
}

private fun getStringBreadType(breadType: Map<BreadFilterType, Boolean>): List<String> {
return breadType.entries.filter { it.value }.map { it.key.name }
}

private fun getStringIngredientType(ingredientType: Map<NutrientFilterType, Boolean>): List<String> {
return ingredientType.entries.filter { it.value }.map { it.key.name }
}

companion object {
const val FILTER_INFO = "filterInfo"
const val MY_PAGE_FRAGMENT = "MyPageFragment"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import com.sopt.geonppang.domain.repository.FilterSettingRepository
import com.sopt.geonppang.presentation.model.AmplitudeFilterSettingInfo
import com.sopt.geonppang.presentation.type.BreadFilterType
import com.sopt.geonppang.presentation.type.FilterInfoType
import com.sopt.geonppang.presentation.type.MainPurposeType
import com.sopt.geonppang.presentation.type.MainPurposeFilterType
import com.sopt.geonppang.presentation.type.NutrientFilterType
import com.sopt.geonppang.presentation.type.UserRoleType
import com.sopt.geonppang.util.UiState
Expand All @@ -34,33 +34,21 @@ class FilterSettingViewModel @Inject constructor(
val previousActivity get() = _previousActivity.asStateFlow()
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

지금 보니 flow가 정말 많이 사용됐다는 느낌이 드는거 같아욤 flow를 유사한 거 까리 뭉텅이로 같이 사용하는 방식으로 해도 좋을 거 같습니당

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

고민해보겠습니다요,,,

private val _currentPage = MutableStateFlow<Int?>(null)
val currentPage get() = _currentPage.asStateFlow()
private val _mainPurposeType = MutableStateFlow<MainPurposeType?>(null)
private val _mainPurposeType = MutableStateFlow<MainPurposeFilterType?>(null)
val mainPurposeType get() = _mainPurposeType.asStateFlow()
val breadFilterType: MutableStateFlow<Map<BreadFilterType, Boolean>> = MutableStateFlow(
mapOf(
BreadFilterType.GLUTENFREE to false,
BreadFilterType.VEGAN to false,
BreadFilterType.NUTFREE to false,
BreadFilterType.SUGARFREE to false
)
)
val nutrientFilterType: MutableStateFlow<Map<NutrientFilterType, Boolean>> = MutableStateFlow(
mapOf(
NutrientFilterType.NUTRIENT to false,
NutrientFilterType.INGREDIENT to false,
NutrientFilterType.NOT to false
)
)
val breadFilterTypeList: MutableStateFlow<List<Int>> = MutableStateFlow(emptyList())
private val _nutrientFilterType = MutableStateFlow<NutrientFilterType?>(null)
val nutrientFilterType get() = _nutrientFilterType.asStateFlow()
val isFilterBtnEnabled: StateFlow<Boolean> = combine(
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

combine을 사용하지 않고 이를 해결할 수 있는 방법은 없는지 알아봐도 좋을 거 같아영

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

여러 개의 flow를 한 번에 관찰해야 하는 경우에 combine, zip, merge 등등 여러 방법을 사용할 수 있지만, 지금처럼 여러 개의 flow를 관찰하고 결과를 내야 하는 경우에는 combine을 사용하는 방법이 제일 적합할 것 같다는 생각이 듭니다요,,! 다른 좋은 방법이 있을까염?

currentPage,
mainPurposeType,
breadFilterType,
breadFilterTypeList,
nutrientFilterType
) { currentPage, mainPurposeType, breadFilterType, nutrientFilterType ->
when (currentPage) {
0 -> mainPurposeType != null
1 -> breadFilterType.any { it.value }
2 -> nutrientFilterType.any { it.value }
1 -> breadFilterType.isNotEmpty()
2 -> nutrientFilterType != null
else -> false
}
}.stateIn(viewModelScope, SharingStarted.WhileSubscribed(), false)
Expand All @@ -75,52 +63,42 @@ class FilterSettingViewModel @Inject constructor(
_currentPage.value = position
}

fun setMainPurposeType(mainPurposeType: MainPurposeType) {
fun setMainPurposeType(mainPurposeType: MainPurposeFilterType) {
_mainPurposeType.value = mainPurposeType
}

fun setBreadFilterType(breadType: BreadFilterType) {
val isSelected = breadFilterType.value[breadType] ?: return
breadFilterType.value = breadFilterType.value.toMutableMap().apply {
this[breadType] = !isSelected
breadFilterTypeList.value = breadFilterTypeList.value.toMutableList().apply {
if (!remove(breadType.id)) add(breadType.id)
sort()
}
}

fun setNutrientFilterType(nutrientType: NutrientFilterType) {
val isSelected = nutrientFilterType.value[nutrientType] ?: return
nutrientFilterType.value = nutrientFilterType.value.toMutableMap().apply {
this[nutrientType] = !isSelected
}
_nutrientFilterType.value = nutrientType
}

fun setUserFilter() {
viewModelScope.launch {
_mainPurposeType.value?.let {
RequestSettingFilter(
it.name,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

지금보니 이게 뭐람

RequestSettingFilter.BreadType(
breadFilterType.value[BreadFilterType.GLUTENFREE] == true,
breadFilterType.value[BreadFilterType.VEGAN] == true,
breadFilterType.value[BreadFilterType.NUTFREE] == true,
breadFilterType.value[BreadFilterType.SUGARFREE] == true,
),
RequestSettingFilter.NutrientType(
nutrientFilterType.value[NutrientFilterType.NUTRIENT] == true,
nutrientFilterType.value[NutrientFilterType.INGREDIENT] == true,
nutrientFilterType.value[NutrientFilterType.NOT] == true,
_mainPurposeType.value?.let { mainPurposeFilterType ->
_nutrientFilterType.value?.let { nutrientFilterType ->
RequestSettingFilter(
mainPurpose = mainPurposeFilterType.name,
breadTypeList = breadFilterTypeList.value,
nutrientTypeList = listOf(nutrientFilterType.id)
)
)
}?.let {
filterRepository.setUserFilter(
it
)
// 필터를 선택한 경우
}
}?.let { requestSettingFilter ->
filterRepository.setUserFilter(requestSettingFilter)
.onSuccess {
_selectedFilterState.value = UiState.Success(
AmplitudeFilterSettingInfo(
mainPurposeType = _mainPurposeType.value,
breadType = breadFilterType.value,
ingredientType = nutrientFilterType.value,
breadType = breadFilterTypeList.value.mapNotNull { breadFilterTypeId ->
BreadFilterType.values()
.find { it.id == breadFilterTypeId }?.name
},
ingredientType = _nutrientFilterType.value,
)
)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ class FilterViewPagerAdapter(fragmentActivity: FragmentActivity) :
FragmentStateAdapter(fragmentActivity) {

private val filterFragments =
listOf(MainPurposeFilterFragment(), BreadTypeFilterFragment(), NutrientTypeFilterFragment())
listOf(MainPurposeTypeFilterFragment(), BreadTypeFilterFragment(), NutrientTypeFilterFragment())

override fun getItemCount(): Int = filterFragments.size

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,14 @@ import android.os.Bundle
import android.view.View
import androidx.fragment.app.activityViewModels
import com.sopt.geonppang.R
import com.sopt.geonppang.databinding.FragmentMainPurposeFilterBinding
import com.sopt.geonppang.databinding.FragmentMainPurposeTypeFilterBinding
import com.sopt.geonppang.presentation.MainActivity
import com.sopt.geonppang.util.AmplitudeUtils
import com.sopt.geonppang.util.binding.BindingFragment
import com.sopt.geonppang.util.extension.setOnSingleClickListener

class MainPurposeFilterFragment :
BindingFragment<FragmentMainPurposeFilterBinding>(R.layout.fragment_main_purpose_filter) {
class MainPurposeTypeFilterFragment :
BindingFragment<FragmentMainPurposeTypeFilterBinding>(R.layout.fragment_main_purpose_type_filter) {
private val viewModel: FilterSettingViewModel by activityViewModels()

override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
Expand All @@ -25,11 +25,11 @@ class MainPurposeFilterFragment :
}

private fun addListeners() {
binding.layoutMainPurposeSkip.setOnClickListener {
binding.layoutMainPurposeTypeFilterSkip.setOnClickListener {
moveToMain()
}

binding.tvMainPurposeSkip.setOnSingleClickListener {
binding.tvMainPurposeTypeFilterSkip.setOnSingleClickListener {
AmplitudeUtils.trackEvent(CLICK_SKIP)
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
package com.sopt.geonppang.presentation.model

import com.sopt.geonppang.presentation.type.BreadFilterType
import com.sopt.geonppang.presentation.type.MainPurposeType
import com.sopt.geonppang.presentation.type.MainPurposeFilterType
import com.sopt.geonppang.presentation.type.NutrientFilterType

data class AmplitudeFilterSettingInfo(
val mainPurposeType: MainPurposeType?,
val breadType: Map<BreadFilterType, Boolean>,
val ingredientType: Map<NutrientFilterType, Boolean>
val mainPurposeType: MainPurposeFilterType?,
val breadType: List<String>,
val ingredientType: NutrientFilterType?
)
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import com.sopt.geonppang.domain.model.Bakery
import com.sopt.geonppang.domain.model.MyReview
import com.sopt.geonppang.domain.model.Profile
import com.sopt.geonppang.domain.repository.MyPageRepository
import com.sopt.geonppang.presentation.type.MainPurposeType
import com.sopt.geonppang.presentation.type.MainPurposeFilterType
import com.sopt.geonppang.util.UiState
import dagger.hilt.android.lifecycle.HiltViewModel
import kotlinx.coroutines.flow.MutableStateFlow
Expand Down Expand Up @@ -67,9 +67,9 @@ class MyPageViewModel @Inject constructor(

fun setMainPurposeTitle(): Int? {
return when (profileInfo.value?.mainPurpose) {
MainPurposeType.DIET.name -> MainPurposeType.DIET.titleRes
MainPurposeType.HEALTH.name -> MainPurposeType.HEALTH.titleRes
MainPurposeType.VEGAN.name -> MainPurposeType.VEGAN.titleRes
MainPurposeFilterType.DIET.name -> MainPurposeFilterType.DIET.titleRes
MainPurposeFilterType.HEALTH.name -> MainPurposeFilterType.HEALTH.titleRes
MainPurposeFilterType.VEGAN.name -> MainPurposeFilterType.VEGAN.titleRes
else -> null
}
}
Expand Down
Loading
Loading