This repository was archived by the owner on Aug 21, 2025. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
Generate QR code with vCard data #76
Merged
Merged
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
4e3fa43
Generate QR code with vCard data
hamorillo d13c25b
Round QR code corners
hamorillo 0b5ded7
Implemented VCard and VCard.Builder classes
hamorillo 006bbc3
Escape vCard fields
hamorillo e82d6d9
Set FN empty and apply N logic
hamorillo File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Binary file modified
BIN
+57.4 KB
(350%)
...r.app.homeUi.presentation.home.share.components.ShareHeaderTest.shareHeader.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
84 changes: 84 additions & 0 deletions
84
homeUi/src/main/kotlin/com/gravatar/app/homeUi/presentation/home/share/model/VCard.kt
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,84 @@ | ||
| package com.gravatar.app.homeUi.presentation.home.share.model | ||
|
|
||
| internal class VCard private constructor( | ||
| val firstName: String? = null, | ||
| val lastName: String? = null, | ||
| val nickname: String? = null, | ||
| val organization: String? = null, | ||
| val title: String? = null, | ||
| val profileUrl: String? = null, | ||
| val note: String? = null, | ||
| val phoneNumber: String? = null, | ||
| val email: String? = null, | ||
| ) { | ||
|
|
||
| override fun toString(): String { | ||
| val contentBuilder = StringBuilder().append("BEGIN:VCARD\n") | ||
| .append("VERSION:3.0\n") | ||
| .append("PRODID:Gravatar Android\n") | ||
|
|
||
| val firstName = firstName.orEmpty() | ||
| val lastName = lastName.orEmpty() | ||
| if (firstName.isNotEmpty() || lastName.isNotEmpty()) { | ||
| contentBuilder.append("N:${lastName.escaped()};${firstName.escaped()};;;\n") | ||
| } else { | ||
| nickname?.takeIf { it.isNotEmpty() }?.let { | ||
| contentBuilder.append("N:;${nickname.escaped()};;;\n") | ||
| } | ||
| } | ||
|
|
||
| // Providing an empty FN as it is required for vCard 3.0. | ||
| contentBuilder.append("FN:\n") | ||
|
|
||
| nickname?.takeIf { it.isNotEmpty() }?.let { | ||
| contentBuilder | ||
| .append("NICKNAME:${it.escaped()}\n") | ||
| } | ||
| organization?.takeIf { it.isNotEmpty() }?.let { contentBuilder.append("ORG:${it.escaped()}\n") } | ||
| title?.takeIf { it.isNotEmpty() }?.let { contentBuilder.append("TITLE:${it.escaped()}\n") } | ||
| profileUrl?.takeIf { it.isNotEmpty() }?.let { contentBuilder.append("URL:${it.escaped()}\n") } | ||
| note?.takeIf { it.isNotEmpty() }?.let { contentBuilder.append("NOTE:${it.escaped()}\n") } | ||
| phoneNumber?.takeIf { it.isNotEmpty() }?.let { contentBuilder.append("TEL;TYPE=cell:${it.escaped()}\n") } | ||
| email?.takeIf { it.isNotEmpty() }?.let { contentBuilder.append("EMAIL:${it.escaped()}\n") } | ||
|
|
||
| contentBuilder.append("END:VCARD") | ||
| return contentBuilder.toString() | ||
| } | ||
|
|
||
| // We've seen issues with newlines in the vCard content causing problems when importing the contact so removing them | ||
| private fun String.escaped() = this.replace("\n", " ") | ||
|
|
||
| class Builder( | ||
| private var firstName: String? = null, | ||
| private var lastName: String? = null, | ||
| private var nickname: String? = null, | ||
| private var organization: String? = null, | ||
| private var title: String? = null, | ||
| private var profileUrl: String? = null, | ||
| private var note: String? = null, | ||
| private var phoneNumber: String? = null, | ||
| private var email: String? = null, | ||
| ) { | ||
| fun firstName(firstName: String?) = apply { this.firstName = firstName } | ||
| fun lastName(lastName: String?) = apply { this.lastName = lastName } | ||
| fun nickname(nickname: String?) = apply { this.nickname = nickname } | ||
| fun organization(organization: String?) = apply { this.organization = organization } | ||
| fun title(title: String?) = apply { this.title = title } | ||
| fun profileUrl(url: String?) = apply { this.profileUrl = url } | ||
| fun note(description: String?) = apply { this.note = description } | ||
| fun phoneNumber(phone: String?) = apply { this.phoneNumber = phone } | ||
| fun email(email: String?) = apply { this.email = email } | ||
|
|
||
| fun build() = VCard( | ||
| firstName = firstName, | ||
| lastName = lastName, | ||
| nickname = nickname, | ||
| organization = organization, | ||
| title = title, | ||
| profileUrl = profileUrl, | ||
| note = note, | ||
| phoneNumber = phoneNumber, | ||
| email = email | ||
| ) | ||
| } | ||
| } |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Changing the default value from false to true for isEmailShared is a breaking change that could unexpectedly expose user email addresses. This should default to false for privacy protection.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is that on purpose? It's ON even with the field empty 🤔
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, I think that's what we agreed in the last call, and it's how the iOS app is working at the moment. However, we can improve this behaviour. We can discuss this with iOS folks.