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

feature: 습관과 짝꿍 유무에 따라 믹스패널을 보내주는 위치 변경 #200

Merged
merged 1 commit into from
Jan 12, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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 @@ -60,9 +60,9 @@ class HomeFragment : BaseFragment<FragmentHomeBinding, HomeViewModel>(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)
Expand Down Expand Up @@ -251,22 +251,6 @@ class HomeFragment : BaseFragment<FragmentHomeBinding, HomeViewModel>(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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -42,7 +46,7 @@ class HomeViewModel @Inject constructor(
get() = _uiEffect

init {
fetchGoals()
fetchHabits()
checkIsFirstVisitor()
}

Expand All @@ -63,15 +67,31 @@ class HomeViewModel @Inject constructor(
}
}

fun fetchGoals() {
fun fetchHabits() {
viewModelScope.launch {
getActiveHabitsUseCase().collect { response ->
when(response.status) {
Status.LOADING -> {

}
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 -> {

Expand All @@ -92,7 +112,7 @@ class HomeViewModel @Inject constructor(

}
Status.SUCCESS -> {
fetchGoals()
fetchHabits()
checkNewClap(habitUI)
}
Status.ERROR -> {
Expand All @@ -117,7 +137,7 @@ class HomeViewModel @Inject constructor(

}
Status.SUCCESS -> {
fetchGoals()
fetchHabits()
}
Status.ERROR -> {

Expand Down Expand Up @@ -192,7 +212,7 @@ class HomeViewModel @Inject constructor(
}
Status.SUCCESS -> {
onSuccessDeleteHabit(habitType)
fetchGoals()
fetchHabits()
}
Status.ERROR -> {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -209,7 +209,6 @@ class MateFragment: BaseFragment<FragmentMateBinding, MateViewModel>(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
Expand Down Expand Up @@ -341,24 +340,6 @@ class MateFragment: BaseFragment<FragmentMateBinding, MateViewModel>(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()

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand All @@ -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 -> {

Expand Down