Skip to content

Add: vCard Version selection for export #344#439

Open
jguegel wants to merge 3 commits intoFossifyOrg:mainfrom
jguegel:vcard-export-344
Open

Add: vCard Version selection for export #344#439
jguegel wants to merge 3 commits intoFossifyOrg:mainfrom
jguegel:vcard-export-344

Conversation

@jguegel
Copy link
Contributor

@jguegel jguegel commented Dec 15, 2025

Type of change(s)

  • Bug fix
  • Feature / enhancement
  • Infrastructure / tooling (CI, build, deps, tests)
  • Documentation

What changed and why

  • Added selection for vCard Version, for allowing also sharing contacts with e.g. whatsapp by selecting Version 3.0

Tests performed

  • changed setting and tried exports to different IM

Before & after preview

  • new Setting "vCard Version"
ignoreImageMinify ignoreImageMinify

Closes the following issue(s)

Checklist

  • I read the contribution guidelines.
  • I manually tested my changes on device/emulator (if applicable).
  • I updated the "Unreleased" section in CHANGELOG.md (if applicable).
  • I have self-reviewed my pull request (no typos, formatting errors, etc.).
  • All checks are passing.

@jguegel jguegel requested a review from naveensingh as a code owner December 15, 2025 17:42
@jguegel
Copy link
Contributor Author

jguegel commented Dec 15, 2025

note:
detekt not passing:
VcfExporter.kt:157:17: Function addEvents is nested too deeply. [NestedBlockDepth]
VcfExporter.kt:24:7: Class 'VcfExporter' with '17' functions detected. Defined threshold inside classes is set to '11' [TooManyFunctions]

  • please advise how to "simplify" (i actually only added the getVCardVersion function, but detekt wouldn't let me pass)
  • also likely using string for version not correct, but couldn't make it work with int

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)
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

typo Address

.date(dateTime.dayOfMonth)
.build()

if (event.type == Event.TYPE_BIRTHDAY) {
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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) {
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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"
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Sharing a contact with whatsapp does not work

2 participants