feat(android): import private Shopee probe tasks
This commit is contained in:
@@ -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"
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user