feat(android): import private Shopee probe tasks

This commit is contained in:
QiuSW
2026-07-25 19:06:28 +08:00
parent d57c4ae2d4
commit 1c1c158149
25 changed files with 1034 additions and 34 deletions
@@ -0,0 +1,35 @@
package com.roubao.autopilot.task
import android.content.Context
import com.roubao.task.ProbeTask
import com.roubao.task.ProbeTaskJson
import com.roubao.task.TaskSource
import java.nio.charset.StandardCharsets
import java.util.concurrent.atomic.AtomicInteger
class FixtureTaskSource(
context: Context,
private val taskDocumentAsset: String = DEFAULT_TASK_DOCUMENT_ASSET
) : TaskSource {
private val assetManager = context.applicationContext.assets
private val nextIndex = AtomicInteger(0)
private val tasks: List<ProbeTask> by lazy(LazyThreadSafetyMode.SYNCHRONIZED) {
val payload = assetManager.open(taskDocumentAsset).bufferedReader(
StandardCharsets.UTF_8
).use { it.readText() }
ProbeTaskJson.decode(payload)
}
override suspend fun nextTask(): ProbeTask? {
val index = nextIndex.getAndIncrement()
return tasks.getOrNull(index)
}
fun referenceImageAsset(task: ProbeTask): String =
"$FIXTURE_ASSET_ROOT/${task.referenceImage.relativePath}"
companion object {
private const val FIXTURE_ASSET_ROOT = "probe-fixtures"
private const val DEFAULT_TASK_DOCUMENT_ASSET = "$FIXTURE_ASSET_ROOT/tasks.json"
}
}