Merge pull request #824 from pavelpoley/task/default-number
Set default phone number for contact
This commit is contained in:
commit
2a3cf10d21
|
@ -63,7 +63,7 @@ android {
|
|||
}
|
||||
|
||||
dependencies {
|
||||
implementation 'com.github.SimpleMobileTools:Simple-Commons:34fdfce71c'
|
||||
implementation 'com.github.SimpleMobileTools:Simple-Commons:1bc50d636c'
|
||||
implementation 'com.googlecode.ez-vcard:ez-vcard:0.11.3'
|
||||
implementation 'com.github.tibbi:IndicatorFastScroll:4524cd0b61'
|
||||
implementation 'androidx.swiperefreshlayout:swiperefreshlayout:1.1.0'
|
||||
|
|
|
@ -31,7 +31,6 @@ import com.simplemobiletools.contacts.pro.extensions.sendEmailIntent
|
|||
import com.simplemobiletools.contacts.pro.extensions.shareContacts
|
||||
import com.simplemobiletools.contacts.pro.helpers.ContactsHelper
|
||||
import com.simplemobiletools.contacts.pro.models.Contact
|
||||
import java.util.*
|
||||
|
||||
abstract class ContactActivity : SimpleActivity() {
|
||||
protected val PICK_RINGTONE_INTENT_ID = 1500
|
||||
|
@ -128,13 +127,18 @@ abstract class ContactActivity : SimpleActivity() {
|
|||
if (numbers.size == 1) {
|
||||
launchSendSMSIntent(numbers.first().value)
|
||||
} else if (numbers.size > 1) {
|
||||
val items = ArrayList<RadioItem>()
|
||||
numbers.forEachIndexed { index, phoneNumber ->
|
||||
items.add(RadioItem(index, phoneNumber.value, phoneNumber.value))
|
||||
}
|
||||
val primaryNumber = numbers.find { it.isPrimary }
|
||||
if (primaryNumber != null) {
|
||||
launchSendSMSIntent(primaryNumber.value)
|
||||
} else {
|
||||
val items = ArrayList<RadioItem>()
|
||||
numbers.forEachIndexed { index, phoneNumber ->
|
||||
items.add(RadioItem(index, phoneNumber.value, phoneNumber.value))
|
||||
}
|
||||
|
||||
RadioGroupDialog(this, items) {
|
||||
launchSendSMSIntent(it as String)
|
||||
RadioGroupDialog(this, items) {
|
||||
launchSendSMSIntent(it as String)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -22,6 +22,7 @@ import android.widget.EditText
|
|||
import android.widget.ImageView
|
||||
import android.widget.RelativeLayout
|
||||
import android.widget.TextView
|
||||
import androidx.core.content.ContextCompat
|
||||
import com.simplemobiletools.commons.dialogs.ConfirmationAdvancedDialog
|
||||
import com.simplemobiletools.commons.dialogs.RadioGroupDialog
|
||||
import com.simplemobiletools.commons.dialogs.SelectAlarmSoundDialog
|
||||
|
@ -470,7 +471,9 @@ class EditContactActivity : ContactActivity() {
|
|||
}
|
||||
|
||||
private fun setupPhoneNumbers() {
|
||||
contact!!.phoneNumbers.forEachIndexed { index, number ->
|
||||
val phoneNumbers = contact!!.phoneNumbers
|
||||
|
||||
phoneNumbers.forEachIndexed { index, number ->
|
||||
var numberHolder = contact_numbers_holder.getChildAt(index)
|
||||
if (numberHolder == null) {
|
||||
numberHolder = layoutInflater.inflate(R.layout.item_edit_phone_number, contact_numbers_holder, false)
|
||||
|
@ -481,9 +484,59 @@ class EditContactActivity : ContactActivity() {
|
|||
contact_number.setText(number.value)
|
||||
contact_number.tag = number.normalizedNumber
|
||||
setupPhoneNumberTypePicker(contact_number_type, number.type, number.label)
|
||||
if (highlightLastPhoneNumber && index == contact!!.phoneNumbers.size - 1) {
|
||||
if (highlightLastPhoneNumber && index == phoneNumbers.size - 1) {
|
||||
numberViewToColor = contact_number
|
||||
}
|
||||
|
||||
default_toggle_icon.tag = if (number.isPrimary) 1 else 0
|
||||
}
|
||||
}
|
||||
|
||||
initNumberHolders()
|
||||
}
|
||||
|
||||
private fun setDefaultNumber(selected: ImageView) {
|
||||
val numbersCount = contact_numbers_holder.childCount
|
||||
for (i in 0 until numbersCount) {
|
||||
val toggleIcon = contact_numbers_holder.getChildAt(i).default_toggle_icon
|
||||
if (toggleIcon != selected) {
|
||||
toggleIcon.tag = 0
|
||||
}
|
||||
}
|
||||
|
||||
selected.tag = if (selected.tag == 1) 0 else 1
|
||||
|
||||
initNumberHolders()
|
||||
}
|
||||
|
||||
private fun initNumberHolders() {
|
||||
val numbersCount = contact_numbers_holder.childCount
|
||||
|
||||
if (numbersCount == 1) {
|
||||
contact_numbers_holder.getChildAt(0).default_toggle_icon.beGone()
|
||||
return
|
||||
}
|
||||
|
||||
for (i in 0 until numbersCount) {
|
||||
val toggleIcon = contact_numbers_holder.getChildAt(i).default_toggle_icon
|
||||
val isPrimary = toggleIcon.tag == 1
|
||||
|
||||
val drawableId = if (isPrimary) {
|
||||
R.drawable.ic_star_vector
|
||||
} else {
|
||||
R.drawable.ic_star_outline_vector
|
||||
}
|
||||
|
||||
val drawable = ContextCompat.getDrawable(this@EditContactActivity, drawableId)
|
||||
drawable?.apply {
|
||||
mutate()
|
||||
setTint(getProperTextColor())
|
||||
}
|
||||
|
||||
toggleIcon.setImageDrawable(drawable)
|
||||
toggleIcon.beVisible()
|
||||
toggleIcon.setOnClickListener {
|
||||
setDefaultNumber(toggleIcon)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1037,7 +1090,9 @@ class EditContactActivity : ContactActivity() {
|
|||
if (PhoneNumberUtils.compare(number.normalizePhoneNumber(), fetchedNormalizedNumber)) {
|
||||
normalizedNumber = fetchedNormalizedNumber
|
||||
}
|
||||
phoneNumbers.add(PhoneNumber(number, numberType, numberLabel, normalizedNumber))
|
||||
|
||||
val isPrimary = numberHolder.default_toggle_icon.tag == 1
|
||||
phoneNumbers.add(PhoneNumber(number, numberType, numberLabel, normalizedNumber, isPrimary))
|
||||
}
|
||||
}
|
||||
return phoneNumbers
|
||||
|
@ -1176,6 +1231,8 @@ class EditContactActivity : ContactActivity() {
|
|||
numberHolder.contact_number.requestFocus()
|
||||
showKeyboard(numberHolder.contact_number)
|
||||
}
|
||||
numberHolder.default_toggle_icon.tag = 0
|
||||
initNumberHolders()
|
||||
}
|
||||
|
||||
private fun addNewEmailField() {
|
||||
|
|
|
@ -44,13 +44,18 @@ fun SimpleActivity.startCall(contact: Contact) {
|
|||
if (numbers.size == 1) {
|
||||
startCallIntent(numbers.first().value)
|
||||
} else if (numbers.size > 1) {
|
||||
val items = ArrayList<RadioItem>()
|
||||
numbers.forEachIndexed { index, phoneNumber ->
|
||||
items.add(RadioItem(index, "${phoneNumber.value} (${getPhoneNumberTypeText(phoneNumber.type, phoneNumber.label)})", phoneNumber.value))
|
||||
}
|
||||
val primaryNumber = contact.phoneNumbers.find { it.isPrimary }
|
||||
if (primaryNumber != null) {
|
||||
startCallIntent(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) {
|
||||
startCallIntent(it as String)
|
||||
RadioGroupDialog(this, items) {
|
||||
startCallIntent(it as String)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -281,7 +281,8 @@ class ContactsHelper(val context: Context) {
|
|||
Phone.NUMBER,
|
||||
Phone.NORMALIZED_NUMBER,
|
||||
Phone.TYPE,
|
||||
Phone.LABEL
|
||||
Phone.LABEL,
|
||||
Phone.IS_PRIMARY
|
||||
)
|
||||
|
||||
val selection = if (contactId == null) getSourcesSelection() else "${Data.RAW_CONTACT_ID} = ?"
|
||||
|
@ -293,12 +294,13 @@ class ContactsHelper(val context: Context) {
|
|||
val normalizedNumber = cursor.getStringValue(Phone.NORMALIZED_NUMBER) ?: number.normalizePhoneNumber()
|
||||
val type = cursor.getIntValue(Phone.TYPE)
|
||||
val label = cursor.getStringValue(Phone.LABEL) ?: ""
|
||||
val isPrimary = cursor.getIntValue(Phone.IS_PRIMARY) != 0
|
||||
|
||||
if (phoneNumbers[id] == null) {
|
||||
phoneNumbers.put(id, ArrayList())
|
||||
}
|
||||
|
||||
val phoneNumber = PhoneNumber(number, type, label, normalizedNumber)
|
||||
val phoneNumber = PhoneNumber(number, type, label, normalizedNumber, isPrimary)
|
||||
phoneNumbers[id].add(phoneNumber)
|
||||
}
|
||||
|
||||
|
@ -944,6 +946,7 @@ class ContactsHelper(val context: Context) {
|
|||
withValue(Phone.NORMALIZED_NUMBER, it.normalizedNumber)
|
||||
withValue(Phone.TYPE, it.type)
|
||||
withValue(Phone.LABEL, it.label)
|
||||
withValue(Phone.IS_PRIMARY, it.isPrimary)
|
||||
operations.add(build())
|
||||
}
|
||||
}
|
||||
|
@ -1253,6 +1256,7 @@ class ContactsHelper(val context: Context) {
|
|||
withValue(Phone.NORMALIZED_NUMBER, it.normalizedNumber)
|
||||
withValue(Phone.TYPE, it.type)
|
||||
withValue(Phone.LABEL, it.label)
|
||||
withValue(Phone.IS_PRIMARY, it.isPrimary)
|
||||
operations.add(build())
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,5 +1,7 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:app="http://schemas.android.com/apk/res-auto"
|
||||
xmlns:tools="http://schemas.android.com/tools"
|
||||
android:id="@+id/contact_number_holder"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
|
@ -10,7 +12,8 @@
|
|||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_centerVertical="true"
|
||||
android:layout_toStartOf="@+id/contact_number_type"
|
||||
android:layout_marginEnd="0dp"
|
||||
android:layout_toStartOf="@+id/default_toggle_icon"
|
||||
android:hint="@string/number"
|
||||
android:inputType="phone"
|
||||
android:lines="1"
|
||||
|
@ -19,6 +22,18 @@
|
|||
android:textCursorDrawable="@null"
|
||||
android:textSize="@dimen/bigger_text_size" />
|
||||
|
||||
<ImageView
|
||||
android:id="@+id/default_toggle_icon"
|
||||
android:layout_width="@dimen/contact_icons_size"
|
||||
android:layout_height="@dimen/contact_icons_size"
|
||||
android:layout_centerInParent="true"
|
||||
android:layout_marginEnd="0dp"
|
||||
android:layout_toStartOf="@+id/contact_number_type"
|
||||
android:background="?attr/selectableItemBackgroundBorderless"
|
||||
android:padding="@dimen/tiny_margin"
|
||||
android:visibility="gone"
|
||||
app:srcCompat="@drawable/ic_star_outline_vector" />
|
||||
|
||||
<com.simplemobiletools.commons.views.MyTextView
|
||||
android:id="@+id/contact_number_type"
|
||||
android:layout_width="wrap_content"
|
||||
|
@ -28,10 +43,11 @@
|
|||
android:layout_alignParentEnd="true"
|
||||
android:layout_centerVertical="true"
|
||||
android:background="?attr/selectableItemBackground"
|
||||
android:gravity="center"
|
||||
android:gravity="center_vertical|end"
|
||||
android:minWidth="70dp"
|
||||
android:paddingStart="@dimen/medium_margin"
|
||||
android:paddingEnd="@dimen/medium_margin"
|
||||
android:text="@string/mobile"
|
||||
android:textSize="@dimen/bigger_text_size" />
|
||||
android:textSize="@dimen/bigger_text_size"
|
||||
tools:text="@string/mobile" />
|
||||
|
||||
</RelativeLayout>
|
||||
|
|
Loading…
Reference in New Issue