@@ -30,12 +30,14 @@ import androidx.appcompat.widget.TooltipCompat
3030import androidx.coordinatorlayout.widget.CoordinatorLayout
3131import androidx.lifecycle.lifecycleScope
3232import androidx.lifecycle.observe
33+ import androidx.lifecycle.whenStarted
3334import com.github.shadowsocks.MainActivity
3435import com.github.shadowsocks.R
3536import com.github.shadowsocks.bg.BaseService
3637import com.github.shadowsocks.net.HttpsTest
3738import com.google.android.material.bottomappbar.BottomAppBar
3839import kotlinx.coroutines.Dispatchers
40+ import kotlinx.coroutines.launch
3941import kotlinx.coroutines.withContext
4042
4143class StatsBar @JvmOverloads constructor(context : Context , attrs : AttributeSet ? = null ,
@@ -76,8 +78,8 @@ class StatsBar @JvmOverloads constructor(context: Context, attrs: AttributeSet?
7678
7779 fun changeState (state : BaseService .State ) {
7880 val activity = context as MainActivity
79- fun postWhenStarted (what : () -> Unit ) = activity.lifecycleScope.launchWhenStarted {
80- withContext(Dispatchers .Main ) { what() }
81+ fun postWhenStarted (what : () -> Unit ) = activity.lifecycleScope.launch {
82+ withContext(Dispatchers .Main ) { activity.whenStarted { what() } }
8183 }
8284 if ((state == BaseService .State .Connected ).also { hideOnScroll = it }) {
8385 postWhenStarted { performShow() }
0 commit comments