Skip to content

Commit

Permalink
[feature/#928] refactor auth file
Browse files Browse the repository at this point in the history
  • Loading branch information
leeeyubin committed Nov 5, 2024
1 parent 743a7a6 commit a4d74a3
Showing 1 changed file with 18 additions and 22 deletions.
40 changes: 18 additions & 22 deletions app/src/main/java/org/sopt/official/feature/auth/AuthActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -42,12 +42,10 @@ import androidx.compose.ui.platform.LocalContext
import androidx.compose.ui.tooling.preview.Preview
import androidx.core.app.NotificationCompat
import androidx.core.view.isVisible
import androidx.lifecycle.compose.LocalLifecycleOwner
import androidx.lifecycle.flowWithLifecycle
import androidx.lifecycle.lifecycleScope
import dagger.hilt.android.AndroidEntryPoint
import javax.inject.Inject
import kotlinx.coroutines.flow.launchIn
import kotlinx.coroutines.flow.onEach
import kotlinx.coroutines.launch
import org.sopt.official.BuildConfig
import org.sopt.official.R
Expand All @@ -66,6 +64,7 @@ import org.sopt.official.designsystem.SoptTheme
import org.sopt.official.feature.home.HomeActivity
import org.sopt.official.network.model.response.OAuthToken
import org.sopt.official.network.persistence.SoptDataStore
import javax.inject.Inject

@AndroidEntryPoint
class AuthActivity : AppCompatActivity() {
Expand All @@ -84,6 +83,7 @@ class AuthActivity : AppCompatActivity() {
setContent {
SoptTheme {
val context = LocalContext.current
val lifecycleOwner = LocalLifecycleOwner.current

LaunchedEffect(true) {
if (dataStore.accessToken.isNotEmpty()) {
Expand All @@ -107,28 +107,24 @@ class AuthActivity : AppCompatActivity() {
}
}

LaunchedEffect(viewModel.uiEvent, lifecycleOwner) {
viewModel.uiEvent.flowWithLifecycle(lifecycle = lifecycleOwner.lifecycle)
.collect { event ->
when (event) {
is AuthUiEvent.Success -> startActivity(
HomeActivity.getIntent(context, HomeActivity.StartArgs(event.userStatus))
)

is AuthUiEvent.Failure -> startActivity(
HomeActivity.getIntent(context, HomeActivity.StartArgs(UserStatus.UNAUTHENTICATED))
)
}
}
}

AuthScreen()
}
}

initAnimation()
collectUiEvent()
}

private fun collectUiEvent() {
viewModel.uiEvent
.flowWithLifecycle(lifecycle)
.onEach { event ->
when (event) {
is AuthUiEvent.Success -> startActivity(
HomeActivity.getIntent(this, HomeActivity.StartArgs(event.userStatus))
)

is AuthUiEvent.Failure -> startActivity(
HomeActivity.getIntent(this, HomeActivity.StartArgs(UserStatus.UNAUTHENTICATED))
)
}
}.launchIn(lifecycleScope)
}

private fun initAnimation() {
Expand Down

0 comments on commit a4d74a3

Please sign in to comment.