From 8a97162cf82cd5e8fbfd3b7ef02f48d0033882d2 Mon Sep 17 00:00:00 2001 From: juhwankim-dev Date: Fri, 13 Jan 2023 06:11:04 +0900 Subject: [PATCH] =?UTF-8?q?feature:=20=EC=8A=B5=EA=B4=80=EA=B3=BC=20?= =?UTF-8?q?=EC=A7=9D=EA=BF=8D=20=EC=9C=A0=EB=AC=B4=EC=97=90=20=EB=94=B0?= =?UTF-8?q?=EB=9D=BC=20=EB=AF=B9=EC=8A=A4=ED=8C=A8=EB=84=90=EC=9D=84=20?= =?UTF-8?q?=EB=B3=B4=EB=82=B4=EC=A3=BC=EB=8A=94=20=EC=9C=84=EC=B9=98=20?= =?UTF-8?q?=EB=B3=80=EA=B2=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../threedays/home/home/HomeFragment.kt | 20 ++---------- .../threedays/home/home/HomeViewModel.kt | 32 +++++++++++++++---- .../depromeet/threedays/mate/MateFragment.kt | 19 ----------- .../depromeet/threedays/mate/MateViewModel.kt | 22 ++++++++++++- 4 files changed, 49 insertions(+), 44 deletions(-) diff --git a/presentation/home/src/main/java/com/depromeet/threedays/home/home/HomeFragment.kt b/presentation/home/src/main/java/com/depromeet/threedays/home/home/HomeFragment.kt index 69925311..a88ec1ea 100644 --- a/presentation/home/src/main/java/com/depromeet/threedays/home/home/HomeFragment.kt +++ b/presentation/home/src/main/java/com/depromeet/threedays/home/home/HomeFragment.kt @@ -60,9 +60,9 @@ class HomeFragment : BaseFragment(R.layout.f private val addResultLauncher = registerForActivityResult(ActivityResultContracts.StartActivityForResult()) { result -> when(result.resultCode) { - RESULT_CREATE -> viewModel.fetchGoals() + RESULT_CREATE -> viewModel.fetchHabits() RESULT_UPDATE -> { - viewModel.fetchGoals() + viewModel.fetchHabits() ThreeDaysToast().show( requireContext(), resources.getString(com.depromeet.threedays.core.R.string.toast_habit_modify_complete) @@ -251,22 +251,6 @@ class HomeFragment : BaseFragment(R.layout.f viewLifecycleOwner.repeatOnLifecycle(Lifecycle.State.STARTED) { launch { viewModel.habits.collect { list -> - if (list.isEmpty()) { - AnalyticsUtil.event( - name = ThreeDaysEvent.HomeDefaultViewed.toString(), - properties = mapOf( - MixPanelEvent.ScreenName to Screen.HomeDefault.toString() - ) - ) - } else { - AnalyticsUtil.event( - name = ThreeDaysEvent.HomeActivatedViewed.toString(), - properties = mapOf( - MixPanelEvent.ScreenName to Screen.HomeActivated.toString() - ) - ) - } - habitAdapter.submitList(list.sortedBy { it.createAt }) binding.clNoGoal.visibility = if (list.isEmpty()) View.VISIBLE else View.GONE diff --git a/presentation/home/src/main/java/com/depromeet/threedays/home/home/HomeViewModel.kt b/presentation/home/src/main/java/com/depromeet/threedays/home/home/HomeViewModel.kt index 686aaef4..505b97f6 100644 --- a/presentation/home/src/main/java/com/depromeet/threedays/home/home/HomeViewModel.kt +++ b/presentation/home/src/main/java/com/depromeet/threedays/home/home/HomeViewModel.kt @@ -2,6 +2,10 @@ package com.depromeet.threedays.home.home import androidx.lifecycle.viewModelScope import com.depromeet.threedays.core.BaseViewModel +import com.depromeet.threedays.core.analytics.AnalyticsUtil +import com.depromeet.threedays.core.analytics.MixPanelEvent +import com.depromeet.threedays.core.analytics.Screen +import com.depromeet.threedays.core.analytics.ThreeDaysEvent import com.depromeet.threedays.domain.entity.OnboardingType import com.depromeet.threedays.domain.entity.Status import com.depromeet.threedays.domain.usecase.DeleteHabitUseCase @@ -42,7 +46,7 @@ class HomeViewModel @Inject constructor( get() = _uiEffect init { - fetchGoals() + fetchHabits() checkIsFirstVisitor() } @@ -63,7 +67,7 @@ class HomeViewModel @Inject constructor( } } - fun fetchGoals() { + fun fetchHabits() { viewModelScope.launch { getActiveHabitsUseCase().collect { response -> when(response.status) { @@ -71,7 +75,23 @@ class HomeViewModel @Inject constructor( } Status.SUCCESS -> { - _habits.value = response.data!!.map { it.toHabitUI() } + val habits = response.data!! + _habits.value = habits.map { it.toHabitUI() } + if (habits.isEmpty()) { + AnalyticsUtil.event( + name = ThreeDaysEvent.HomeDefaultViewed.toString(), + properties = mapOf( + MixPanelEvent.ScreenName to Screen.HomeDefault.toString() + ) + ) + } else { + AnalyticsUtil.event( + name = ThreeDaysEvent.HomeActivatedViewed.toString(), + properties = mapOf( + MixPanelEvent.ScreenName to Screen.HomeActivated.toString() + ) + ) + } } Status.ERROR -> { @@ -92,7 +112,7 @@ class HomeViewModel @Inject constructor( } Status.SUCCESS -> { - fetchGoals() + fetchHabits() checkNewClap(habitUI) } Status.ERROR -> { @@ -117,7 +137,7 @@ class HomeViewModel @Inject constructor( } Status.SUCCESS -> { - fetchGoals() + fetchHabits() } Status.ERROR -> { @@ -192,7 +212,7 @@ class HomeViewModel @Inject constructor( } Status.SUCCESS -> { onSuccessDeleteHabit(habitType) - fetchGoals() + fetchHabits() } Status.ERROR -> { diff --git a/presentation/mate/src/main/java/com/depromeet/threedays/mate/MateFragment.kt b/presentation/mate/src/main/java/com/depromeet/threedays/mate/MateFragment.kt index 2dbdfb54..a89978f9 100644 --- a/presentation/mate/src/main/java/com/depromeet/threedays/mate/MateFragment.kt +++ b/presentation/mate/src/main/java/com/depromeet/threedays/mate/MateFragment.kt @@ -209,7 +209,6 @@ class MateFragment: BaseFragment(R.layout.fr if (it.isMateInitialized) { if( (it.hasMate && it.isHabitInitialized) || !it.hasMate) { binding.progressMate.gone() - sendEvent(it.hasMate) showMateOrDefaultView( hasMate = it.hasMate, backgroundResColor = it.backgroundResColor @@ -341,24 +340,6 @@ class MateFragment: BaseFragment(R.layout.fr ) } - private fun sendEvent(hasMate: Boolean) { - if(hasMate) { - AnalyticsUtil.event( - name = ThreeDaysEvent.MateHomeViewed.toString(), - properties = mapOf( - MixPanelEvent.ScreenName to Screen.MateHome.toString(), - ) - ) - } else { - AnalyticsUtil.event( - name = ThreeDaysEvent.MateDefaultViewed.toString(), - properties = mapOf( - MixPanelEvent.ScreenName to Screen.MateDefault.toString(), - ) - ) - } - } - override fun onStop() { super.onStop() diff --git a/presentation/mate/src/main/java/com/depromeet/threedays/mate/MateViewModel.kt b/presentation/mate/src/main/java/com/depromeet/threedays/mate/MateViewModel.kt index f6661449..7f1cc2bb 100644 --- a/presentation/mate/src/main/java/com/depromeet/threedays/mate/MateViewModel.kt +++ b/presentation/mate/src/main/java/com/depromeet/threedays/mate/MateViewModel.kt @@ -2,6 +2,10 @@ package com.depromeet.threedays.mate import androidx.lifecycle.viewModelScope import com.depromeet.threedays.core.BaseViewModel +import com.depromeet.threedays.core.analytics.AnalyticsUtil +import com.depromeet.threedays.core.analytics.MixPanelEvent +import com.depromeet.threedays.core.analytics.Screen +import com.depromeet.threedays.core.analytics.ThreeDaysEvent import com.depromeet.threedays.domain.entity.Color import com.depromeet.threedays.domain.entity.OnboardingType import com.depromeet.threedays.domain.entity.Status @@ -58,7 +62,7 @@ class MateViewModel @Inject constructor( val myMate = response.data!!.find { it.status == "ACTIVE" } _uiState.update { it.copy( - mate = myMate?.toMateUI() , + mate = myMate?.toMateUI(), hasMate = myMate != null, backgroundResColor = if(myMate == null) { core_design.color.white @@ -72,6 +76,22 @@ class MateViewModel @Inject constructor( fetchHabit(it.habitId) } checkMateAchieveMaxLevel(uiState.value.mate) + + if (myMate == null) { + AnalyticsUtil.event( + name = ThreeDaysEvent.MateDefaultViewed.toString(), + properties = mapOf( + MixPanelEvent.ScreenName to Screen.MateDefault.toString(), + ) + ) + } else { + AnalyticsUtil.event( + name = ThreeDaysEvent.MateHomeViewed.toString(), + properties = mapOf( + MixPanelEvent.ScreenName to Screen.MateHome.toString(), + ) + ) + } } Status.ERROR -> {