Skip to content

Commit

Permalink
Issues boostcampwm-2022#287 feat: SAA 구조로 변경 Intro -> Fragment 로 변경
Browse files Browse the repository at this point in the history
  • Loading branch information
audxo112 committed Feb 27, 2023
1 parent 3d135d9 commit eca278a
Show file tree
Hide file tree
Showing 7 changed files with 17 additions and 80 deletions.
Original file line number Diff line number Diff line change
@@ -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<Boolean> {
return userRepository.isLogin()
}
}
18 changes: 0 additions & 18 deletions features/ui-intro/src/main/AndroidManifest.xml

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -18,24 +17,20 @@ 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
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

Expand All @@ -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()
Expand All @@ -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 -> {}
}
Expand Down Expand Up @@ -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)
Expand Down
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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>(SignInState.None)
val signInState = _signInState.asStateFlow()

suspend fun isLogin() = isLoginUserUseCase()

suspend fun login(): Result<Unit> {
return loginUseCase()
}
Expand Down
10 changes: 0 additions & 10 deletions features/ui-main/src/main/AndroidManifest.xml

This file was deleted.

0 comments on commit eca278a

Please sign in to comment.