Merge pull request #1716 from Merkost/contacts_refactoring
Shared calls logic extracted to commons library
This commit is contained in:
commit
275c6804a5
1 changed files with 35 additions and 0 deletions
|
@ -8,10 +8,14 @@ import android.os.Handler
|
|||
import android.os.Looper
|
||||
import android.provider.ContactsContract
|
||||
import com.simplemobiletools.commons.R
|
||||
import com.simplemobiletools.commons.activities.BaseSimpleActivity
|
||||
import com.simplemobiletools.commons.databases.ContactsDatabase
|
||||
import com.simplemobiletools.commons.dialogs.CallConfirmationDialog
|
||||
import com.simplemobiletools.commons.dialogs.RadioGroupDialog
|
||||
import com.simplemobiletools.commons.helpers.*
|
||||
import com.simplemobiletools.commons.interfaces.ContactsDao
|
||||
import com.simplemobiletools.commons.interfaces.GroupsDao
|
||||
import com.simplemobiletools.commons.models.RadioItem
|
||||
import com.simplemobiletools.commons.models.contacts.Contact
|
||||
import com.simplemobiletools.commons.models.contacts.ContactSource
|
||||
import com.simplemobiletools.commons.models.contacts.Organization
|
||||
|
@ -321,3 +325,34 @@ fun Context.getSocialActions(id: Int): ArrayList<SocialAction> {
|
|||
}
|
||||
return socialActions
|
||||
}
|
||||
|
||||
fun BaseSimpleActivity.initiateCall(contact: Contact, onStartCallIntent: (phoneNumber: String) -> Unit) {
|
||||
val numbers = contact.phoneNumbers
|
||||
if (numbers.size == 1) {
|
||||
onStartCallIntent(numbers.first().value)
|
||||
} else if (numbers.size > 1) {
|
||||
val primaryNumber = contact.phoneNumbers.find { it.isPrimary }
|
||||
if (primaryNumber != null) {
|
||||
onStartCallIntent(primaryNumber.value)
|
||||
} else {
|
||||
val items = ArrayList<RadioItem>()
|
||||
numbers.forEachIndexed { index, phoneNumber ->
|
||||
items.add(RadioItem(index, "${phoneNumber.value} (${getPhoneNumberTypeText(phoneNumber.type, phoneNumber.label)})", phoneNumber.value))
|
||||
}
|
||||
|
||||
RadioGroupDialog(this, items) {
|
||||
onStartCallIntent(it as String)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fun BaseSimpleActivity.tryInitiateCall(contact: Contact, onStartCallIntent: (phoneNumber: String) -> Unit) {
|
||||
if (baseConfig.showCallConfirmation) {
|
||||
CallConfirmationDialog(this, contact.getNameToDisplay()) {
|
||||
initiateCall(contact, onStartCallIntent)
|
||||
}
|
||||
} else {
|
||||
initiateCall(contact, onStartCallIntent)
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue