From 81518b52c5b54200c952f75fc7cec047a0ed36d2 Mon Sep 17 00:00:00 2001 From: jinukeu Date: Sat, 10 Feb 2024 00:59:47 +0900 Subject: [PATCH 1/2] =?UTF-8?q?fix:=20B=20=EC=B9=B4=ED=86=A1=20=EA=B3=84?= =?UTF-8?q?=EC=A0=95=20=EB=A1=9C=EA=B7=B8=EC=9D=B8=20=EC=8B=9C,=20?= =?UTF-8?q?=EB=B0=9B=EC=95=84=EC=9A=94=20=ED=83=AD=EC=97=90=EC=84=9C=20A?= =?UTF-8?q?=20=EC=B9=B4=ED=86=A1=20=EA=B3=84=EC=A0=95=EC=9C=BC=EB=A1=9C=20?= =?UTF-8?q?=EC=9E=85=EB=A0=A5=ED=95=9C=20=EB=82=B4=EC=9A=A9=EC=9D=B4=20?= =?UTF-8?q?=EB=B3=B4=EC=97=AC=EC=A7=80=EB=8A=94=20=EC=9D=B4=EC=8A=88=20?= =?UTF-8?q?=ED=95=B4=EA=B2=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../com/susu/feature/mypage/main/MyPageDefaultScreen.kt | 4 ++-- .../susu/feature/mypage/navigation/MyPageNavigation.kt | 4 ++-- .../main/java/com/susu/feature/navigator/MainScreen.kt | 8 +++++++- 3 files changed, 11 insertions(+), 5 deletions(-) diff --git a/feature/mypage/src/main/java/com/susu/feature/mypage/main/MyPageDefaultScreen.kt b/feature/mypage/src/main/java/com/susu/feature/mypage/main/MyPageDefaultScreen.kt index b0f240d0..51f3556e 100644 --- a/feature/mypage/src/main/java/com/susu/feature/mypage/main/MyPageDefaultScreen.kt +++ b/feature/mypage/src/main/java/com/susu/feature/mypage/main/MyPageDefaultScreen.kt @@ -57,7 +57,7 @@ import com.susu.feature.mypage.main.component.MyPageMenuItem fun MyPageDefaultRoute( padding: PaddingValues, viewModel: MyPageViewModel = hiltViewModel(), - navigateToLogin: () -> Unit, + restartMainActivity: () -> Unit, navigateToInfo: () -> Unit, navigateToSocial: () -> Unit, navigateToPrivacyPolicy: () -> Unit, @@ -77,7 +77,7 @@ fun MyPageDefaultRoute( viewModel.sideEffect.collectWithLifecycle { sideEffect -> when (sideEffect) { - MyPageEffect.NavigateToLogin -> navigateToLogin() + MyPageEffect.NavigateToLogin -> restartMainActivity() MyPageEffect.NavigateToInfo -> navigateToInfo() MyPageEffect.NavigateToSocial -> navigateToSocial() is MyPageEffect.ShowSnackbar -> onShowSnackbar(SnackbarToken(message = sideEffect.msg)) diff --git a/feature/mypage/src/main/java/com/susu/feature/mypage/navigation/MyPageNavigation.kt b/feature/mypage/src/main/java/com/susu/feature/mypage/navigation/MyPageNavigation.kt index 874a6dd7..41028d6e 100644 --- a/feature/mypage/src/main/java/com/susu/feature/mypage/navigation/MyPageNavigation.kt +++ b/feature/mypage/src/main/java/com/susu/feature/mypage/navigation/MyPageNavigation.kt @@ -30,7 +30,7 @@ fun NavController.navigateMyPagePrivacyPolicy() { fun NavGraphBuilder.myPageNavGraph( padding: PaddingValues, - navigateToLogin: () -> Unit, + restartMainActivity: () -> Unit, navigateToInfo: () -> Unit, navigateToSocial: () -> Unit, navigateToPrivacyPolicy: () -> Unit, @@ -42,7 +42,7 @@ fun NavGraphBuilder.myPageNavGraph( composable(route = MyPageRoute.defaultRoute) { MyPageDefaultRoute( padding = padding, - navigateToLogin = navigateToLogin, + restartMainActivity = restartMainActivity, navigateToInfo = navigateToInfo, navigateToSocial = navigateToSocial, navigateToPrivacyPolicy = navigateToPrivacyPolicy, diff --git a/feature/navigator/src/main/java/com/susu/feature/navigator/MainScreen.kt b/feature/navigator/src/main/java/com/susu/feature/navigator/MainScreen.kt index be6af001..6d7edf89 100644 --- a/feature/navigator/src/main/java/com/susu/feature/navigator/MainScreen.kt +++ b/feature/navigator/src/main/java/com/susu/feature/navigator/MainScreen.kt @@ -1,5 +1,6 @@ package com.susu.feature.navigator +import android.content.Intent import androidx.compose.animation.AnimatedVisibility import androidx.compose.animation.EnterTransition import androidx.compose.animation.ExitTransition @@ -226,7 +227,12 @@ internal fun MainScreen( myPageNavGraph( padding = innerPadding, - navigateToLogin = navigator::navigateLogin, + restartMainActivity = { + val intent = Intent(context, MainActivity::class.java).apply { + flags = Intent.FLAG_ACTIVITY_NEW_TASK or Intent.FLAG_ACTIVITY_CLEAR_TASK or Intent.FLAG_ACTIVITY_CLEAR_TOP + } + context.startActivity(intent) + }, navigateToInfo = navigator::navigateMyPageInfo, navigateToSocial = navigator::navigateMyPageSocial, navigateToPrivacyPolicy = navigator::navigateMyPagePrivacyPolicy, From d2a765cf2754c6c84585e2e78b7571c8fa859f60 Mon Sep 17 00:00:00 2001 From: yangsooplus Date: Sat, 10 Feb 2024 20:11:02 +0900 Subject: [PATCH 2/2] =?UTF-8?q?feat:=20=EC=95=B1=20=EC=B4=88=EA=B8=B0=20?= =?UTF-8?q?=EC=A7=84=EC=9E=85,=20=ED=83=88=ED=87=B4=20=EC=8B=9C=EC=97=90?= =?UTF-8?q?=EB=A7=8C=20=ED=9A=8C=EC=9B=90=EA=B0=80=EC=9E=85=20=ED=88=AC?= =?UTF-8?q?=ED=91=9C=20=EB=85=B8=EC=B6=9C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- data/src/main/java/com/susu/data/Constants.kt | 10 +++++++ .../data/repository/LoginRepositoryImpl.kt | 19 +++++++++--- .../data/repository/SignUpRepositoryImpl.kt | 29 +++++++++++++++---- .../data/repository/UserRepositoryImpl.kt | 2 ++ .../java/com/susu/data/remote/Constants.kt | 5 ---- .../com/susu/data/remote/di/NetworkModule.kt | 2 +- .../domain/repository/SignUpRepository.kt | 1 + .../CheckShowOnboardVoteUseCase.kt | 13 +++++++++ .../loginsignup/social/KakaoLoginHelper.kt | 3 -- .../susu/feature/navigator/MainActivity.kt | 1 - .../susu/feature/navigator/MainViewModel.kt | 6 ++-- 11 files changed, 70 insertions(+), 21 deletions(-) create mode 100644 data/src/main/java/com/susu/data/Constants.kt delete mode 100644 data/src/main/java/com/susu/data/remote/Constants.kt create mode 100644 domain/src/main/java/com/susu/domain/usecase/loginsignup/CheckShowOnboardVoteUseCase.kt diff --git a/data/src/main/java/com/susu/data/Constants.kt b/data/src/main/java/com/susu/data/Constants.kt new file mode 100644 index 00000000..4a0e6fd2 --- /dev/null +++ b/data/src/main/java/com/susu/data/Constants.kt @@ -0,0 +1,10 @@ +package com.susu.data + +import androidx.datastore.preferences.core.booleanPreferencesKey + +object Constants { + const val RETROFIT_TAG = "Retrofit" + + private const val SHOW_ONBOARD_VOTE = "Onboarding" + val showOnboardingVoteKey = booleanPreferencesKey(SHOW_ONBOARD_VOTE) +} diff --git a/data/src/main/java/com/susu/data/data/repository/LoginRepositoryImpl.kt b/data/src/main/java/com/susu/data/data/repository/LoginRepositoryImpl.kt index ed50e7b1..8b4c0559 100644 --- a/data/src/main/java/com/susu/data/data/repository/LoginRepositoryImpl.kt +++ b/data/src/main/java/com/susu/data/data/repository/LoginRepositoryImpl.kt @@ -1,5 +1,10 @@ package com.susu.data.data.repository +import androidx.datastore.core.DataStore +import androidx.datastore.preferences.core.Preferences +import androidx.datastore.preferences.core.edit +import com.susu.core.model.Token +import com.susu.data.Constants import com.susu.data.remote.api.AuthService import com.susu.data.remote.model.request.AccessTokenRequest import com.susu.data.remote.model.response.toDomain @@ -8,12 +13,18 @@ import javax.inject.Inject class LoginRepositoryImpl @Inject constructor( private val authService: AuthService, + private val dataStore: DataStore, ) : LoginRepository { override suspend fun login( provider: String, oauthAccessToken: String, - ) = authService.login( - provider = provider, - accessTokenRequest = AccessTokenRequest(oauthAccessToken), - ).getOrThrow().toDomain() + ): Token { + dataStore.edit { preferences -> + preferences[Constants.showOnboardingVoteKey] = false + } + return authService.login( + provider = provider, + accessTokenRequest = AccessTokenRequest(oauthAccessToken), + ).getOrThrow().toDomain() + } } diff --git a/data/src/main/java/com/susu/data/data/repository/SignUpRepositoryImpl.kt b/data/src/main/java/com/susu/data/data/repository/SignUpRepositoryImpl.kt index 410565e2..9eb3a4d9 100644 --- a/data/src/main/java/com/susu/data/data/repository/SignUpRepositoryImpl.kt +++ b/data/src/main/java/com/susu/data/data/repository/SignUpRepositoryImpl.kt @@ -1,25 +1,38 @@ package com.susu.data.data.repository +import androidx.datastore.core.DataStore +import androidx.datastore.preferences.core.Preferences +import androidx.datastore.preferences.core.edit import com.susu.core.model.SignUpUser +import com.susu.core.model.Token +import com.susu.data.Constants.showOnboardingVoteKey import com.susu.data.remote.api.SignUpService import com.susu.data.remote.model.request.toData import com.susu.data.remote.model.response.toDomain import com.susu.domain.repository.SignUpRepository +import kotlinx.coroutines.flow.firstOrNull +import kotlinx.coroutines.flow.map import javax.inject.Inject class SignUpRepositoryImpl @Inject constructor( private val signUpService: SignUpService, + private val dataStore: DataStore, ) : SignUpRepository { override suspend fun signUp( provider: String, oauthAccessToken: String, signUpUser: SignUpUser, - ) = signUpService.signUp( - provider = provider, - accessToken = oauthAccessToken, - user = signUpUser.toData(), - ).getOrThrow().toDomain() + ): Token { + dataStore.edit { preferences -> + preferences[showOnboardingVoteKey] = false + } + return signUpService.signUp( + provider = provider, + accessToken = oauthAccessToken, + user = signUpUser.toData(), + ).getOrThrow().toDomain() + } override suspend fun canRegister( provider: String, @@ -30,4 +43,10 @@ class SignUpRepositoryImpl @Inject constructor( accessToken = oauthAccessToken, ).getOrThrow().canRegister } + + override suspend fun getShowOnboardVote(): Boolean? { + return dataStore.data.map { preferences -> + preferences[showOnboardingVoteKey] + }.firstOrNull() + } } diff --git a/data/src/main/java/com/susu/data/data/repository/UserRepositoryImpl.kt b/data/src/main/java/com/susu/data/data/repository/UserRepositoryImpl.kt index b11e4ead..871a6729 100644 --- a/data/src/main/java/com/susu/data/data/repository/UserRepositoryImpl.kt +++ b/data/src/main/java/com/susu/data/data/repository/UserRepositoryImpl.kt @@ -6,6 +6,7 @@ import androidx.datastore.preferences.core.edit import androidx.datastore.preferences.core.stringPreferencesKey import com.susu.core.model.User import com.susu.core.model.exception.UserNotFoundException +import com.susu.data.Constants.showOnboardingVoteKey import com.susu.data.remote.api.AuthService import com.susu.data.remote.api.UserService import com.susu.data.remote.model.request.UserPatchRequest @@ -63,6 +64,7 @@ class UserRepositoryImpl @Inject constructor( override suspend fun withdraw() { dataStore.edit { preferences -> preferences.remove(userKey) + preferences.remove(showOnboardingVoteKey) } authService.withdraw().getOrThrow() } diff --git a/data/src/main/java/com/susu/data/remote/Constants.kt b/data/src/main/java/com/susu/data/remote/Constants.kt deleted file mode 100644 index e8f01df1..00000000 --- a/data/src/main/java/com/susu/data/remote/Constants.kt +++ /dev/null @@ -1,5 +0,0 @@ -package com.susu.data.remote - -object Constants { - const val RETROFIT_TAG = "Retrofit" -} diff --git a/data/src/main/java/com/susu/data/remote/di/NetworkModule.kt b/data/src/main/java/com/susu/data/remote/di/NetworkModule.kt index e9595078..77baabc4 100644 --- a/data/src/main/java/com/susu/data/remote/di/NetworkModule.kt +++ b/data/src/main/java/com/susu/data/remote/di/NetworkModule.kt @@ -1,7 +1,7 @@ package com.susu.data.remote.di import com.jakewharton.retrofit2.converter.kotlinx.serialization.asConverterFactory -import com.susu.data.remote.Constants.RETROFIT_TAG +import com.susu.data.Constants.RETROFIT_TAG import com.susu.data.remote.network.TokenAuthenticator import com.susu.data.remote.network.TokenInterceptor import com.susu.data.remote.retrofit.ResultCallAdapterFactory diff --git a/domain/src/main/java/com/susu/domain/repository/SignUpRepository.kt b/domain/src/main/java/com/susu/domain/repository/SignUpRepository.kt index a617c201..191810a4 100644 --- a/domain/src/main/java/com/susu/domain/repository/SignUpRepository.kt +++ b/domain/src/main/java/com/susu/domain/repository/SignUpRepository.kt @@ -6,4 +6,5 @@ import com.susu.core.model.Token interface SignUpRepository { suspend fun signUp(provider: String, oauthAccessToken: String, signUpUser: SignUpUser): Token suspend fun canRegister(provider: String, oauthAccessToken: String): Boolean + suspend fun getShowOnboardVote(): Boolean? } diff --git a/domain/src/main/java/com/susu/domain/usecase/loginsignup/CheckShowOnboardVoteUseCase.kt b/domain/src/main/java/com/susu/domain/usecase/loginsignup/CheckShowOnboardVoteUseCase.kt new file mode 100644 index 00000000..f322eb12 --- /dev/null +++ b/domain/src/main/java/com/susu/domain/usecase/loginsignup/CheckShowOnboardVoteUseCase.kt @@ -0,0 +1,13 @@ +package com.susu.domain.usecase.loginsignup + +import com.susu.core.common.runCatchingIgnoreCancelled +import com.susu.domain.repository.SignUpRepository +import javax.inject.Inject + +class CheckShowOnboardVoteUseCase @Inject constructor( + private val signUpRepository: SignUpRepository, +) { + suspend operator fun invoke() = runCatchingIgnoreCancelled { + signUpRepository.getShowOnboardVote() + }.getOrNull() +} diff --git a/feature/loginsignup/src/main/java/com/susu/feature/loginsignup/social/KakaoLoginHelper.kt b/feature/loginsignup/src/main/java/com/susu/feature/loginsignup/social/KakaoLoginHelper.kt index dc85caad..317d9d20 100644 --- a/feature/loginsignup/src/main/java/com/susu/feature/loginsignup/social/KakaoLoginHelper.kt +++ b/feature/loginsignup/src/main/java/com/susu/feature/loginsignup/social/KakaoLoginHelper.kt @@ -1,7 +1,6 @@ package com.susu.feature.loginsignup.social import android.content.Context -import com.kakao.sdk.auth.AuthApiClient import com.kakao.sdk.auth.TokenManagerProvider import com.kakao.sdk.common.model.AuthError import com.kakao.sdk.common.model.ClientError @@ -10,8 +9,6 @@ import com.kakao.sdk.user.UserApiClient import timber.log.Timber object KakaoLoginHelper { - val hasKakaoLoginHistory - get() = AuthApiClient.instance.hasToken() fun login( context: Context, diff --git a/feature/navigator/src/main/java/com/susu/feature/navigator/MainActivity.kt b/feature/navigator/src/main/java/com/susu/feature/navigator/MainActivity.kt index 6e002707..b68be32b 100644 --- a/feature/navigator/src/main/java/com/susu/feature/navigator/MainActivity.kt +++ b/feature/navigator/src/main/java/com/susu/feature/navigator/MainActivity.kt @@ -43,7 +43,6 @@ class MainActivity : ComponentActivity() { if (uiState.isNavigating) { KakaoLoginHelper.getAccessToken { accessToken -> viewModel.navigate( - hasKakaoLoginHistory = KakaoLoginHelper.hasKakaoLoginHistory, kakaoAccessToken = accessToken, ) } diff --git a/feature/navigator/src/main/java/com/susu/feature/navigator/MainViewModel.kt b/feature/navigator/src/main/java/com/susu/feature/navigator/MainViewModel.kt index 37f89739..b21392a2 100644 --- a/feature/navigator/src/main/java/com/susu/feature/navigator/MainViewModel.kt +++ b/feature/navigator/src/main/java/com/susu/feature/navigator/MainViewModel.kt @@ -9,6 +9,7 @@ import com.susu.core.ui.SnsProviders import com.susu.core.ui.base.BaseViewModel import com.susu.domain.usecase.categoryconfig.GetCategoryConfigUseCase import com.susu.domain.usecase.loginsignup.CheckCanRegisterUseCase +import com.susu.domain.usecase.loginsignup.CheckShowOnboardVoteUseCase import com.susu.domain.usecase.loginsignup.LoginUseCase import dagger.hilt.android.lifecycle.HiltViewModel import kotlinx.coroutines.delay @@ -22,6 +23,7 @@ import javax.inject.Inject class MainViewModel @Inject constructor( private val loginUseCase: LoginUseCase, private val checkCanRegisterUseCase: CheckCanRegisterUseCase, + private val checkShowOnboardVoteUseCase: CheckShowOnboardVoteUseCase, private val getCategoryConfigUseCase: GetCategoryConfigUseCase, ) : BaseViewModel(MainState()) { companion object { @@ -59,8 +61,8 @@ class MainViewModel @Inject constructor( intent { copy(isInitializing = false) } } - fun navigate(hasKakaoLoginHistory: Boolean, kakaoAccessToken: String?) = viewModelScope.launch { - if (hasKakaoLoginHistory.not()) { + fun navigate(kakaoAccessToken: String?) = viewModelScope.launch { + if (checkShowOnboardVoteUseCase() == null) { intent { copy(isNavigating = false) } return@launch }