This commit is contained in:
世界 2023-08-08 20:41:28 +08:00
parent b4a6c47155
commit 3ec2c767c8
No known key found for this signature in database
GPG key ID: CD109927C34A63C4
2 changed files with 27 additions and 10 deletions

View file

@ -100,19 +100,24 @@ class GroupsFragment : Fragment(), CommandClientHandler {
commandClient = null
}
private var displayed = false
private fun updateDisplayed(newValue: Boolean) {
if (displayed != newValue) {
displayed = newValue
binding.statusText.isVisible = !displayed
binding.container.isVisible = displayed
}
}
override fun connected() {
val binding = _binding ?: return
lifecycleScope.launch(Dispatchers.Main) {
binding.statusText.isVisible = false
binding.container.isVisible = true
updateDisplayed(true)
}
}
override fun disconnected(message: String?) {
val binding = _binding ?: return
lifecycleScope.launch(Dispatchers.Main) {
binding.statusText.isVisible = true
binding.container.isVisible = false
updateDisplayed(false)
}
}
@ -123,6 +128,7 @@ class GroupsFragment : Fragment(), CommandClientHandler {
groups.add(message.next())
}
activity?.runOnUiThread {
updateDisplayed(groups.isNotEmpty())
adapter.groups = groups
adapter.notifyDataSetChanged()
}

View file

@ -34,6 +34,7 @@ class DashboardFragment : Fragment(R.layout.fragment_dashboard) {
private fun onCreate() {
val activity = activity ?: return
binding.dashboardPager.adapter = Adapter(this)
binding.dashboardPager.offscreenPageLimit = Page.values().size
TabLayoutMediator(binding.dashboardTabLayout, binding.dashboardPager) { tab, position ->
tab.setText(Page.values()[position].titleRes)
}.attach()
@ -42,8 +43,7 @@ class DashboardFragment : Fragment(R.layout.fragment_dashboard) {
Status.Stopped -> {
binding.fab.setImageResource(R.drawable.ic_play_arrow_24)
binding.fab.show()
binding.dashboardTabLayout.isVisible = false
binding.dashboardPager.isUserInputEnabled = false
disablePager()
}
Status.Starting -> {
@ -53,12 +53,12 @@ class DashboardFragment : Fragment(R.layout.fragment_dashboard) {
Status.Started -> {
binding.fab.setImageResource(R.drawable.ic_stop_24)
binding.fab.show()
binding.dashboardTabLayout.isVisible = true
binding.dashboardPager.isUserInputEnabled = true
enablePager()
}
Status.Stopping -> {
binding.fab.hide()
disablePager()
}
else -> {}
@ -79,6 +79,17 @@ class DashboardFragment : Fragment(R.layout.fragment_dashboard) {
}
}
private fun enablePager() {
binding.dashboardTabLayout.isVisible = true
binding.dashboardPager.isUserInputEnabled = true
}
private fun disablePager() {
binding.dashboardTabLayout.isVisible = false
binding.dashboardPager.isUserInputEnabled = false
binding.dashboardPager.setCurrentItem(0, false)
}
enum class Page(@StringRes val titleRes: Int, val fragmentClass: Class<out Fragment>) {
Overview(R.string.title_overview, OverviewFragment::class.java),
Groups(R.string.title_groups, GroupsFragment::class.java);