Update: 2026-06-30 03:05:30

This commit is contained in:
Hamza-Ayed
2026-06-30 03:05:30 +03:00
parent 11140bca49
commit fdfe225b7b
7 changed files with 27 additions and 26 deletions

View File

@@ -19,8 +19,7 @@ enum class BotState {
SEARCHING_START, SEARCHING_START,
SEARCHING_END, SEARCHING_END,
READING_PRICE, READING_PRICE,
SUBMITTING, SUBMITTING
BETWEEN_TRIPS
} }
class ScraperAccessibilityService : AccessibilityService() { class ScraperAccessibilityService : AccessibilityService() {
@@ -65,7 +64,7 @@ class ScraperAccessibilityService : AccessibilityService() {
private fun startPolling() { private fun startPolling() {
pollingJob = serviceScope.launch { pollingJob = serviceScope.launch {
while (isActive) { while (isActive) {
if (currentState == BotState.IDLE || currentState == BotState.BETWEEN_TRIPS) { if (currentState == BotState.IDLE) {
Log.d(TAG, "Polling for tasks as ${workerClient.deviceId}...") Log.d(TAG, "Polling for tasks as ${workerClient.deviceId}...")
val result = workerClient.fetchTask() val result = workerClient.fetchTask()
@@ -74,13 +73,10 @@ class ScraperAccessibilityService : AccessibilityService() {
handleTask(task) handleTask(task)
} else { } else {
Log.d(TAG, "No tasks available.") Log.d(TAG, "No tasks available.")
if (currentState == BotState.BETWEEN_TRIPS) {
currentState = BotState.IDLE
currentTask = null
}
} }
} }
delay(3000) // Poll every 15 seconds
delay(15000)
} }
} }
} }
@@ -94,14 +90,6 @@ class ScraperAccessibilityService : AccessibilityService() {
taxiFPickupDone = false taxiFPickupDone = false
taxiFDestinationDone = 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 currentState = BotState.LAUNCHING_APP
// Launch the App // Launch the App
@@ -390,10 +378,6 @@ class ScraperAccessibilityService : AccessibilityService() {
// Extract numeric digits from price // Extract numeric digits from price
val numericPrice = rawPrice.replace(Regex("[^0-9.]"), "").toDoubleOrNull() ?: 0.0 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 { serviceScope.launch {
Log.i(TAG, "Submitting price $numericPrice for task $taskId...") Log.i(TAG, "Submitting price $numericPrice for task $taskId...")
val success = workerClient.submitPrice( val success = workerClient.submitPrice(
@@ -412,6 +396,25 @@ class ScraperAccessibilityService : AccessibilityService() {
} else { } else {
Log.e(TAG, "Failed to submit price.") Log.e(TAG, "Failed to submit price.")
} }
// Wait 3 seconds, then fetch next trip directly (no relaunch)
delay(3000)
val nextResult = workerClient.fetchTask()
if (nextResult != null && nextResult.optBoolean("has_task", false)) {
val nextTask = nextResult.getJSONObject("task")
val nextApp = nextTask.optString("app")
Log.i(TAG, "Multi-trip: Fetched next task for $nextApp, going directly to SEARCHING_START")
currentTask = nextTask
currentAppName = nextApp
taxiFPickupDone = false
taxiFDestinationDone = false
currentState = BotState.SEARCHING_START
} else {
Log.d(TAG, "Multi-trip: No more tasks, going IDLE.")
currentState = BotState.IDLE
currentTask = null
}
} }
} }
@@ -739,13 +742,11 @@ class ScraperAccessibilityService : AccessibilityService() {
val cheapest = prices.minByOrNull { it.first } ?: prices.first() val cheapest = prices.minByOrNull { it.first } ?: prices.first()
Log.i(TAG, "TaxiF: Submitting cheapest price: ${cheapest.second.take(50)} = ${cheapest.first} JOD") Log.i(TAG, "TaxiF: Submitting cheapest price: ${cheapest.second.take(50)} = ${cheapest.first} JOD")
submitPriceToServer("${cheapest.first} JOD") submitPriceToServer("${cheapest.first} JOD")
return } else {
} Log.w(TAG, "TaxiF: No JOD prices found, falling back to generic search")
Log.w(TAG, "TaxiF: No JOD prices found, falling back to generic search") searchPriceByCurrency(rootNode)
searchPriceByCurrency(rootNode)
if (currentState != BotState.BETWEEN_TRIPS) {
currentState = BotState.IDLE
} }
currentState = BotState.IDLE
} }
private fun findHorizontalRecyclerView(node: android.view.accessibility.AccessibilityNodeInfo?): android.view.accessibility.AccessibilityNodeInfo? { private fun findHorizontalRecyclerView(node: android.view.accessibility.AccessibilityNodeInfo?): android.view.accessibility.AccessibilityNodeInfo? {