From 10537f343e995dd3936fb358679498eae5005806 Mon Sep 17 00:00:00 2001 From: cardzap-ewan <97097403+cardzap-ewan@users.noreply.github.com> Date: Tue, 6 Dec 2022 08:51:13 +0000 Subject: [PATCH 1/4] Added LOGO and GEO elements --- lib/contact.dart | 11 ++++++++++- lib/vcard.dart | 22 ++++++++++++++++++++++ 2 files changed, 32 insertions(+), 1 deletion(-) diff --git a/lib/contact.dart b/lib/contact.dart index 03ad4c8b..a967a9f0 100644 --- a/lib/contact.dart +++ b/lib/contact.dart @@ -78,6 +78,9 @@ class Contact { /// The full-resolution contact picture. Uint8List? photo; + /// The Logo element + Uint8List? logo; + /// Returns the full-resolution photo if available, the thumbnail otherwise. Uint8List? get photoOrThumbnail => photo ?? thumbnail; @@ -134,6 +137,7 @@ class Contact { this.displayName = '', this.thumbnail, this.photo, + this.logo, this.isStarred = false, Name? name, List? phones, @@ -163,6 +167,7 @@ class Contact { displayName: (json['displayName'] as String?) ?? '', thumbnail: json['thumbnail'] as Uint8List?, photo: json['photo'] as Uint8List?, + logo: json['logo'] as Uint8List?, isStarred: (json['isStarred'] as bool?) ?? false, name: Name.fromJson(Map.from(json['name'] ?? {})), phones: ((json['phones'] as List?) ?? []) @@ -200,12 +205,14 @@ class Contact { Map toJson({ bool withThumbnail = true, bool withPhoto = true, + bool withLogo = true, }) => Map.from({ 'id': id, 'displayName': displayName, 'thumbnail': withThumbnail ? thumbnail : null, 'photo': withPhoto ? photo : null, + 'logo': withLogo ? logo : null, 'isStarred': isStarred, 'name': name.toJson(), 'phones': phones.map((x) => x.toJson()).toList(), @@ -226,6 +233,7 @@ class Contact { displayName.hashCode ^ thumbnail.hashCode ^ photo.hashCode ^ + logo.hashCode ^ isStarred.hashCode ^ name.hashCode ^ _listHashCode(phones) ^ @@ -244,6 +252,7 @@ class Contact { o.displayName == displayName && o.thumbnail == thumbnail && o.photo == photo && + o.logo == logo && o.isStarred == isStarred && o.name == name && _listEqual(o.phones, phones) && @@ -258,7 +267,7 @@ class Contact { @override String toString() => 'Contact(id=$id, displayName=$displayName, thumbnail=$thumbnail, ' - 'photo=$photo, isStarred=$isStarred, name=$name, phones=$phones, ' + 'photo=$photo, logo=$logo, isStarred=$isStarred, name=$name, phones=$phones, ' 'emails=$emails, addresses=$addresses, organizations=$organizations, ' 'websites=$websites, socialMedias=$socialMedias, events=$events, ' 'notes=$notes, accounts=$accounts, groups=$groups)'; diff --git a/lib/vcard.dart b/lib/vcard.dart index 67e127e4..668bb5cf 100644 --- a/lib/vcard.dart +++ b/lib/vcard.dart @@ -116,6 +116,28 @@ class VCardParser { // Pass. } break; + case 'LOGO': + // The content can be base64-encoded or a URL. Try to decode it, and + // ignore the line if it fails. + try { + contact.logo = base64.decode(decode(content)); + } on FormatException { + // Pass. + } + break; + case 'GEO': + if (content.isNotEmpty && content.contains(';')) { + final split = content.split(';'); + try { + contact.geo = [ + double.parse(split[0]), + double.parse(split[1]) + ]; + } on FormatException { + //pass + } + } + break; case 'N': // Format is N:;;;; final parts = content.split(';'); From 181e2899c97d8d5467c46a4095b746157b44e041 Mon Sep 17 00:00:00 2001 From: cardzap-ewan <97097403+cardzap-ewan@users.noreply.github.com> Date: Tue, 6 Dec 2022 08:51:51 +0000 Subject: [PATCH 2/4] Revert "Added LOGO and GEO elements" This reverts commit 10537f343e995dd3936fb358679498eae5005806. --- lib/contact.dart | 11 +---------- lib/vcard.dart | 22 ---------------------- 2 files changed, 1 insertion(+), 32 deletions(-) diff --git a/lib/contact.dart b/lib/contact.dart index a967a9f0..03ad4c8b 100644 --- a/lib/contact.dart +++ b/lib/contact.dart @@ -78,9 +78,6 @@ class Contact { /// The full-resolution contact picture. Uint8List? photo; - /// The Logo element - Uint8List? logo; - /// Returns the full-resolution photo if available, the thumbnail otherwise. Uint8List? get photoOrThumbnail => photo ?? thumbnail; @@ -137,7 +134,6 @@ class Contact { this.displayName = '', this.thumbnail, this.photo, - this.logo, this.isStarred = false, Name? name, List? phones, @@ -167,7 +163,6 @@ class Contact { displayName: (json['displayName'] as String?) ?? '', thumbnail: json['thumbnail'] as Uint8List?, photo: json['photo'] as Uint8List?, - logo: json['logo'] as Uint8List?, isStarred: (json['isStarred'] as bool?) ?? false, name: Name.fromJson(Map.from(json['name'] ?? {})), phones: ((json['phones'] as List?) ?? []) @@ -205,14 +200,12 @@ class Contact { Map toJson({ bool withThumbnail = true, bool withPhoto = true, - bool withLogo = true, }) => Map.from({ 'id': id, 'displayName': displayName, 'thumbnail': withThumbnail ? thumbnail : null, 'photo': withPhoto ? photo : null, - 'logo': withLogo ? logo : null, 'isStarred': isStarred, 'name': name.toJson(), 'phones': phones.map((x) => x.toJson()).toList(), @@ -233,7 +226,6 @@ class Contact { displayName.hashCode ^ thumbnail.hashCode ^ photo.hashCode ^ - logo.hashCode ^ isStarred.hashCode ^ name.hashCode ^ _listHashCode(phones) ^ @@ -252,7 +244,6 @@ class Contact { o.displayName == displayName && o.thumbnail == thumbnail && o.photo == photo && - o.logo == logo && o.isStarred == isStarred && o.name == name && _listEqual(o.phones, phones) && @@ -267,7 +258,7 @@ class Contact { @override String toString() => 'Contact(id=$id, displayName=$displayName, thumbnail=$thumbnail, ' - 'photo=$photo, logo=$logo, isStarred=$isStarred, name=$name, phones=$phones, ' + 'photo=$photo, isStarred=$isStarred, name=$name, phones=$phones, ' 'emails=$emails, addresses=$addresses, organizations=$organizations, ' 'websites=$websites, socialMedias=$socialMedias, events=$events, ' 'notes=$notes, accounts=$accounts, groups=$groups)'; diff --git a/lib/vcard.dart b/lib/vcard.dart index 668bb5cf..67e127e4 100644 --- a/lib/vcard.dart +++ b/lib/vcard.dart @@ -116,28 +116,6 @@ class VCardParser { // Pass. } break; - case 'LOGO': - // The content can be base64-encoded or a URL. Try to decode it, and - // ignore the line if it fails. - try { - contact.logo = base64.decode(decode(content)); - } on FormatException { - // Pass. - } - break; - case 'GEO': - if (content.isNotEmpty && content.contains(';')) { - final split = content.split(';'); - try { - contact.geo = [ - double.parse(split[0]), - double.parse(split[1]) - ]; - } on FormatException { - //pass - } - } - break; case 'N': // Format is N:;;;; final parts = content.split(';'); From 8a98dd0a62a7902251e81dcb3a856ae06c6b0384 Mon Sep 17 00:00:00 2001 From: cardzap-ewan <97097403+cardzap-ewan@users.noreply.github.com> Date: Tue, 6 Dec 2022 08:52:25 +0000 Subject: [PATCH 3/4] Revert "Revert "Added LOGO and GEO elements"" This reverts commit 181e2899c97d8d5467c46a4095b746157b44e041. --- lib/contact.dart | 11 ++++++++++- lib/vcard.dart | 22 ++++++++++++++++++++++ 2 files changed, 32 insertions(+), 1 deletion(-) diff --git a/lib/contact.dart b/lib/contact.dart index 03ad4c8b..a967a9f0 100644 --- a/lib/contact.dart +++ b/lib/contact.dart @@ -78,6 +78,9 @@ class Contact { /// The full-resolution contact picture. Uint8List? photo; + /// The Logo element + Uint8List? logo; + /// Returns the full-resolution photo if available, the thumbnail otherwise. Uint8List? get photoOrThumbnail => photo ?? thumbnail; @@ -134,6 +137,7 @@ class Contact { this.displayName = '', this.thumbnail, this.photo, + this.logo, this.isStarred = false, Name? name, List? phones, @@ -163,6 +167,7 @@ class Contact { displayName: (json['displayName'] as String?) ?? '', thumbnail: json['thumbnail'] as Uint8List?, photo: json['photo'] as Uint8List?, + logo: json['logo'] as Uint8List?, isStarred: (json['isStarred'] as bool?) ?? false, name: Name.fromJson(Map.from(json['name'] ?? {})), phones: ((json['phones'] as List?) ?? []) @@ -200,12 +205,14 @@ class Contact { Map toJson({ bool withThumbnail = true, bool withPhoto = true, + bool withLogo = true, }) => Map.from({ 'id': id, 'displayName': displayName, 'thumbnail': withThumbnail ? thumbnail : null, 'photo': withPhoto ? photo : null, + 'logo': withLogo ? logo : null, 'isStarred': isStarred, 'name': name.toJson(), 'phones': phones.map((x) => x.toJson()).toList(), @@ -226,6 +233,7 @@ class Contact { displayName.hashCode ^ thumbnail.hashCode ^ photo.hashCode ^ + logo.hashCode ^ isStarred.hashCode ^ name.hashCode ^ _listHashCode(phones) ^ @@ -244,6 +252,7 @@ class Contact { o.displayName == displayName && o.thumbnail == thumbnail && o.photo == photo && + o.logo == logo && o.isStarred == isStarred && o.name == name && _listEqual(o.phones, phones) && @@ -258,7 +267,7 @@ class Contact { @override String toString() => 'Contact(id=$id, displayName=$displayName, thumbnail=$thumbnail, ' - 'photo=$photo, isStarred=$isStarred, name=$name, phones=$phones, ' + 'photo=$photo, logo=$logo, isStarred=$isStarred, name=$name, phones=$phones, ' 'emails=$emails, addresses=$addresses, organizations=$organizations, ' 'websites=$websites, socialMedias=$socialMedias, events=$events, ' 'notes=$notes, accounts=$accounts, groups=$groups)'; diff --git a/lib/vcard.dart b/lib/vcard.dart index 67e127e4..668bb5cf 100644 --- a/lib/vcard.dart +++ b/lib/vcard.dart @@ -116,6 +116,28 @@ class VCardParser { // Pass. } break; + case 'LOGO': + // The content can be base64-encoded or a URL. Try to decode it, and + // ignore the line if it fails. + try { + contact.logo = base64.decode(decode(content)); + } on FormatException { + // Pass. + } + break; + case 'GEO': + if (content.isNotEmpty && content.contains(';')) { + final split = content.split(';'); + try { + contact.geo = [ + double.parse(split[0]), + double.parse(split[1]) + ]; + } on FormatException { + //pass + } + } + break; case 'N': // Format is N:;;;; final parts = content.split(';'); From 0b2176ef08cf71681b295b2fb8d26a2bd3cf63ac Mon Sep 17 00:00:00 2001 From: cardzap-ewan <97097403+cardzap-ewan@users.noreply.github.com> Date: Tue, 6 Dec 2022 11:02:21 +0000 Subject: [PATCH 4/4] Stupid bug fix --- lib/contact.dart | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/lib/contact.dart b/lib/contact.dart index a967a9f0..651c9d6b 100644 --- a/lib/contact.dart +++ b/lib/contact.dart @@ -84,6 +84,9 @@ class Contact { /// Returns the full-resolution photo if available, the thumbnail otherwise. Uint8List? get photoOrThumbnail => photo ?? thumbnail; + /// The GEO element + List? geo; + /// Whether the contact is starred (Android only). bool isStarred; @@ -295,6 +298,7 @@ class Contact { /// "-//Apple Inc.//Mac OS X 10.15.7//EN" String toVCard({ bool withPhoto = true, + bool withLogo = true, String? productId, bool includeDate = false, }) { @@ -332,6 +336,17 @@ class Contact { v4 ? 'PHOTO:data:image/jpeg;base64,' : 'PHOTO;ENCODING=b;TYPE=JPEG:'; lines.add(prefix + encoding); } + if (withLogo && logo != null) { + final encoding = vCardEncode(base64.encode(logo!)); + final prefix = + v4 ? 'LOGO:data:image/jpeg;base64,' : 'LOGO;ENCODING=b;TYPE=JPEG:'; + lines.add(prefix + encoding); + } + if (geo != null && geo!.length == 2) { + final encoding = vCardEncode( + '${geo![0].toStringAsFixed(5)};${geo![1].toStringAsFixed(5)}'); + lines.add('GEO:$encoding'); + } lines.addAll([ name.toVCard(), phones.map((x) => x.toVCard()).expand((x) => x),