Skip to content

Commit 190a97f

Browse files
author
Ven
committed
feat: 增加自定义步骤轮询间隔
1 parent e87866b commit 190a97f

File tree

3 files changed

+7
-4
lines changed

3 files changed

+7
-4
lines changed

assists/src/main/java/com/ven/assist/step/StepCollector.kt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,9 +36,10 @@ class StepCollector(private val clazzName: String) {
3636
fun nextLoop(
3737
step: Int,
3838
loopDuration: Long = 5000,
39+
loopInterval: Long = 250,
3940
next: (stepOperator: StepOperator) -> Boolean
4041
): StepCollector {
41-
stepOperatorMap[step] = StepOperator(clazzName, step, loopDuration, next)
42+
stepOperatorMap[step] = StepOperator(clazzName, step, loopDuration = loopDuration, loopInterval = loopInterval, next)
4243
return this
4344
}
4445
}

assists/src/main/java/com/ven/assist/step/StepManager.kt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,8 @@ object StepManager {
3131
* @param isBegin 是否是初始执行,true则会忽略[isStop]直接开始执行,false则会判断[isStop]是否停止
3232
*/
3333
fun <T : StepImpl> execute(stepImpl: Class<T>, step: Int, delay: Long = Assists.Config.defaultStepDelay, data: Any? = null, isBegin: Boolean = false) {
34-
if (isStop && !isBegin) return
34+
if (isBegin) isStop = false
35+
if (isStop) return
3536
Log.d(Assists.Config.logTag, "execute->${stepImpl.simpleName}:$step-delay:$delay")
3637
stepCollector[stepImpl.name] ?: register(stepImpl)
3738
stepCollector[stepImpl.name]?.get(step)?.let {

assists/src/main/java/com/ven/assist/step/StepOperator.kt

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ class StepOperator(
1010
private val clazzName: String,
1111
val step: Int,
1212
val loopDuration: Long = 0,
13+
val loopInterval: Long = 250,
1314
val next: ((stepOperator: StepOperator) -> Boolean)? = null,
1415
) {
1516

@@ -23,7 +24,7 @@ class StepOperator(
2324
Assists.ListenerManager.stepListener.forEach { it.onStepStop() }
2425
return
2526
}
26-
Log.d(Assists.Config.logTag,"step->$clazzName:$step-delay:$delay")
27+
Log.d(Assists.Config.logTag, "step->$clazzName:$step-delay:$delay")
2728

2829
next?.let {
2930
if (loopDuration == 0L) {
@@ -43,7 +44,7 @@ class StepOperator(
4344
return@runOnUiThreadDelayed
4445
}
4546
loopDownTimer?.cancel()
46-
loopDownTimer = object : CountDownTimer(loopDuration, 250) {
47+
loopDownTimer = object : CountDownTimer(loopDuration, loopInterval) {
4748
override fun onTick(millisUntilFinished: Long) {
4849
loopSurplusTime = millisUntilFinished
4950
loopSurplusSecond = millisUntilFinished / 1000f

0 commit comments

Comments
 (0)