diff --git a/app/build.gradle b/app/build.gradle index 16f18252..fc1fb411 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -41,7 +41,7 @@ android { } dependencies { - implementation 'com.simplemobiletools:commons:4.7.1' + implementation 'com.simplemobiletools:commons:4.7.2' implementation 'joda-time:joda-time:2.9.9' implementation 'com.facebook.stetho:stetho:1.5.0' implementation 'com.android.support.constraint:constraint-layout:1.1.3' diff --git a/app/src/main/kotlin/com/simplemobiletools/contacts/activities/EditContactActivity.kt b/app/src/main/kotlin/com/simplemobiletools/contacts/activities/EditContactActivity.kt index b3b0a187..267129bd 100644 --- a/app/src/main/kotlin/com/simplemobiletools/contacts/activities/EditContactActivity.kt +++ b/app/src/main/kotlin/com/simplemobiletools/contacts/activities/EditContactActivity.kt @@ -21,6 +21,7 @@ import com.simplemobiletools.commons.helpers.PERMISSION_READ_CONTACTS import com.simplemobiletools.commons.helpers.PERMISSION_WRITE_CONTACTS import com.simplemobiletools.commons.models.RadioItem import com.simplemobiletools.contacts.R +import com.simplemobiletools.contacts.dialogs.CustomLabelDialog import com.simplemobiletools.contacts.dialogs.SelectGroupsDialog import com.simplemobiletools.contacts.extensions.* import com.simplemobiletools.contacts.helpers.* @@ -641,12 +642,19 @@ class EditContactActivity : ContactActivity() { RadioItem(CommonDataKinds.Phone.TYPE_FAX_WORK, getString(R.string.work_fax)), RadioItem(CommonDataKinds.Phone.TYPE_FAX_HOME, getString(R.string.home_fax)), RadioItem(CommonDataKinds.Phone.TYPE_PAGER, getString(R.string.pager)), - RadioItem(CommonDataKinds.Phone.TYPE_OTHER, getString(R.string.other)) + RadioItem(CommonDataKinds.Phone.TYPE_OTHER, getString(R.string.other)), + RadioItem(CommonDataKinds.Phone.TYPE_CUSTOM, getString(R.string.custom)) ) val currentNumberTypeId = getPhoneNumberTypeId(numberTypeField.value) RadioGroupDialog(this, items, currentNumberTypeId) { - numberTypeField.text = getPhoneNumberTypeText(it as Int, "") + if (it as Int == CommonDataKinds.Phone.TYPE_CUSTOM) { + CustomLabelDialog(this) { + numberTypeField.text = it + } + } else { + numberTypeField.text = getPhoneNumberTypeText(it, "") + } } } @@ -655,12 +663,19 @@ class EditContactActivity : ContactActivity() { RadioItem(CommonDataKinds.Email.TYPE_HOME, getString(R.string.home)), RadioItem(CommonDataKinds.Email.TYPE_WORK, getString(R.string.work)), RadioItem(CommonDataKinds.Email.TYPE_MOBILE, getString(R.string.mobile)), - RadioItem(CommonDataKinds.Email.TYPE_OTHER, getString(R.string.other)) + RadioItem(CommonDataKinds.Email.TYPE_OTHER, getString(R.string.other)), + RadioItem(CommonDataKinds.Email.TYPE_CUSTOM, getString(R.string.custom)) ) val currentEmailTypeId = getEmailTypeId(emailTypeField.value) RadioGroupDialog(this, items, currentEmailTypeId) { - emailTypeField.text = getEmailTypeText(it as Int, "") + if (it as Int == CommonDataKinds.Email.TYPE_CUSTOM) { + CustomLabelDialog(this) { + emailTypeField.text = it + } + } else { + emailTypeField.text = getEmailTypeText(it, "") + } } } @@ -668,12 +683,19 @@ class EditContactActivity : ContactActivity() { val items = arrayListOf( RadioItem(CommonDataKinds.StructuredPostal.TYPE_HOME, getString(R.string.home)), RadioItem(CommonDataKinds.StructuredPostal.TYPE_WORK, getString(R.string.work)), - RadioItem(CommonDataKinds.StructuredPostal.TYPE_OTHER, getString(R.string.other)) + RadioItem(CommonDataKinds.StructuredPostal.TYPE_OTHER, getString(R.string.other)), + RadioItem(CommonDataKinds.StructuredPostal.TYPE_CUSTOM, getString(R.string.custom)) ) val currentAddressTypeId = getAddressTypeId(addressTypeField.value) RadioGroupDialog(this, items, currentAddressTypeId) { - addressTypeField.text = getAddressTypeText(it as Int, "") + if (it as Int == CommonDataKinds.StructuredPostal.TYPE_CUSTOM) { + CustomLabelDialog(this) { + addressTypeField.text = it + } + } else { + addressTypeField.text = getAddressTypeText(it, "") + } } } @@ -752,9 +774,10 @@ class EditContactActivity : ContactActivity() { val numberHolder = contact_numbers_holder.getChildAt(i) val number = numberHolder.contact_number.value val numberType = getPhoneNumberTypeId(numberHolder.contact_number_type.value) + val numberLabel = if (numberType == CommonDataKinds.Phone.TYPE_CUSTOM) numberHolder.contact_number_type.value else "" if (number.isNotEmpty()) { - phoneNumbers.add(PhoneNumber(number, numberType, "")) + phoneNumbers.add(PhoneNumber(number, numberType, numberLabel)) } } return phoneNumbers @@ -767,9 +790,10 @@ class EditContactActivity : ContactActivity() { val emailHolder = contact_emails_holder.getChildAt(i) val email = emailHolder.contact_email.value val emailType = getEmailTypeId(emailHolder.contact_email_type.value) + val emailLabel = if (emailType == CommonDataKinds.Email.TYPE_CUSTOM) emailHolder.contact_email_type.value else "" if (email.isNotEmpty()) { - emails.add(Email(email, emailType, "")) + emails.add(Email(email, emailType, emailLabel)) } } return emails @@ -782,9 +806,10 @@ class EditContactActivity : ContactActivity() { val addressHolder = contact_addresses_holder.getChildAt(i) val address = addressHolder.contact_address.value val addressType = getAddressTypeId(addressHolder.contact_address_type.value) + val addressLabel = if (addressType == CommonDataKinds.StructuredPostal.TYPE_CUSTOM) addressHolder.contact_address_type.value else "" if (address.isNotEmpty()) { - addresses.add(Address(address, addressType, "")) + addresses.add(Address(address, addressType, addressLabel)) } } return addresses @@ -1027,14 +1052,16 @@ class EditContactActivity : ContactActivity() { getString(R.string.work_fax) -> CommonDataKinds.Phone.TYPE_FAX_WORK getString(R.string.home_fax) -> CommonDataKinds.Phone.TYPE_FAX_HOME getString(R.string.pager) -> CommonDataKinds.Phone.TYPE_PAGER - else -> CommonDataKinds.Phone.TYPE_OTHER + getString(R.string.other) -> CommonDataKinds.Phone.TYPE_OTHER + else -> CommonDataKinds.Phone.TYPE_CUSTOM } private fun getEmailTypeId(value: String) = when (value) { getString(R.string.home) -> CommonDataKinds.Email.TYPE_HOME getString(R.string.work) -> CommonDataKinds.Email.TYPE_WORK getString(R.string.mobile) -> CommonDataKinds.Email.TYPE_MOBILE - else -> CommonDataKinds.Email.TYPE_OTHER + getString(R.string.other) -> CommonDataKinds.Email.TYPE_OTHER + else -> CommonDataKinds.Email.TYPE_CUSTOM } private fun getEventTypeId(value: String) = when (value) { @@ -1046,6 +1073,7 @@ class EditContactActivity : ContactActivity() { private fun getAddressTypeId(value: String) = when (value) { getString(R.string.home) -> CommonDataKinds.StructuredPostal.TYPE_HOME getString(R.string.work) -> CommonDataKinds.StructuredPostal.TYPE_WORK - else -> CommonDataKinds.StructuredPostal.TYPE_OTHER + getString(R.string.other) -> CommonDataKinds.StructuredPostal.TYPE_OTHER + else -> CommonDataKinds.StructuredPostal.TYPE_CUSTOM } } diff --git a/app/src/main/kotlin/com/simplemobiletools/contacts/dialogs/CustomLabelDialog.kt b/app/src/main/kotlin/com/simplemobiletools/contacts/dialogs/CustomLabelDialog.kt new file mode 100644 index 00000000..047f5fe5 --- /dev/null +++ b/app/src/main/kotlin/com/simplemobiletools/contacts/dialogs/CustomLabelDialog.kt @@ -0,0 +1,36 @@ +package com.simplemobiletools.contacts.dialogs + +import android.support.v7.app.AlertDialog +import com.simplemobiletools.commons.activities.BaseSimpleActivity +import com.simplemobiletools.commons.extensions.setupDialogStuff +import com.simplemobiletools.commons.extensions.showKeyboard +import com.simplemobiletools.commons.extensions.toast +import com.simplemobiletools.commons.extensions.value +import com.simplemobiletools.contacts.R +import kotlinx.android.synthetic.main.dialog_custom_label.view.* + +class CustomLabelDialog(val activity: BaseSimpleActivity, val callback: (label: String) -> Unit) { + init { + + val view = activity.layoutInflater.inflate(R.layout.dialog_custom_label, null) + + AlertDialog.Builder(activity) + .setPositiveButton(R.string.ok, null) + .setNegativeButton(R.string.cancel, null) + .create().apply { + activity.setupDialogStuff(view, this, R.string.label) { + showKeyboard(view.custom_label_edittext) + getButton(AlertDialog.BUTTON_POSITIVE).setOnClickListener { + val label = view.custom_label_edittext.value + if (label.isEmpty()) { + activity.toast(R.string.empty_name) + return@setOnClickListener + } + + callback(label) + dismiss() + } + } + } + } +} diff --git a/app/src/main/kotlin/com/simplemobiletools/contacts/helpers/ContactsHelper.kt b/app/src/main/kotlin/com/simplemobiletools/contacts/helpers/ContactsHelper.kt index b3d441b6..bc3699c0 100644 --- a/app/src/main/kotlin/com/simplemobiletools/contacts/helpers/ContactsHelper.kt +++ b/app/src/main/kotlin/com/simplemobiletools/contacts/helpers/ContactsHelper.kt @@ -862,6 +862,7 @@ class ContactsHelper(val activity: Activity) { withValue(ContactsContract.Data.MIMETYPE, CommonDataKinds.Phone.CONTENT_ITEM_TYPE) withValue(CommonDataKinds.Phone.NUMBER, it.value) withValue(CommonDataKinds.Phone.TYPE, it.type) + withValue(CommonDataKinds.Phone.LABEL, it.label) operations.add(build()) } } @@ -881,6 +882,7 @@ class ContactsHelper(val activity: Activity) { withValue(ContactsContract.Data.MIMETYPE, CommonDataKinds.Email.CONTENT_ITEM_TYPE) withValue(CommonDataKinds.Email.DATA, it.value) withValue(CommonDataKinds.Email.TYPE, it.type) + withValue(CommonDataKinds.Email.LABEL, it.label) operations.add(build()) } } @@ -900,6 +902,7 @@ class ContactsHelper(val activity: Activity) { withValue(ContactsContract.Data.MIMETYPE, CommonDataKinds.StructuredPostal.CONTENT_ITEM_TYPE) withValue(CommonDataKinds.StructuredPostal.FORMATTED_ADDRESS, it.value) withValue(CommonDataKinds.StructuredPostal.TYPE, it.type) + withValue(CommonDataKinds.StructuredPostal.LABEL, it.label) operations.add(build()) } } @@ -1140,6 +1143,7 @@ class ContactsHelper(val activity: Activity) { withValue(ContactsContract.Data.MIMETYPE, CommonDataKinds.Phone.CONTENT_ITEM_TYPE) withValue(CommonDataKinds.Phone.NUMBER, it.value) withValue(CommonDataKinds.Phone.TYPE, it.type) + withValue(CommonDataKinds.Phone.LABEL, it.label) operations.add(build()) } } @@ -1151,6 +1155,7 @@ class ContactsHelper(val activity: Activity) { withValue(ContactsContract.Data.MIMETYPE, CommonDataKinds.Email.CONTENT_ITEM_TYPE) withValue(CommonDataKinds.Email.DATA, it.value) withValue(CommonDataKinds.Email.TYPE, it.type) + withValue(CommonDataKinds.Email.LABEL, it.label) operations.add(build()) } } @@ -1162,6 +1167,7 @@ class ContactsHelper(val activity: Activity) { withValue(ContactsContract.Data.MIMETYPE, CommonDataKinds.StructuredPostal.CONTENT_ITEM_TYPE) withValue(CommonDataKinds.StructuredPostal.FORMATTED_ADDRESS, it.value) withValue(CommonDataKinds.StructuredPostal.TYPE, it.type) + withValue(CommonDataKinds.StructuredPostal.LABEL, it.label) operations.add(build()) } } diff --git a/app/src/main/res/layout/dialog_custom_label.xml b/app/src/main/res/layout/dialog_custom_label.xml new file mode 100644 index 00000000..746ae0cd --- /dev/null +++ b/app/src/main/res/layout/dialog_custom_label.xml @@ -0,0 +1,19 @@ + + + + + +