File tree Expand file tree Collapse file tree 2 files changed +31
-1
lines changed
androidMain/kotlin/org/mifospay/feature/send/money
commonMain/kotlin/org/mifospay/feature/send/money Expand file tree Collapse file tree 2 files changed +31
-1
lines changed Original file line number Diff line number Diff line change @@ -31,8 +31,10 @@ class AndroidContactRepository(
3131 }
3232
3333 override suspend fun searchContacts (query : String ): List <Contact > {
34+ val normalizedQuery = PhoneNumberUtils .normalizeSearchQuery(query)
35+ // Search by name (contains) and phone number (starts with normalized query)
3436 val selection = " ${ContactsContract .CommonDataKinds .Phone .DISPLAY_NAME } LIKE ? OR ${ContactsContract .CommonDataKinds .Phone .NUMBER } LIKE ?"
35- val selectionArgs = arrayOf(" %$query %" , " % $query %" )
37+ val selectionArgs = arrayOf(" %$query %" , " $normalizedQuery %" )
3638 val rawContacts = queryContacts(selection, selectionArgs)
3739 return PhoneNumberUtils .filterAndFormatContacts(rawContacts)
3840 }
Original file line number Diff line number Diff line change @@ -159,4 +159,32 @@ object PhoneNumberUtils {
159159 }
160160 .distinctBy { contact -> contact.phoneNumber }
161161 }
162+
163+ /* *
164+ * Normalizes a phone number for search purposes by removing country code and spaces
165+ * This allows searching with or without +91 prefix
166+ */
167+ fun normalizePhoneNumberForSearch (phoneNumber : String ): String {
168+ return phoneNumber
169+ .replace(" +91" , " " )
170+ .replace(" " , " " )
171+ .replace(" -" , " " )
172+ .replace(" (" , " " )
173+ .replace(" )" , " " )
174+ .trim()
175+ }
176+
177+ /* *
178+ * Normalizes a search query for phone number matching
179+ * Removes +91 prefix and spaces to match against normalized phone numbers
180+ */
181+ fun normalizeSearchQuery (query : String ): String {
182+ return query
183+ .replace(" +91" , " " )
184+ .replace(" " , " " )
185+ .replace(" -" , " " )
186+ .replace(" (" , " " )
187+ .replace(" )" , " " )
188+ .trim()
189+ }
162190}
You can’t perform that action at this time.
0 commit comments