Skip to content

Commit

Permalink
Merge pull request #303 from team-yello/add/#301-onboarding-highschoo…
Browse files Browse the repository at this point in the history
…l-amplitude

[ADD/#301] OnBoarding / 학력 선택, 고등학교 Amplitude, User Properties 추가 & flowWithLifecycle 적용
  • Loading branch information
minju1459 authored Oct 18, 2023
2 parents a85ba96 + f113cff commit 21791d4
Show file tree
Hide file tree
Showing 17 changed files with 177 additions and 66 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,10 @@ class GetAlarmActivity :
private val requestPermissionLauncher =
registerForActivityResult(ActivityResultContracts.RequestPermission()) { isGranted: Boolean ->
if (isGranted) {
AmplitudeUtils.updateUserProperties("user_pushnotification", "enabled")
AmplitudeUtils.updateUserProperties(EVENT_PUSH_NOTIFICATION, VALUE_ENABLED)
startTutorialActivity()
} else {
AmplitudeUtils.updateUserProperties("user_pushnotification", "disabled")
AmplitudeUtils.updateUserProperties(EVENT_PUSH_NOTIFICATION, VALUE_DISABLED)
startTutorialActivity()
}
}
Expand All @@ -50,7 +50,7 @@ class GetAlarmActivity :

private fun askNotificationPermission() {
binding.btnStartYello.setOnSingleClickListener {
AmplitudeUtils.trackEventWithProperties("click_onboarding_notification")
AmplitudeUtils.trackEventWithProperties(EVENT_CLICK_ONBOARDING_NOTIFICATION)
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.TIRAMISU) {
if (ContextCompat.checkSelfPermission(
this,
Expand Down Expand Up @@ -81,5 +81,9 @@ class GetAlarmActivity :
putExtra("isFromOnBoarding", isFromOnBoarding)
}
private const val NONE_ANIMATION = 0
private const val EVENT_PUSH_NOTIFICATION = "user_pushnotification"
private const val VALUE_ENABLED = "enabled"
private const val VALUE_DISABLED = "disabled"
private const val EVENT_CLICK_ONBOARDING_NOTIFICATION = "click_onboarding_notification"
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ class OnBoardingViewModel @Inject constructor(
val studentType = MutableLiveData("")
val university: String get() = universityText.value?.trim() ?: ""
val universityText = MutableLiveData("")
private val highSchool: String get() = highSchoolText.value?.trim() ?: ""
val highSchool: String get() = highSchoolText.value?.trim() ?: ""
val highSchoolText = MutableLiveData("")

val departmentText = MutableLiveData("")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,8 +62,8 @@ class AddFriendFragment : BindingFragment<FragmentAddFriendBinding>(R.layout.fra
private fun setConfirmBtnClickListener() {
binding.btnAddFriendNext.setOnSingleClickListener {
AmplitudeUtils.trackEventWithProperties(
"click_onboarding_next",
JSONObject().put("onboard_view", "friends"),
EVENT_CLICK_ONBOARDING_NEXT,
JSONObject().put(NAME_ONBOARD_VIEW, VALUE_FRIENDS),
)
val activity = requireActivity() as OnBoardingActivity
activity.progressBarPlus()
Expand All @@ -78,6 +78,7 @@ class AddFriendFragment : BindingFragment<FragmentAddFriendBinding>(R.layout.fra
viewModel.initFriendPagingVariable()
viewModel.addListWithKakaoIdList()
}

private fun setInfinityScroll() {
binding.rvFriendList.addOnScrollListener(object : RecyclerView.OnScrollListener() {
override fun onScrolled(recyclerView: RecyclerView, dx: Int, dy: Int) {
Expand Down Expand Up @@ -108,13 +109,16 @@ class AddFriendFragment : BindingFragment<FragmentAddFriendBinding>(R.layout.fra
selectedItemIdList.addAll(friendsList.map { friend -> friend.id })
viewModel.selectedFriendCount.value = friendsList.size
}

is UiState.Failure -> {
stopShimmerView()
yelloSnackbar(binding.root, getString(R.string.onboarding_add_friend_error))
}

is UiState.Loading -> {
startShimmerView()
}

is UiState.Empty -> {}
}
}
Expand All @@ -141,4 +145,10 @@ class AddFriendFragment : BindingFragment<FragmentAddFriendBinding>(R.layout.fra
super.onDestroyView()
_adapter = null
}

companion object {
private const val EVENT_CLICK_ONBOARDING_NEXT = "click_onboarding_next"
private const val NAME_ONBOARD_VIEW = "onboard_view"
private const val VALUE_FRIENDS = "friends"
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ class CodeFragment : BindingFragment<FragmentCodeBinding>(R.layout.fragment_code
viewModel.postSignupState.observe(viewLifecycleOwner) { state ->
when (state) {
is UiState.Success -> {
AmplitudeUtils.setUserDataProperties("user_signup_date")
AmplitudeUtils.setUserDataProperties(PROPERTY_USER_SIGHUP_DATE)
val intent = Intent(activity, GetAlarmActivity::class.java)
startActivity(intent)
(activity as? OnBoardingActivity)?.endTutorialActivity()
Expand Down Expand Up @@ -107,24 +107,39 @@ class CodeFragment : BindingFragment<FragmentCodeBinding>(R.layout.fragment_code
}

private fun amplitudeCodeSkipInfo() {
AmplitudeUtils.trackEventWithProperties("complete_onboarding_finish")
AmplitudeUtils.trackEventWithProperties(EVENT_COMPLETE_ONBOARDING_FINISH)
AmplitudeUtils.trackEventWithProperties(
"click_onboarding_recommend",
JSONObject().put("rec_exist", "pass"),
EVENT_CLICK_ONBOARDING_RECOMMEND,
JSONObject().put(NAME_REC_EXIST, VALUE_PASS),
)
AmplitudeUtils.updateUserProperties("user_recommend", "no")
AmplitudeUtils.updateUserProperties("user_name", viewModel.name)
AmplitudeUtils.updateUserProperties("user_sex", viewModel.gender)
AmplitudeUtils.updateUserProperties(PROPERTY_USER_RECOMMEND, VALUE_NO)
AmplitudeUtils.updateUserProperties(PROPERTY_USER_NAME, viewModel.name)
AmplitudeUtils.updateUserProperties(PROPERTY_USER_SEX, viewModel.gender)
}

private fun amplitudeCodeNextInfo() {
AmplitudeUtils.trackEventWithProperties("complete_onboarding_finish")
AmplitudeUtils.trackEventWithProperties(EVENT_COMPLETE_ONBOARDING_FINISH)
AmplitudeUtils.trackEventWithProperties(
"click_onboarding_recommend",
JSONObject().put("rec_exist", "next"),
EVENT_CLICK_ONBOARDING_RECOMMEND,
JSONObject().put(NAME_REC_EXIST,VALUE_NEXT),
)
AmplitudeUtils.updateUserProperties("user_recommend", "yes")
AmplitudeUtils.updateUserProperties("user_sex", viewModel.gender)
AmplitudeUtils.updateUserProperties("user_name", viewModel.name)
AmplitudeUtils.updateUserProperties(PROPERTY_USER_RECOMMEND, VALUE_YES)
AmplitudeUtils.updateUserProperties(PROPERTY_USER_NAME, viewModel.name)
AmplitudeUtils.updateUserProperties(PROPERTY_USER_SEX, viewModel.gender)
}

companion object {
private const val PROPERTY_USER_SIGHUP_DATE = "user_signup_date"
private const val EVENT_COMPLETE_ONBOARDING_FINISH = "complete_onboarding_finish"
private const val EVENT_CLICK_ONBOARDING_RECOMMEND = "click_onboarding_recommend"
private const val NAME_REC_EXIST = "rec_exist"
private const val VALUE_PASS = "pass"
private const val VALUE_NEXT = "next"
private const val PROPERTY_USER_RECOMMEND = "user_recommend"
private const val VALUE_NO = "no"
private const val VALUE_YES = "yes"
private const val PROPERTY_USER_NAME = "user_name"
private const val PROPERTY_USER_SEX = "user_sex"

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,12 @@ import com.el.yello.presentation.onboarding.activity.OnBoardingActivity
import com.el.yello.presentation.onboarding.activity.OnBoardingViewModel
import com.el.yello.presentation.onboarding.fragment.highschoolinfo.group.GroupDialogFragment
import com.el.yello.presentation.onboarding.fragment.highschoolinfo.school.SearchDialogHighSchoolFragment
import com.el.yello.util.amplitude.AmplitudeUtils
import com.el.yello.util.context.yelloSnackbar
import com.example.domain.enum.GradeEnum
import com.example.ui.base.BindingFragment
import com.example.ui.view.setOnSingleClickListener
import org.json.JSONObject

class HighSchoolInfoFragment :
BindingFragment<FragmentHighschoolBinding>(R.layout.fragment_highschool) {
Expand Down Expand Up @@ -98,8 +100,31 @@ class HighSchoolInfoFragment :
private fun setConfirmBtnClickListener() {
binding.btnHighschoolinfoNextBtn.setOnSingleClickListener {
findNavController().navigate(R.id.action_highschoolInfoFragment_to_yelIoIdFragment)
amplitudeHighSchoolInfo()
val activity = requireActivity() as OnBoardingActivity
activity.progressBarPlus()
}
}

private fun amplitudeHighSchoolInfo() {
AmplitudeUtils.trackEventWithProperties(
EVENT_CLICK_ONBOARDING_NEXT,
JSONObject().put(NAME_ONBOARD_VIEW, VALUE_SCHOOL),
)
AmplitudeUtils.updateUserProperties(PROPERTY_USER_SCHOOL, viewModel.highSchool)
AmplitudeUtils.updateUserProperties(
PROPERTY_USER_DEPARTMENT,
viewModel.highSchoolGroupText.value.toString(),
)
AmplitudeUtils.updateUserIntProperties(PROPERTY_USER_GRADE, viewModel.studentId)
}

companion object {
private const val EVENT_CLICK_ONBOARDING_NEXT = "click_onboarding_next"
private const val NAME_ONBOARD_VIEW = "onboard_view"
private const val VALUE_SCHOOL = "school"
private const val PROPERTY_USER_SCHOOL = "user_school"
private const val PROPERTY_USER_DEPARTMENT = "user_department"
private const val PROPERTY_USER_GRADE = "user_grade"
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import android.view.View
import android.view.WindowManager
import androidx.core.widget.doAfterTextChanged
import androidx.fragment.app.activityViewModels
import androidx.lifecycle.flowWithLifecycle
import androidx.lifecycle.lifecycleScope
import androidx.lifecycle.viewModelScope
import androidx.recyclerview.widget.LinearLayoutManager
Expand All @@ -25,7 +26,8 @@ import com.google.android.material.bottomsheet.BottomSheetBehavior
import com.google.android.material.bottomsheet.BottomSheetDialog
import kotlinx.coroutines.Job
import kotlinx.coroutines.delay
import kotlinx.coroutines.flow.collectLatest
import kotlinx.coroutines.flow.launchIn
import kotlinx.coroutines.flow.onEach
import kotlinx.coroutines.launch

class SearchDialogHighSchoolFragment :
Expand Down Expand Up @@ -78,20 +80,21 @@ class SearchDialogHighSchoolFragment :
}

private fun setupHighSchoolData() {
lifecycleScope.launch {
viewModel.highSchoolState.collectLatest { state ->
viewModel.highSchoolState.flowWithLifecycle(viewLifecycleOwner.lifecycle)
.onEach { state ->
when (state) {
is UiState.Success -> {
adapter?.submitList(state.data.groupNameList)
}

is UiState.Failure -> {
yelloSnackbar(binding.root, getString(R.string.msg_error))
}
is UiState.Loading -> {}
is UiState.Empty -> {}

is UiState.Loading -> return@onEach
is UiState.Empty -> return@onEach
}
}
}
}.launchIn(viewLifecycleOwner.lifecycleScope)
}

private fun storeHighSchool(school: String) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,11 @@ import com.el.yello.R
import com.el.yello.databinding.FragmentSelectStudentTypeBinding
import com.el.yello.presentation.onboarding.activity.OnBoardingActivity
import com.el.yello.presentation.onboarding.activity.OnBoardingViewModel
import com.el.yello.util.amplitude.AmplitudeUtils
import com.example.domain.enum.StudentTypeEnum
import com.example.ui.base.BindingFragment
import com.example.ui.view.setOnSingleClickListener
import org.json.JSONObject

class SelectStudentFragment :
BindingFragment<FragmentSelectStudentTypeBinding>(R.layout.fragment_select_student_type) {
Expand Down Expand Up @@ -40,6 +42,8 @@ class SelectStudentFragment :
binding.tvStudentUniversity.setTextColor(resources.getColor(R.color.grayscales_700))
binding.btnSelectTypeNext.setOnSingleClickListener {
findNavController().navigate(R.id.action_selectStudentFragment_to_highschoolInfoFragment)
amplitudeSelectStudent()
AmplitudeUtils.updateUserProperties(EVENT_STUDENT_TYPE, VALUE_HIGH_SCHOOL)
val activity = requireActivity() as OnBoardingActivity
activity.progressBarPlus()
}
Expand All @@ -53,11 +57,26 @@ class SelectStudentFragment :
binding.tvStudentHighschool.setTextColor(resources.getColor(R.color.grayscales_700))
binding.btnSelectTypeNext.setOnSingleClickListener {
findNavController().navigate(R.id.action_selectStudentFragment_to_universityInfoFragment)
amplitudeSelectStudent()
AmplitudeUtils.updateUserProperties(EVENT_STUDENT_TYPE, VALUE_UNIVERSITY)
val activity = requireActivity() as OnBoardingActivity
activity.progressBarPlus()
}
}
}
}
}

private fun amplitudeSelectStudent() {
AmplitudeUtils.trackEventWithProperties(
"click_onboarding_next",
JSONObject().put("onboard_view", "student_type"),
)
}

companion object {
private const val EVENT_STUDENT_TYPE = "user_student_type"
private const val VALUE_HIGH_SCHOOL = "highschool"
private const val VALUE_UNIVERSITY = "university"
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -89,15 +89,21 @@ class UniversityInfoFragment :

private fun amplitudeUniversityInfo() {
AmplitudeUtils.trackEventWithProperties(
"click_onboarding_next",
JSONObject().put("onboard_view", "school"),
EVENT_CLICK_ONBOARDING_NEXT,
JSONObject().put(NAME_ONBOARD_VIEW, VALUE_SCHOOL),
)
AmplitudeUtils.updateUserProperties("user_school", viewModel.university)
AmplitudeUtils.updateUserProperties("user_department", viewModel.departmentState.toString())
AmplitudeUtils.updateUserIntProperties("user_grade", viewModel.studentId)
AmplitudeUtils.updateUserProperties(PROPERTY_USER_SCHOOL, viewModel.university)
AmplitudeUtils.updateUserProperties(PROPERTY_USER_DEPARTMENT, viewModel.departmentText.value.toString())
AmplitudeUtils.updateUserIntProperties(PROPERTY_USER_GRADE, viewModel.studentId)
}
companion object {
const val OVERLAP_MIN_ID = 1
const val OVERLAP_MAX_ID = 3
private const val OVERLAP_MIN_ID = 1
private const val OVERLAP_MAX_ID = 3
private const val EVENT_CLICK_ONBOARDING_NEXT = "click_onboarding_next"
private const val NAME_ONBOARD_VIEW = "onboard_view"
private const val VALUE_SCHOOL = "school"
private const val PROPERTY_USER_SCHOOL = "user_school"
private const val PROPERTY_USER_DEPARTMENT = "user_department"
private const val PROPERTY_USER_GRADE = "user_grade"
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import android.view.View
import android.view.WindowManager
import androidx.core.widget.doAfterTextChanged
import androidx.fragment.app.activityViewModels
import androidx.lifecycle.flowWithLifecycle
import androidx.lifecycle.lifecycleScope
import androidx.lifecycle.viewModelScope
import androidx.recyclerview.widget.LinearLayoutManager
Expand All @@ -25,7 +26,8 @@ import com.google.android.material.bottomsheet.BottomSheetBehavior
import com.google.android.material.bottomsheet.BottomSheetDialog
import kotlinx.coroutines.Job
import kotlinx.coroutines.delay
import kotlinx.coroutines.flow.collectLatest
import kotlinx.coroutines.flow.launchIn
import kotlinx.coroutines.flow.onEach
import kotlinx.coroutines.launch
import timber.log.Timber

Expand Down Expand Up @@ -80,21 +82,22 @@ class SearchDialogDepartmentFragment :
}

private fun setupDepartmentData() {
lifecycleScope.launch {
viewModel.departmentState.collectLatest { state ->
viewModel.departmentState.flowWithLifecycle(viewLifecycleOwner.lifecycle)
.onEach { state ->
Timber.d("GET GROUP LIST OBSERVE : $state")
when (state) {
is UiState.Success -> {
adapter?.submitList(state.data.groupList)
}

is UiState.Failure -> {
yelloSnackbar(binding.root, getString(R.string.msg_error))
}
is UiState.Loading -> {}
is UiState.Empty -> {}

is UiState.Loading -> return@onEach
is UiState.Empty -> return@onEach
}
}
}
}.launchIn(viewLifecycleOwner.lifecycleScope)
}

private fun storeUniversityGroup(department: String, groupId: Long) {
Expand Down Expand Up @@ -144,14 +147,18 @@ class SearchDialogDepartmentFragment :
}

private fun recyclerviewScroll() {
binding.rvDepartmentList.setOnTouchListener { view, motionEvent ->
when (motionEvent.action) {
MotionEvent.ACTION_MOVE -> {
binding.layoutDepartmentDialog.requestDisallowInterceptTouchEvent(true)
binding.rvDepartmentList.addOnItemTouchListener(object : RecyclerView.OnItemTouchListener {
override fun onInterceptTouchEvent(rv: RecyclerView, e: MotionEvent): Boolean {
when (e.action) {
MotionEvent.ACTION_MOVE -> {
binding.layoutDepartmentDialog.requestDisallowInterceptTouchEvent(true)
}
}
return false
}
return@setOnTouchListener false
}
override fun onTouchEvent(rv: RecyclerView, e: MotionEvent) {}
override fun onRequestDisallowInterceptTouchEvent(disallowIntercept: Boolean) {}
})
}

override fun onDestroyView() {
Expand Down
Loading

0 comments on commit 21791d4

Please sign in to comment.