Skip to content

Commit

Permalink
feat: 스플래쉬에서 강제업데이트 다이얼로그 구현
Browse files Browse the repository at this point in the history
  • Loading branch information
yeonjeen committed Dec 25, 2024
1 parent 21aa8ab commit c1ec4c2
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 3 deletions.
24 changes: 21 additions & 3 deletions app/src/main/java/com/into/websoso/ui/splash/SplashActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import com.into.websoso.common.ui.base.BaseActivity
import com.into.websoso.databinding.ActivityLoginBinding
import com.into.websoso.ui.login.LoginActivity
import com.into.websoso.ui.main.MainActivity
import com.into.websoso.ui.splash.dialog.MinimumVersionDialogFragment
import dagger.hilt.android.AndroidEntryPoint
import kotlinx.coroutines.delay
import kotlinx.coroutines.launch
Expand All @@ -21,15 +22,22 @@ class SplashActivity : BaseActivity<ActivityLoginBinding>(R.layout.activity_spla

setupObserver()
splashViewModel.autoLogin()
showMinimumVersionDialog()
}

private fun setupObserver() {
splashViewModel.isAutoLogin.observe(this) { isAutoLogin ->
lifecycleScope.launch {
delay(1000L)
when (isAutoLogin) {
true -> navigateToMainActivity()
false -> navigateToLoginActivity()
splashViewModel.updateMinimumVersion { isUpdateRequired ->
if (isUpdateRequired) {
showMinimumVersionDialog()
} else {
when (isAutoLogin) {
true -> navigateToMainActivity()
false -> navigateToLoginActivity()
}
}
}
}
}
Expand All @@ -44,4 +52,14 @@ class SplashActivity : BaseActivity<ActivityLoginBinding>(R.layout.activity_spla
startActivity(LoginActivity.getIntent(this))
finish()
}

private fun showMinimumVersionDialog() {
val dialog = MinimumVersionDialogFragment.newInstance()
dialog.isCancelable = false
dialog.show(supportFragmentManager, MINIMUM_VERSION_TAG)
}

companion object {
private const val MINIMUM_VERSION_TAG = "MinimumVersionDialog"
}
}
14 changes: 14 additions & 0 deletions app/src/main/java/com/into/websoso/ui/splash/SplashViewModel.kt
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,15 @@ import androidx.lifecycle.MutableLiveData
import androidx.lifecycle.ViewModel
import androidx.lifecycle.viewModelScope
import com.into.websoso.data.repository.AuthRepository
import com.into.websoso.data.repository.VersionRepository
import dagger.hilt.android.lifecycle.HiltViewModel
import kotlinx.coroutines.launch
import javax.inject.Inject

@HiltViewModel
class SplashViewModel @Inject constructor(
private val authRepository: AuthRepository,
private val versionRepository: VersionRepository,
) : ViewModel() {

private var _isAutoLogin = MutableLiveData(false)
Expand All @@ -32,4 +34,16 @@ class SplashViewModel @Inject constructor(
}
}
}

fun updateMinimumVersion(onUpdateRequired: (Boolean) -> Unit) {
viewModelScope.launch {
runCatching {
versionRepository.isUpdateRequired()
}.onSuccess { isUpdateRequired ->
onUpdateRequired(isUpdateRequired)
}.onFailure {
onUpdateRequired(false)
}
}
}
}

0 comments on commit c1ec4c2

Please sign in to comment.