Skip to content

Commit 3b84609

Browse files
author
Ven
committed
opt: 步骤数据传递指定类型
1 parent 3006e8a commit 3b84609

File tree

6 files changed

+14
-11
lines changed

6 files changed

+14
-11
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -120,4 +120,4 @@ StepManager.beginExecute(OpenWechat::class.java, 1)
120120

121121
| 交流群 | 个人微信 |
122122
|:---------:|:-----------:|
123-
| <img src="https://github.com/ven-coder/Assists/blob/master/graphics/1693440317864.png" width=200/> | <img src="https://raw.githubusercontent.com/ven-coder/assists/master/graphics/wechat1.jpg" width=200/>
123+
| <img src="https://github.com/ven-coder/Assists/blob/master/graphics/1694582375808.png" width=200/> | <img src="https://raw.githubusercontent.com/ven-coder/assists/master/graphics/wechat1.jpg" width=200/>
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
package com.ven.assist.step
2+
3+
data class StepData(
4+
var code: Int = 0, var message: String = "", var data: Any? = null
5+
)

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ object StepManager {
1717
* @param step 步骤序号
1818
* @param delay 步骤执行延迟时间,默认[Assists.Config.defaultStepDelay]
1919
*/
20-
private fun <T : StepImpl> beginExecute(stepImpl: Class<T>, step: Int, delay: Long = Assists.Config.defaultStepDelay, data: Any? = null): StepManager {
20+
private fun <T : StepImpl> beginExecute(stepImpl: Class<T>, step: Int, delay: Long = Assists.Config.defaultStepDelay, data: StepData? = null): StepManager {
2121
isStop = false
2222
execute(stepImpl, step, delay, data)
2323
return this
@@ -30,7 +30,7 @@ object StepManager {
3030
* @param delay 步骤执行延迟时间,默认[Assists.Config.defaultStepDelay]
3131
* @param isBegin 是否是初始执行,true则会忽略[isStop]直接开始执行,false则会判断[isStop]是否停止
3232
*/
33-
fun <T : StepImpl> execute(stepImpl: Class<T>, step: Int, delay: Long = Assists.Config.defaultStepDelay, data: Any? = null, isBegin: Boolean = false) {
33+
fun <T : StepImpl> execute(stepImpl: Class<T>, step: Int, delay: Long = Assists.Config.defaultStepDelay, data: StepData? = null, isBegin: Boolean = false) {
3434
if (isBegin) isStop = false
3535
if (isStop) return
3636
Log.d(Assists.Config.logTag, "execute->${stepImpl.name}:$step-delay:$delay")

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

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
package com.ven.assist.step
22

33
import android.os.CountDownTimer
4-
import android.util.Log
54
import com.blankj.utilcode.util.LogUtils
65
import com.blankj.utilcode.util.ThreadUtils
76
import com.ven.assist.Assists
@@ -17,15 +16,13 @@ class StepOperator(
1716
private var loopDownTimer: CountDownTimer? = null
1817
var loopSurplusTime: Long = 0
1918
var loopSurplusSecond: Float = 0f
20-
var data: Any? = null
19+
var data: StepData? = null
2120

2221
fun execute(delay: Long) {
2322
if (StepManager.isStop) {
2423
Assists.ListenerManager.stepListener.forEach { it.onStepStop() }
2524
return
2625
}
27-
Log.d(Assists.Config.logTag, "step->$clazzName:$step-delay:$delay")
28-
2926
next?.let {
3027
if (loopDuration == 0L) {
3128
ThreadUtils.runOnUiThreadDelayed({

graphics/1694582375808.png

142 KB
Loading

simple/src/main/java/com/ven/assists/simple/step/ScrollContacts.kt

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import com.ven.assist.Assists
77
import com.ven.assist.ext.click
88
import com.ven.assist.ext.getBoundsInScreen
99
import com.ven.assist.step.StepCollector
10+
import com.ven.assist.step.StepData
1011
import com.ven.assist.step.StepImpl
1112
import com.ven.assist.step.StepManager
1213
import com.ven.assist.ui.UIOperate
@@ -32,12 +33,12 @@ class ScrollContacts : StepImpl {
3233
) {
3334
OverManager.log("已打开微信主页,点击【通讯录】")
3435
it.parent.parent.click()
35-
StepManager.execute(this::class.java, Step.STEP_3, data = 1)
36+
StepManager.execute(this::class.java, Step.STEP_3, data = StepData(data = 1))
3637
return@nextLoop true
3738
}
3839
}
3940

40-
if (0f==it.loopSurplusSecond){
41+
if (0f == it.loopSurplusSecond) {
4142
StepManager.execute(this::class.java, Step.STEP_1)
4243
}
4344

@@ -54,7 +55,7 @@ class ScrollContacts : StepImpl {
5455
OverManager.log("停止滚动")
5556
return@next
5657
}
57-
StepManager.execute(this::class.java, Step.STEP_3, data = ((step.data as Int) + 1))
58+
StepManager.execute(this::class.java, Step.STEP_3, data = StepData(data = (step.data?.data as Int) + 1))
5859
return@next
5960
}
6061

@@ -69,7 +70,7 @@ class ScrollContacts : StepImpl {
6970
OverManager.log("停止滚动")
7071
return@next
7172
}
72-
StepManager.execute(this::class.java, Step.STEP_3, data = ((step.data as Int) + 1))
73+
StepManager.execute(this::class.java, Step.STEP_3, data = StepData(data = (step.data?.data as Int) + 1))
7374
return@next
7475
}
7576
}

0 commit comments

Comments
 (0)