diff --git a/app/build.gradle b/app/build.gradle index a62a215e..e1e969cc 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -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' diff --git a/app/src/main/kotlin/com/simplemobiletools/contacts/pro/activities/ContactActivity.kt b/app/src/main/kotlin/com/simplemobiletools/contacts/pro/activities/ContactActivity.kt index 05de1d4c..785852e4 100644 --- a/app/src/main/kotlin/com/simplemobiletools/contacts/pro/activities/ContactActivity.kt +++ b/app/src/main/kotlin/com/simplemobiletools/contacts/pro/activities/ContactActivity.kt @@ -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() - 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() + 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) + } } } } diff --git a/app/src/main/kotlin/com/simplemobiletools/contacts/pro/activities/EditContactActivity.kt b/app/src/main/kotlin/com/simplemobiletools/contacts/pro/activities/EditContactActivity.kt index 3ede526f..8642b7ac 100644 --- a/app/src/main/kotlin/com/simplemobiletools/contacts/pro/activities/EditContactActivity.kt +++ b/app/src/main/kotlin/com/simplemobiletools/contacts/pro/activities/EditContactActivity.kt @@ -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() { diff --git a/app/src/main/kotlin/com/simplemobiletools/contacts/pro/extensions/Activity.kt b/app/src/main/kotlin/com/simplemobiletools/contacts/pro/extensions/Activity.kt index 853b8959..22823187 100644 --- a/app/src/main/kotlin/com/simplemobiletools/contacts/pro/extensions/Activity.kt +++ b/app/src/main/kotlin/com/simplemobiletools/contacts/pro/extensions/Activity.kt @@ -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() - 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() + 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) + } } } } diff --git a/app/src/main/kotlin/com/simplemobiletools/contacts/pro/helpers/ContactsHelper.kt b/app/src/main/kotlin/com/simplemobiletools/contacts/pro/helpers/ContactsHelper.kt index 6365ff0e..fdc677d3 100644 --- a/app/src/main/kotlin/com/simplemobiletools/contacts/pro/helpers/ContactsHelper.kt +++ b/app/src/main/kotlin/com/simplemobiletools/contacts/pro/helpers/ContactsHelper.kt @@ -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()) } } diff --git a/app/src/main/res/layout/item_edit_phone_number.xml b/app/src/main/res/layout/item_edit_phone_number.xml index d48da51c..e69b7760 100644 --- a/app/src/main/res/layout/item_edit_phone_number.xml +++ b/app/src/main/res/layout/item_edit_phone_number.xml @@ -1,5 +1,7 @@ + + + android:textSize="@dimen/bigger_text_size" + tools:text="@string/mobile" />