Skip to content

Commit

Permalink
feat(#333): Network off 일때 다이얼로그 출력
Browse files Browse the repository at this point in the history
  • Loading branch information
jaehan4707 committed May 11, 2024
1 parent f8da52a commit 6188f72
Showing 1 changed file with 23 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import boostcamp.and07.mindsync.databinding.ActivityMainBinding
import boostcamp.and07.mindsync.ui.base.BaseActivity
import boostcamp.and07.mindsync.ui.base.BaseActivityViewModel
import boostcamp.and07.mindsync.ui.boardlist.UsersAdapter
import boostcamp.and07.mindsync.ui.dialog.DisConnectedNetworkDialog
import boostcamp.and07.mindsync.ui.profile.ProfileActivity
import boostcamp.and07.mindsync.ui.space.list.SpaceListFragmentDirections
import boostcamp.and07.mindsync.ui.util.ThrottleDuration
Expand Down Expand Up @@ -54,6 +55,7 @@ class MainActivity :
setSideBarNavigation()
setBinding()
observeEvent()
showDisconnectedNetworkDialog()
}

override fun getViewModel(): BaseActivityViewModel {
Expand Down Expand Up @@ -83,6 +85,22 @@ class MainActivity :
}
}

private fun showDisconnectedNetworkDialog() {
val dialog = DisConnectedNetworkDialog(mainViewModel.isConnected)
lifecycleScope.launch {
repeatOnLifecycle(Lifecycle.State.STARTED) {
mainViewModel.isConnected.collectLatest { isConnected ->
if (isConnected.not()) {
dialog.show(
this@MainActivity.supportFragmentManager,
"DisConnectedNetworkDialog",
)
}
}
}
}
}

private fun setNavController() {
val navHostFragment =
(supportFragmentManager.findFragmentById(R.id.fcv_main_nav_host) as NavHostFragment)
Expand Down Expand Up @@ -213,7 +231,11 @@ class MainActivity :
spaceAdapter.setSideBarClickListener(
object : SpaceClickListener {
override fun onClickSpace(space: Space) {
navController.navigate(SpaceListFragmentDirections.actionToBoardListFragment(spaceId = space.id))
navController.navigate(
SpaceListFragmentDirections.actionToBoardListFragment(
spaceId = space.id,
),
)
mainViewModel.updateCurrentSpace(space)
}
},
Expand Down

0 comments on commit 6188f72

Please sign in to comment.