Update: 2026-06-30 03:00:22
This commit is contained in:
Binary file not shown.
Binary file not shown.
@@ -19,7 +19,8 @@ enum class BotState {
|
||||
SEARCHING_START,
|
||||
SEARCHING_END,
|
||||
READING_PRICE,
|
||||
SUBMITTING
|
||||
SUBMITTING,
|
||||
BETWEEN_TRIPS
|
||||
}
|
||||
|
||||
class ScraperAccessibilityService : AccessibilityService() {
|
||||
@@ -64,7 +65,7 @@ class ScraperAccessibilityService : AccessibilityService() {
|
||||
private fun startPolling() {
|
||||
pollingJob = serviceScope.launch {
|
||||
while (isActive) {
|
||||
if (currentState == BotState.IDLE) {
|
||||
if (currentState == BotState.IDLE || currentState == BotState.BETWEEN_TRIPS) {
|
||||
Log.d(TAG, "Polling for tasks as ${workerClient.deviceId}...")
|
||||
val result = workerClient.fetchTask()
|
||||
|
||||
@@ -73,10 +74,13 @@ class ScraperAccessibilityService : AccessibilityService() {
|
||||
handleTask(task)
|
||||
} else {
|
||||
Log.d(TAG, "No tasks available.")
|
||||
if (currentState == BotState.BETWEEN_TRIPS) {
|
||||
currentState = BotState.IDLE
|
||||
currentTask = null
|
||||
}
|
||||
}
|
||||
// Poll every 15 seconds
|
||||
delay(15000)
|
||||
}
|
||||
delay(3000)
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -90,6 +94,14 @@ class ScraperAccessibilityService : AccessibilityService() {
|
||||
|
||||
taxiFPickupDone = false
|
||||
taxiFDestinationDone = false
|
||||
|
||||
// Between trips: app already open, skip launch & nav → directly SEARCHING_START
|
||||
if (currentState == BotState.BETWEEN_TRIPS) {
|
||||
currentState = BotState.SEARCHING_START
|
||||
Log.i(TAG, "Between trips: State -> SEARCHING_START (skip launch)")
|
||||
return
|
||||
}
|
||||
|
||||
currentState = BotState.LAUNCHING_APP
|
||||
|
||||
// Launch the App
|
||||
@@ -378,6 +390,10 @@ class ScraperAccessibilityService : AccessibilityService() {
|
||||
// Extract numeric digits from price
|
||||
val numericPrice = rawPrice.replace(Regex("[^0-9.]"), "").toDoubleOrNull() ?: 0.0
|
||||
|
||||
// Go to between-trips mode immediately (synchronous)
|
||||
// This prevents collectAndScrollPrices from overriding with IDLE
|
||||
currentState = BotState.BETWEEN_TRIPS
|
||||
|
||||
serviceScope.launch {
|
||||
Log.i(TAG, "Submitting price $numericPrice for task $taskId...")
|
||||
val success = workerClient.submitPrice(
|
||||
@@ -396,10 +412,6 @@ class ScraperAccessibilityService : AccessibilityService() {
|
||||
} else {
|
||||
Log.e(TAG, "Failed to submit price.")
|
||||
}
|
||||
|
||||
// Go back to IDLE
|
||||
currentState = BotState.IDLE
|
||||
currentTask = null
|
||||
}
|
||||
}
|
||||
|
||||
@@ -727,12 +739,14 @@ class ScraperAccessibilityService : AccessibilityService() {
|
||||
val cheapest = prices.minByOrNull { it.first } ?: prices.first()
|
||||
Log.i(TAG, "TaxiF: Submitting cheapest price: ${cheapest.second.take(50)} = ${cheapest.first} JOD")
|
||||
submitPriceToServer("${cheapest.first} JOD")
|
||||
} else {
|
||||
return
|
||||
}
|
||||
Log.w(TAG, "TaxiF: No JOD prices found, falling back to generic search")
|
||||
searchPriceByCurrency(rootNode)
|
||||
}
|
||||
if (currentState != BotState.BETWEEN_TRIPS) {
|
||||
currentState = BotState.IDLE
|
||||
}
|
||||
}
|
||||
|
||||
private fun findHorizontalRecyclerView(node: android.view.accessibility.AccessibilityNodeInfo?): android.view.accessibility.AccessibilityNodeInfo? {
|
||||
if (node == null) return null
|
||||
|
||||
Reference in New Issue
Block a user