Skip to content

Commit

Permalink
[MERGE]#188 -> develop
Browse files Browse the repository at this point in the history
[REFACTOR/#188] μ½”λ“œ λ¦¬νŽ™ν† λ§ 및 navigate ν™•μž₯ν•¨μˆ˜ κ΅¬ν˜„
  • Loading branch information
chattymin authored Jan 25, 2024
2 parents f4b34fe + fa16c6b commit 891a5c2
Show file tree
Hide file tree
Showing 13 changed files with 427 additions and 520 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,12 @@ import androidx.lifecycle.lifecycleScope
import com.going.domain.entity.AuthState
import com.going.presentation.R
import com.going.presentation.dashboard.DashBoardActivity
import com.going.presentation.databinding.ActivitySigninBinding
import com.going.presentation.databinding.ActivitySignInBinding
import com.going.presentation.onboarding.signup.SignUpActivity
import com.going.presentation.setting.SettingActivity.Companion.TERMS_URL
import com.going.presentation.tendency.splash.TendencySplashActivity
import com.going.presentation.util.initOnBackPressedListener
import com.going.presentation.util.navigateToScreen
import com.going.ui.base.BaseActivity
import com.going.ui.extension.setOnSingleClickListener
import com.going.ui.extension.toast
Expand All @@ -21,19 +23,24 @@ import kotlinx.coroutines.flow.launchIn
import kotlinx.coroutines.flow.onEach

@AndroidEntryPoint
class SignInActivity : BaseActivity<ActivitySigninBinding>(R.layout.activity_signin) {
class SignInActivity : BaseActivity<ActivitySignInBinding>(R.layout.activity_sign_in) {

private val viewModel by viewModels<SignInViewModel>()

override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)

clearToken()
initKakaoLoginBtnClickListener()
initTermsBtnClickListener()
observeInfo()
initOnBackPressedListener()
}

private fun clearToken() {
viewModel.clearToken()
}

private fun initKakaoLoginBtnClickListener() {
binding.btnSignIn.setOnSingleClickListener {
viewModel.startKakaoLogIn(this)
Expand Down Expand Up @@ -62,43 +69,12 @@ class SignInActivity : BaseActivity<ActivitySigninBinding>(R.layout.activity_sig
private fun observePostChangeTokenState() {
viewModel.postChangeTokenState.flowWithLifecycle(lifecycle).onEach { state ->
when (state) {
AuthState.LOADING -> return@onEach
AuthState.SUCCESS -> navigateToDashBoardScreen()
AuthState.SUCCESS -> navigateToScreen<DashBoardActivity>()
AuthState.FAILURE -> toast(getString(R.string.server_error))
AuthState.SIGNUP -> navigateToOnboardingScreen()
AuthState.SIGNIN -> return@onEach
AuthState.TENDENCY -> navigateToTendencyScreen()
AuthState.EMPTY -> return@onEach
AuthState.SIGNUP -> navigateToScreen<SignUpActivity>()
AuthState.TENDENCY -> navigateToScreen<TendencySplashActivity>()
else -> return@onEach
}
}.launchIn(lifecycleScope)
}

private fun navigateToDashBoardScreen() {
Intent(this, DashBoardActivity::class.java).apply {
addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP)
startActivity(this)
}
finish()
}

private fun navigateToOnboardingScreen() {
Intent(this, SignUpActivity::class.java).apply {
addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP)
startActivity(this)
}
finish()
}

private fun navigateToTendencyScreen() {
Intent(this, TendencySplashActivity::class.java).apply {
addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP)
startActivity(this)
}
finish()
}

companion object {
const val TERMS_URL =
"https://goinggoing.notion.site/75f5d981a5b842a6be74a9dc17ca67de?pvs=74"
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ class SignInViewModel @Inject constructor(
}
}

// μ„œλ²„ν†΅μ‹  - 카카였 토큰 λ³΄λ‚΄μ„œ μ„œλΉ„μŠ€ 토큰 λ°›μ•„μ˜€κΈ° - μ„œλ²„μ™€ ν˜‘μ˜ ν›„ μˆ˜μ •μ˜ˆμ •
// μ„œλ²„ν†΅μ‹  - 카카였 토큰 λ³΄λ‚΄μ„œ μ„œλΉ„μŠ€ 토큰 λ°›μ•„μ˜€κΈ°
private fun changeTokenFromServer(
accessToken: String,
platform: String = KAKAO,
Expand Down Expand Up @@ -93,6 +93,10 @@ class SignInViewModel @Inject constructor(
}
}

fun clearToken() {
tokenRepository.clearInfo()
}

companion object {
const val KAKAO = "kakao"
const val SIGN_UP = "e4041"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,12 @@ import androidx.lifecycle.flowWithLifecycle
import androidx.lifecycle.lifecycleScope
import com.going.domain.entity.AuthState
import com.going.presentation.R
import com.going.presentation.dashboard.DashBoardActivity
import com.going.presentation.databinding.ActivitySignUpBinding
import com.going.presentation.onboarding.splash.SplashActivity
import com.going.presentation.tendency.splash.TendencySplashActivity
import com.going.presentation.util.initOnBackPressedListener
import com.going.presentation.util.navigateToScreen
import com.going.ui.base.BaseActivity
import com.going.ui.extension.setOnSingleClickListener
import com.going.ui.extension.toast
Expand Down Expand Up @@ -78,30 +80,11 @@ class SignUpActivity :
private fun observeIsSignUpState() {
viewModel.isSignUpState.flowWithLifecycle(lifecycle).onEach { state ->
when (state) {
AuthState.LOADING -> return@onEach
AuthState.SUCCESS -> navigateToTendencySplashScreen()
AuthState.SUCCESS -> navigateToScreen<TendencySplashActivity>()
AuthState.FAILURE -> toast(getString(R.string.server_error))
AuthState.SIGNUP -> return@onEach
AuthState.SIGNIN -> navigateToSplashScreen()
AuthState.TENDENCY -> return@onEach
AuthState.EMPTY -> return@onEach
AuthState.SIGNIN -> navigateToScreen<SplashActivity>()
else -> return@onEach
}
}.launchIn(lifecycleScope)
}

private fun navigateToSplashScreen() {
Intent(this, SplashActivity::class.java).apply {
addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP)
startActivity(this)
}
finish()
}

private fun navigateToTendencySplashScreen() {
Intent(this, TendencySplashActivity::class.java).apply {
addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP)
startActivity(this)
}
finish()
}
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package com.going.presentation.onboarding.splash

