Skip to content

Commit

Permalink
Merge pull request #221 from GEON-PPANG/mod-filter-view
Browse files Browse the repository at this point in the history
[mod] 필터뷰 슈정
  • Loading branch information
jihyunniiii authored Feb 14, 2024
2 parents 895ddb7 + 6336c2b commit 295649c
Show file tree
Hide file tree
Showing 21 changed files with 305 additions and 340 deletions.
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()
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(
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,
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

0 comments on commit 295649c

Please sign in to comment.