Skip to content

Commit

Permalink
Merge pull request #600 from WideChat/karan_add_contact_fallback
Browse files Browse the repository at this point in the history
Add fallbacks for country code determination
  • Loading branch information
ear-dev authored Aug 7, 2019
2 parents e98c6af + d2e592b commit 395c267
Showing 1 changed file with 13 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,19 @@ class ContactsSyncWorker(context : Context, params : WorkerParameters)
}

private fun formatPhoneNumber(phone: String, country:String): String? {
return PhoneNumberUtils.formatNumberToE164(phone.replace("-|\\s|\\(|\\)".toRegex(), ""), country)
var number = PhoneNumberUtils.formatNumberToE164(phone.replace("-|\\s|\\(|\\)".toRegex(), ""), country)

// Default fallback: Mexico
if (number==null) {
number = PhoneNumberUtils.formatNumberToE164(phone.replace("-|\\s|\\(|\\)".toRegex(), ""), "MX")
}

// Default fallback, second priority: US
if (number==null) {
number = PhoneNumberUtils.formatNumberToE164(phone.replace("-|\\s|\\(|\\)".toRegex(), ""), "US")
}

return number
}

}

0 comments on commit 395c267

Please sign in to comment.