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_START,
|
||||||
SEARCHING_END,
|
SEARCHING_END,
|
||||||
READING_PRICE,
|
READING_PRICE,
|
||||||
SUBMITTING
|
SUBMITTING,
|
||||||
|
BETWEEN_TRIPS
|
||||||
}
|
}
|
||||||
|
|
||||||
class ScraperAccessibilityService : AccessibilityService() {
|
class ScraperAccessibilityService : AccessibilityService() {
|
||||||
@@ -64,7 +65,7 @@ class ScraperAccessibilityService : AccessibilityService() {
|
|||||||
private fun startPolling() {
|
private fun startPolling() {
|
||||||
pollingJob = serviceScope.launch {
|
pollingJob = serviceScope.launch {
|
||||||
while (isActive) {
|
while (isActive) {
|
||||||
if (currentState == BotState.IDLE) {
|
if (currentState == BotState.IDLE || currentState == BotState.BETWEEN_TRIPS) {
|
||||||
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()
|
||||||
|
|
||||||
@@ -73,10 +74,13 @@ 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
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// Poll every 15 seconds
|
delay(3000)
|
||||||
delay(15000)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -90,6 +94,14 @@ 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
|
||||||
@@ -378,6 +390,10 @@ 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(
|
||||||
@@ -396,10 +412,6 @@ class ScraperAccessibilityService : AccessibilityService() {
|
|||||||
} else {
|
} else {
|
||||||
Log.e(TAG, "Failed to submit price.")
|
Log.e(TAG, "Failed to submit price.")
|
||||||
}
|
}
|
||||||
|
|
||||||
// Go back to IDLE
|
|
||||||
currentState = BotState.IDLE
|
|
||||||
currentTask = null
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -727,11 +739,13 @@ 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")
|
||||||
} else {
|
return
|
||||||
Log.w(TAG, "TaxiF: No JOD prices found, falling back to generic search")
|
}
|
||||||
searchPriceByCurrency(rootNode)
|
Log.w(TAG, "TaxiF: No JOD prices found, falling back to generic search")
|
||||||
|
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? {
|
||||||
|
|||||||
Reference in New Issue
Block a user