updating some code style and shortening it, no real change

This commit is contained in:
tibbi
2020-04-27 23:09:44 +02:00
parent 7aa9cfa328
commit 6b55adefbd
11 changed files with 326 additions and 334 deletions

View File

@ -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
@ -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
}
}

View File

@ -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
}
@ -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
}
@ -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))
@ -1147,13 +1137,13 @@ class EditContactActivity : ContactActivity() {
private fun parseIntentData(data: ArrayList<ContentValues>) {
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
}
}

View File

@ -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
})
}

View File

@ -1,18 +1,17 @@
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(

View File

@ -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!!) }

View File

@ -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
}
}

View File

@ -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,18 +119,18 @@ 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)
}
@ -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 {