From eca278ad50c19758819cd77d4dfee15b1088e388 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EA=B9=80=EB=AA=85=EC=84=9D?= Date: Mon, 27 Feb 2023 21:31:31 +0900 Subject: [PATCH] =?UTF-8?q?Issues=20#287=20feat:=20SAA=20=EA=B5=AC?= =?UTF-8?q?=EC=A1=B0=EB=A1=9C=20=EB=B3=80=EA=B2=BD=20Intro=20->=20Fragment?= =?UTF-8?q?=20=EB=A1=9C=20=EB=B3=80=EA=B2=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../domain/usecase/user/IsLoginUserUseCase.kt | 3 +- .../ui-intro/src/main/AndroidManifest.xml | 18 ------- .../lighthouse/features/intro/di/IntroNav.kt | 12 ----- .../ui/{IntroActivity.kt => IntroFragment.kt} | 50 ++++++------------- .../features/intro/ui/IntroViewModel.kt | 4 -- ...{activity_intro.xml => fragment_intro.xml} | 0 features/ui-main/src/main/AndroidManifest.xml | 10 ---- 7 files changed, 17 insertions(+), 80 deletions(-) delete mode 100644 features/ui-intro/src/main/AndroidManifest.xml delete mode 100644 features/ui-intro/src/main/java/com/lighthouse/features/intro/di/IntroNav.kt rename features/ui-intro/src/main/java/com/lighthouse/features/intro/ui/{IntroActivity.kt => IntroFragment.kt} (77%) rename features/ui-intro/src/main/res/layout/{activity_intro.xml => fragment_intro.xml} (100%) delete mode 100644 features/ui-main/src/main/AndroidManifest.xml diff --git a/domain/src/main/java/com/lighthouse/domain/usecase/user/IsLoginUserUseCase.kt b/domain/src/main/java/com/lighthouse/domain/usecase/user/IsLoginUserUseCase.kt index d7fbbeee0..c98b591db 100644 --- a/domain/src/main/java/com/lighthouse/domain/usecase/user/IsLoginUserUseCase.kt +++ b/domain/src/main/java/com/lighthouse/domain/usecase/user/IsLoginUserUseCase.kt @@ -1,13 +1,14 @@ package com.lighthouse.domain.usecase.user import com.lighthouse.domain.repository.user.UserRepository +import kotlinx.coroutines.flow.Flow import javax.inject.Inject class IsLoginUserUseCase @Inject constructor( private val userRepository: UserRepository ) { - suspend operator fun invoke(): Boolean { + operator fun invoke(): Flow { return userRepository.isLogin() } } diff --git a/features/ui-intro/src/main/AndroidManifest.xml b/features/ui-intro/src/main/AndroidManifest.xml deleted file mode 100644 index faa162bea..000000000 --- a/features/ui-intro/src/main/AndroidManifest.xml +++ /dev/null @@ -1,18 +0,0 @@ - - - - - - - - - - - - - \ No newline at end of file diff --git a/features/ui-intro/src/main/java/com/lighthouse/features/intro/di/IntroNav.kt b/features/ui-intro/src/main/java/com/lighthouse/features/intro/di/IntroNav.kt deleted file mode 100644 index f6bc4ab42..000000000 --- a/features/ui-intro/src/main/java/com/lighthouse/features/intro/di/IntroNav.kt +++ /dev/null @@ -1,12 +0,0 @@ -package com.lighthouse.features.intro.di - -import android.content.Context -import com.lighthouse.features.common.navigator.MainNavigator -import javax.inject.Inject - -class IntroNav @Inject constructor( - private val mainNavigator: MainNavigator -) { - - fun openMain(context: Context) = mainNavigator.openMain(context) -} diff --git a/features/ui-intro/src/main/java/com/lighthouse/features/intro/ui/IntroActivity.kt b/features/ui-intro/src/main/java/com/lighthouse/features/intro/ui/IntroFragment.kt similarity index 77% rename from features/ui-intro/src/main/java/com/lighthouse/features/intro/ui/IntroActivity.kt rename to features/ui-intro/src/main/java/com/lighthouse/features/intro/ui/IntroFragment.kt index 12b8f0299..0f4e798e1 100644 --- a/features/ui-intro/src/main/java/com/lighthouse/features/intro/ui/IntroActivity.kt +++ b/features/ui-intro/src/main/java/com/lighthouse/features/intro/ui/IntroFragment.kt @@ -2,11 +2,10 @@ package com.lighthouse.features.intro.ui import android.graphics.drawable.AnimatedVectorDrawable import android.os.Bundle +import android.view.View import androidx.activity.result.contract.ActivityResultContracts -import androidx.activity.viewModels -import androidx.appcompat.app.AppCompatActivity -import androidx.core.splashscreen.SplashScreen.Companion.installSplashScreen -import androidx.databinding.DataBindingUtil +import androidx.fragment.app.Fragment +import androidx.fragment.app.viewModels import androidx.lifecycle.lifecycleScope import com.google.android.material.snackbar.Snackbar import com.lighthouse.auth.google.exception.FailedApiException @@ -18,8 +17,7 @@ import com.lighthouse.features.common.ext.repeatOnStarted import com.lighthouse.features.common.ext.show import com.lighthouse.features.common.utils.throttle.onThrottleClick import com.lighthouse.features.intro.R -import com.lighthouse.features.intro.databinding.ActivityIntroBinding -import com.lighthouse.features.intro.di.IntroNav +import com.lighthouse.features.intro.databinding.FragmentIntroBinding import com.lighthouse.features.intro.exception.FailedSaveLoginUserException import com.lighthouse.features.intro.model.SignInState import dagger.hilt.android.AndroidEntryPoint @@ -27,15 +25,12 @@ import kotlinx.coroutines.launch import javax.inject.Inject @AndroidEntryPoint -class IntroActivity : AppCompatActivity() { +class IntroFragment : Fragment(R.layout.fragment_intro) { - private lateinit var binding: ActivityIntroBinding + private lateinit var binding: FragmentIntroBinding private val viewModel: IntroViewModel by viewModels() - @Inject - lateinit var nav: IntroNav - @Inject lateinit var googleClient: GoogleClient @@ -53,28 +48,8 @@ class IntroActivity : AppCompatActivity() { } } - override fun onCreate(savedInstanceState: Bundle?) { - installSplashScreen() - super.onCreate(savedInstanceState) - lifecycleScope.launch { - if (viewModel.isLogin()) { - openMainScreen() - } else { - openIntroScreen() - } - } - } - - private fun openMainScreen() { - nav.openMain(this) - finish() - } - - private fun openIntroScreen() { - binding = DataBindingUtil.setContentView( - this@IntroActivity, - R.layout.activity_intro - ) + override fun onViewCreated(view: View, savedInstanceState: Bundle?) { + super.onViewCreated(view, savedInstanceState) animateLogo() setUpSignInStateFlow() @@ -95,13 +70,13 @@ class IntroActivity : AppCompatActivity() { progressDialog?.dismiss() } progressDialog = ProgressDialog() - progressDialog?.show(supportFragmentManager) + progressDialog?.show(childFragmentManager) } else { progressDialog?.dismiss() } when (state) { - is SignInState.Success -> openMainScreen() + is SignInState.Success -> signInSuccess() is SignInState.Failed -> signInFailed(state.e) else -> {} } @@ -134,6 +109,11 @@ class IntroActivity : AppCompatActivity() { } } + private fun signInSuccess() { + val message = getString(R.string.login_success) + showSnackBar(message) + } + private fun signInFailed(e: Exception) { val message = when (e) { is FailedApiException -> getString(R.string.google_login_failed) diff --git a/features/ui-intro/src/main/java/com/lighthouse/features/intro/ui/IntroViewModel.kt b/features/ui-intro/src/main/java/com/lighthouse/features/intro/ui/IntroViewModel.kt index 18bb8feea..1590cb93e 100644 --- a/features/ui-intro/src/main/java/com/lighthouse/features/intro/ui/IntroViewModel.kt +++ b/features/ui-intro/src/main/java/com/lighthouse/features/intro/ui/IntroViewModel.kt @@ -1,7 +1,6 @@ package com.lighthouse.features.intro.ui import androidx.lifecycle.ViewModel -import com.lighthouse.domain.usecase.user.IsLoginUserUseCase import com.lighthouse.domain.usecase.user.LoginUseCase import com.lighthouse.features.intro.model.SignInState import dagger.hilt.android.lifecycle.HiltViewModel @@ -11,15 +10,12 @@ import javax.inject.Inject @HiltViewModel internal class IntroViewModel @Inject constructor( - private val isLoginUserUseCase: IsLoginUserUseCase, private val loginUseCase: LoginUseCase ) : ViewModel() { private val _signInState = MutableStateFlow(SignInState.None) val signInState = _signInState.asStateFlow() - suspend fun isLogin() = isLoginUserUseCase() - suspend fun login(): Result { return loginUseCase() } diff --git a/features/ui-intro/src/main/res/layout/activity_intro.xml b/features/ui-intro/src/main/res/layout/fragment_intro.xml similarity index 100% rename from features/ui-intro/src/main/res/layout/activity_intro.xml rename to features/ui-intro/src/main/res/layout/fragment_intro.xml diff --git a/features/ui-main/src/main/AndroidManifest.xml b/features/ui-main/src/main/AndroidManifest.xml deleted file mode 100644 index 8b2573a53..000000000 --- a/features/ui-main/src/main/AndroidManifest.xml +++ /dev/null @@ -1,10 +0,0 @@ - - - - - - - \ No newline at end of file