Skip to content

Commit

Permalink
Merge pull request #587 from Team-WSS/bugfix/583
Browse files Browse the repository at this point in the history
bugfix: 회원탈퇴 후 회원가입 시 푸시알림이 오지 않는 현상
  • Loading branch information
m6z1 authored Feb 21, 2025
2 parents 6d56316 + 4b86df0 commit 9f935f4
Show file tree
Hide file tree
Showing 2 changed files with 68 additions and 63 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ class WithdrawSecondActivity : BaseActivity<ActivityWithdrawSecondBinding>(R.lay
}

override fun onWithdrawCheckAgreeButtonClick() {
withdrawSecondViewModel.updateIsWithdrawCheckAgree()
withdrawSecondViewModel.updateIsWithdrawAgreementChecked()
}

override fun onWithdrawButtonClick() {
Expand All @@ -78,7 +78,7 @@ class WithdrawSecondActivity : BaseActivity<ActivityWithdrawSecondBinding>(R.lay
}

private fun setupObserver() {
withdrawSecondViewModel.isWithdrawCheckAgree.observe(this) { isAgree ->
withdrawSecondViewModel.isWithdrawAgreementChecked.observe(this) { isAgree ->
updateWithdrawCheckAgreeButtonImage(isAgree)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,88 +6,93 @@ import androidx.lifecycle.MutableLiveData
import androidx.lifecycle.ViewModel
import androidx.lifecycle.viewModelScope
import com.into.websoso.data.repository.AuthRepository
import com.into.websoso.data.repository.PushMessageRepository
import com.into.websoso.data.repository.UserRepository
import dagger.hilt.android.lifecycle.HiltViewModel
import kotlinx.coroutines.launch
import javax.inject.Inject

@HiltViewModel
class WithdrawSecondViewModel @Inject constructor(
private val authRepository: AuthRepository,
private val userRepository: UserRepository,
) : ViewModel() {
private val _withdrawReason: MutableLiveData<String> = MutableLiveData("")
val withdrawReason: LiveData<String> get() = _withdrawReason
class WithdrawSecondViewModel
@Inject
constructor(
private val authRepository: AuthRepository,
private val pushMessageRepository: PushMessageRepository,
private val userRepository: UserRepository,
) : ViewModel() {
private val _withdrawReason: MutableLiveData<String> = MutableLiveData("")
val withdrawReason: LiveData<String> get() = _withdrawReason

private val _isWithdrawCheckAgree: MutableLiveData<Boolean> = MutableLiveData(false)
val isWithdrawCheckAgree: LiveData<Boolean> get() = _isWithdrawCheckAgree
private val _isWithdrawAgreementChecked: MutableLiveData<Boolean> = MutableLiveData(false)
val isWithdrawAgreementChecked: LiveData<Boolean> get() = _isWithdrawAgreementChecked

private val _isWithdrawButtonEnabled: MediatorLiveData<Boolean> = MediatorLiveData(false)
val isWithdrawButtonEnabled: LiveData<Boolean> get() = _isWithdrawButtonEnabled
private val _isWithdrawButtonEnabled: MediatorLiveData<Boolean> = MediatorLiveData(false)
val isWithdrawButtonEnabled: LiveData<Boolean> get() = _isWithdrawButtonEnabled

private val _isWithDrawSuccess: MutableLiveData<Boolean> = MutableLiveData(false)
val isWithDrawSuccess: LiveData<Boolean> get() = _isWithDrawSuccess
private val _isWithDrawSuccess: MutableLiveData<Boolean> = MutableLiveData(false)
val isWithDrawSuccess: LiveData<Boolean> get() = _isWithDrawSuccess

val withdrawEtcReason: MutableLiveData<String> = MutableLiveData()
val withdrawEtcReason: MutableLiveData<String> = MutableLiveData()

val withdrawEtcReasonCount: MediatorLiveData<Int> = MediatorLiveData()
val withdrawEtcReasonCount: MediatorLiveData<Int> = MediatorLiveData()

init {
withdrawEtcReasonCount.addSource(withdrawEtcReason) { reason ->
withdrawEtcReasonCount.value = reason.length
}
init {
withdrawEtcReasonCount.addSource(withdrawEtcReason) { reason ->
withdrawEtcReasonCount.value = reason.length
}

_isWithdrawButtonEnabled.addSource(withdrawReason) {
_isWithdrawButtonEnabled.value = isEnabled()
}
_isWithdrawButtonEnabled.addSource(isWithdrawCheckAgree) {
_isWithdrawButtonEnabled.value = isEnabled()
}
_isWithdrawButtonEnabled.addSource(withdrawEtcReason) {
_isWithdrawButtonEnabled.value = isEnabled()
_isWithdrawButtonEnabled.addSource(withdrawReason) {
_isWithdrawButtonEnabled.value = isEnabled()
}
_isWithdrawButtonEnabled.addSource(isWithdrawAgreementChecked) {
_isWithdrawButtonEnabled.value = isEnabled()
}
_isWithdrawButtonEnabled.addSource(withdrawEtcReason) {
_isWithdrawButtonEnabled.value = isEnabled()
}
}
}

private fun isEnabled(): Boolean {
val isReasonNotBlank: Boolean = _withdrawReason.value?.isNotBlank() == true
val isWithdrawAgree: Boolean = _isWithdrawCheckAgree.value == true
val isEtcReasonValid =
_withdrawReason.value == ETC_INPUT_REASON && withdrawEtcReason.value?.isNotBlank() == true
private fun isEnabled(): Boolean {
val isReasonNotBlank: Boolean = _withdrawReason.value?.isNotBlank() == true
val isWithdrawAgreement: Boolean = _isWithdrawAgreementChecked.value == true
val isEtcReasonValid =
_withdrawReason.value == ETC_INPUT_REASON && withdrawEtcReason.value?.isNotBlank() == true

return when {
_withdrawReason.value == ETC_INPUT_REASON -> isEtcReasonValid && isWithdrawAgree
isReasonNotBlank && isWithdrawAgree -> true
else -> false
return when {
_withdrawReason.value == ETC_INPUT_REASON -> isEtcReasonValid && isWithdrawAgreement
isReasonNotBlank && isWithdrawAgreement -> true
else -> false
}
}
}

fun updateWithdrawReason(reason: String) {
_withdrawReason.value = reason
}
fun updateWithdrawReason(reason: String) {
_withdrawReason.value = reason
}

fun updateIsWithdrawCheckAgree() {
_isWithdrawCheckAgree.value = isWithdrawCheckAgree.value?.not()
}
fun updateIsWithdrawAgreementChecked() {
_isWithdrawAgreementChecked.value = isWithdrawAgreementChecked.value?.not()
}

fun withdraw() {
viewModelScope.launch {
runCatching {
val withdrawReason = when (withdrawReason.value) {
ETC_INPUT_REASON -> withdrawEtcReason.value
else -> withdrawReason.value
} ?: ""
authRepository.withdraw(withdrawReason)
}.onSuccess {
_isWithDrawSuccess.value = true
userRepository.removeTermsAgreementChecked()
authRepository.updateIsAutoLogin(false)
}.onFailure {
_isWithDrawSuccess.value = false
fun withdraw() {
viewModelScope.launch {
runCatching {
val withdrawReason = when (withdrawReason.value) {
ETC_INPUT_REASON -> withdrawEtcReason.value
else -> withdrawReason.value
} ?: ""
authRepository.withdraw(withdrawReason)
}.onSuccess {
_isWithDrawSuccess.value = true
authRepository.updateIsAutoLogin(false)
userRepository.removeTermsAgreementChecked()
pushMessageRepository.clearFCMToken()
}.onFailure {
_isWithDrawSuccess.value = false
}
}
}
}

companion object {
private const val ETC_INPUT_REASON = "직접입력"
companion object {
private const val ETC_INPUT_REASON = "직접입력"
}
}
}

0 comments on commit 9f935f4

Please sign in to comment.