From 6566fadf85ff5e3d722512a8714a04eb148c1583 Mon Sep 17 00:00:00 2001 From: Pavel Poley Date: Wed, 18 May 2022 13:48:38 +0300 Subject: [PATCH 1/6] default number --- app/build.gradle | 2 +- .../pro/activities/ContactActivity.kt | 18 ++++-- .../pro/activities/EditContactActivity.kt | 64 ++++++++++++++++++- .../contacts/pro/extensions/Activity.kt | 17 +++-- .../contacts/pro/helpers/ContactsHelper.kt | 8 ++- .../res/layout/item_edit_phone_number.xml | 15 ++++- 6 files changed, 104 insertions(+), 20 deletions(-) diff --git a/app/build.gradle b/app/build.gradle index a62a215e..7c0f683c 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.pavelpoley:Simple-Commons:1c1017d62a' 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..0a30a47a 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,58 @@ 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 drawable = if (isPrimary) { + ContextCompat.getDrawable(this@EditContactActivity, R.drawable.ic_star_vector) + } else { + ContextCompat.getDrawable(this@EditContactActivity, R.drawable.ic_star_outline_vector) + } + + drawable?.apply { + mutate() + setTint(getProperTextColor()) + } + + toggleIcon.setImageDrawable(drawable) + toggleIcon.beVisible() + toggleIcon.setOnClickListener { + setDefaultNumber(toggleIcon) } } } @@ -1037,7 +1089,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 +1230,10 @@ class EditContactActivity : ContactActivity() { numberHolder.contact_number.requestFocus() showKeyboard(numberHolder.contact_number) } + numberHolder.default_toggle_icon.apply { + 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..c1ddb1f4 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,6 @@ + + From 94e12917daab1b7ea4bd5d4bcd7a5c983713f81a Mon Sep 17 00:00:00 2001 From: Pavel Poley Date: Wed, 18 May 2022 15:25:02 +0300 Subject: [PATCH 2/6] switch to the original commons repository --- app/build.gradle | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/build.gradle b/app/build.gradle index 7c0f683c..e1e969cc 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -63,7 +63,7 @@ android { } dependencies { - implementation 'com.github.pavelpoley:Simple-Commons:1c1017d62a' + 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' From 1b2d3e7093599f4e8c5d2981287663a60eec635b Mon Sep 17 00:00:00 2001 From: Tibor Kaputa Date: Sat, 21 May 2022 22:18:13 +0200 Subject: [PATCH 3/6] adding minor tweaks --- .../res/layout/item_edit_phone_number.xml | 32 ++++++++++--------- 1 file changed, 17 insertions(+), 15 deletions(-) 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 c1ddb1f4..0243b017 100644 --- a/app/src/main/res/layout/item_edit_phone_number.xml +++ b/app/src/main/res/layout/item_edit_phone_number.xml @@ -1,6 +1,7 @@ + + - - + android:textSize="@dimen/bigger_text_size" + tools:text="@string/mobile" /> From b45dfc889ea34a046677f488e83b39f352790237 Mon Sep 17 00:00:00 2001 From: Tibor Kaputa Date: Sat, 21 May 2022 22:19:39 +0200 Subject: [PATCH 4/6] correcting padding --- app/src/main/res/layout/item_edit_phone_number.xml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) 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 0243b017..2decfcff 100644 --- a/app/src/main/res/layout/item_edit_phone_number.xml +++ b/app/src/main/res/layout/item_edit_phone_number.xml @@ -43,8 +43,8 @@ android:layout_centerVertical="true" android:background="?attr/selectableItemBackground" android:gravity="center_vertical|end" - android:minWidth="60dp" - android:paddingStart="@dimen/small_margin" + android:minWidth="70dp" + android:paddingStart="@dimen/medium_margin" android:paddingEnd="@dimen/medium_margin" android:textSize="@dimen/bigger_text_size" tools:text="@string/mobile" /> From 6a18f86ac7e25e4b99f2fcfc348b6541bbfbcaae Mon Sep 17 00:00:00 2001 From: Tibor Kaputa Date: Sat, 21 May 2022 22:20:35 +0200 Subject: [PATCH 5/6] show some click effect on pressing the star --- app/src/main/res/layout/item_edit_phone_number.xml | 1 + 1 file changed, 1 insertion(+) 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 2decfcff..e69b7760 100644 --- a/app/src/main/res/layout/item_edit_phone_number.xml +++ b/app/src/main/res/layout/item_edit_phone_number.xml @@ -29,6 +29,7 @@ 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" /> From 02e9040cdc8ad0939eca7da0b8ec32f3de19f5b0 Mon Sep 17 00:00:00 2001 From: Tibor Kaputa Date: Sat, 21 May 2022 22:24:18 +0200 Subject: [PATCH 6/6] minor code style update --- .../contacts/pro/activities/EditContactActivity.kt | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) 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 0a30a47a..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 @@ -521,12 +521,13 @@ class EditContactActivity : ContactActivity() { val toggleIcon = contact_numbers_holder.getChildAt(i).default_toggle_icon val isPrimary = toggleIcon.tag == 1 - val drawable = if (isPrimary) { - ContextCompat.getDrawable(this@EditContactActivity, R.drawable.ic_star_vector) + val drawableId = if (isPrimary) { + R.drawable.ic_star_vector } else { - ContextCompat.getDrawable(this@EditContactActivity, R.drawable.ic_star_outline_vector) + R.drawable.ic_star_outline_vector } + val drawable = ContextCompat.getDrawable(this@EditContactActivity, drawableId) drawable?.apply { mutate() setTint(getProperTextColor()) @@ -1230,9 +1231,7 @@ class EditContactActivity : ContactActivity() { numberHolder.contact_number.requestFocus() showKeyboard(numberHolder.contact_number) } - numberHolder.default_toggle_icon.apply { - tag = 0 - } + numberHolder.default_toggle_icon.tag = 0 initNumberHolders() }