Commit 74d782e7 authored by alep's avatar alep

WIP: before pull

parent 501198d0
package com.whoscall
import com.facebook.react.bridge.ReactApplicationContext
import com.facebook.react.bridge.ReactContextBaseJavaModule
import com.facebook.react.bridge.ReactMethod
import com.facebook.react.bridge.Promise
import org.json.JSONArray
class ContactModule(reactContext: ReactApplicationContext) :
ReactContextBaseJavaModule(reactContext) {
override fun getName(): String = "ContactModule"
@ReactMethod
fun getDisplayName(contactsJson: String, incomingNumber: String, promise: Promise) {
try {
val arr = JSONArray(contactsJson)
val normIncoming = normalize(incomingNumber)
for (i in 0 until arr.length()) {
val obj = arr.getJSONObject(i)
val number = normalize(obj.getString("number"))
val name = obj.getString("name")
if (normIncoming == number) {
promise.resolve(name)
return
}
}
promise.resolve(null)
} catch (e: Exception) {
promise.reject("ERR", e)
}
}
private fun normalize(n: String): String {
return n.replace(Regex("[^+0-9]"), "")
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment