-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #105 from POLZZAK/feat/my_notice_etc
[FEAT] 계정관리, 이용약관
- Loading branch information
Showing
46 changed files
with
1,447 additions
and
76 deletions.
There are no files selected for viewing
17 changes: 17 additions & 0 deletions
17
app/src/main/java/com/polzzak_android/presentation/common/item/FullLoadingItem.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
package com.polzzak_android.presentation.common.item | ||
|
||
import com.polzzak_android.R | ||
import com.polzzak_android.databinding.ItemFullLoadingBinding | ||
import com.polzzak_android.presentation.common.util.BindableItem | ||
|
||
class FullLoadingItem : BindableItem<ItemFullLoadingBinding>() { | ||
override val layoutRes: Int = R.layout.item_full_loading | ||
|
||
override fun areItemsTheSame(other: BindableItem<*>): Boolean = other is FullLoadingItem | ||
|
||
override fun areContentsTheSame(other: BindableItem<*>): Boolean = other is FullLoadingItem | ||
|
||
override fun bind(binding: ItemFullLoadingBinding, position: Int) { | ||
//do nothing | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
172 changes: 172 additions & 0 deletions
172
.../polzzak_android/presentation/feature/myPage/accountmanagement/MyAccountDeleteFragment.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,172 @@ | ||
package com.polzzak_android.presentation.feature.myPage.accountmanagement | ||
|
||
import androidx.fragment.app.DialogFragment | ||
import androidx.fragment.app.viewModels | ||
import androidx.navigation.fragment.findNavController | ||
import com.polzzak_android.R | ||
import com.polzzak_android.databinding.FragmentMyAccountDeleteBinding | ||
import com.polzzak_android.presentation.common.model.ButtonCount | ||
import com.polzzak_android.presentation.common.model.CommonButtonModel | ||
import com.polzzak_android.presentation.common.model.ModelState | ||
import com.polzzak_android.presentation.common.util.SpannableBuilder | ||
import com.polzzak_android.presentation.component.dialog.CommonDialogContent | ||
import com.polzzak_android.presentation.component.dialog.CommonDialogHelper | ||
import com.polzzak_android.presentation.component.dialog.CommonDialogModel | ||
import com.polzzak_android.presentation.component.dialog.DialogStyleType | ||
import com.polzzak_android.presentation.component.dialog.OnButtonClickListener | ||
import com.polzzak_android.presentation.component.toolbar.ToolbarData | ||
import com.polzzak_android.presentation.component.toolbar.ToolbarHelper | ||
import com.polzzak_android.presentation.feature.myPage.accountmanagement.MyAccountManagementFragment.Companion.ARGUMENT_NICKNAME_KEY | ||
import com.polzzak_android.presentation.feature.myPage.accountmanagement.base.BaseMyAccountFragment | ||
import timber.log.Timber | ||
|
||
class MyAccountDeleteFragment : BaseMyAccountFragment<FragmentMyAccountDeleteBinding>() { | ||
override val layoutResId: Int = R.layout.fragment_my_account_delete | ||
|
||
private val myAccountDeleteViewModel by viewModels<MyAccountDeleteViewModel>() | ||
|
||
private var currentDialog: DialogFragment? = null | ||
|
||
override fun initView() { | ||
super.initView() | ||
initToolbar() | ||
with(binding) { | ||
val nickName = arguments?.getString(ARGUMENT_NICKNAME_KEY) ?: "" | ||
tvTitle.text = getString(R.string.my_account_management_delete_title, nickName) | ||
with(inMenuDeleteLink) { | ||
tvContent.text = | ||
getText(R.string.my_account_management_delete_menu_delete_link) | ||
root.setOnClickListener { | ||
myAccountDeleteViewModel.toggleDeleteLink() | ||
} | ||
} | ||
with(inMenuDeletePoint) { | ||
tvContent.text = | ||
getText(R.string.my_account_management_delete_menu_delete_point) | ||
root.setOnClickListener { | ||
myAccountDeleteViewModel.toggleDeletePoint() | ||
} | ||
} | ||
with(inMenuDeleteSocialAccountData) { | ||
tvContent.text = | ||
getText(R.string.my_account_management_delete_menu_delete_social_account_data) | ||
root.setOnClickListener { | ||
myAccountDeleteViewModel.toggleDeleteSocialAccountData() | ||
} | ||
} | ||
with(inMenuDeleteStampAndCoupon) { | ||
tvContent.text = | ||
getText(R.string.my_account_management_delete_menu_delete_stamp_and_coupon) | ||
root.setOnClickListener { | ||
myAccountDeleteViewModel.toggleDeleteStampAndCoupon() | ||
} | ||
} | ||
tvBtnDeleteAccount.setOnClickListener { | ||
val context = context ?: return@setOnClickListener | ||
val dialogTitleSpannable = SpannableBuilder.build(context) { | ||
span( | ||
text = getString(R.string.my_account_management_delete_dialog_title), | ||
style = R.style.subtitle_18_600, | ||
textColor = R.color.gray_700 | ||
) | ||
} | ||
val dialog = CommonDialogHelper.getInstance( | ||
content = CommonDialogModel( | ||
type = DialogStyleType.ALERT, | ||
content = CommonDialogContent(title = dialogTitleSpannable), | ||
button = CommonButtonModel( | ||
buttonCount = ButtonCount.TWO, | ||
positiveButtonText = getString(R.string.my_account_management_delete_dialog_btn_positive), | ||
negativeButtonText = getString(R.string.my_account_management_delete_dialog_btn_negative) | ||
) | ||
), | ||
onConfirmListener = { | ||
object : OnButtonClickListener { | ||
override fun setBusinessLogic() { | ||
myAccountDeleteViewModel.deleteAccount() | ||
} | ||
|
||
override fun getReturnValue(value: Any) { | ||
//do nothing | ||
} | ||
} | ||
} | ||
) | ||
showDialog(dialogFragment = dialog) | ||
} | ||
} | ||
} | ||
|
||
private fun initToolbar() { | ||
ToolbarHelper( | ||
data = ToolbarData( | ||
popStack = findNavController(), | ||
titleText = getString(R.string.my_account_management) | ||
), | ||
toolbar = binding.inToolbar | ||
).set() | ||
} | ||
|
||
override fun initObserver() { | ||
super.initObserver() | ||
myAccountDeleteViewModel.myAccountMenuLiveData.observe(viewLifecycleOwner) { | ||
with(binding) { | ||
inMenuDeleteLink.ivBtnCheck.isSelected = it.isCheckedDeleteLink | ||
inMenuDeletePoint.ivBtnCheck.isSelected = it.isCheckedDeletePoint | ||
inMenuDeleteSocialAccountData.ivBtnCheck.isSelected = | ||
it.isCheckedDeleteSocialAccountData | ||
inMenuDeleteStampAndCoupon.ivBtnCheck.isSelected = it.isCheckedDeleteStampAndCoupon | ||
tvBtnDeleteAccount.isEnabled = it.isAllChecked() | ||
} | ||
} | ||
|
||
myAccountDeleteViewModel.deleteAccountLiveData.observe(viewLifecycleOwner) { | ||
val context = context ?: return@observe | ||
when (it) { | ||
is ModelState.Loading -> { | ||
val dialogTitleSpannable = SpannableBuilder.build(context) { | ||
span( | ||
text = getString(R.string.my_account_management_delete_dialog_title), | ||
style = R.style.subtitle_18_600, | ||
textColor = R.color.gray_700 | ||
) | ||
} | ||
val loadingDialog = CommonDialogHelper.getInstance( | ||
content = CommonDialogModel( | ||
type = DialogStyleType.LOADING, | ||
content = CommonDialogContent(title = dialogTitleSpannable), | ||
button = CommonButtonModel(ButtonCount.ZERO) | ||
) | ||
) | ||
showDialog(dialogFragment = loadingDialog) | ||
} | ||
|
||
is ModelState.Success -> { | ||
dismissCurrentDialog() | ||
Timber.d("회원탈퇴") | ||
findRootNavigationOwner()?.backToTheLoginFragment() | ||
} | ||
|
||
is ModelState.Error -> { | ||
//TODO error handling | ||
} | ||
} | ||
} | ||
} | ||
|
||
private fun showDialog(dialogFragment: DialogFragment) { | ||
currentDialog?.dismiss() | ||
currentDialog = dialogFragment | ||
dialogFragment.show(childFragmentManager, null) | ||
} | ||
|
||
private fun dismissCurrentDialog() { | ||
currentDialog?.dismiss() | ||
currentDialog = null | ||
} | ||
|
||
override fun onPause() { | ||
super.onPause() | ||
currentDialog?.dismiss() | ||
} | ||
} |
60 changes: 60 additions & 0 deletions
60
...polzzak_android/presentation/feature/myPage/accountmanagement/MyAccountDeleteViewModel.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
package com.polzzak_android.presentation.feature.myPage.accountmanagement | ||
|
||
import androidx.lifecycle.LiveData | ||
import androidx.lifecycle.MutableLiveData | ||
import androidx.lifecycle.ViewModel | ||
import androidx.lifecycle.viewModelScope | ||
import com.polzzak_android.presentation.common.model.ModelState | ||
import com.polzzak_android.presentation.feature.myPage.accountmanagement.model.MyAccountDeleteMenuModel | ||
import kotlinx.coroutines.Job | ||
import kotlinx.coroutines.delay | ||
import kotlinx.coroutines.launch | ||
|
||
class MyAccountDeleteViewModel : ViewModel() { | ||
private val _myAccountMenuLiveData = MutableLiveData<MyAccountDeleteMenuModel>() | ||
val myAccountMenuLiveData: LiveData<MyAccountDeleteMenuModel> = _myAccountMenuLiveData | ||
|
||
private val _deleteAccountLiveData = MutableLiveData<ModelState<Unit>>() | ||
val deleteAccountLiveData: LiveData<ModelState<Unit>> = _deleteAccountLiveData | ||
private var deleteAccountJob: Job? = null | ||
|
||
fun toggleDeleteSocialAccountData() { | ||
_myAccountMenuLiveData.value = | ||
(myAccountMenuLiveData.value ?: MyAccountDeleteMenuModel()).run { | ||
copy(isCheckedDeleteSocialAccountData = !isCheckedDeleteSocialAccountData) | ||
} | ||
} | ||
|
||
fun toggleDeleteLink() { | ||
_myAccountMenuLiveData.value = | ||
(myAccountMenuLiveData.value ?: MyAccountDeleteMenuModel()).run { | ||
copy(isCheckedDeleteLink = !isCheckedDeleteLink) | ||
} | ||
} | ||
|
||
fun toggleDeletePoint() { | ||
_myAccountMenuLiveData.value = | ||
(myAccountMenuLiveData.value ?: MyAccountDeleteMenuModel()).run { | ||
copy(isCheckedDeletePoint = !isCheckedDeletePoint) | ||
} | ||
} | ||
|
||
fun toggleDeleteStampAndCoupon() { | ||
_myAccountMenuLiveData.value = | ||
(myAccountMenuLiveData.value ?: MyAccountDeleteMenuModel()).run { | ||
copy(isCheckedDeleteStampAndCoupon = !isCheckedDeleteStampAndCoupon) | ||
} | ||
} | ||
|
||
fun deleteAccount() { | ||
if (deleteAccountJob?.isCompleted == false) return | ||
deleteAccountJob = viewModelScope.launch { | ||
//TODO 회원탈퇴 API 호출 | ||
_deleteAccountLiveData.value = ModelState.Loading() | ||
delay(2000) | ||
//onSuccess | ||
_deleteAccountLiveData.value = ModelState.Success(Unit) | ||
} | ||
|
||
} | ||
} |
Oops, something went wrong.