Skip to content

Commit 3afa13d

Browse files
committed
v1.5.0 included screen-size into device response data and modified AbstractModel.generateWidgets to be able to access this response data (ActionResult) directly
1 parent f185f51 commit 3afa13d

File tree

6 files changed

+58
-15
lines changed

6 files changed

+58
-15
lines changed

build.gradle.kts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919

2020
import org.jetbrains.kotlin.gradle.tasks.KotlinCompile
2121

22-
version = "1.4.4"
22+
version = "1.5.0"
2323
group = "org.droidmate"
2424

2525
plugins {
@@ -39,7 +39,7 @@ dependencies {
3939
// compile("org.droidmate:deviceDaemonLib") {
4040
// in theory it should be 'api', but for some reason that does not work for transitive classpath dependencies
4141
version {
42-
require("[2.4.1, 2.5[")
42+
require("[2.4.1, 2.6[")
4343
}
4444
}
4545

src/main/kotlin/org/droidmate/explorationModel/ExplorationTrace.kt

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -192,6 +192,29 @@ open class ExplorationTrace<S,W>(private val watcher: MutableList<ModelFeatureI>
192192
return trace.getOrNull { it.lastOrNull() }
193193
}
194194

195+
/**
196+
* in contrast to [last] this method returns a list containing exactly the last action or
197+
* in case the last entry was action queue all actions which belong to this queue
198+
*/
199+
suspend fun lastActionSequence(): List<Interaction<W>> {
200+
val actions: List<Interaction<W>> = trace.getAll()
201+
val res = mutableListOf<Interaction<W>>()
202+
val last = actions.lastOrNull() ?: return emptyList()
203+
if (last.actionType.isQueueEnd()){
204+
var numQueues = 1
205+
var idx = actions.size-2
206+
while (idx >= 0 && numQueues > 0){
207+
val a = actions[idx--]
208+
when {
209+
a.actionType.isQueueEnd() -> numQueues++
210+
a.actionType.isQueueStart() -> numQueues --
211+
else -> res.add(a)
212+
}
213+
}
214+
} else res.add(last)
215+
return res
216+
}
217+
195218
/** this has to access a co-routine actor prefer using [size] if synchronization is not critical */
196219
suspend fun isEmpty(): Boolean{
197220
return trace.get { it.isEmpty() }

src/main/kotlin/org/droidmate/explorationModel/config/ModelConfig.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ class ModelConfig private constructor(path: Path,
4646
private val config: Configuration,
4747
@Suppress("MemberVisibilityCanBePrivate") // used by some model features to restore/load their state
4848
val isLoadC: Boolean = false) : Configuration by config {
49-
/** @path path-string locationg the base directory where all model data is supposed to be dumped */
49+
/** @path path-string locating the base directory where all model data is supposed to be dumped */
5050

5151
constructor(path: Path, appName: String, isLoadC: Boolean = false): this(path.toAbsolutePath(), appName, resourceConfig, isLoadC)
5252

src/main/kotlin/org/droidmate/explorationModel/factory/AbstractModel.kt

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -139,12 +139,19 @@ abstract class AbstractModel<S,W>: CoroutineScope where S: State<W>, W: Widget {
139139

140140
private fun generateWidgets(action: ActionResult, @Suppress("UNUSED_PARAMETER") trace: ExplorationTrace<S,W>): Collection<W>{
141141
val elements: Map<Int, UiElementPropertiesI> = action.guiSnapshot.widgets.associateBy { it.idHash }
142+
return generateWidgets(action, elements)
143+
}
144+
145+
open fun generateWidgets(action: ActionResult, elements: Map<Int, UiElementPropertiesI>): Collection<W>{
142146
return generateWidgets(elements)
143147
}
144148

145149
/** used on model update to compute the list of UI elements contained in the current UI screen ([State]).
146150
* used by ModelParser to create [Widget] object from persisted data
147151
*/
152+
@Deprecated("this function signature will change " +
153+
"please use generateWidgets(action: ActionResult, elements: Map<Int, UiElementPropertiesI>) instead",
154+
replaceWith = ReplaceWith("generateWidgets(action, elements)"))
148155
open fun generateWidgets(elements: Map<Int, UiElementPropertiesI>): Collection<W>{
149156
val widgets = HashMap<Int,W>()
150157
val workQueue = LinkedList<UiElementPropertiesI>().apply {

src/main/kotlin/org/droidmate/explorationModel/interaction/NavigateTo.kt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import org.droidmate.deviceInterface.exploration.ExplorationAction
77
import org.droidmate.deviceInterface.exploration.Rectangle
88
import org.droidmate.deviceInterface.exploration.Swipe
99
import org.droidmate.explorationModel.debugOut
10+
import org.droidmate.explorationModel.interaction.Widget.Companion.copy
1011
import java.util.*
1112
import kotlin.math.abs
1213
import kotlin.math.max

src/main/kotlin/org/droidmate/explorationModel/interaction/Widget.kt

Lines changed: 24 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ import java.util.*
3030
import kotlin.collections.HashMap
3131

3232
@Suppress("unused")
33-
open class Widget private constructor(properties: UiElementPropertiesI,
33+
open class Widget protected constructor(properties: UiElementPropertiesI,
3434
val parentId: ConcreteId?, overrideId: ConcreteId?): UiElementPropertiesI {
3535

3636
constructor(properties: UiElementPropertiesI, parentId: ConcreteId?): this(properties,parentId,null)
@@ -111,10 +111,30 @@ open class Widget private constructor(properties: UiElementPropertiesI,
111111
return relevantProperties.joinToString("<;>").toUUID()
112112
}
113113

114+
@JvmOverloads open fun <W: Widget> copy(boundaries: Rectangle, visibleBounds:Rectangle,
115+
defVisible:Boolean, id:ConcreteId?,
116+
init: (properties: UiElementPropertiesI)-> W ): W{
117+
val properties: MutableMap<String,Any?> = HashMap()
118+
StringCreator.annotatedProperties.forEach { p ->
119+
properties[p.property.name] = p.property.call(this)
120+
}
121+
properties[this::boundaries.name] = boundaries
122+
properties[this::visibleBounds.name] = visibleBounds
123+
properties[this::definedAsVisible.name] = defVisible
124+
125+
return init(UiElementP(properties))
126+
}
114127

115128
companion object {
116129
/** used for dummy initializations, if nullable is undesirable */
117130
internal val emptyWidget by lazy{ Widget(DummyProperties,null) }
131+
132+
fun <W: Widget> W.copy(boundaries: Rectangle = this.boundaries, visibleBounds:Rectangle = this.visibleBounds,
133+
defVisible:Boolean=this.definedAsVisible, id:ConcreteId? = null,
134+
init: (properties: UiElementPropertiesI)-> W = {
135+
properties ->
136+
Widget(properties, parentId, id) as W
137+
}): W = copy(boundaries, visibleBounds, defVisible, id, init)
118138
}
119139

120140
/*** overwritten functions ***/
@@ -170,17 +190,9 @@ open class Widget private constructor(properties: UiElementPropertiesI,
170190
final override val definedAsVisible: Boolean = properties.definedAsVisible
171191
final override val hasUncoveredArea: Boolean = properties.hasUncoveredArea
172192

173-
@JvmOverloads open fun copy(boundaries: Rectangle = this.boundaries, visibleBounds:Rectangle = this.visibleBounds,
174-
defVisible:Boolean=this.definedAsVisible, id:ConcreteId? = null): Widget{
175-
val properties: MutableMap<String,Any?> = HashMap()
176-
StringCreator.annotatedProperties.forEach { p ->
177-
properties[p.property.name] = p.property.call(this)
178-
}
179-
properties[this::boundaries.name] = boundaries
180-
properties[this::visibleBounds.name] = visibleBounds
181-
properties[this::definedAsVisible.name] = defVisible
182-
return Widget(UiElementP(properties),parentId,id)
183-
}
193+
184194
/* end override */
185195

186196
}
197+
198+

0 commit comments

Comments
 (0)