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

[ADD/#187] 유료뷰 대응 amplitude 추가 #188

Merged
merged 12 commits into from
Dec 2, 2024
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 @@ -10,8 +10,10 @@ data class SignupRequestDto(
val birthYear: String,
@SerialName("sex")
val sex: String,
@SerialName("phoneNumber")
val phoneNumber: String?,
) {
companion object {
fun SignupRequestModel.toDto() = SignupRequestDto(birthYear, sex)
fun SignupRequestModel.toDto() = SignupRequestDto(birthYear, sex, phoneNumber)
}
}
2 changes: 1 addition & 1 deletion data/src/main/java/kr/genti/data/service/CreateService.kt
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ interface CreateService {
@Body request: KeyRequestDto,
): BaseResponse<Boolean>

@GET("api/v1/users/examples/with-picture-square/{type}")
@GET("api/v2/users/examples/with-picture-square/{type}")
suspend fun getPromptExample(
@Path("type") type: String
): BaseResponse<List<PromptExampleDto>>
Expand Down
2 changes: 1 addition & 1 deletion data/src/main/java/kr/genti/data/service/InfoService.kt
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import retrofit2.http.DELETE
import retrofit2.http.POST

interface InfoService {
@POST("api/v1/users/signup")
@POST("api/v2/users/signup")
suspend fun postSignupData(
@Body request: SignupRequestDto,
): BaseResponse<SignUpUserDto>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,5 @@ package kr.genti.domain.entity.request
data class SignupRequestModel(
val birthYear: String,
val sex: String,
val phoneNumber: String?,
)
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ class SignupActivity : BaseActivity<ActivitySignupBinding>(R.layout.activity_sig
initSubmitBtnListener()
observePostSignupState()
observeYearInputState()
observePhoneInputState()
}

private fun initView() {
Expand All @@ -48,9 +49,7 @@ class SignupActivity : BaseActivity<ActivitySignupBinding>(R.layout.activity_sig
}

private fun observePostSignupState() {
viewModel.postSignupState
.flowWithLifecycle(lifecycle)
.distinctUntilChanged()
viewModel.postSignupState.flowWithLifecycle(lifecycle).distinctUntilChanged()
.onEach { state ->
when (state) {
is UiState.Success -> {
Expand All @@ -76,6 +75,15 @@ class SignupActivity : BaseActivity<ActivitySignupBinding>(R.layout.activity_sig
}.launchIn(lifecycleScope)
}

private fun observePhoneInputState() {
viewModel.isPhoneAllSelected.flowWithLifecycle(lifecycle).distinctUntilChanged()
.onEach { isAllSelected ->
if (isAllSelected) {
hideKeyboard(binding.root)
}
}.launchIn(lifecycleScope)
}

private fun setAmplitudeUserProperty(state: UiState.Success<SignUpUserModel>) {
AmplitudeManager.apply {
trackEvent("complete_infoget")
Expand All @@ -88,7 +96,10 @@ class SignupActivity : BaseActivity<ActivitySignupBinding>(R.layout.activity_sig
updateIntProperties("user_picturedownload", 0)
updateIntProperties("user_main_scroll", 0)
updateIntProperties("user_promptsuggest_refresh", 0)
updateIntProperties("user_piccreate", 0)
updateIntProperties("user_piccreate_total", 0)
updateIntProperties("user_piccreate_original", 0)
updateIntProperties("user_piccreate_oneparent", 0)
updateIntProperties("user_piccreate_twoparents", 0)
updateBooleanProperties("user_alarm", false)
updateBooleanProperties("user_verified", false)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,12 @@ constructor(
private val _isYearAllSelected = MutableStateFlow<Boolean>(false)
val isYearAllSelected: StateFlow<Boolean> = _isYearAllSelected

val selectedPhone = MutableLiveData<String?>()
val isPhoneSelected = MutableLiveData<Boolean>(false)

private val _isPhoneAllSelected = MutableStateFlow<Boolean>(false)
val isPhoneAllSelected: StateFlow<Boolean> = _isPhoneAllSelected

val isAllSelected = MutableLiveData<Boolean>(false)

private val _postSignupState = MutableStateFlow<UiState<SignUpUserModel>>(UiState.Empty)
Expand All @@ -49,6 +55,11 @@ constructor(
checkAllSelected()
}

fun checkPhone() {
isPhoneSelected.value = selectedPhone.value?.isNotEmpty()
_isPhoneAllSelected.value = selectedPhone.value?.length == 11
}

private fun checkAllSelected() {
isAllSelected.value = isGenderSelected.value == true && isYearAllSelected.value == true
}
Expand All @@ -60,6 +71,7 @@ constructor(
SignupRequestModel(
selectedYear.value.toString(),
selectedGender.value.toString(),
selectedPhone.value
),
).onSuccess {
userRepository.setUserRole(ROLE_USER)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,7 @@ import dagger.hilt.android.lifecycle.HiltViewModel
import kotlinx.coroutines.async
import kotlinx.coroutines.awaitAll
import kotlinx.coroutines.coroutineScope
import kotlinx.coroutines.flow.MutableSharedFlow
import kotlinx.coroutines.flow.MutableStateFlow
import kotlinx.coroutines.flow.SharedFlow
import kotlinx.coroutines.flow.StateFlow
import kotlinx.coroutines.launch
import kr.genti.core.state.UiState
Expand All @@ -27,6 +25,7 @@ import kr.genti.domain.enums.PictureNumber
import kr.genti.domain.enums.PictureRatio
import kr.genti.domain.repository.CreateRepository
import kr.genti.domain.repository.UploadRepository
import kr.genti.presentation.util.AmplitudeManager
import javax.inject.Inject

@HiltViewModel
Expand All @@ -37,6 +36,7 @@ constructor(
private val uploadRepository: UploadRepository,
) : ViewModel() {
var isCreatingParentPic = false
var currentType: String = TYPE_FREE_ONE

val prompt = MutableLiveData<String>()
val isWritten = MutableLiveData(false)
Expand Down Expand Up @@ -66,8 +66,8 @@ constructor(
private val _totalGeneratingState = MutableStateFlow<UiState<Boolean>>(UiState.Empty)
val totalGeneratingState: StateFlow<UiState<Boolean>> = _totalGeneratingState

private val _purchaseValidError = MutableSharedFlow<String>()
val purchaseValidError: SharedFlow<String> = _purchaseValidError
private val _purchaseValidState = MutableStateFlow<UiState<Boolean>>(UiState.Empty)
val purchaseValidState: StateFlow<UiState<Boolean>> = _purchaseValidState

private var imageS3KeyList = listOf<KeyRequestModel>()
private var firstImageS3KeyList = listOf<KeyRequestModel>()
Expand Down Expand Up @@ -114,11 +114,7 @@ constructor(

fun getExamplePrompt() {
_getExampleState.value = UiState.Loading
val currentType = when {
!isCreatingParentPic -> TYPE_FREE_ONE
selectedNumber.value == PictureNumber.ONE -> TYPE_PAID_ONE
else -> TYPE_PAID_TWO
}
setCurrentType()
viewModelScope.launch {
runCatching {
createRepository.getPromptExample(currentType)
Expand All @@ -130,6 +126,20 @@ constructor(
}
}

private fun setCurrentType() {
currentType = when {
!isCreatingParentPic -> TYPE_FREE_ONE

selectedNumber.value == PictureNumber.ONE -> TYPE_PAID_ONE.also {
AmplitudeManager.trackEvent("view_oneparentpreset")
}

else -> TYPE_PAID_TWO.also {
AmplitudeManager.trackEvent("view_twoparentspreset")
}
}
}

fun startSendingImages() {
_totalGeneratingState.value = UiState.Loading
if (selectedNumber.value != PictureNumber.TWO) {
Expand Down Expand Up @@ -219,6 +229,12 @@ constructor(
createRepository.postToCreate(request)
}
result.onSuccess {
if (isCreatingParentPic) {
AmplitudeManager.plusIntProperties("user_piccreate_oneparent")
} else {
AmplitudeManager.plusIntProperties("user_piccreate_original")
}
AmplitudeManager.plusIntProperties("user_piccreate_total")
_totalGeneratingState.value = UiState.Success(it)
}.onFailure {
_totalGeneratingState.value = UiState.Failure(it.message.toString())
Expand All @@ -236,6 +252,8 @@ constructor(
selectedRatio.value ?: return@launch,
)
).onSuccess {
AmplitudeManager.plusIntProperties("user_piccreate_twoparents")
AmplitudeManager.plusIntProperties("user_piccreate_total")
_totalGeneratingState.value = UiState.Success(isCreatingParentPic)
}.onFailure {
_totalGeneratingState.value = UiState.Failure(it.message.toString())
Expand All @@ -253,20 +271,35 @@ constructor(
)
).onSuccess { isValidSuccess ->
if (isValidSuccess) {
_purchaseValidState.value = UiState.Success(true)
when (currentType) {
TYPE_PAID_ONE -> AmplitudeManager.trackEvent(
"complete_payment", mapOf("picture_type" to "oneparent")
)

TYPE_PAID_TWO -> AmplitudeManager.trackEvent(
"complete_payment", mapOf("picture_type" to "twoparents")
)
}
startSendingImages()
} else {
_purchaseValidError.emit(VALIDATION_FALSE)
_purchaseValidState.value = UiState.Failure(false.toString())
}
}.onFailure {
_purchaseValidError.emit(SERVER_ERROR)
_purchaseValidState.value = UiState.Failure(it.message.orEmpty())
}
}
}

companion object {
const val VALIDATION_FALSE = "VALIDATION_FALSE"
const val SERVER_ERROR = "SERVER_ERROR"
fun startValidProcessLoading() {
_purchaseValidState.value = UiState.Loading
}

fun resetValidProcessLoading() {
_purchaseValidState.value = UiState.Empty
}

companion object {
const val TYPE_FREE_ONE = "FREE_ONE"
const val TYPE_PAID_ONE = "PAID_ONE"
const val TYPE_PAID_TWO = "PAID_TWO"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@ class DefineFragment() : BaseFragment<FragmentDefineBinding>(R.layout.fragment_d
private val adapter
get() = requireNotNull(_adapter) { getString(R.string.adapter_not_initialized_error_msg) }

private var amplitudePage: Map<String, String>? = null

override fun onViewCreated(
view: View,
savedInstanceState: Bundle?,
Expand All @@ -50,14 +52,17 @@ class DefineFragment() : BaseFragment<FragmentDefineBinding>(R.layout.fragment_d
private fun initView() {
binding.vm = viewModel
viewModel.getExamplePrompt()
if (viewModel.isCreatingParentPic) {
amplitudePage = mapOf(PROPERTY_PAGE to "createparent1")
} else {
amplitudePage = mapOf(PROPERTY_PAGE to "create1")
}
}

private fun initCreateBtnListener() {
binding.btnCreateNext.setOnSingleClickListener {
AmplitudeManager.trackEvent(
EVENT_CLICK_BTN,
mapOf(PROPERTY_PAGE to "create1"),
mapOf(PROPERTY_BTN to "next"),
EVENT_CLICK_BTN, amplitudePage, mapOf(PROPERTY_BTN to "next"),
)
findNavController().navigate(R.id.action_define_to_pose)
viewModel.modCurrentPercent(33)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ import kr.genti.presentation.util.AmplitudeManager.PROPERTY_PAGE
class PoseFragment() : BaseFragment<FragmentPoseBinding>(R.layout.fragment_pose) {
private val viewModel by activityViewModels<CreateViewModel>()

private var amplitudePage: Map<String, String>? = null

override fun onViewCreated(
view: View,
savedInstanceState: Bundle?,
Expand All @@ -32,14 +34,17 @@ class PoseFragment() : BaseFragment<FragmentPoseBinding>(R.layout.fragment_pose)

private fun initView() {
binding.vm = viewModel
if (viewModel.isCreatingParentPic) {
amplitudePage = mapOf(PROPERTY_PAGE to "createparent2")
} else {
amplitudePage = mapOf(PROPERTY_PAGE to "create2")
}
}

private fun initNextBtnListener() {
binding.btnPoseNext.setOnSingleClickListener {
AmplitudeManager.trackEvent(
EVENT_CLICK_BTN,
mapOf(PROPERTY_PAGE to "create2"),
mapOf(PROPERTY_BTN to "next"),
EVENT_CLICK_BTN, amplitudePage, mapOf(PROPERTY_BTN to "next"),
)
findNavController().navigate(R.id.action_pose_to_selfie)
viewModel.modCurrentPercent(34)
Expand Down
Loading