import android.app.AlertDialog
import android.content.Intent
import android.os.Bundle
import android.os.Handler
import android.os.Looper
Expand All @@ -14,6 +13,7 @@ import com.going.presentation.dashboard.DashBoardActivity
import com.going.presentation.databinding.ActivitySplashBinding
import com.going.presentation.onboarding.signin.SignInActivity
import com.going.presentation.tendency.splash.TendencySplashActivity
import com.going.presentation.util.navigateToScreen
import com.going.ui.base.BaseActivity
import com.going.ui.extension.setStatusBarColorFromResource
import dagger.hilt.android.AndroidEntryPoint
Expand Down Expand Up @@ -49,21 +49,18 @@ class SplashActivity : BaseActivity<ActivitySplashBinding>(R.layout.activity_spl
if (viewModel.getHasAccessToken()) {
viewModel.getUserState()
} else {
navigateToSignInScreen()
navigateToScreen<SignInActivity>()
}
}, 2200)
}

private fun observeUserState() {
viewModel.userState.flowWithLifecycle(lifecycle).onEach { state ->
when (state) {
AuthState.LOADING -> return@onEach
AuthState.SUCCESS -> navigateToDashBoardScreen()
AuthState.FAILURE -> navigateToSignInScreen()
AuthState.SIGNUP -> return@onEach
AuthState.SIGNIN -> return@onEach
AuthState.TENDENCY -> navigateToTendencyScreen()
AuthState.EMPTY -> return@onEach
AuthState.SUCCESS -> navigateToScreen<DashBoardActivity>()
AuthState.FAILURE -> navigateToScreen<SignInActivity>()
AuthState.TENDENCY -> navigateToScreen<TendencySplashActivity>()
else -> return@onEach
}
}.launchIn(lifecycleScope)
}
Expand All @@ -80,28 +77,4 @@ class SplashActivity : BaseActivity<ActivitySplashBinding>(R.layout.activity_spl
}
.create()
.show()

