Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for structured address representations (new) #32

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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 @@ -535,6 +535,7 @@ open class BaseConfig(val context: Context) {
SHOW_CONTACT_FIELDS,
SHOW_FIRST_NAME_FIELD or SHOW_SURNAME_FIELD or SHOW_PHONE_NUMBERS_FIELD or SHOW_EMAILS_FIELD or
SHOW_ADDRESSES_FIELD or SHOW_EVENTS_FIELD or SHOW_NOTES_FIELD or SHOW_GROUPS_FIELD or SHOW_CONTACT_SOURCE_FIELD
or SHOW_STRUCTURED_ADDRESSES_FIELD
)
set(showContactFields) = prefs.edit().putInt(SHOW_CONTACT_FIELDS, showContactFields).apply()
var showDialpadButton: Boolean
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -602,6 +602,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 @@ -1009,6 +1024,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 @@ -1303,6 +1325,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
@@ -1,6 +1,7 @@
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