Skip to content

Commit

Permalink
refactor(#174): BaseActivity에서 LogoutEventRepsoitory collect 제거
Browse files Browse the repository at this point in the history
추후 BaseViewModel을 이용해 추가할 예정
  • Loading branch information
yang1318 committed Dec 6, 2023
1 parent 38b0c17 commit dde3b2e
Showing 1 changed file with 0 additions and 33 deletions.
Original file line number Diff line number Diff line change
@@ -1,28 +1,15 @@
package boostcamp.and07.mindsync.ui.base

import android.content.Intent
import android.os.Bundle
import androidx.appcompat.app.AppCompatActivity
import androidx.databinding.DataBindingUtil
import androidx.databinding.ViewDataBinding
import androidx.lifecycle.Lifecycle
import androidx.lifecycle.lifecycleScope
import androidx.lifecycle.repeatOnLifecycle
import boostcamp.and07.mindsync.data.repository.login.LogoutEvent
import boostcamp.and07.mindsync.data.repository.login.LogoutEventRepository
import boostcamp.and07.mindsync.ui.login.LoginActivity
import kotlinx.coroutines.flow.collectLatest
import kotlinx.coroutines.launch
import javax.inject.Inject

abstract class BaseActivity<T : ViewDataBinding>(private val layoutResId: Int) :
AppCompatActivity() {
private var _binding: T? = null
val binding get() = _binding!!

@Inject
lateinit var logoutRepository: LogoutEventRepository

override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
_binding = DataBindingUtil.setContentView(this, layoutResId)
Expand All @@ -32,29 +19,9 @@ abstract class BaseActivity<T : ViewDataBinding>(private val layoutResId: Int) :

abstract fun init()

open fun setLogoutObserve() {
lifecycleScope.launch {
repeatOnLifecycle(Lifecycle.State.STARTED) {
logoutRepository.logoutEvent.collectLatest { event ->
when (event) {
is LogoutEvent.Logout -> {
navigateToLoginScreen()
}
}
}
}
}
}

override fun onDestroy() {
super.onDestroy()
_binding = null
}

private fun navigateToLoginScreen() {
val intent = Intent(this, LoginActivity::class.java)
intent.flags = Intent.FLAG_ACTIVITY_CLEAR_TASK
startActivity(intent)
finish()
}
}

0 comments on commit dde3b2e

Please sign in to comment.