private fun navigateToDashBoardScreen() {
Intent(this, DashBoardActivity::class.java).apply {
addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP)
startActivity(this)
}
finish()
}

private fun navigateToTendencyScreen() {
Intent(this, TendencySplashActivity::class.java).apply {
addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP)
startActivity(this)
}
finish()
}

private fun navigateToSignInScreen() {
Intent(this, SignInActivity::class.java).apply {
addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP)
startActivity(this)
}
finish()
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ class SettingActivity : BaseActivity<ActivitySettingBinding>(R.layout.activity_s
"https://goinggoing.notion.site/FAQ-920f6ad93fea46a983061f412e15cad1?pvs=74"
private const val PRIVACY_POLICY_URL =
"https://goinggoing.notion.site/c4d5513bba2c4c20aaf9e21522289304?pvs=74"
private const val TERMS_URL =
const val TERMS_URL =
"https://goinggoing.notion.site/75f5d981a5b842a6be74a9dc17ca67de?pvs=74"
private const val ABOUT_DOORIP_URL =
"https://goinggoing.notion.site/758273e2bebb477aac0adb0195359f21"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import com.going.presentation.databinding.ActivityTendencyResultBinding
import com.going.presentation.tendency.splash.TendencySplashActivity
import com.going.presentation.util.downloadImage
import com.going.presentation.util.initOnBackPressedListener
import com.going.presentation.util.navigateToScreen
import com.going.ui.base.BaseActivity
import com.going.ui.extension.UiState
import com.going.ui.extension.setBulletPoint
Expand Down Expand Up @@ -46,10 +47,9 @@ class TendencyResultActivity :
private fun observeUserInfoState() {
viewModel.userInfoState.flowWithLifecycle(lifecycle).onEach { state ->
when (state) {
is UiState.Loading -> return@onEach
is UiState.Success -> bindTendencyInfo(state.data.name, state.data.result)
is UiState.Failure -> toast(state.msg)
is UiState.Empty -> return@onEach
else -> return@onEach
}
}.launchIn(lifecycleScope)
}
Expand Down Expand Up @@ -97,7 +97,7 @@ class TendencyResultActivity :

private fun initRestartBtnClickListener() {
binding.btnTendencyTestRestart.setOnSingleClickListener {
navigateToTendencySplashScreen()
navigateToScreen<TendencySplashActivity>()
}
}

Expand All @@ -109,26 +109,15 @@ class TendencyResultActivity :

private fun initFinishBtnClickListener() {
binding.btnTendencyResultFinish.setOnSingleClickListener {
navigateToDashBoardScreen()
navigateToScreen<DashBoardActivity>(
listOf(
Intent.FLAG_ACTIVITY_NEW_TASK,
Intent.FLAG_ACTIVITY_CLEAR_TASK,
),
)
}
}

private fun navigateToTendencySplashScreen() {
Intent(this, TendencySplashActivity::class.java).apply {
addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP)
startActivity(this)
}
finish()
}

private fun navigateToDashBoardScreen() {
Intent(this, DashBoardActivity::class.java).apply {
startActivity(this)
finishAffinity()
}
finish()
}

override fun onRequestPermissionsResult(
requestCode: Int,
permissions: Array<out String>,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import com.going.presentation.R
import com.going.presentation.databinding.ActivityTendencySplashBinding
import com.going.presentation.tendency.ttest.TendencyTestActivity
import com.going.presentation.util.initOnBackPressedListener
import com.going.presentation.util.navigateToScreen
import com.going.ui.base.BaseActivity
import com.going.ui.extension.setOnSingleClickListener

Expand All @@ -21,15 +22,7 @@ class TendencySplashActivity :

private fun initStartBtnClickListener() {
binding.btnTendencySplashStart.setOnSingleClickListener {
navigateToTendencyTestScreen()
navigateToScreen<TendencyTestActivity>()
}
}

private fun navigateToTendencyTestScreen() {
Intent(this, TendencyTestActivity::class.java).apply {
addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP)
startActivity(this)
}
finish()
}
}
Loading

0 comments on commit 891a5c2

Please sign in to comment.