Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -661,6 +661,7 @@ const val SHOW_WEBSITES_FIELD = 8192
const val SHOW_NICKNAME_FIELD = 16384
const val SHOW_IMS_FIELD = 32768
const val SHOW_RINGTONE_FIELD = 65536
const val SHOW_STRUCTURED_ADDRESSES_FIELD = 131072

const val DEFAULT_EMAIL_TYPE = ContactsContract.CommonDataKinds.Email.TYPE_HOME
const val DEFAULT_PHONE_NUMBER_TYPE = ContactsContract.CommonDataKinds.Phone.TYPE_MOBILE
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -361,6 +361,13 @@ class ContactsHelper(val context: Context) {
val projection = arrayOf(
Data.RAW_CONTACT_ID,
CommonDataKinds.StructuredPostal.FORMATTED_ADDRESS,
CommonDataKinds.StructuredPostal.COUNTRY,
CommonDataKinds.StructuredPostal.REGION,
CommonDataKinds.StructuredPostal.CITY,
CommonDataKinds.StructuredPostal.POSTCODE,
CommonDataKinds.StructuredPostal.POBOX,
CommonDataKinds.StructuredPostal.STREET,
CommonDataKinds.StructuredPostal.NEIGHBORHOOD,
CommonDataKinds.StructuredPostal.TYPE,
CommonDataKinds.StructuredPostal.LABEL
)
Expand All @@ -371,14 +378,22 @@ class ContactsHelper(val context: Context) {
context.queryCursor(uri, projection, selection, selectionArgs, showErrors = true) { cursor ->
val id = cursor.getIntValue(Data.RAW_CONTACT_ID)
val address = cursor.getStringValue(CommonDataKinds.StructuredPostal.FORMATTED_ADDRESS) ?: return@queryCursor
val country = cursor.getStringValue(CommonDataKinds.StructuredPostal.COUNTRY) ?: ""
val region = cursor.getStringValue(CommonDataKinds.StructuredPostal.REGION) ?: ""
val city = cursor.getStringValue(CommonDataKinds.StructuredPostal.CITY) ?: ""
val postcode = cursor.getStringValue(CommonDataKinds.StructuredPostal.POSTCODE) ?: ""
val pobox = cursor.getStringValue(CommonDataKinds.StructuredPostal.POBOX) ?: ""
val street = cursor.getStringValue(CommonDataKinds.StructuredPostal.STREET) ?: ""
val neighborhood = cursor.getStringValue(CommonDataKinds.StructuredPostal.NEIGHBORHOOD) ?: ""
val type = cursor.getIntValue(CommonDataKinds.StructuredPostal.TYPE)
val label = cursor.getStringValue(CommonDataKinds.StructuredPostal.LABEL) ?: ""

if (addresses[id] == null) {
addresses.put(id, ArrayList())
}

addresses[id]!!.add(Address(address, type, label))
addresses[id]!!.add(Address(address, type, label, country, region, city, postcode, pobox, street,
neighborhood))
}

return addresses
Expand Down Expand Up @@ -1006,6 +1021,13 @@ class ContactsHelper(val context: Context) {
withValue(Data.RAW_CONTACT_ID, contact.id)
withValue(Data.MIMETYPE, CommonDataKinds.StructuredPostal.CONTENT_ITEM_TYPE)
withValue(CommonDataKinds.StructuredPostal.FORMATTED_ADDRESS, it.value)
withValue(CommonDataKinds.StructuredPostal.COUNTRY, it.country)
withValue(CommonDataKinds.StructuredPostal.REGION, it.region)
withValue(CommonDataKinds.StructuredPostal.CITY, it.city)
withValue(CommonDataKinds.StructuredPostal.POSTCODE, it.postcode)
withValue(CommonDataKinds.StructuredPostal.POBOX, it.pobox)
withValue(CommonDataKinds.StructuredPostal.STREET, it.street)
withValue(CommonDataKinds.StructuredPostal.NEIGHBORHOOD, it.neighborhood)
withValue(CommonDataKinds.StructuredPostal.TYPE, it.type)
withValue(CommonDataKinds.StructuredPostal.LABEL, it.label)
operations.add(build())
Expand Down Expand Up @@ -1300,6 +1322,13 @@ class ContactsHelper(val context: Context) {
withValueBackReference(Data.RAW_CONTACT_ID, 0)
withValue(Data.MIMETYPE, CommonDataKinds.StructuredPostal.CONTENT_ITEM_TYPE)
withValue(CommonDataKinds.StructuredPostal.FORMATTED_ADDRESS, it.value)
withValue(CommonDataKinds.StructuredPostal.COUNTRY, it.country)
withValue(CommonDataKinds.StructuredPostal.REGION, it.region)
withValue(CommonDataKinds.StructuredPostal.CITY, it.city)
withValue(CommonDataKinds.StructuredPostal.POSTCODE, it.postcode)
withValue(CommonDataKinds.StructuredPostal.POBOX, it.pobox)
withValue(CommonDataKinds.StructuredPostal.STREET, it.street)
withValue(CommonDataKinds.StructuredPostal.NEIGHBORHOOD, it.neighborhood)
withValue(CommonDataKinds.StructuredPostal.TYPE, it.type)
withValue(CommonDataKinds.StructuredPostal.LABEL, it.label)
operations.add(build())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,19 @@ class VcfExporter {

contact.addresses.forEach {
val address = Address()
address.streetAddress = it.value
if (listOf(it.country, it.region, it.city, it.postcode, it.pobox, it.street, it.neighborhood)
.map{it.isNullOrEmpty()}
.reduce{a, b -> a || b}) {
address.country = it.country
address.region = it.region
address.locality = it.city
address.postalCode = it.postcode
address.poBox = it.pobox
address.streetAddress = it.street
address.extendedAddress = it.neighborhood
} else {
address.streetAddress = it.value
}
address.parameters.addType(getAddressTypeLabel(it.type, it.label))
card.addAddress(address)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,15 @@ package org.fossify.commons.models.contacts
import kotlinx.serialization.Serializable

@Serializable
data class Address(var value: String, var type: Int, var label: String)
data class Address(
var value: String,
var type: Int,
var label: String,
var country: String,
var region: String,
var city: String,
var postcode: String,
var pobox: String,
var street: String,
var neighborhood: String,
)
Loading