mirror of
https://github.com/SimpleMobileTools/Simple-Contacts.git
synced 2025-06-05 21:59:27 +02:00
fetch contact websites
This commit is contained in:
@ -467,7 +467,8 @@ class EditContactActivity : ContactActivity() {
|
||||
supportActionBar?.title = resources.getString(R.string.new_contact)
|
||||
val contactSource = if (hasContactPermissions()) config.lastUsedContactSource else SMT_PRIVATE
|
||||
val organization = Organization("", "")
|
||||
contact = Contact(0, "", "", "", "", "", "", ArrayList(), ArrayList(), ArrayList(), ArrayList(), contactSource, 0, 0, "", null, "", ArrayList(), organization)
|
||||
contact = Contact(0, "", "", "", "", "", "", ArrayList(), ArrayList(), ArrayList(), ArrayList(), contactSource, 0, 0, "", null, "",
|
||||
ArrayList(), organization, ArrayList())
|
||||
contact_source.text = getPublicContactSource(contact!!.source)
|
||||
contact_source.setOnClickListener {
|
||||
showContactSourcePicker(contact!!.source) {
|
||||
|
@ -240,7 +240,8 @@ abstract class MyViewPagerFragment(context: Context, attributeSet: AttributeSet)
|
||||
it.addresses.any { it.value.contains(text, true) } ||
|
||||
it.notes.contains(text, true) ||
|
||||
it.organization.company.contains(text, true) ||
|
||||
it.organization.jobPosition.contains(text, true)
|
||||
it.organization.jobPosition.contains(text, true) ||
|
||||
it.websites.any { it.contains(text, true) }
|
||||
} as ArrayList
|
||||
|
||||
Contact.sorting = config.sorting
|
||||
|
@ -87,8 +87,9 @@ class ContactsHelper(val activity: BaseSimpleActivity) {
|
||||
val notes = ""
|
||||
val groups = ArrayList<Group>()
|
||||
val organization = Organization("", "")
|
||||
val websites = ArrayList<String>()
|
||||
val contact = Contact(id, prefix, firstName, middleName, surname, suffix, photoUri, number, emails, addresses, events,
|
||||
accountName, starred, contactId, thumbnailUri, null, notes, groups, organization)
|
||||
accountName, starred, contactId, thumbnailUri, null, notes, groups, organization, websites)
|
||||
contacts.put(id, contact)
|
||||
} while (cursor.moveToNext())
|
||||
}
|
||||
@ -139,6 +140,13 @@ class ContactsHelper(val activity: BaseSimpleActivity) {
|
||||
val key = organizations.keyAt(i)
|
||||
contacts[key]?.organization = organizations.valueAt(i)
|
||||
}
|
||||
|
||||
val websites = getWebsites()
|
||||
size = websites.size()
|
||||
for (i in 0 until size) {
|
||||
val key = websites.keyAt(i)
|
||||
contacts[key]?.websites = websites.valueAt(i)
|
||||
}
|
||||
}
|
||||
|
||||
private fun getPhoneNumbers(contactId: Int? = null): SparseArray<ArrayList<PhoneNumber>> {
|
||||
@ -369,6 +377,46 @@ class ContactsHelper(val activity: BaseSimpleActivity) {
|
||||
return organizations
|
||||
}
|
||||
|
||||
private fun getWebsites(contactId: Int? = null): SparseArray<ArrayList<String>> {
|
||||
val websites = SparseArray<ArrayList<String>>()
|
||||
val uri = ContactsContract.Data.CONTENT_URI
|
||||
val projection = arrayOf(
|
||||
ContactsContract.Data.RAW_CONTACT_ID,
|
||||
CommonDataKinds.Website.URL
|
||||
)
|
||||
|
||||
var selection = "${ContactsContract.Data.MIMETYPE} = ?"
|
||||
var selectionArgs = arrayOf(CommonDataKinds.Website.CONTENT_ITEM_TYPE)
|
||||
|
||||
if (contactId != null) {
|
||||
selection += " AND ${ContactsContract.Data.RAW_CONTACT_ID} = ?"
|
||||
selectionArgs = arrayOf(CommonDataKinds.Website.CONTENT_ITEM_TYPE, contactId.toString())
|
||||
}
|
||||
|
||||
var cursor: Cursor? = null
|
||||
try {
|
||||
cursor = activity.contentResolver.query(uri, projection, selection, selectionArgs, null)
|
||||
if (cursor?.moveToFirst() == true) {
|
||||
do {
|
||||
val id = cursor.getIntValue(ContactsContract.Data.RAW_CONTACT_ID)
|
||||
val url = cursor.getStringValue(CommonDataKinds.Website.URL) ?: continue
|
||||
|
||||
if (websites[id] == null) {
|
||||
websites.put(id, ArrayList())
|
||||
}
|
||||
|
||||
websites[id]!!.add(url)
|
||||
} while (cursor.moveToNext())
|
||||
}
|
||||
} catch (e: Exception) {
|
||||
activity.showErrorToast(e)
|
||||
} finally {
|
||||
cursor?.close()
|
||||
}
|
||||
|
||||
return websites
|
||||
}
|
||||
|
||||
private fun getContactGroups(storedGroups: ArrayList<Group>, contactId: Int? = null): SparseArray<ArrayList<Group>> {
|
||||
val groups = SparseArray<ArrayList<Group>>()
|
||||
if (!activity.hasContactPermissions()) {
|
||||
@ -560,8 +608,9 @@ class ContactsHelper(val activity: BaseSimpleActivity) {
|
||||
val groups = getContactGroups(storedGroups, contactId)[contactId] ?: ArrayList()
|
||||
val thumbnailUri = cursor.getStringValue(CommonDataKinds.StructuredName.PHOTO_THUMBNAIL_URI) ?: ""
|
||||
val organization = getOrganizations(id)[id] ?: Organization("", "")
|
||||
val websites = getWebsites(id)[id] ?: ArrayList()
|
||||
return Contact(id, prefix, firstName, middleName, surname, suffix, photoUri, number, emails, addresses, events, accountName,
|
||||
starred, contactId, thumbnailUri, null, notes, groups, organization)
|
||||
starred, contactId, thumbnailUri, null, notes, groups, organization, websites)
|
||||
}
|
||||
} finally {
|
||||
cursor?.close()
|
||||
|
@ -295,8 +295,10 @@ class DBHelper private constructor(val context: Context) : SQLiteOpenHelper(cont
|
||||
val jobPosition = cursor.getStringValue(COL_JOB_POSITION)
|
||||
val organization = Organization(company, jobPosition)
|
||||
|
||||
val websites = ArrayList<String>()
|
||||
|
||||
val contact = Contact(id, prefix, firstName, middleName, surname, suffix, "", phoneNumbers, emails, addresses, events,
|
||||
SMT_PRIVATE, starred, id, "", photo, notes, groups, organization)
|
||||
SMT_PRIVATE, starred, id, "", photo, notes, groups, organization, websites)
|
||||
contacts.add(contact)
|
||||
}
|
||||
}
|
||||
|
@ -26,13 +26,14 @@ class VcfImporter(val activity: SimpleActivity) {
|
||||
private var curSuffix = ""
|
||||
private var curPhotoUri = ""
|
||||
private var curNotes = ""
|
||||
private var curCompany = ""
|
||||
private var curJobPosition = ""
|
||||
private var curPhoneNumbers = ArrayList<PhoneNumber>()
|
||||
private var curEmails = ArrayList<Email>()
|
||||
private var curEvents = ArrayList<Event>()
|
||||
private var curAddresses = ArrayList<Address>()
|
||||
private var curGroups = ArrayList<Group>()
|
||||
private var curCompany = ""
|
||||
private var curJobPosition = ""
|
||||
private var curWebsites = ArrayList<String>()
|
||||
|
||||
private var isGettingPhoto = false
|
||||
private var currentPhotoString = StringBuilder()
|
||||
@ -253,7 +254,7 @@ class VcfImporter(val activity: SimpleActivity) {
|
||||
private fun saveContact(source: String) {
|
||||
val organization = Organization(curCompany, curJobPosition)
|
||||
val contact = Contact(0, curPrefix, curFirstName, curMiddleName, curSurname, curSuffix, curPhotoUri, curPhoneNumbers, curEmails, curAddresses, curEvents,
|
||||
source, 0, 0, "", null, curNotes, curGroups, organization)
|
||||
source, 0, 0, "", null, curNotes, curGroups, organization, curWebsites)
|
||||
if (ContactsHelper(activity).insertContact(contact)) {
|
||||
contactsImported++
|
||||
}
|
||||
@ -267,13 +268,14 @@ class VcfImporter(val activity: SimpleActivity) {
|
||||
curSuffix = ""
|
||||
curPhotoUri = ""
|
||||
curNotes = ""
|
||||
curCompany = ""
|
||||
curJobPosition = ""
|
||||
curPhoneNumbers = ArrayList()
|
||||
curEmails = ArrayList()
|
||||
curEvents = ArrayList()
|
||||
curAddresses = ArrayList()
|
||||
curGroups = ArrayList()
|
||||
curCompany = ""
|
||||
curJobPosition = ""
|
||||
curWebsites = ArrayList()
|
||||
|
||||
isGettingPhoto = false
|
||||
currentPhotoString = StringBuilder()
|
||||
|
@ -8,7 +8,7 @@ import com.simplemobiletools.commons.helpers.SORT_DESCENDING
|
||||
data class Contact(val id: Int, var prefix: String, var firstName: String, var middleName: String, var surname: String, var suffix: 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, val contactId: Int, val thumbnailUri: String, var photo: Bitmap?, var notes: String,
|
||||
var groups: ArrayList<Group>, var organization: Organization) : Comparable<Contact> {
|
||||
var groups: ArrayList<Group>, var organization: Organization, var websites: ArrayList<String>) : Comparable<Contact> {
|
||||
companion object {
|
||||
var sorting = 0
|
||||
var startWithSurname = false
|
||||
|
BIN
app/src/main/res/drawable-hdpi/ic_link.png
Normal file
BIN
app/src/main/res/drawable-hdpi/ic_link.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 334 B |
BIN
app/src/main/res/drawable-xhdpi/ic_link.png
Normal file
BIN
app/src/main/res/drawable-xhdpi/ic_link.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 371 B |
BIN
app/src/main/res/drawable-xxhdpi/ic_link.png
Normal file
BIN
app/src/main/res/drawable-xxhdpi/ic_link.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 537 B |
BIN
app/src/main/res/drawable-xxxhdpi/ic_link.png
Normal file
BIN
app/src/main/res/drawable-xxxhdpi/ic_link.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 704 B |
Reference in New Issue
Block a user