mirror of
https://github.com/SimpleMobileTools/Simple-Contacts.git
synced 2025-03-28 17:10:03 +01:00
fix #644, fixing a glitch at saving contact without first name
This commit is contained in:
parent
3eaca0ef79
commit
8449b00b7d
app/src/main/kotlin/com/simplemobiletools/contacts/pro
adapters
extensions
helpers
models
@ -15,7 +15,10 @@ import com.bumptech.glide.signature.ObjectKey
|
||||
import com.simplemobiletools.commons.adapters.MyRecyclerViewAdapter
|
||||
import com.simplemobiletools.commons.dialogs.ConfirmationDialog
|
||||
import com.simplemobiletools.commons.dialogs.RadioGroupDialog
|
||||
import com.simplemobiletools.commons.extensions.*
|
||||
import com.simplemobiletools.commons.extensions.beVisibleIf
|
||||
import com.simplemobiletools.commons.extensions.getTextSize
|
||||
import com.simplemobiletools.commons.extensions.highlightTextFromNumbers
|
||||
import com.simplemobiletools.commons.extensions.highlightTextPart
|
||||
import com.simplemobiletools.commons.helpers.*
|
||||
import com.simplemobiletools.commons.models.RadioItem
|
||||
import com.simplemobiletools.commons.views.FastScroller
|
||||
|
@ -36,7 +36,7 @@ fun Context.getEmptyContact(): Contact {
|
||||
val originalContactSource = if (hasContactPermissions()) config.lastUsedContactSource else SMT_PRIVATE
|
||||
val organization = Organization("", "")
|
||||
return Contact(0, "", "", "", "", "", "", "", ArrayList(), ArrayList(), ArrayList(), ArrayList(), originalContactSource, 0, 0, "",
|
||||
null, "", ArrayList(), organization, ArrayList(), ArrayList())
|
||||
null, "", ArrayList(), organization, ArrayList(), ArrayList(), DEFAULT_MIMETYPE)
|
||||
}
|
||||
|
||||
fun Context.viewContact(contact: Contact) {
|
||||
|
@ -101,6 +101,7 @@ const val DEFAULT_EVENT_TYPE = CommonDataKinds.Event.TYPE_BIRTHDAY
|
||||
const val DEFAULT_ORGANIZATION_TYPE = CommonDataKinds.Organization.TYPE_WORK
|
||||
const val DEFAULT_WEBSITE_TYPE = CommonDataKinds.Website.TYPE_HOMEPAGE
|
||||
const val DEFAULT_IM_TYPE = CommonDataKinds.Im.PROTOCOL_SKYPE
|
||||
const val DEFAULT_MIMETYPE = CommonDataKinds.StructuredName.CONTENT_ITEM_TYPE
|
||||
|
||||
// apps with special handling
|
||||
const val TELEGRAM_PACKAGE = "org.telegram.messenger"
|
||||
|
@ -151,6 +151,7 @@ class ContactsHelper(val context: Context) {
|
||||
var middleName = ""
|
||||
var surname = ""
|
||||
var suffix = ""
|
||||
val mimetype = cursor.getStringValue(Data.MIMETYPE)
|
||||
|
||||
// ignore names at Organization type contacts
|
||||
if (cursor.getStringValue(Data.MIMETYPE) == StructuredName.CONTENT_ITEM_TYPE) {
|
||||
@ -176,7 +177,7 @@ class ContactsHelper(val context: Context) {
|
||||
val websites = ArrayList<String>()
|
||||
val ims = ArrayList<IM>()
|
||||
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, mimetype)
|
||||
|
||||
contacts.put(id, contact)
|
||||
}
|
||||
@ -695,9 +696,10 @@ class ContactsHelper(val context: Context) {
|
||||
var middleName = ""
|
||||
var surname = ""
|
||||
var suffix = ""
|
||||
val mimetype = cursor.getStringValue(Data.MIMETYPE)
|
||||
|
||||
// ignore names at Organization type contacts
|
||||
if (cursor.getStringValue(Data.MIMETYPE) == StructuredName.CONTENT_ITEM_TYPE) {
|
||||
if (mimetype == StructuredName.CONTENT_ITEM_TYPE) {
|
||||
prefix = cursor.getStringValue(StructuredName.PREFIX) ?: ""
|
||||
firstName = cursor.getStringValue(StructuredName.GIVEN_NAME) ?: ""
|
||||
middleName = cursor.getStringValue(StructuredName.MIDDLE_NAME) ?: ""
|
||||
@ -721,7 +723,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, mimetype)
|
||||
}
|
||||
}
|
||||
|
||||
@ -858,8 +860,8 @@ class ContactsHelper(val context: Context) {
|
||||
try {
|
||||
val operations = ArrayList<ContentProviderOperation>()
|
||||
ContentProviderOperation.newUpdate(Data.CONTENT_URI).apply {
|
||||
val selection = "${Data.RAW_CONTACT_ID} = ? AND (${Data.MIMETYPE} = ? OR ${Data.MIMETYPE} = ?)"
|
||||
val selectionArgs = arrayOf(contact.id.toString(), StructuredName.CONTENT_ITEM_TYPE, CommonDataKinds.Organization.CONTENT_ITEM_TYPE)
|
||||
val selection = "${Data.RAW_CONTACT_ID} = ? AND ${Data.MIMETYPE} = ?"
|
||||
val selectionArgs = arrayOf(contact.id.toString(), contact.mimetype)
|
||||
withSelection(selection, selectionArgs)
|
||||
withValue(StructuredName.PREFIX, contact.prefix)
|
||||
withValue(StructuredName.GIVEN_NAME, contact.firstName)
|
||||
|
@ -138,11 +138,16 @@ class VcfImporter(val activity: SimpleActivity) {
|
||||
}
|
||||
|
||||
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, DEFAULT_MIMETYPE)
|
||||
|
||||
// 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) {
|
||||
contact.organization.company = ezContact.formattedName.value
|
||||
contact.mimetype = CommonDataKinds.Organization.CONTENT_ITEM_TYPE
|
||||
}
|
||||
|
||||
if (contact.isABusinessContact()) {
|
||||
contact.mimetype = CommonDataKinds.Organization.CONTENT_ITEM_TYPE
|
||||
}
|
||||
|
||||
if (ContactsHelper(activity).insertContact(contact)) {
|
||||
|
@ -13,7 +13,7 @@ import com.simplemobiletools.contacts.pro.helpers.SMT_PRIVATE
|
||||
data class Contact(var id: Int, var prefix: String, var firstName: String, var middleName: String, var surname: String, var suffix: String, var nickname: String,
|
||||
var photoUri: String, var phoneNumbers: ArrayList<PhoneNumber>, var emails: ArrayList<Email>, var addresses: ArrayList<Address>,
|
||||
var events: ArrayList<Event>, var source: String, var starred: Int, var contactId: Int, var thumbnailUri: String, var photo: Bitmap?, var notes: String,
|
||||
var groups: ArrayList<Group>, var organization: Organization, var websites: ArrayList<String>, var IMs: ArrayList<IM>) :
|
||||
var groups: ArrayList<Group>, var organization: Organization, var websites: ArrayList<String>, var IMs: ArrayList<IM>, var mimetype: String) :
|
||||
Comparable<Contact> {
|
||||
companion object {
|
||||
var sorting = 0
|
||||
|
Loading…
x
Reference in New Issue
Block a user