From 4668b01487022bd01c1027b69dd7cda37e5a1f66 Mon Sep 17 00:00:00 2001 From: jinuemong Date: Fri, 26 Jan 2024 04:16:13 +0900 Subject: [PATCH] =?UTF-8?q?[Feat]:=20=EC=83=98=ED=94=8C=20=EC=8A=A4?= =?UTF-8?q?=ED=81=AC=EB=A6=B0=20&=20=EB=AA=A8=EB=8D=B8=20=EA=B8=B0?= =?UTF-8?q?=EB=8A=A5=20=EA=B5=AC=ED=98=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../presentation/ui/main/MainActivity.kt | 1 + .../main/kakao_login_sample/SampleScreen.kt | 20 ++++++++++ .../kakao_login_sample/SampleViewModel.kt | 39 +++++++++++++++++++ 3 files changed, 60 insertions(+) create mode 100644 presentation/src/main/kotlin/ac/dnd/bookkeeping/android/presentation/ui/main/kakao_login_sample/SampleScreen.kt create mode 100644 presentation/src/main/kotlin/ac/dnd/bookkeeping/android/presentation/ui/main/kakao_login_sample/SampleViewModel.kt diff --git a/presentation/src/main/kotlin/ac/dnd/bookkeeping/android/presentation/ui/main/MainActivity.kt b/presentation/src/main/kotlin/ac/dnd/bookkeeping/android/presentation/ui/main/MainActivity.kt index 113bc09f..9cff7a5c 100644 --- a/presentation/src/main/kotlin/ac/dnd/bookkeeping/android/presentation/ui/main/MainActivity.kt +++ b/presentation/src/main/kotlin/ac/dnd/bookkeeping/android/presentation/ui/main/MainActivity.kt @@ -9,6 +9,7 @@ class MainActivity : BaseActivity() { override fun initView() { setContent { MainScreen() +// SampleScreen() } } } diff --git a/presentation/src/main/kotlin/ac/dnd/bookkeeping/android/presentation/ui/main/kakao_login_sample/SampleScreen.kt b/presentation/src/main/kotlin/ac/dnd/bookkeeping/android/presentation/ui/main/kakao_login_sample/SampleScreen.kt new file mode 100644 index 00000000..4ceb7d12 --- /dev/null +++ b/presentation/src/main/kotlin/ac/dnd/bookkeeping/android/presentation/ui/main/kakao_login_sample/SampleScreen.kt @@ -0,0 +1,20 @@ +package ac.dnd.bookkeeping.android.presentation.ui.main.kakao_login_sample + +import androidx.compose.runtime.Composable +import androidx.compose.runtime.LaunchedEffect +import androidx.compose.runtime.mutableStateOf +import androidx.compose.runtime.remember +import androidx.hilt.navigation.compose.hiltViewModel + +@Composable +fun SampleScreen( + viewModel: SampleViewModel = hiltViewModel() +) { + val loginState = remember { mutableStateOf(true) } + LaunchedEffect(Unit) { + if (loginState.value) { + viewModel.login() + } + loginState.value = false + } +} diff --git a/presentation/src/main/kotlin/ac/dnd/bookkeeping/android/presentation/ui/main/kakao_login_sample/SampleViewModel.kt b/presentation/src/main/kotlin/ac/dnd/bookkeeping/android/presentation/ui/main/kakao_login_sample/SampleViewModel.kt new file mode 100644 index 00000000..093b00ac --- /dev/null +++ b/presentation/src/main/kotlin/ac/dnd/bookkeeping/android/presentation/ui/main/kakao_login_sample/SampleViewModel.kt @@ -0,0 +1,39 @@ +package ac.dnd.bookkeeping.android.presentation.ui.main.kakao_login_sample + +import ac.dnd.bookkeeping.android.domain.repository.social_login.SocialLoginRepository +import ac.dnd.bookkeeping.android.presentation.common.base.BaseViewModel +import androidx.lifecycle.SavedStateHandle +import dagger.hilt.android.lifecycle.HiltViewModel +import timber.log.Timber +import javax.inject.Inject + +@HiltViewModel +class SampleViewModel @Inject constructor( + private val savedStateHandle: SavedStateHandle, + private val socialLoginRepository: SocialLoginRepository +) : BaseViewModel() { + + fun login() = launch { + socialLoginRepository.login() + .onSuccess { + getUserInfo() + Timber.d("user token(for check login state): $it") + } + .onFailure { + Timber.d("login error: ${it.message}") + } + } + + private fun getUserInfo() = launch { + socialLoginRepository.getUserInfo() + .onSuccess { + + Timber.d("user email: ${it.email}") + Timber.d("user id: ${it.socialId}") + Timber.d("user name: ${it.name}") + } + .onFailure { + Timber.d("login error: ${it.message}") + } + } +}