Merge pull request #953 from Mylloon/fix/GH-952

Use PREF for the preference rather than the number type
This commit is contained in:
Tibor Kaputa 2023-03-07 19:17:14 +01:00 committed by GitHub
commit 85fa2fc5ac
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 18 additions and 2 deletions

View File

@ -73,6 +73,9 @@ class VcfExporter {
contact.phoneNumbers.forEach {
val phoneNumber = Telephone(it.value)
phoneNumber.parameters.addType(getPhoneNumberTypeLabel(it.type, it.label))
if (it.isPrimary) {
phoneNumber.parameters.addType(getPreferredType(1))
}
card.addTelephoneNumber(phoneNumber)
}
@ -201,4 +204,6 @@ class VcfExporter {
StructuredPostal.TYPE_OTHER -> OTHER
else -> label
}
private fun getPreferredType(value: Int) = "$PREF=$value"
}

View File

@ -64,8 +64,9 @@ class VcfImporter(val activity: SimpleActivity) {
} else {
""
}
val preferred = getPreferredValue(it.types.lastOrNull()?.value) == 1
phoneNumbers.add(PhoneNumber(number, type, label, number.normalizePhoneNumber()))
phoneNumbers.add(PhoneNumber(number, type, label, number.normalizePhoneNumber(), preferred))
}
val emails = ArrayList<Email>()
@ -267,7 +268,7 @@ class VcfImporter(val activity: SimpleActivity) {
Phone.TYPE_WORK
}
}
PREF, MAIN -> Phone.TYPE_MAIN
MAIN -> Phone.TYPE_MAIN
WORK_FAX -> Phone.TYPE_FAX_WORK
HOME_FAX -> Phone.TYPE_FAX_HOME
FAX -> Phone.TYPE_FAX_WORK
@ -308,4 +309,14 @@ class VcfImporter(val activity: SimpleActivity) {
return activity.getCachePhotoUri(file).toString()
}
private fun getPreferredValue(type: String?): Int {
if (type != null) {
if (type.startsWith("$PREF=".lowercase())) {
return type.split("=")[1].toInt()
}
}
return -1
}
}