Skip to content

Your phone, on your command. Gotcha is world's first fully on-device AI copilot for Android that turns natural language into real device actions — safely.

feat: update currency regex for Indian grouping support and prioritize smart actions in overlay menu

Rishabh Bajpaie1b460c2ae2f
diff --git a/app/src/main/java/com/gotcha/service/SmartActionDetector.kt b/app/src/main/java/com/gotcha/service/SmartActionDetector.kt
index 65eb516..d5bdae6 100644
--- a/app/src/main/java/com/gotcha/service/SmartActionDetector.kt
+++ b/app/src/main/java/com/gotcha/service/SmartActionDetector.kt
@@ -130,8 +130,8 @@ object SmartActionDetector {
)
private val currencyPattern: Pattern = Pattern.compile(
- "([¥€£$]|₹|INR|Rs\\.?)\\s?\\d{1,6}(\\.\\d{2})?\\b" +
- "|\\b\\d{1,6}(\\.\\d{2})?\\s?(USD|EUR|GBP|INR|JPY|CAD|AUD|₹|Rs\\.?)\\b",
+ "([¥€£$]|₹|INR|Rs\\.?)\\s?\\d{1,6}(?:,\\d{2,3})*(?:\\.\\d{2})?\\b" +
+ "|\\b\\d{1,6}(?:,\\d{2,3})*(?:\\.\\d{2})?\\s?(USD|EUR|GBP|INR|JPY|CAD|AUD|₹|Rs\\.?)\\b",
Pattern.CASE_INSENSITIVE
)
diff --git a/app/src/main/java/com/gotcha/ui/AssistiveBallOverlay.kt b/app/src/main/java/com/gotcha/ui/AssistiveBallOverlay.kt
index a820432..cf06971 100644
--- a/app/src/main/java/com/gotcha/ui/AssistiveBallOverlay.kt
+++ b/app/src/main/java/com/gotcha/ui/AssistiveBallOverlay.kt
@@ -171,12 +171,7 @@ class AssistiveBallOverlay(context: Context) {
fun setProactiveSessionItems(items: List<ProactiveSessionItem>) {
mainHandler.post {
proactiveSessionItems = items
- if (items.isNotEmpty()) {
- val topEntity = items.first().entity
- topEntity.primaryAction?.let { action ->
- setSmartActionAvailable(action.label, action.prompt)
- }
- } else {
+ if (items.isEmpty()) {
clearSmartAction()
}
}
@@ -193,10 +188,6 @@ class AssistiveBallOverlay(context: Context) {
fun setSmartActionAvailable(label: String, prompt: String, altLabel: String?, altPrompt: String?) {
mainHandler.post {
if (isCallActive()) return@post
- val currentLabel = pendingSmartAction?.first ?: ""
- if (currentLabel.contains("copied", ignoreCase = true) && !label.contains("copied", ignoreCase = true)) {
- return@post
- }
if (label == lastOfferedLabel) return@post
lastOfferedLabel = label
@@ -366,6 +357,25 @@ class AssistiveBallOverlay(context: Context) {
}
private fun buildProactiveMenuContent(menuCard: LinearLayout, colors: OverlayPalette) {
+ // Always show clipboard/smart action at the top
+ pendingSmartAction?.let { (label, prompt) ->
+ menuCard.addView(
+ tapButton(label, colors) {
+ removeMenu()
+ onSmartActionSelected(prompt)
+ }
+ )
+ }
+ pendingSmartActionAlt?.let { (altLabel, altPrompt) ->
+ menuCard.addView(
+ tapButton(altLabel, colors) {
+ removeMenu()
+ onSmartActionSelected(altPrompt)
+ }
+ )
+ }
+
+ // Then show proactive screen-scan entities if any
if (proactiveSessionItems.isNotEmpty()) {
val scroll = ScrollView(appContext).apply {
layoutParams = LinearLayout.LayoutParams(
@@ -421,23 +431,6 @@ class AssistiveBallOverlay(context: Context) {
}
scroll.addView(listContent)
menuCard.addView(scroll)
- } else {
- pendingSmartAction?.let { (label, prompt) ->
- menuCard.addView(
- tapButton(label, colors) {
- removeMenu()
- onSmartActionSelected(prompt)
- }
- )
- }
- pendingSmartActionAlt?.let { (altLabel, altPrompt) ->
- menuCard.addView(
- tapButton(altLabel, colors) {
- removeMenu()
- onSmartActionSelected(altPrompt)
- }
- )
- }
}
}
diff --git a/app/src/test/java/com/gotcha/service/SmartActionDetectorTest.kt b/app/src/test/java/com/gotcha/service/SmartActionDetectorTest.kt
index d10540e..6b9e483 100644
--- a/app/src/test/java/com/gotcha/service/SmartActionDetectorTest.kt
+++ b/app/src/test/java/com/gotcha/service/SmartActionDetectorTest.kt
@@ -87,6 +87,54 @@ class SmartActionDetectorTest {
)
}
+ @Test
+ fun `detectAll finds Indian-format comma-grouped currency INR`() {
+ val entities = SmartActionDetector.detectAll("Total is INR1,23,456")
+ val currency = entities.firstOrNull { it.type == EntityType.CURRENCY }
+ assertNotNull("Should detect INR1,23,456 as a currency", currency)
+ assertTrue("rawValue should contain the full number", currency!!.rawValue.contains("1,23,456"))
+ assertTrue(currency.actions.any { it.label.contains("Convert") })
+ }
+
+ @Test
+ fun `detectAll finds rupee symbol with Indian comma grouping and decimal`() {
+ val entities = SmartActionDetector.detectAll("Price is ₹12,34,567.89")
+ val currency = entities.firstOrNull { it.type == EntityType.CURRENCY }
+ assertNotNull("Should detect ₹12,34,567.89 as a currency", currency)
+ assertTrue(currency!!.rawValue.contains("12,34,567.89"))
+ assertTrue(currency.actions.any { it.label.contains("Convert") })
+ }
+
+ @Test
+ fun `detectAll finds western comma-formatted dollar amount`() {
+ val entities = SmartActionDetector.detectAll("Total is $1,234,567.89 USD")
+ val currency = entities.firstOrNull { it.type == EntityType.CURRENCY }
+ assertNotNull("Should detect $1,234,567.89 USD as a currency", currency)
+ }
+
+ @Test
+ fun `detectAll finds Rs format with Indian comma grouping`() {
+ val entities = SmartActionDetector.detectAll("Cost Rs. 12,34,567")
+ val currency = entities.firstOrNull { it.type == EntityType.CURRENCY }
+ assertNotNull("Should detect Rs. 12,34,567 as a currency", currency)
+ assertTrue(currency!!.rawValue.contains("12,34,567"))
+ }
+
+ @Test
+ fun `detectAll finds euro symbol with comma-grouped thousands`() {
+ val entities = SmartActionDetector.detectAll("Price is €1,234.56", targetCurrency = "USD")
+ val currency = entities.firstOrNull { it.type == EntityType.CURRENCY }
+ assertNotNull("Should detect €1,234.56 as a currency", currency)
+ assertTrue(currency!!.actions.any { it.label.contains("Convert") })
+ }
+
+ @Test
+ fun `detectAll still finds plain digit currency amounts`() {
+ val entities = SmartActionDetector.detectAll("Price is ₹1250")
+ val currency = entities.firstOrNull { it.type == EntityType.CURRENCY }
+ assertNotNull("Should still detect plain ₹1250", currency)
+ }
+
@Test
fun `isTextInLanguage detects whether text matches target language`() {
assertTrue(SmartActionDetector.isTextInLanguage("Call us at (415) 555-0199 for assistance", "English"))