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 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() { override fun connected() {
val binding = _binding ?: return
lifecycleScope.launch(Dispatchers.Main) { lifecycleScope.launch(Dispatchers.Main) {
binding.statusText.isVisible = false updateDisplayed(true)
binding.container.isVisible = true
} }
} }
override fun disconnected(message: String?) { override fun disconnected(message: String?) {
val binding = _binding ?: return
lifecycleScope.launch(Dispatchers.Main) { lifecycleScope.launch(Dispatchers.Main) {
binding.statusText.isVisible = true updateDisplayed(false)
binding.container.isVisible = false
} }
} }
@ -123,6 +128,7 @@ class GroupsFragment : Fragment(), CommandClientHandler {
groups.add(message.next()) groups.add(message.next())
} }
activity?.runOnUiThread { activity?.runOnUiThread {
updateDisplayed(groups.isNotEmpty())
adapter.groups = groups adapter.groups = groups
adapter.notifyDataSetChanged() adapter.notifyDataSetChanged()
} }

View file

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