mirror of
https://github.com/SagerNet/sing-box-for-android.git
synced 2025-04-03 20:07:38 +03:00
Fixes
This commit is contained in:
parent
b4a6c47155
commit
3ec2c767c8
2 changed files with 27 additions and 10 deletions
|
@ -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()
|
||||
}
|
||||
|
|
|
@ -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);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue