From 7c367ef6fe3b19a42f7b3844d176742a3fe6df57 Mon Sep 17 00:00:00 2001 From: jun <50354282+wjdwns@users.noreply.github.com> Date: Thu, 9 Nov 2023 21:41:44 +0900 Subject: [PATCH] =?UTF-8?q?Feature/#201=20=ED=83=88=ED=87=B4=ED=95=98?= =?UTF-8?q?=EA=B8=B0=20=EB=B0=8F=20=EC=84=9C=EB=B2=84=20url=20=EB=B3=80?= =?UTF-8?q?=EA=B2=BD=20(#202)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * 탈퇴하기 구현 * 서버 url 변경 --- .../depromeet/housekeeper/data/ApiService.kt | 3 ++ .../data/dataSource/RemoteDataSource.kt | 1 + .../data/dataSource/RemoteDataSourceImpl.kt | 5 +++ .../data/repository/UserRepository.kt | 1 + .../ui/custom/dialog/FairerDialog.kt | 30 ++++++++++++++-- .../ui/settings/SettingFragment.kt | 20 +++++++++-- .../ui/settings/SettingViewModel.kt | 34 +++++++++++++++++-- .../housekeeper/ui/signIn/LoginFragment.kt | 4 +-- app/src/main/res/layout/fragment_setting.xml | 20 ++++++++++- app/src/main/res/values/strings.xml | 3 ++ .../main/res/xml/remote_config_default.xml | 4 +-- 11 files changed, 113 insertions(+), 12 deletions(-) diff --git a/app/src/main/java/com/depromeet/housekeeper/data/ApiService.kt b/app/src/main/java/com/depromeet/housekeeper/data/ApiService.kt index e4e8f0eb..283bc848 100644 --- a/app/src/main/java/com/depromeet/housekeeper/data/ApiService.kt +++ b/app/src/main/java/com/depromeet/housekeeper/data/ApiService.kt @@ -79,6 +79,9 @@ interface ApiService { @POST("/api/oauth/logout") suspend fun logout() + @POST("/api/oauth/signout") + suspend fun signOut() + /** * presets diff --git a/app/src/main/java/com/depromeet/housekeeper/data/dataSource/RemoteDataSource.kt b/app/src/main/java/com/depromeet/housekeeper/data/dataSource/RemoteDataSource.kt index 990e2e38..84a1b241 100644 --- a/app/src/main/java/com/depromeet/housekeeper/data/dataSource/RemoteDataSource.kt +++ b/app/src/main/java/com/depromeet/housekeeper/data/dataSource/RemoteDataSource.kt @@ -49,6 +49,7 @@ interface RemoteDataSource { */ suspend fun getGoogleLogin(socialType: SocialType): Flow> suspend fun logout(): Flow> + suspend fun signOut(): Flow> /** * presets diff --git a/app/src/main/java/com/depromeet/housekeeper/data/dataSource/RemoteDataSourceImpl.kt b/app/src/main/java/com/depromeet/housekeeper/data/dataSource/RemoteDataSourceImpl.kt index b57ee321..24cf31e7 100644 --- a/app/src/main/java/com/depromeet/housekeeper/data/dataSource/RemoteDataSourceImpl.kt +++ b/app/src/main/java/com/depromeet/housekeeper/data/dataSource/RemoteDataSourceImpl.kt @@ -112,6 +112,11 @@ class RemoteDataSourceImpl @Inject constructor( apiService.logout() }.flowOn(ioDispatcher) + override suspend fun signOut( + ): Flow> = safeFlow { + apiService.signOut() + }.flowOn(ioDispatcher) + /** * presets diff --git a/app/src/main/java/com/depromeet/housekeeper/data/repository/UserRepository.kt b/app/src/main/java/com/depromeet/housekeeper/data/repository/UserRepository.kt index e9a9a4f9..a90bff90 100644 --- a/app/src/main/java/com/depromeet/housekeeper/data/repository/UserRepository.kt +++ b/app/src/main/java/com/depromeet/housekeeper/data/repository/UserRepository.kt @@ -35,6 +35,7 @@ class UserRepository @Inject constructor( suspend fun logout(): Flow> = remoteDataSource.logout() + suspend fun signOut() : Flow> = remoteDataSource.signOut() /** * teams */ diff --git a/app/src/main/java/com/depromeet/housekeeper/ui/custom/dialog/FairerDialog.kt b/app/src/main/java/com/depromeet/housekeeper/ui/custom/dialog/FairerDialog.kt index 036dca6b..ceb39503 100644 --- a/app/src/main/java/com/depromeet/housekeeper/ui/custom/dialog/FairerDialog.kt +++ b/app/src/main/java/com/depromeet/housekeeper/ui/custom/dialog/FairerDialog.kt @@ -59,8 +59,34 @@ class FairerDialog(private val context: Context, private val type: DialogType) { logoutDialog.dismiss() } logoutDialog.show() + } + + fun showSignOutDialog() { + initDialog(logoutDialog, R.layout.dialog_logout) + + val btnDialogCancel = + logoutDialog.findViewById(R.id.dialog_logout_cancel_btn) + val btnDialogOk = logoutDialog.findViewById(R.id.dialog_logout_ok_btn) + val tvDialogTitle = logoutDialog.findViewById(R.id.dialog_logout_title_tv) + val outsideDialog = logoutDialog.findViewById(R.id.dialog_logout_outside) + + tvDialogTitle.setText(R.string.fairer_dialog_sign_out_title) + btnDialogOk.setText(R.string.fairer_dialog_sign_out_btn_text) + btnDialogOk.setTextColor(context.getColor(R.color.negative_20)) + + outsideDialog.setOnClickListener { + logoutDialog.dismiss() + } + btnDialogCancel.setOnClickListener { + logoutDialog.dismiss() + } + btnDialogOk.setOnClickListener { + onItemClickListener.onItemClick() + logoutDialog.dismiss() + } + logoutDialog.show() } fun showDialog() { @@ -171,5 +197,5 @@ class FairerDialog(private val context: Context, private val type: DialogType) { } enum class DialogType { - CHANGE, DELETE, EDIT, LOGOUT, EXIT -} \ No newline at end of file + CHANGE, DELETE, EDIT, LOGOUT, EXIT, SIGN_OUT +} diff --git a/app/src/main/java/com/depromeet/housekeeper/ui/settings/SettingFragment.kt b/app/src/main/java/com/depromeet/housekeeper/ui/settings/SettingFragment.kt index d5356eaa..8dcbc6ac 100644 --- a/app/src/main/java/com/depromeet/housekeeper/ui/settings/SettingFragment.kt +++ b/app/src/main/java/com/depromeet/housekeeper/ui/settings/SettingFragment.kt @@ -86,14 +86,30 @@ class SettingFragment : BaseFragment(R.layout.fragment_s } binding.logoutRow.setOnClickListener { - showLogoutDialog() + showWithdrawDialog() + } + + binding.signOutRow.setOnClickListener { + showSignOutDialog() } } - private fun showLogoutDialog() { + private fun showWithdrawDialog() { val dialog = FairerDialog(requireContext(), DialogType.LOGOUT) dialog.showLogoutDialog() + dialog.onItemClickListener = object : FairerDialog.OnItemClickListener { + override fun onItemClick() { + viewModel.withdraw(requireContext()) + findNavController().navigate(R.id.action_settingFragment_to_loginFragment) + } + } + } + + private fun showSignOutDialog() { + val dialog = FairerDialog(requireContext(), DialogType.SIGN_OUT) + dialog.showSignOutDialog() + dialog.onItemClickListener = object : FairerDialog.OnItemClickListener { override fun onItemClick() { viewModel.signOut(requireContext()) diff --git a/app/src/main/java/com/depromeet/housekeeper/ui/settings/SettingViewModel.kt b/app/src/main/java/com/depromeet/housekeeper/ui/settings/SettingViewModel.kt index 5487c301..07814d1a 100644 --- a/app/src/main/java/com/depromeet/housekeeper/ui/settings/SettingViewModel.kt +++ b/app/src/main/java/com/depromeet/housekeeper/ui/settings/SettingViewModel.kt @@ -57,12 +57,42 @@ class SettingViewModel @Inject constructor( } } + fun withdraw(context: Context) { + viewModelScope.launch { + userRepository.signOut().collectLatest { + withContext(Dispatchers.IO) { + tokenManager.deleteTokens() + } + PrefsManager.setUserProfile(ProfileData("", "", "")) + + val gso = GoogleSignInOptions.Builder(GoogleSignInOptions.DEFAULT_SIGN_IN) + .requestEmail() + .build() + + val mGoogleSignInClient = GoogleSignIn.getClient(context, gso) + + mGoogleSignInClient.signOut() + .addOnCompleteListener { res -> + if (res.isComplete) + Timber.d("google sign out") + } + + mGoogleSignInClient.revokeAccess() + .addOnCompleteListener { res -> + if (res.isComplete) + Timber.d("google account deleted") + } + receiveApiResult(it) ?: return@collectLatest + } + } + } + /** * Network Communication */ private fun logout() { viewModelScope.launch { - withContext(Dispatchers.IO){ + withContext(Dispatchers.IO) { tokenManager.deleteTokens() } userRepository.logout().collectLatest { @@ -71,4 +101,4 @@ class SettingViewModel @Inject constructor( } } } -} \ No newline at end of file +} diff --git a/app/src/main/java/com/depromeet/housekeeper/ui/signIn/LoginFragment.kt b/app/src/main/java/com/depromeet/housekeeper/ui/signIn/LoginFragment.kt index f5956c38..2ebb2c72 100644 --- a/app/src/main/java/com/depromeet/housekeeper/ui/signIn/LoginFragment.kt +++ b/app/src/main/java/com/depromeet/housekeeper/ui/signIn/LoginFragment.kt @@ -188,7 +188,5 @@ class LoginFragment : BaseFragment(R.layout.fragment_login findNavController().navigate(LoginFragmentDirections.actionLoginFragmentToJoinGroupFragment()) } } - } - -} \ No newline at end of file +} diff --git a/app/src/main/res/layout/fragment_setting.xml b/app/src/main/res/layout/fragment_setting.xml index 1690fb8c..24d481b9 100644 --- a/app/src/main/res/layout/fragment_setting.xml +++ b/app/src/main/res/layout/fragment_setting.xml @@ -234,7 +234,25 @@ app:layout_constraintStart_toStartOf="parent" app:layout_constraintTop_toTopOf="parent" /> + + + + - \ No newline at end of file + diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 12a05000..62ce4394 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -48,10 +48,12 @@ 취소 확인 로그아웃 + 탈퇴하기 그룹 나가기 집안일을 삭제하시겠어요? 삭제하시면 다시 복구할 수 없습니다. 로그아웃 하시겠습니까? + 탈퇴하시겠습니까? 정말 나가시겠습니까? 모든 집안일 기록이 사라집니다. @@ -143,6 +145,7 @@ 정보 버전 로그아웃 + 탈퇴하기 이름 프로필을 설정해주세요. 상태 메세지 diff --git a/app/src/main/res/xml/remote_config_default.xml b/app/src/main/res/xml/remote_config_default.xml index 44f14342..9e35cbfd 100644 --- a/app/src/main/res/xml/remote_config_default.xml +++ b/app/src/main/res/xml/remote_config_default.xml @@ -2,6 +2,6 @@ server_url - http://fairer-env.eba-w7ubjjfy.ap-northeast-2.elasticbeanstalk.com + http://fairer.shop - \ No newline at end of file +