Skip to content

Commit 5494970

Browse files
committed
review: keep STARTED gate on delayed connecting animation
Plain lifecycleScope.launch (replacing launchWhenStarted) could run the delayed progress show() while the activity is stopped. Gate the UI mutation with withStarted to preserve the lifecycle-aware behavior (matches StatsBar).
1 parent 12a999e commit 5494970

1 file changed

Lines changed: 7 additions & 2 deletions

File tree

app/src/main/java/io/nekohasekai/sagernet/widget/ServiceButton.kt

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import androidx.appcompat.widget.TooltipCompat
1212
import androidx.dynamicanimation.animation.DynamicAnimation
1313
import androidx.lifecycle.LifecycleOwner
1414
import androidx.lifecycle.lifecycleScope
15+
import androidx.lifecycle.withStarted
1516
import androidx.vectordrawable.graphics.drawable.Animatable2Compat
1617
import androidx.vectordrawable.graphics.drawable.AnimatedVectorDrawableCompat
1718
import com.google.android.material.floatingactionbutton.FloatingActionButton
@@ -67,8 +68,12 @@ class ServiceButton @JvmOverloads constructor(
6768
hideProgress()
6869
delayedAnimation = (context as LifecycleOwner).lifecycleScope.launch {
6970
delay(context.resources.getInteger(android.R.integer.config_mediumAnimTime) + 1000L)
70-
isIndeterminate = true
71-
show()
71+
// Gate the UI mutation on STARTED so a delayed progress reveal doesn't run
72+
// while the activity is stopped (the old launchWhenStarted suspended here).
73+
(context as LifecycleOwner).withStarted {
74+
isIndeterminate = true
75+
show()
76+
}
7277
}
7378
}
7479
}

0 commit comments

Comments
 (0)