Commit 698e6674 authored by Mygod's avatar Mygod

Refine code

parent 39840f2a
...@@ -38,7 +38,6 @@ import com.github.shadowsocks.net.HttpsTest ...@@ -38,7 +38,6 @@ import com.github.shadowsocks.net.HttpsTest
import com.google.android.material.bottomappbar.BottomAppBar import com.google.android.material.bottomappbar.BottomAppBar
import kotlinx.coroutines.Dispatchers import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.launch import kotlinx.coroutines.launch
import kotlinx.coroutines.withContext
class StatsBar @JvmOverloads constructor(context: Context, attrs: AttributeSet? = null, class StatsBar @JvmOverloads constructor(context: Context, attrs: AttributeSet? = null,
defStyleAttr: Int = R.attr.bottomAppBarStyle) : defStyleAttr: Int = R.attr.bottomAppBarStyle) :
...@@ -78,8 +77,8 @@ class StatsBar @JvmOverloads constructor(context: Context, attrs: AttributeSet? ...@@ -78,8 +77,8 @@ class StatsBar @JvmOverloads constructor(context: Context, attrs: AttributeSet?
fun changeState(state: BaseService.State) { fun changeState(state: BaseService.State) {
val activity = context as MainActivity val activity = context as MainActivity
fun postWhenStarted(what: () -> Unit) = activity.lifecycleScope.launch { fun postWhenStarted(what: () -> Unit) = activity.lifecycleScope.launch(Dispatchers.Main) {
withContext(Dispatchers.Main) { activity.whenStarted { what() } } activity.whenStarted { what() }
} }
if ((state == BaseService.State.Connected).also { hideOnScroll = it }) { if ((state == BaseService.State.Connected).also { hideOnScroll = it }) {
postWhenStarted { performShow() } postWhenStarted { performShow() }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment