Add: vCard Version selection for export #344#439
Add: vCard Version selection for export #344#439jguegel wants to merge 3 commits intoFossifyOrg:mainfrom
Conversation
|
note:
please be patient, just trying to help the community, if too much is wrong just close the PR |
| addPhoneNumbers(card, contact) | ||
| addEmails(card, contact) | ||
| addEvents(card, contact) | ||
| addAdress(card, contact) |
| .date(dateTime.dayOfMonth) | ||
| .build() | ||
|
|
||
| if (event.type == Event.TYPE_BIRTHDAY) { |
There was a problem hiding this comment.
those are too many levels of nesting for the linter.
Maybe separate into several functions. Also store results which you want to use several times and try to use early-returns (checking for the negative logic and return instead of nesting positive logics)
here some example code:
private fun addEvents(card: VCard, contact: Contact) {
contact.events
.filter { it.type == Event.TYPE_ANNIVERSARY || it.type == Event.TYPE_BIRTHDAY }
.forEach { event -> addEventToCard(card, event) }
}
private fun addEventToCard(card: VCard, event: org.fossify.commons.models.contacts.Event) {
val dateTime = event.value.getDateTimeFromDateString(false)
val isBirthday = event.type == Event.TYPE_BIRTHDAY
if (event.value.startsWith("--")) {
val partial = PartialDate.builder()
.month(dateTime.monthOfYear)
.date(dateTime.dayOfMonth)
.build()
if (isBirthday) card.birthdays.add(Birthday(partial))
else card.anniversaries.add(Anniversary(partial))
return
}
val date = LocalDate.of(dateTime.year, dateTime.monthOfYear, dateTime.dayOfMonth)
if (isBirthday) card.birthdays.add(Birthday(date))
else card.anniversaries.add(Anniversary(date))
}
| .joinToString(separator = " ") | ||
| } | ||
|
|
||
| private fun addPhoneNumbers(card: VCard, contact: Contact) { |
There was a problem hiding this comment.
you have added 12 new functions to this class which seems to be over the linters threshold. Such big classes are hard to read and maintain and might be a first pointer to overboarding complexity.
Anyhow, to get this fixed here now, you might want to bundle some functions into new objects or even better into helper classes. Here some ideas:
private object CardPropertyAdder {
fun addAllProperties(context: Context, card: VCard, contact: Contact) {
addPhoneNumbers(card, contact)
addEmails(card, contact)
addEvents(card, contact)
addAddress(card, contact)
addIMs(card, contact)
addNotes(card, contact)
addOrganization(card, contact)
addWebsites(card, contact)
addPhoto(context, card, contact)
addGroups(card, contact)
}
private fun addPhoneNumbers(card: VCard, contact: Contact) {
...
}
private fun addEmails(card: VCard, contact: Contact) {
...
}
private fun addEvents(card: VCard, contact: Contact) {
...
}
private fun addEventToCard(card: VCard, event: org.fossify.commons.models.contacts.Event) {
...
}
private fun addEventProperty(card: VCard, eventType: Int, partial: PartialDate) {
...
}
private fun addEventProperty(card: VCard, eventType: Int, date: LocalDate) {
...
}
private fun addPhoto(context: Context, card: VCard, contact: Contact) {
...
}
private fun addIMs(card: VCard, contact: Contact) {
...
}
private fun addNotes(card: VCard, contact: Contact) {
...
}
private fun addOrganization(card: VCard, contact: Contact) {
...
}
private fun addWebsites(card: VCard, contact: Contact) {
...
}
private fun addAddress(card: VCard, contact: Contact) {
...
}
private fun addGroups(card: VCard, contact: Contact) {
...
}
}
and
private object TypeLabelMapper {
fun getPhoneNumberTypeLabel(type: Int, label: String) = when (type) {
...
}
fun getEmailTypeLabel(type: Int, label: String) = when (type) {
...
}
fun getAddressTypeLabel(type: Int, label: String) = when (type) {
...
}
fun getPreferredType(value: Int) = "$PREF=$value"
}
Type of change(s)
What changed and why
Tests performed
Before & after preview
Closes the following issue(s)
Checklist
CHANGELOG.md(if applicable).