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 cdb316b8..76924b6f 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 @@ -3,7 +3,7 @@ package com.simplemobiletools.contacts.pro.activities import android.graphics.Bitmap import android.graphics.drawable.ColorDrawable import android.graphics.drawable.Drawable -import android.provider.ContactsContract +import android.provider.ContactsContract.CommonDataKinds.* import android.widget.ImageView import com.bumptech.glide.Glide import com.bumptech.glide.load.DataSource @@ -48,30 +48,30 @@ abstract class ContactActivity : SimpleActivity() { fun updateContactPhoto(path: String, photoView: ImageView, bitmap: Bitmap? = null) { currentContactPhotoPath = path val options = RequestOptions() - .diskCacheStrategy(DiskCacheStrategy.RESOURCE) - .centerCrop() + .diskCacheStrategy(DiskCacheStrategy.RESOURCE) + .centerCrop() if (isDestroyed || isFinishing) { return } Glide.with(this) - .load(bitmap ?: path) - .transition(DrawableTransitionOptions.withCrossFade()) - .apply(options) - .apply(RequestOptions.circleCropTransform()) - .listener(object : RequestListener { - override fun onResourceReady(resource: Drawable?, model: Any?, target: Target?, dataSource: DataSource?, isFirstResource: Boolean): Boolean { - photoView.setPadding(0, 0, 0, 0) - photoView.background = ColorDrawable(0) - return false - } + .load(bitmap ?: path) + .transition(DrawableTransitionOptions.withCrossFade()) + .apply(options) + .apply(RequestOptions.circleCropTransform()) + .listener(object : RequestListener { + override fun onResourceReady(resource: Drawable?, model: Any?, target: Target?, dataSource: DataSource?, isFirstResource: Boolean): Boolean { + photoView.setPadding(0, 0, 0, 0) + photoView.background = ColorDrawable(0) + return false + } - override fun onLoadFailed(e: GlideException?, model: Any?, target: Target?, isFirstResource: Boolean): Boolean { - showPhotoPlaceholder(photoView) - return true - } - }).into(photoView) + override fun onLoadFailed(e: GlideException?, model: Any?, target: Target?, isFirstResource: Boolean): Boolean { + showPhotoPlaceholder(photoView) + return true + } + }).into(photoView) } fun deleteContact() { @@ -121,67 +121,67 @@ abstract class ContactActivity : SimpleActivity() { } fun getPhoneNumberTypeText(type: Int, label: String): String { - return if (type == ContactsContract.CommonDataKinds.BaseTypes.TYPE_CUSTOM) { + return if (type == BaseTypes.TYPE_CUSTOM) { label } else { getString(when (type) { - ContactsContract.CommonDataKinds.Phone.TYPE_MOBILE -> R.string.mobile - ContactsContract.CommonDataKinds.Phone.TYPE_HOME -> R.string.home - ContactsContract.CommonDataKinds.Phone.TYPE_WORK -> R.string.work - ContactsContract.CommonDataKinds.Phone.TYPE_MAIN -> R.string.main_number - ContactsContract.CommonDataKinds.Phone.TYPE_FAX_WORK -> R.string.work_fax - ContactsContract.CommonDataKinds.Phone.TYPE_FAX_HOME -> R.string.home_fax - ContactsContract.CommonDataKinds.Phone.TYPE_PAGER -> R.string.pager + Phone.TYPE_MOBILE -> R.string.mobile + Phone.TYPE_HOME -> R.string.home + Phone.TYPE_WORK -> R.string.work + Phone.TYPE_MAIN -> R.string.main_number + Phone.TYPE_FAX_WORK -> R.string.work_fax + Phone.TYPE_FAX_HOME -> R.string.home_fax + Phone.TYPE_PAGER -> R.string.pager else -> R.string.other }) } } fun getEmailTypeText(type: Int, label: String): String { - return if (type == ContactsContract.CommonDataKinds.BaseTypes.TYPE_CUSTOM) { + return if (type == BaseTypes.TYPE_CUSTOM) { label } else { getString(when (type) { - ContactsContract.CommonDataKinds.Email.TYPE_HOME -> R.string.home - ContactsContract.CommonDataKinds.Email.TYPE_WORK -> R.string.work - ContactsContract.CommonDataKinds.Email.TYPE_MOBILE -> R.string.mobile + Email.TYPE_HOME -> R.string.home + Email.TYPE_WORK -> R.string.work + Email.TYPE_MOBILE -> R.string.mobile else -> R.string.other }) } } fun getAddressTypeText(type: Int, label: String): String { - return if (type == ContactsContract.CommonDataKinds.BaseTypes.TYPE_CUSTOM) { + return if (type == BaseTypes.TYPE_CUSTOM) { label } else { getString(when (type) { - ContactsContract.CommonDataKinds.StructuredPostal.TYPE_HOME -> R.string.home - ContactsContract.CommonDataKinds.StructuredPostal.TYPE_WORK -> R.string.work + StructuredPostal.TYPE_HOME -> R.string.home + StructuredPostal.TYPE_WORK -> R.string.work else -> R.string.other }) } } fun getIMTypeText(type: Int, label: String): String { - return if (type == ContactsContract.CommonDataKinds.Im.PROTOCOL_CUSTOM) { + return if (type == Im.PROTOCOL_CUSTOM) { label } else { getString(when (type) { - ContactsContract.CommonDataKinds.Im.PROTOCOL_AIM -> R.string.aim - ContactsContract.CommonDataKinds.Im.PROTOCOL_MSN -> R.string.windows_live - ContactsContract.CommonDataKinds.Im.PROTOCOL_YAHOO -> R.string.yahoo - ContactsContract.CommonDataKinds.Im.PROTOCOL_SKYPE -> R.string.skype - ContactsContract.CommonDataKinds.Im.PROTOCOL_QQ -> R.string.qq - ContactsContract.CommonDataKinds.Im.PROTOCOL_GOOGLE_TALK -> R.string.hangouts - ContactsContract.CommonDataKinds.Im.PROTOCOL_ICQ -> R.string.icq + Im.PROTOCOL_AIM -> R.string.aim + Im.PROTOCOL_MSN -> R.string.windows_live + Im.PROTOCOL_YAHOO -> R.string.yahoo + Im.PROTOCOL_SKYPE -> R.string.skype + Im.PROTOCOL_QQ -> R.string.qq + Im.PROTOCOL_GOOGLE_TALK -> R.string.hangouts + Im.PROTOCOL_ICQ -> R.string.icq else -> R.string.jabber }) } } fun getEventTextId(type: Int) = when (type) { - ContactsContract.CommonDataKinds.Event.TYPE_ANNIVERSARY -> R.string.anniversary - ContactsContract.CommonDataKinds.Event.TYPE_BIRTHDAY -> R.string.birthday + Event.TYPE_ANNIVERSARY -> R.string.anniversary + Event.TYPE_BIRTHDAY -> R.string.birthday else -> R.string.other } } 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 4a3d26e4..a36a2c95 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 @@ -9,6 +9,7 @@ import android.graphics.Bitmap import android.net.Uri import android.os.Bundle import android.provider.ContactsContract.CommonDataKinds +import android.provider.ContactsContract.CommonDataKinds.* import android.provider.MediaStore import android.view.Menu import android.view.MenuItem @@ -29,6 +30,9 @@ import com.simplemobiletools.contacts.pro.dialogs.SelectGroupsDialog import com.simplemobiletools.contacts.pro.extensions.* import com.simplemobiletools.contacts.pro.helpers.* import com.simplemobiletools.contacts.pro.models.* +import com.simplemobiletools.contacts.pro.models.Email +import com.simplemobiletools.contacts.pro.models.Event +import com.simplemobiletools.contacts.pro.models.Organization import kotlinx.android.synthetic.main.activity_edit_contact.* import kotlinx.android.synthetic.main.item_edit_address.view.* import kotlinx.android.synthetic.main.item_edit_email.view.* @@ -220,36 +224,22 @@ class EditContactActivity : ContactActivity() { } val textColor = config.textColor - contact_send_sms.applyColorFilter(textColor) - contact_start_call.applyColorFilter(textColor) - contact_send_email.applyColorFilter(textColor) - contact_name_image.applyColorFilter(textColor) - contact_numbers_image.applyColorFilter(textColor) - contact_emails_image.applyColorFilter(textColor) - contact_addresses_image.applyColorFilter(textColor) - contact_ims_image.applyColorFilter(textColor) - contact_events_image.applyColorFilter(textColor) - contact_notes_image.applyColorFilter(textColor) - contact_organization_image.applyColorFilter(textColor) - contact_websites_image.applyColorFilter(textColor) - contact_groups_image.applyColorFilter(textColor) - contact_source_image.applyColorFilter(textColor) + arrayOf(contact_send_sms, contact_start_call, contact_send_email, contact_name_image, contact_numbers_image, contact_emails_image, contact_addresses_image, + contact_ims_image, contact_events_image, contact_notes_image, contact_organization_image, contact_websites_image, contact_groups_image, + contact_source_image).forEach { + it.applyColorFilter(textColor) + } val adjustedPrimaryColor = getAdjustedPrimaryColor() - contact_numbers_add_new.applyColorFilter(adjustedPrimaryColor) - contact_numbers_add_new.background.applyColorFilter(textColor) - contact_emails_add_new.applyColorFilter(adjustedPrimaryColor) - contact_emails_add_new.background.applyColorFilter(textColor) - contact_addresses_add_new.applyColorFilter(adjustedPrimaryColor) - contact_addresses_add_new.background.applyColorFilter(textColor) - contact_ims_add_new.applyColorFilter(adjustedPrimaryColor) - contact_ims_add_new.background.applyColorFilter(textColor) - contact_events_add_new.applyColorFilter(adjustedPrimaryColor) - contact_events_add_new.background.applyColorFilter(textColor) - contact_websites_add_new.applyColorFilter(adjustedPrimaryColor) - contact_websites_add_new.background.applyColorFilter(textColor) - contact_groups_add_new.applyColorFilter(adjustedPrimaryColor) - contact_groups_add_new.background.applyColorFilter(textColor) + arrayOf(contact_numbers_add_new, contact_emails_add_new, contact_addresses_add_new, contact_ims_add_new, contact_events_add_new, + contact_websites_add_new, contact_groups_add_new).forEach { + it.applyColorFilter(adjustedPrimaryColor) + } + + arrayOf(contact_numbers_add_new.background, contact_emails_add_new.background, contact_addresses_add_new.background, contact_ims_add_new.background, + contact_events_add_new.background, contact_websites_add_new.background, contact_groups_add_new.background).forEach { + it.applyColorFilter(textColor) + } contact_toggle_favorite.setOnClickListener { toggleFavorite() } contact_photo.setOnClickListener { trySetPhoto() } @@ -755,20 +745,20 @@ class EditContactActivity : ContactActivity() { private fun showNumberTypePicker(numberTypeField: TextView) { val items = arrayListOf( - RadioItem(CommonDataKinds.Phone.TYPE_MOBILE, getString(R.string.mobile)), - RadioItem(CommonDataKinds.Phone.TYPE_HOME, getString(R.string.home)), - RadioItem(CommonDataKinds.Phone.TYPE_WORK, getString(R.string.work)), - RadioItem(CommonDataKinds.Phone.TYPE_MAIN, getString(R.string.main_number)), - 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_CUSTOM, getString(R.string.custom)) + RadioItem(Phone.TYPE_MOBILE, getString(R.string.mobile)), + RadioItem(Phone.TYPE_HOME, getString(R.string.home)), + RadioItem(Phone.TYPE_WORK, getString(R.string.work)), + RadioItem(Phone.TYPE_MAIN, getString(R.string.main_number)), + RadioItem(Phone.TYPE_FAX_WORK, getString(R.string.work_fax)), + RadioItem(Phone.TYPE_FAX_HOME, getString(R.string.home_fax)), + RadioItem(Phone.TYPE_PAGER, getString(R.string.pager)), + RadioItem(Phone.TYPE_OTHER, getString(R.string.other)), + RadioItem(Phone.TYPE_CUSTOM, getString(R.string.custom)) ) val currentNumberTypeId = getPhoneNumberTypeId(numberTypeField.value) RadioGroupDialog(this, items, currentNumberTypeId) { - if (it as Int == CommonDataKinds.Phone.TYPE_CUSTOM) { + if (it as Int == Phone.TYPE_CUSTOM) { CustomLabelDialog(this) { numberTypeField.text = it } @@ -780,11 +770,11 @@ class EditContactActivity : ContactActivity() { private fun showEmailTypePicker(emailTypeField: TextView) { val items = arrayListOf( - 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_CUSTOM, getString(R.string.custom)) + 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_CUSTOM, getString(R.string.custom)) ) val currentEmailTypeId = getEmailTypeId(emailTypeField.value) @@ -801,15 +791,15 @@ class EditContactActivity : ContactActivity() { private fun showAddressTypePicker(addressTypeField: TextView) { 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_CUSTOM, getString(R.string.custom)) + RadioItem(StructuredPostal.TYPE_HOME, getString(R.string.home)), + RadioItem(StructuredPostal.TYPE_WORK, getString(R.string.work)), + RadioItem(StructuredPostal.TYPE_OTHER, getString(R.string.other)), + RadioItem(StructuredPostal.TYPE_CUSTOM, getString(R.string.custom)) ) val currentAddressTypeId = getAddressTypeId(addressTypeField.value) RadioGroupDialog(this, items, currentAddressTypeId) { - if (it as Int == CommonDataKinds.StructuredPostal.TYPE_CUSTOM) { + if (it as Int == StructuredPostal.TYPE_CUSTOM) { CustomLabelDialog(this) { addressTypeField.text = it } @@ -821,20 +811,20 @@ class EditContactActivity : ContactActivity() { private fun showIMTypePicker(imTypeField: TextView) { val items = arrayListOf( - RadioItem(CommonDataKinds.Im.PROTOCOL_AIM, getString(R.string.aim)), - RadioItem(CommonDataKinds.Im.PROTOCOL_MSN, getString(R.string.windows_live)), - RadioItem(CommonDataKinds.Im.PROTOCOL_YAHOO, getString(R.string.yahoo)), - RadioItem(CommonDataKinds.Im.PROTOCOL_SKYPE, getString(R.string.skype)), - RadioItem(CommonDataKinds.Im.PROTOCOL_QQ, getString(R.string.qq)), - RadioItem(CommonDataKinds.Im.PROTOCOL_GOOGLE_TALK, getString(R.string.hangouts)), - RadioItem(CommonDataKinds.Im.PROTOCOL_ICQ, getString(R.string.icq)), - RadioItem(CommonDataKinds.Im.PROTOCOL_JABBER, getString(R.string.jabber)), - RadioItem(CommonDataKinds.Im.PROTOCOL_CUSTOM, getString(R.string.custom)) + RadioItem(Im.PROTOCOL_AIM, getString(R.string.aim)), + RadioItem(Im.PROTOCOL_MSN, getString(R.string.windows_live)), + RadioItem(Im.PROTOCOL_YAHOO, getString(R.string.yahoo)), + RadioItem(Im.PROTOCOL_SKYPE, getString(R.string.skype)), + RadioItem(Im.PROTOCOL_QQ, getString(R.string.qq)), + RadioItem(Im.PROTOCOL_GOOGLE_TALK, getString(R.string.hangouts)), + RadioItem(Im.PROTOCOL_ICQ, getString(R.string.icq)), + RadioItem(Im.PROTOCOL_JABBER, getString(R.string.jabber)), + RadioItem(Im.PROTOCOL_CUSTOM, getString(R.string.custom)) ) val currentIMTypeId = getIMTypeId(imTypeField.value) RadioGroupDialog(this, items, currentIMTypeId) { - if (it as Int == CommonDataKinds.Im.PROTOCOL_CUSTOM) { + if (it as Int == Im.PROTOCOL_CUSTOM) { CustomLabelDialog(this) { imTypeField.text = it } @@ -846,9 +836,9 @@ class EditContactActivity : ContactActivity() { private fun showEventTypePicker(eventTypeField: TextView) { val items = arrayListOf( - RadioItem(CommonDataKinds.Event.TYPE_ANNIVERSARY, getString(R.string.anniversary)), - RadioItem(CommonDataKinds.Event.TYPE_BIRTHDAY, getString(R.string.birthday)), - RadioItem(CommonDataKinds.Event.TYPE_OTHER, getString(R.string.other)) + RadioItem(CommonDataKinds.Event.TYPE_ANNIVERSARY, getString(R.string.anniversary)), + RadioItem(CommonDataKinds.Event.TYPE_BIRTHDAY, getString(R.string.birthday)), + RadioItem(CommonDataKinds.Event.TYPE_OTHER, getString(R.string.other)) ) val currentEventTypeId = getEventTypeId(eventTypeField.value) @@ -922,7 +912,7 @@ 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 "" + val numberLabel = if (numberType == Phone.TYPE_CUSTOM) numberHolder.contact_number_type.value else "" if (number.isNotEmpty()) { phoneNumbers.add(PhoneNumber(number, numberType, numberLabel, number.normalizeNumber())) @@ -954,7 +944,7 @@ 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 "" + val addressLabel = if (addressType == StructuredPostal.TYPE_CUSTOM) addressHolder.contact_address_type.value else "" if (address.isNotEmpty()) { addresses.add(Address(address, addressType, addressLabel)) @@ -970,7 +960,7 @@ class EditContactActivity : ContactActivity() { val IMsHolder = contact_ims_holder.getChildAt(i) val IM = IMsHolder.contact_im.value val IMType = getIMTypeId(IMsHolder.contact_im_type.value) - val IMLabel = if (IMType == CommonDataKinds.Im.PROTOCOL_CUSTOM) IMsHolder.contact_im_type.value else "" + val IMLabel = if (IMType == Im.PROTOCOL_CUSTOM) IMsHolder.contact_im_type.value else "" if (IM.isNotEmpty()) { IMs.add(IM(IM, IMType, IMLabel)) @@ -1128,8 +1118,8 @@ class EditContactActivity : ContactActivity() { private fun trySetPhoto() { val items = arrayListOf( - RadioItem(TAKE_PHOTO, getString(R.string.take_photo)), - RadioItem(CHOOSE_PHOTO, getString(R.string.choose_photo)) + RadioItem(TAKE_PHOTO, getString(R.string.take_photo)), + RadioItem(CHOOSE_PHOTO, getString(R.string.choose_photo)) ) if (currentContactPhotoPath.isNotEmpty() || contact!!.photo != null) { @@ -1147,13 +1137,13 @@ class EditContactActivity : ContactActivity() { private fun parseIntentData(data: ArrayList) { data.forEach { - when (it.get(CommonDataKinds.StructuredName.MIMETYPE)) { + when (it.get(StructuredName.MIMETYPE)) { CommonDataKinds.Email.CONTENT_ITEM_TYPE -> parseEmail(it) - CommonDataKinds.StructuredPostal.CONTENT_ITEM_TYPE -> parseAddress(it) + StructuredPostal.CONTENT_ITEM_TYPE -> parseAddress(it) CommonDataKinds.Organization.CONTENT_ITEM_TYPE -> parseOrganization(it) CommonDataKinds.Event.CONTENT_ITEM_TYPE -> parseEvent(it) - CommonDataKinds.Website.CONTENT_ITEM_TYPE -> parseWebsite(it) - CommonDataKinds.Note.CONTENT_ITEM_TYPE -> parseNote(it) + Website.CONTENT_ITEM_TYPE -> parseWebsite(it) + Note.CONTENT_ITEM_TYPE -> parseNote(it) } } } @@ -1166,9 +1156,9 @@ class EditContactActivity : ContactActivity() { } private fun parseAddress(contentValues: ContentValues) { - val type = contentValues.getAsInteger(CommonDataKinds.StructuredPostal.DATA2) ?: DEFAULT_ADDRESS_TYPE - val addressValue = contentValues.getAsString(CommonDataKinds.StructuredPostal.DATA4) - ?: contentValues.getAsString(CommonDataKinds.StructuredPostal.DATA1) ?: return + val type = contentValues.getAsInteger(StructuredPostal.DATA2) ?: DEFAULT_ADDRESS_TYPE + val addressValue = contentValues.getAsString(StructuredPostal.DATA4) + ?: contentValues.getAsString(StructuredPostal.DATA1) ?: return val address = Address(addressValue, type, "") contact!!.addresses.add(address) } @@ -1187,12 +1177,12 @@ class EditContactActivity : ContactActivity() { } private fun parseWebsite(contentValues: ContentValues) { - val website = contentValues.getAsString(CommonDataKinds.Website.DATA1) ?: return + val website = contentValues.getAsString(Website.DATA1) ?: return contact!!.websites.add(website) } private fun parseNote(contentValues: ContentValues) { - val note = contentValues.getAsString(CommonDataKinds.Note.DATA1) ?: return + val note = contentValues.getAsString(Note.DATA1) ?: return contact!!.notes = note } @@ -1226,15 +1216,15 @@ class EditContactActivity : ContactActivity() { } private fun getPhoneNumberTypeId(value: String) = when (value) { - getString(R.string.mobile) -> CommonDataKinds.Phone.TYPE_MOBILE - getString(R.string.home) -> CommonDataKinds.Phone.TYPE_HOME - getString(R.string.work) -> CommonDataKinds.Phone.TYPE_WORK - getString(R.string.main_number) -> CommonDataKinds.Phone.TYPE_MAIN - 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 - getString(R.string.other) -> CommonDataKinds.Phone.TYPE_OTHER - else -> CommonDataKinds.Phone.TYPE_CUSTOM + getString(R.string.mobile) -> Phone.TYPE_MOBILE + getString(R.string.home) -> Phone.TYPE_HOME + getString(R.string.work) -> Phone.TYPE_WORK + getString(R.string.main_number) -> Phone.TYPE_MAIN + getString(R.string.work_fax) -> Phone.TYPE_FAX_WORK + getString(R.string.home_fax) -> Phone.TYPE_FAX_HOME + getString(R.string.pager) -> Phone.TYPE_PAGER + getString(R.string.other) -> Phone.TYPE_OTHER + else -> Phone.TYPE_CUSTOM } private fun getEmailTypeId(value: String) = when (value) { @@ -1252,21 +1242,21 @@ 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 - getString(R.string.other) -> CommonDataKinds.StructuredPostal.TYPE_OTHER - else -> CommonDataKinds.StructuredPostal.TYPE_CUSTOM + getString(R.string.home) -> StructuredPostal.TYPE_HOME + getString(R.string.work) -> StructuredPostal.TYPE_WORK + getString(R.string.other) -> StructuredPostal.TYPE_OTHER + else -> StructuredPostal.TYPE_CUSTOM } private fun getIMTypeId(value: String) = when (value) { - getString(R.string.aim) -> CommonDataKinds.Im.PROTOCOL_AIM - getString(R.string.windows_live) -> CommonDataKinds.Im.PROTOCOL_MSN - getString(R.string.yahoo) -> CommonDataKinds.Im.PROTOCOL_YAHOO - getString(R.string.skype) -> CommonDataKinds.Im.PROTOCOL_SKYPE - getString(R.string.qq) -> CommonDataKinds.Im.PROTOCOL_QQ - getString(R.string.hangouts) -> CommonDataKinds.Im.PROTOCOL_GOOGLE_TALK - getString(R.string.icq) -> CommonDataKinds.Im.PROTOCOL_ICQ - getString(R.string.jabber) -> CommonDataKinds.Im.PROTOCOL_JABBER - else -> CommonDataKinds.Im.PROTOCOL_CUSTOM + getString(R.string.aim) -> Im.PROTOCOL_AIM + getString(R.string.windows_live) -> Im.PROTOCOL_MSN + getString(R.string.yahoo) -> Im.PROTOCOL_YAHOO + getString(R.string.skype) -> Im.PROTOCOL_SKYPE + getString(R.string.qq) -> Im.PROTOCOL_QQ + getString(R.string.hangouts) -> Im.PROTOCOL_GOOGLE_TALK + getString(R.string.icq) -> Im.PROTOCOL_ICQ + getString(R.string.jabber) -> Im.PROTOCOL_JABBER + else -> Im.PROTOCOL_CUSTOM } } diff --git a/app/src/main/kotlin/com/simplemobiletools/contacts/pro/activities/InsertOrEditContactActivity.kt b/app/src/main/kotlin/com/simplemobiletools/contacts/pro/activities/InsertOrEditContactActivity.kt index c1143280..a26c63cf 100644 --- a/app/src/main/kotlin/com/simplemobiletools/contacts/pro/activities/InsertOrEditContactActivity.kt +++ b/app/src/main/kotlin/com/simplemobiletools/contacts/pro/activities/InsertOrEditContactActivity.kt @@ -38,8 +38,8 @@ class InsertOrEditContactActivity : SimpleActivity(), RefreshContactsListener { private var searchMenuItem: MenuItem? = null private val contactsFavoritesList = arrayListOf( - CONTACTS_TAB_MASK, - FAVORITES_TAB_MASK + CONTACTS_TAB_MASK, + FAVORITES_TAB_MASK ) override fun onCreate(savedInstanceState: Bundle?) { @@ -116,17 +116,17 @@ class InsertOrEditContactActivity : SimpleActivity(), RefreshContactsListener { } insert_or_edit_tabs_holder.onTabSelectionChanged( - tabUnselectedAction = { - it.icon?.applyColorFilter(config.textColor) - }, - tabSelectedAction = { - if (isSearchOpen) { - getCurrentFragment()?.onSearchQueryChanged("") - searchMenuItem?.collapseActionView() - } - viewpager.currentItem = it.position - it.icon?.applyColorFilter(getAdjustedPrimaryColor()) + tabUnselectedAction = { + it.icon?.applyColorFilter(config.textColor) + }, + tabSelectedAction = { + if (isSearchOpen) { + getCurrentFragment()?.onSearchQueryChanged("") + searchMenuItem?.collapseActionView() } + viewpager.currentItem = it.position + it.icon?.applyColorFilter(getAdjustedPrimaryColor()) + } ) insert_or_edit_tabs_holder.removeAllTabs() diff --git a/app/src/main/kotlin/com/simplemobiletools/contacts/pro/activities/MainActivity.kt b/app/src/main/kotlin/com/simplemobiletools/contacts/pro/activities/MainActivity.kt index 5a259bbb..5cc5c609 100644 --- a/app/src/main/kotlin/com/simplemobiletools/contacts/pro/activities/MainActivity.kt +++ b/app/src/main/kotlin/com/simplemobiletools/contacts/pro/activities/MainActivity.kt @@ -313,11 +313,11 @@ class MainActivity : SimpleActivity(), RefreshContactsListener { val intent = Intent(this, DialpadActivity::class.java) intent.action = Intent.ACTION_VIEW return ShortcutInfo.Builder(this, "launch_dialpad") - .setShortLabel(newEvent) - .setLongLabel(newEvent) - .setIcon(Icon.createWithBitmap(bmp)) - .setIntent(intent) - .build() + .setShortLabel(newEvent) + .setLongLabel(newEvent) + .setIcon(Icon.createWithBitmap(bmp)) + .setIntent(intent) + .build() } @SuppressLint("NewApi") @@ -330,11 +330,11 @@ class MainActivity : SimpleActivity(), RefreshContactsListener { val intent = Intent(this, EditContactActivity::class.java) intent.action = Intent.ACTION_VIEW return ShortcutInfo.Builder(this, "create_new_contact") - .setShortLabel(newEvent) - .setLongLabel(newEvent) - .setIcon(Icon.createWithBitmap(bmp)) - .setIntent(intent) - .build() + .setShortLabel(newEvent) + .setLongLabel(newEvent) + .setIcon(Icon.createWithBitmap(bmp)) + .setIntent(intent) + .build() } private fun getCurrentFragment(): MyViewPagerFragment? { @@ -398,17 +398,17 @@ class MainActivity : SimpleActivity(), RefreshContactsListener { } main_tabs_holder.onTabSelectionChanged( - tabUnselectedAction = { - it.icon?.applyColorFilter(config.textColor) - }, - tabSelectedAction = { - if (isSearchOpen) { - getCurrentFragment()?.onSearchQueryChanged("") - searchMenuItem?.collapseActionView() - } - viewpager.currentItem = it.position - it.icon?.applyColorFilter(getAdjustedPrimaryColor()) + tabUnselectedAction = { + it.icon?.applyColorFilter(config.textColor) + }, + tabSelectedAction = { + if (isSearchOpen) { + getCurrentFragment()?.onSearchQueryChanged("") + searchMenuItem?.collapseActionView() } + viewpager.currentItem = it.position + it.icon?.applyColorFilter(getAdjustedPrimaryColor()) + } ) if (intent?.action == Intent.ACTION_VIEW && intent.data != null) { @@ -561,10 +561,10 @@ class MainActivity : SimpleActivity(), RefreshContactsListener { val licenses = LICENSE_JODA or LICENSE_GLIDE or LICENSE_GSON or LICENSE_INDICATOR_FAST_SCROLL val faqItems = arrayListOf( - FAQItem(R.string.faq_1_title, R.string.faq_1_text), - FAQItem(R.string.faq_2_title_commons, R.string.faq_2_text_commons), - FAQItem(R.string.faq_6_title_commons, R.string.faq_6_text_commons), - FAQItem(R.string.faq_7_title_commons, R.string.faq_7_text_commons) + FAQItem(R.string.faq_1_title, R.string.faq_1_text), + FAQItem(R.string.faq_2_title_commons, R.string.faq_2_text_commons), + FAQItem(R.string.faq_6_title_commons, R.string.faq_6_text_commons), + FAQItem(R.string.faq_7_title_commons, R.string.faq_7_text_commons) ) startAboutActivity(R.string.app_name, licenses, BuildConfig.VERSION_NAME, faqItems, true) diff --git a/app/src/main/kotlin/com/simplemobiletools/contacts/pro/activities/SelectContactActivity.kt b/app/src/main/kotlin/com/simplemobiletools/contacts/pro/activities/SelectContactActivity.kt index af80e499..1b680541 100644 --- a/app/src/main/kotlin/com/simplemobiletools/contacts/pro/activities/SelectContactActivity.kt +++ b/app/src/main/kotlin/com/simplemobiletools/contacts/pro/activities/SelectContactActivity.kt @@ -6,6 +6,8 @@ import android.content.Intent import android.net.Uri import android.os.Bundle import android.provider.ContactsContract +import android.provider.ContactsContract.CommonDataKinds.Email +import android.provider.ContactsContract.CommonDataKinds.Phone import android.view.Menu import android.view.MenuItem import androidx.appcompat.widget.SearchView @@ -46,8 +48,8 @@ class SelectContactActivity : SimpleActivity() { handlePermission(PERMISSION_WRITE_CONTACTS) { if (it) { specialMimeType = when (intent.data) { - ContactsContract.CommonDataKinds.Email.CONTENT_URI -> ContactsContract.CommonDataKinds.Email.CONTENT_ITEM_TYPE - ContactsContract.CommonDataKinds.Phone.CONTENT_URI -> ContactsContract.CommonDataKinds.Phone.CONTENT_ITEM_TYPE + Email.CONTENT_URI -> Email.CONTENT_ITEM_TYPE + Phone.CONTENT_URI -> Phone.CONTENT_ITEM_TYPE else -> null } initContacts() @@ -178,8 +180,8 @@ class SelectContactActivity : SimpleActivity() { var contacts = it.filter { if (specialMimeType != null) { val hasRequiredValues = when (specialMimeType) { - ContactsContract.CommonDataKinds.Email.CONTENT_ITEM_TYPE -> it.emails.isNotEmpty() - ContactsContract.CommonDataKinds.Phone.CONTENT_ITEM_TYPE -> it.phoneNumbers.isNotEmpty() + Email.CONTENT_ITEM_TYPE -> it.emails.isNotEmpty() + Phone.CONTENT_ITEM_TYPE -> it.phoneNumbers.isNotEmpty() else -> true } !it.isPrivate() && hasRequiredValues @@ -242,8 +244,8 @@ class SelectContactActivity : SimpleActivity() { select_contact_placeholder_2.beVisibleIf(contacts.isEmpty()) select_contact_placeholder.beVisibleIf(contacts.isEmpty()) select_contact_placeholder.setText(when (specialMimeType) { - ContactsContract.CommonDataKinds.Email.CONTENT_ITEM_TYPE -> R.string.no_contacts_with_emails - ContactsContract.CommonDataKinds.Phone.CONTENT_ITEM_TYPE -> R.string.no_contacts_with_phone_numbers + Email.CONTENT_ITEM_TYPE -> R.string.no_contacts_with_emails + Phone.CONTENT_ITEM_TYPE -> R.string.no_contacts_with_phone_numbers else -> R.string.no_contacts_found }) } diff --git a/app/src/main/kotlin/com/simplemobiletools/contacts/pro/activities/SettingsActivity.kt b/app/src/main/kotlin/com/simplemobiletools/contacts/pro/activities/SettingsActivity.kt index 0e9eef31..b1764815 100644 --- a/app/src/main/kotlin/com/simplemobiletools/contacts/pro/activities/SettingsActivity.kt +++ b/app/src/main/kotlin/com/simplemobiletools/contacts/pro/activities/SettingsActivity.kt @@ -92,10 +92,10 @@ class SettingsActivity : SimpleActivity() { settings_font_size.text = getFontSizeText() settings_font_size_holder.setOnClickListener { val items = arrayListOf( - RadioItem(FONT_SIZE_SMALL, getString(R.string.small)), - RadioItem(FONT_SIZE_MEDIUM, getString(R.string.medium)), - RadioItem(FONT_SIZE_LARGE, getString(R.string.large)), - RadioItem(FONT_SIZE_EXTRA_LARGE, getString(R.string.extra_large))) + RadioItem(FONT_SIZE_SMALL, getString(R.string.small)), + RadioItem(FONT_SIZE_MEDIUM, getString(R.string.medium)), + RadioItem(FONT_SIZE_LARGE, getString(R.string.large)), + RadioItem(FONT_SIZE_EXTRA_LARGE, getString(R.string.extra_large))) RadioGroupDialog(this@SettingsActivity, items, config.fontSize) { config.fontSize = it as Int @@ -166,9 +166,9 @@ class SettingsActivity : SimpleActivity() { settings_on_contact_click.text = getOnContactClickText() settings_on_contact_click_holder.setOnClickListener { val items = arrayListOf( - RadioItem(ON_CLICK_CALL_CONTACT, getString(R.string.call_contact)), - RadioItem(ON_CLICK_VIEW_CONTACT, getString(R.string.view_contact)), - RadioItem(ON_CLICK_EDIT_CONTACT, getString(R.string.edit_contact))) + RadioItem(ON_CLICK_CALL_CONTACT, getString(R.string.call_contact)), + RadioItem(ON_CLICK_VIEW_CONTACT, getString(R.string.view_contact)), + RadioItem(ON_CLICK_EDIT_CONTACT, getString(R.string.edit_contact))) RadioGroupDialog(this@SettingsActivity, items, config.onContactClick) { config.onContactClick = it as Int diff --git a/app/src/main/kotlin/com/simplemobiletools/contacts/pro/activities/SimpleActivity.kt b/app/src/main/kotlin/com/simplemobiletools/contacts/pro/activities/SimpleActivity.kt index 4ce9f67e..54fed533 100644 --- a/app/src/main/kotlin/com/simplemobiletools/contacts/pro/activities/SimpleActivity.kt +++ b/app/src/main/kotlin/com/simplemobiletools/contacts/pro/activities/SimpleActivity.kt @@ -1,40 +1,39 @@ package com.simplemobiletools.contacts.pro.activities -import android.annotation.TargetApi import android.content.ContentValues import android.content.Intent import android.graphics.drawable.Drawable import android.net.Uri -import android.os.Build -import android.telecom.TelecomManager import com.simplemobiletools.commons.activities.BaseSimpleActivity import com.simplemobiletools.commons.extensions.getColoredDrawableWithColor -import com.simplemobiletools.commons.extensions.toast import com.simplemobiletools.contacts.pro.R import com.simplemobiletools.contacts.pro.extensions.config -import com.simplemobiletools.contacts.pro.helpers.* +import com.simplemobiletools.contacts.pro.helpers.KEY_MAILTO +import com.simplemobiletools.contacts.pro.helpers.KEY_PHONE +import com.simplemobiletools.contacts.pro.helpers.LOCATION_CONTACTS_TAB +import com.simplemobiletools.contacts.pro.helpers.LOCATION_FAVORITES_TAB open class SimpleActivity : BaseSimpleActivity() { override fun getAppIconIDs() = arrayListOf( - R.mipmap.ic_launcher_red, - R.mipmap.ic_launcher_pink, - R.mipmap.ic_launcher_purple, - R.mipmap.ic_launcher_deep_purple, - R.mipmap.ic_launcher_indigo, - R.mipmap.ic_launcher_blue, - R.mipmap.ic_launcher_light_blue, - R.mipmap.ic_launcher_cyan, - R.mipmap.ic_launcher_teal, - R.mipmap.ic_launcher_green, - R.mipmap.ic_launcher_light_green, - R.mipmap.ic_launcher_lime, - R.mipmap.ic_launcher_yellow, - R.mipmap.ic_launcher_amber, - R.mipmap.ic_launcher, - R.mipmap.ic_launcher_deep_orange, - R.mipmap.ic_launcher_brown, - R.mipmap.ic_launcher_blue_grey, - R.mipmap.ic_launcher_grey_black + R.mipmap.ic_launcher_red, + R.mipmap.ic_launcher_pink, + R.mipmap.ic_launcher_purple, + R.mipmap.ic_launcher_deep_purple, + R.mipmap.ic_launcher_indigo, + R.mipmap.ic_launcher_blue, + R.mipmap.ic_launcher_light_blue, + R.mipmap.ic_launcher_cyan, + R.mipmap.ic_launcher_teal, + R.mipmap.ic_launcher_green, + R.mipmap.ic_launcher_light_green, + R.mipmap.ic_launcher_lime, + R.mipmap.ic_launcher_yellow, + R.mipmap.ic_launcher_amber, + R.mipmap.ic_launcher, + R.mipmap.ic_launcher_deep_orange, + R.mipmap.ic_launcher_brown, + R.mipmap.ic_launcher_blue_grey, + R.mipmap.ic_launcher_grey_black ) override fun getAppLauncherName() = getString(R.string.app_launcher_name) diff --git a/app/src/main/kotlin/com/simplemobiletools/contacts/pro/activities/ViewContactActivity.kt b/app/src/main/kotlin/com/simplemobiletools/contacts/pro/activities/ViewContactActivity.kt index 89f34622..d92dc8d6 100644 --- a/app/src/main/kotlin/com/simplemobiletools/contacts/pro/activities/ViewContactActivity.kt +++ b/app/src/main/kotlin/com/simplemobiletools/contacts/pro/activities/ViewContactActivity.kt @@ -176,19 +176,11 @@ class ViewContactActivity : ContactActivity() { } val textColor = config.textColor - contact_send_sms.applyColorFilter(textColor) - contact_start_call.applyColorFilter(textColor) - contact_send_email.applyColorFilter(textColor) - contact_name_image.applyColorFilter(textColor) - contact_numbers_image.applyColorFilter(textColor) - contact_emails_image.applyColorFilter(textColor) - contact_addresses_image.applyColorFilter(textColor) - contact_events_image.applyColorFilter(textColor) - contact_source_image.applyColorFilter(textColor) - contact_notes_image.applyColorFilter(textColor) - contact_organization_image.applyColorFilter(textColor) - contact_websites_image.applyColorFilter(textColor) - contact_groups_image.applyColorFilter(textColor) + arrayOf(contact_send_sms, contact_start_call, contact_send_email, contact_name_image, contact_numbers_image, contact_emails_image, + contact_addresses_image, contact_events_image, contact_source_image, contact_notes_image, contact_organization_image, + contact_websites_image, contact_groups_image).forEach { + it.applyColorFilter(textColor) + } contact_send_sms.setOnClickListener { trySendSMS() } contact_start_call.setOnClickListener { tryStartCall(contact!!) } @@ -288,7 +280,7 @@ class ViewContactActivity : ContactActivity() { contact_nickname.copyOnLongClick(nickname) if (contact_prefix.isGone() && contact_first_name.isGone() && contact_middle_name.isGone() && contact_surname.isGone() && contact_suffix.isGone() - && contact_nickname.isGone()) { + && contact_nickname.isGone()) { contact_name_image.beInvisible() (contact_photo.layoutParams as RelativeLayout.LayoutParams).bottomMargin = resources.getDimension(R.dimen.medium_margin).toInt() } 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 440aeef1..3702d7b2 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 @@ -108,8 +108,8 @@ class ContactsHelper(val context: Context) { private fun fillSourcesFromUri(uri: Uri, sources: HashSet) { val projection = arrayOf( - RawContacts.ACCOUNT_NAME, - RawContacts.ACCOUNT_TYPE + RawContacts.ACCOUNT_NAME, + RawContacts.ACCOUNT_TYPE ) context.queryCursor(uri, projection) { cursor -> @@ -176,7 +176,7 @@ class ContactsHelper(val context: Context) { val websites = ArrayList() val ims = ArrayList() val contact = Contact(id, prefix, firstName, middleName, surname, suffix, nickname, photoUri, numbers, emails, addresses, - events, accountName, starred, contactId, thumbnailUri, null, notes, groups, organization, websites, ims) + events, accountName, starred, contactId, thumbnailUri, null, notes, groups, organization, websites, ims) contacts.put(id, contact) } @@ -252,11 +252,11 @@ class ContactsHelper(val context: Context) { val phoneNumbers = SparseArray>() val uri = Phone.CONTENT_URI val projection = arrayOf( - Data.RAW_CONTACT_ID, - Phone.NUMBER, - Phone.NORMALIZED_NUMBER, - Phone.TYPE, - Phone.LABEL + Data.RAW_CONTACT_ID, + Phone.NUMBER, + Phone.NORMALIZED_NUMBER, + Phone.TYPE, + Phone.LABEL ) val selection = if (contactId == null) getSourcesSelection() else "${Data.RAW_CONTACT_ID} = ?" @@ -284,8 +284,8 @@ class ContactsHelper(val context: Context) { val nicknames = SparseArray() val uri = Data.CONTENT_URI val projection = arrayOf( - Data.RAW_CONTACT_ID, - Nickname.NAME + Data.RAW_CONTACT_ID, + Nickname.NAME ) val selection = getSourcesSelection(true, contactId != null) @@ -304,10 +304,10 @@ class ContactsHelper(val context: Context) { val emails = SparseArray>() val uri = CommonDataKinds.Email.CONTENT_URI val projection = arrayOf( - Data.RAW_CONTACT_ID, - CommonDataKinds.Email.DATA, - CommonDataKinds.Email.TYPE, - CommonDataKinds.Email.LABEL + Data.RAW_CONTACT_ID, + CommonDataKinds.Email.DATA, + CommonDataKinds.Email.TYPE, + CommonDataKinds.Email.LABEL ) val selection = if (contactId == null) getSourcesSelection() else "${Data.RAW_CONTACT_ID} = ?" @@ -333,10 +333,10 @@ class ContactsHelper(val context: Context) { val addresses = SparseArray>() val uri = StructuredPostal.CONTENT_URI val projection = arrayOf( - Data.RAW_CONTACT_ID, - StructuredPostal.FORMATTED_ADDRESS, - StructuredPostal.TYPE, - StructuredPostal.LABEL + Data.RAW_CONTACT_ID, + StructuredPostal.FORMATTED_ADDRESS, + StructuredPostal.TYPE, + StructuredPostal.LABEL ) val selection = if (contactId == null) getSourcesSelection() else "${Data.RAW_CONTACT_ID} = ?" @@ -362,10 +362,10 @@ class ContactsHelper(val context: Context) { val IMs = SparseArray>() val uri = Data.CONTENT_URI val projection = arrayOf( - Data.RAW_CONTACT_ID, - Im.DATA, - Im.PROTOCOL, - Im.CUSTOM_PROTOCOL + Data.RAW_CONTACT_ID, + Im.DATA, + Im.PROTOCOL, + Im.CUSTOM_PROTOCOL ) val selection = getSourcesSelection(true, contactId != null) @@ -391,9 +391,9 @@ class ContactsHelper(val context: Context) { val events = SparseArray>() val uri = Data.CONTENT_URI val projection = arrayOf( - Data.RAW_CONTACT_ID, - CommonDataKinds.Event.START_DATE, - CommonDataKinds.Event.TYPE + Data.RAW_CONTACT_ID, + CommonDataKinds.Event.START_DATE, + CommonDataKinds.Event.TYPE ) val selection = getSourcesSelection(true, contactId != null) @@ -418,8 +418,8 @@ class ContactsHelper(val context: Context) { val notes = SparseArray() val uri = Data.CONTENT_URI val projection = arrayOf( - Data.RAW_CONTACT_ID, - Note.NOTE + Data.RAW_CONTACT_ID, + Note.NOTE ) val selection = getSourcesSelection(true, contactId != null) @@ -438,9 +438,9 @@ class ContactsHelper(val context: Context) { val organizations = SparseArray() val uri = Data.CONTENT_URI val projection = arrayOf( - Data.RAW_CONTACT_ID, - CommonDataKinds.Organization.COMPANY, - CommonDataKinds.Organization.TITLE + Data.RAW_CONTACT_ID, + CommonDataKinds.Organization.COMPANY, + CommonDataKinds.Organization.TITLE ) val selection = getSourcesSelection(true, contactId != null) @@ -465,8 +465,8 @@ class ContactsHelper(val context: Context) { val websites = SparseArray>() val uri = Data.CONTENT_URI val projection = arrayOf( - Data.RAW_CONTACT_ID, - Website.URL + Data.RAW_CONTACT_ID, + Website.URL ) val selection = getSourcesSelection(true, contactId != null) @@ -494,8 +494,8 @@ class ContactsHelper(val context: Context) { val uri = Data.CONTENT_URI val projection = arrayOf( - Data.CONTACT_ID, - Data.DATA1 + Data.CONTACT_ID, + Data.DATA1 ) val selection = getSourcesSelection(true, contactId != null, false) @@ -581,9 +581,9 @@ class ContactsHelper(val context: Context) { val uri = Groups.CONTENT_URI val projection = arrayOf( - Groups._ID, - Groups.TITLE, - Groups.SYSTEM_ID + Groups._ID, + Groups.TITLE, + Groups.SYSTEM_ID ) val selection = "${Groups.AUTO_ADD} = ? AND ${Groups.FAVORITES} = ?" @@ -650,8 +650,8 @@ class ContactsHelper(val context: Context) { fun deleteGroup(id: Long) { val operations = ArrayList() val uri = ContentUris.withAppendedId(Groups.CONTENT_URI, id).buildUpon() - .appendQueryParameter(CALLER_IS_SYNCADAPTER, "true") - .build() + .appendQueryParameter(CALLER_IS_SYNCADAPTER, "true") + .build() operations.add(ContentProviderOperation.newDelete(uri).build()) @@ -721,7 +721,7 @@ class ContactsHelper(val context: Context) { val websites = getWebsites(id)[id] ?: ArrayList() val ims = getIMs(id)[id] ?: ArrayList() return Contact(id, prefix, firstName, middleName, surname, suffix, nickname, photoUri, number, emails, addresses, events, - accountName, starred, contactId, thumbnailUri, null, notes, groups, organization, websites, ims) + accountName, starred, contactId, thumbnailUri, null, notes, groups, organization, websites, ims) } } @@ -743,9 +743,9 @@ class ContactsHelper(val context: Context) { fun getSaveableContactSources(callback: (ArrayList) -> Unit) { ensureBackgroundThread { val ignoredTypes = arrayListOf( - SIGNAL_PACKAGE, - TELEGRAM_PACKAGE, - WHATSAPP_PACKAGE + SIGNAL_PACKAGE, + TELEGRAM_PACKAGE, + WHATSAPP_PACKAGE ) val contactSources = getContactSourcesSync() @@ -806,19 +806,19 @@ class ContactsHelper(val context: Context) { private fun getContactSourceType(accountName: String) = getDeviceContactSources().firstOrNull { it.name == accountName }?.type ?: "" private fun getContactProjection() = arrayOf( - Data.MIMETYPE, - Data.CONTACT_ID, - Data.RAW_CONTACT_ID, - StructuredName.PREFIX, - StructuredName.GIVEN_NAME, - StructuredName.MIDDLE_NAME, - StructuredName.FAMILY_NAME, - StructuredName.SUFFIX, - StructuredName.PHOTO_URI, - StructuredName.PHOTO_THUMBNAIL_URI, - StructuredName.STARRED, - RawContacts.ACCOUNT_NAME, - RawContacts.ACCOUNT_TYPE + Data.MIMETYPE, + Data.CONTACT_ID, + Data.RAW_CONTACT_ID, + StructuredName.PREFIX, + StructuredName.GIVEN_NAME, + StructuredName.MIDDLE_NAME, + StructuredName.FAMILY_NAME, + StructuredName.SUFFIX, + StructuredName.PHOTO_URI, + StructuredName.PHOTO_THUMBNAIL_URI, + StructuredName.STARRED, + RawContacts.ACCOUNT_NAME, + RawContacts.ACCOUNT_TYPE ) private fun getSortString(): String { diff --git a/app/src/main/kotlin/com/simplemobiletools/contacts/pro/helpers/VcfExporter.kt b/app/src/main/kotlin/com/simplemobiletools/contacts/pro/helpers/VcfExporter.kt index c9633926..972ba02a 100644 --- a/app/src/main/kotlin/com/simplemobiletools/contacts/pro/helpers/VcfExporter.kt +++ b/app/src/main/kotlin/com/simplemobiletools/contacts/pro/helpers/VcfExporter.kt @@ -2,6 +2,7 @@ package com.simplemobiletools.contacts.pro.helpers import android.net.Uri import android.provider.ContactsContract.CommonDataKinds +import android.provider.ContactsContract.CommonDataKinds.* import android.provider.MediaStore import com.simplemobiletools.commons.activities.BaseSimpleActivity import com.simplemobiletools.commons.extensions.showErrorToast @@ -15,6 +16,10 @@ import ezvcard.Ezvcard import ezvcard.VCard import ezvcard.parameter.ImageType import ezvcard.property.* +import ezvcard.property.Email +import ezvcard.property.Organization +import ezvcard.property.Photo +import ezvcard.property.StructuredName import ezvcard.util.PartialDate import java.io.OutputStream import java.util.* @@ -67,11 +72,11 @@ class VcfExporter { } contact.events.forEach { - if (it.type == CommonDataKinds.Event.TYPE_ANNIVERSARY || it.type == CommonDataKinds.Event.TYPE_BIRTHDAY) { + if (it.type == Event.TYPE_ANNIVERSARY || it.type == Event.TYPE_BIRTHDAY) { val dateTime = it.value.getDateTimeFromDateString() if (it.value.startsWith("--")) { val partialDate = PartialDate.builder().year(null).month(dateTime.monthOfYear).date(dateTime.dayOfMonth).build() - if (it.type == CommonDataKinds.Event.TYPE_BIRTHDAY) { + if (it.type == Event.TYPE_BIRTHDAY) { card.birthdays.add(Birthday(partialDate)) } else { card.anniversaries.add(Anniversary(partialDate)) @@ -82,7 +87,7 @@ class VcfExporter { set(Calendar.YEAR, dateTime.year) set(Calendar.MONTH, dateTime.monthOfYear - 1) set(Calendar.DAY_OF_MONTH, dateTime.dayOfMonth) - if (it.type == CommonDataKinds.Event.TYPE_BIRTHDAY) { + if (it.type == Event.TYPE_BIRTHDAY) { card.birthdays.add(Birthday(time)) } else { card.anniversaries.add(Anniversary(time)) @@ -101,14 +106,14 @@ class VcfExporter { contact.IMs.forEach { val impp = when (it.type) { - CommonDataKinds.Im.PROTOCOL_AIM -> Impp.aim(it.value) - CommonDataKinds.Im.PROTOCOL_YAHOO -> Impp.yahoo(it.value) - CommonDataKinds.Im.PROTOCOL_MSN -> Impp.msn(it.value) - CommonDataKinds.Im.PROTOCOL_ICQ -> Impp.icq(it.value) - CommonDataKinds.Im.PROTOCOL_SKYPE -> Impp.skype(it.value) - CommonDataKinds.Im.PROTOCOL_GOOGLE_TALK -> Impp(HANGOUTS, it.value) - CommonDataKinds.Im.PROTOCOL_QQ -> Impp(QQ, it.value) - CommonDataKinds.Im.PROTOCOL_JABBER -> Impp(JABBER, it.value) + Im.PROTOCOL_AIM -> Impp.aim(it.value) + Im.PROTOCOL_YAHOO -> Impp.yahoo(it.value) + Im.PROTOCOL_MSN -> Impp.msn(it.value) + Im.PROTOCOL_ICQ -> Impp.icq(it.value) + Im.PROTOCOL_SKYPE -> Impp.skype(it.value) + Im.PROTOCOL_GOOGLE_TALK -> Impp(HANGOUTS, it.value) + Im.PROTOCOL_QQ -> Impp(QQ, it.value) + Im.PROTOCOL_JABBER -> Impp(JABBER, it.value) else -> Impp(it.label, it.value) } @@ -162,14 +167,14 @@ class VcfExporter { } private fun getPhoneNumberTypeLabel(type: Int, label: String) = when (type) { - CommonDataKinds.Phone.TYPE_MOBILE -> CELL - CommonDataKinds.Phone.TYPE_HOME -> HOME - CommonDataKinds.Phone.TYPE_WORK -> WORK - CommonDataKinds.Phone.TYPE_MAIN -> PREF - CommonDataKinds.Phone.TYPE_FAX_WORK -> WORK_FAX - CommonDataKinds.Phone.TYPE_FAX_HOME -> HOME_FAX - CommonDataKinds.Phone.TYPE_PAGER -> PAGER - CommonDataKinds.Phone.TYPE_OTHER -> OTHER + Phone.TYPE_MOBILE -> CELL + Phone.TYPE_HOME -> HOME + Phone.TYPE_WORK -> WORK + Phone.TYPE_MAIN -> PREF + Phone.TYPE_FAX_WORK -> WORK_FAX + Phone.TYPE_FAX_HOME -> HOME_FAX + Phone.TYPE_PAGER -> PAGER + Phone.TYPE_OTHER -> OTHER else -> label } @@ -182,9 +187,9 @@ class VcfExporter { } private fun getAddressTypeLabel(type: Int, label: String) = when (type) { - CommonDataKinds.StructuredPostal.TYPE_HOME -> HOME - CommonDataKinds.StructuredPostal.TYPE_WORK -> WORK - CommonDataKinds.StructuredPostal.TYPE_OTHER -> OTHER + StructuredPostal.TYPE_HOME -> HOME + StructuredPostal.TYPE_WORK -> WORK + StructuredPostal.TYPE_OTHER -> OTHER else -> label } } diff --git a/app/src/main/kotlin/com/simplemobiletools/contacts/pro/helpers/VcfImporter.kt b/app/src/main/kotlin/com/simplemobiletools/contacts/pro/helpers/VcfImporter.kt index a9030e19..fedde9e3 100644 --- a/app/src/main/kotlin/com/simplemobiletools/contacts/pro/helpers/VcfImporter.kt +++ b/app/src/main/kotlin/com/simplemobiletools/contacts/pro/helpers/VcfImporter.kt @@ -3,6 +3,7 @@ package com.simplemobiletools.contacts.pro.helpers import android.graphics.Bitmap import android.graphics.BitmapFactory import android.provider.ContactsContract.CommonDataKinds +import android.provider.ContactsContract.CommonDataKinds.* import android.widget.Toast import com.simplemobiletools.commons.extensions.showErrorToast import com.simplemobiletools.contacts.pro.activities.SimpleActivity @@ -12,6 +13,9 @@ import com.simplemobiletools.contacts.pro.extensions.groupsDB import com.simplemobiletools.contacts.pro.extensions.normalizeNumber import com.simplemobiletools.contacts.pro.helpers.VcfImporter.ImportResult.* import com.simplemobiletools.contacts.pro.models.* +import com.simplemobiletools.contacts.pro.models.Email +import com.simplemobiletools.contacts.pro.models.Event +import com.simplemobiletools.contacts.pro.models.Organization import ezvcard.Ezvcard import ezvcard.VCard import java.io.File @@ -50,7 +54,7 @@ class VcfImporter(val activity: SimpleActivity) { ezContact.telephoneNumbers.forEach { val number = it.text val type = getPhoneNumberTypeId(it.types.firstOrNull()?.value ?: MOBILE, it.types.getOrNull(1)?.value) - val label = if (type == CommonDataKinds.Phone.TYPE_CUSTOM) { + val label = if (type == Phone.TYPE_CUSTOM) { it.types.firstOrNull()?.value ?: "" } else { "" @@ -76,7 +80,7 @@ class VcfImporter(val activity: SimpleActivity) { ezContact.addresses.forEach { val address = it.streetAddress val type = getAddressTypeId(it.types.firstOrNull()?.value ?: HOME) - val label = if (type == CommonDataKinds.StructuredPostal.TYPE_CUSTOM) { + val label = if (type == StructuredPostal.TYPE_CUSTOM) { it.types.firstOrNull()?.value ?: "" } else { "" @@ -115,24 +119,24 @@ class VcfImporter(val activity: SimpleActivity) { val typeString = it.uri.scheme val value = URLDecoder.decode(it.uri.toString().substring(it.uri.scheme.length + 1), "UTF-8") val type = when { - it.isAim -> CommonDataKinds.Im.PROTOCOL_AIM - it.isYahoo -> CommonDataKinds.Im.PROTOCOL_YAHOO - it.isMsn -> CommonDataKinds.Im.PROTOCOL_MSN - it.isIcq -> CommonDataKinds.Im.PROTOCOL_ICQ - it.isSkype -> CommonDataKinds.Im.PROTOCOL_SKYPE - typeString == HANGOUTS -> CommonDataKinds.Im.PROTOCOL_GOOGLE_TALK - typeString == QQ -> CommonDataKinds.Im.PROTOCOL_QQ - typeString == JABBER -> CommonDataKinds.Im.PROTOCOL_JABBER - else -> CommonDataKinds.Im.PROTOCOL_CUSTOM + it.isAim -> Im.PROTOCOL_AIM + it.isYahoo -> Im.PROTOCOL_YAHOO + it.isMsn -> Im.PROTOCOL_MSN + it.isIcq -> Im.PROTOCOL_ICQ + it.isSkype -> Im.PROTOCOL_SKYPE + typeString == HANGOUTS -> Im.PROTOCOL_GOOGLE_TALK + typeString == QQ -> Im.PROTOCOL_QQ + typeString == JABBER -> Im.PROTOCOL_JABBER + else -> Im.PROTOCOL_CUSTOM } - val label = if (type == CommonDataKinds.Im.PROTOCOL_CUSTOM) URLDecoder.decode(typeString, "UTF-8") else "" + val label = if (type == Im.PROTOCOL_CUSTOM) URLDecoder.decode(typeString, "UTF-8") else "" val IM = IM(value, type, label) IMs.add(IM) } val contact = Contact(0, prefix, firstName, middleName, surname, suffix, nickname, photoUri, phoneNumbers, emails, addresses, events, - targetContactSource, starred, contactId, thumbnailUri, photo, notes, groups, organization, websites, IMs) + targetContactSource, starred, contactId, thumbnailUri, photo, notes, groups, organization, websites, IMs) // if there is no N and ORG fields at the given contact, only FN, treat it as an organization if (contact.getNameToDisplay().isEmpty() && contact.organization.isEmpty() && ezContact.formattedName?.value?.isNotEmpty() == true) { @@ -189,28 +193,28 @@ class VcfImporter(val activity: SimpleActivity) { } private fun getPhoneNumberTypeId(type: String, subtype: String?) = when (type.toUpperCase()) { - CELL -> CommonDataKinds.Phone.TYPE_MOBILE + CELL -> Phone.TYPE_MOBILE HOME -> { if (subtype?.toUpperCase() == FAX) { - CommonDataKinds.Phone.TYPE_FAX_HOME + Phone.TYPE_FAX_HOME } else { - CommonDataKinds.Phone.TYPE_HOME + Phone.TYPE_HOME } } WORK -> { if (subtype?.toUpperCase() == FAX) { - CommonDataKinds.Phone.TYPE_FAX_WORK + Phone.TYPE_FAX_WORK } else { - CommonDataKinds.Phone.TYPE_WORK + Phone.TYPE_WORK } } - PREF, MAIN -> CommonDataKinds.Phone.TYPE_MAIN - WORK_FAX -> CommonDataKinds.Phone.TYPE_FAX_WORK - HOME_FAX -> CommonDataKinds.Phone.TYPE_FAX_HOME - FAX -> CommonDataKinds.Phone.TYPE_FAX_WORK - PAGER -> CommonDataKinds.Phone.TYPE_PAGER - OTHER -> CommonDataKinds.Phone.TYPE_OTHER - else -> CommonDataKinds.Phone.TYPE_CUSTOM + PREF, MAIN -> Phone.TYPE_MAIN + WORK_FAX -> Phone.TYPE_FAX_WORK + HOME_FAX -> Phone.TYPE_FAX_HOME + FAX -> Phone.TYPE_FAX_WORK + PAGER -> Phone.TYPE_PAGER + OTHER -> Phone.TYPE_OTHER + else -> Phone.TYPE_CUSTOM } private fun getEmailTypeId(type: String) = when (type.toUpperCase()) { @@ -222,10 +226,10 @@ class VcfImporter(val activity: SimpleActivity) { } private fun getAddressTypeId(type: String) = when (type.toUpperCase()) { - HOME -> CommonDataKinds.StructuredPostal.TYPE_HOME - WORK -> CommonDataKinds.StructuredPostal.TYPE_WORK - OTHER -> CommonDataKinds.StructuredPostal.TYPE_OTHER - else -> CommonDataKinds.StructuredPostal.TYPE_CUSTOM + HOME -> StructuredPostal.TYPE_HOME + WORK -> StructuredPostal.TYPE_WORK + OTHER -> StructuredPostal.TYPE_OTHER + else -> StructuredPostal.TYPE_CUSTOM } private fun savePhoto(byteArray: ByteArray?): String {