Move dashboard fab button to overview

This commit is contained in:
世界 2023-11-10 21:08:39 +08:00
parent 8950a041a2
commit df2cf22428
No known key found for this signature in database
GPG key ID: CD109927C34A63C4
4 changed files with 47 additions and 43 deletions

View file

@ -66,14 +66,44 @@ class OverviewFragment : Fragment() {
binding.profileList.addItemDecoration(divider)
activity.serviceStatus.observe(viewLifecycleOwner) {
binding.statusContainer.isVisible = it == Status.Starting || it == Status.Started
if (it == Status.Stopped) {
binding.clashModeCard.isVisible = false
binding.systemProxyCard.isVisible = false
when (it) {
Status.Stopped -> {
binding.clashModeCard.isVisible = false
binding.systemProxyCard.isVisible = false
binding.fab.setImageResource(R.drawable.ic_play_arrow_24)
binding.fab.show()
}
Status.Starting -> {
binding.fab.hide()
}
Status.Started -> {
statusClient.connect()
clashModeClient.connect()
reloadSystemProxyStatus()
binding.fab.setImageResource(R.drawable.ic_stop_24)
binding.fab.show()
}
Status.Stopping -> {
binding.fab.hide()
}
else -> {}
}
if (it == Status.Started) {
statusClient.connect()
clashModeClient.connect()
reloadSystemProxyStatus()
}
binding.fab.setOnClickListener {
when (activity.serviceStatus.value) {
Status.Stopped -> {
activity.startService()
}
Status.Started -> {
BoxService.stop()
}
else -> {}
}
}
ProfileManager.registerCallback(this::updateProfiles)

View file

@ -10,7 +10,6 @@ import androidx.fragment.app.Fragment
import androidx.viewpager2.adapter.FragmentStateAdapter
import com.google.android.material.tabs.TabLayoutMediator
import io.nekohasekai.sfa.R
import io.nekohasekai.sfa.bg.BoxService
import io.nekohasekai.sfa.constant.Status
import io.nekohasekai.sfa.databinding.FragmentDashboardBinding
import io.nekohasekai.sfa.ui.MainActivity
@ -41,39 +40,15 @@ class DashboardFragment : Fragment(R.layout.fragment_dashboard) {
activity.serviceStatus.observe(viewLifecycleOwner) {
when (it) {
Status.Stopped -> {
binding.fab.setImageResource(R.drawable.ic_play_arrow_24)
binding.fab.show()
disablePager()
}
Status.Starting -> {
binding.fab.hide()
}
Status.Started -> {
binding.fab.setImageResource(R.drawable.ic_stop_24)
binding.fab.show()
enablePager()
}
Status.Stopping -> {
binding.fab.hide()
disablePager()
}
else -> {}
}
}
binding.fab.setOnClickListener {
when (activity.serviceStatus.value) {
Status.Stopped -> {
activity.startService()
}
Status.Started -> {
BoxService.stop()
}
else -> {}
}
}

View file

@ -43,15 +43,4 @@
</LinearLayout>
<com.google.android.material.floatingactionbutton.FloatingActionButton
android:id="@+id/fab"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="bottom|end"
android:layout_margin="16dp"
android:backgroundTint="@color/blue_grey_600"
app:srcCompat="@drawable/ic_play_arrow_24"
app:tint="@android:color/white" />
</androidx.coordinatorlayout.widget.CoordinatorLayout>

View file

@ -518,4 +518,14 @@
</androidx.core.widget.NestedScrollView>
<com.google.android.material.floatingactionbutton.FloatingActionButton
android:id="@+id/fab"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="bottom|end"
android:layout_margin="16dp"
android:backgroundTint="@color/blue_grey_600"
app:srcCompat="@drawable/ic_play_arrow_24"
app:tint="@android:color/white" />
</androidx.coordinatorlayout.widget.CoordinatorLayout>