Skip to content

Commit

Permalink
ref - Refactored photo making for Android contacts
Browse files Browse the repository at this point in the history
---

We've used built-in VisualCard tools to make the image property.

---

Type: ref
Breaking: False
Doc Required: False
Backport Required: False
Part: 1/1
  • Loading branch information
AptiviCEO committed Oct 3, 2024
1 parent d336b28 commit 3475617
Showing 1 changed file with 5 additions and 24 deletions.
29 changes: 5 additions & 24 deletions VisualCard.Extras/Converters/AndroidContactsDb.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
using System.Collections.Generic;
using System.IO;
using System.Text;
using Textify.General;
using VisualCard.Parsers;
using VisualCard.Parts;

Expand Down Expand Up @@ -667,31 +668,11 @@ ORDER BY
// | d15: Encoded photo
// ---> will get converted to VCard line:
// PHOTO;ENCODING=BLOB;JPEG:d15
const string _photoSpecifierWithType = "PHOTO;";
const string _photoSpecifierWithType = "PHOTO;ENCODING=BLOB;TYPE=JPEG:";
const int maxChars = 74;
const int maxCharsFirst = 48;

// Unquote the encoded photo
d15 = d15.Substring(d15.IndexOf("'") + 1);
d15 = d15.Substring(0, d15.IndexOf("'"));

// Construct the photo block
StringBuilder photoBlock = new();
int selectedMax = maxCharsFirst;
int processed = 0;
for (int currCharNum = 0; currCharNum < d15.Length; currCharNum++)
{
photoBlock.Append(d15[currCharNum]);
processed++;
if (processed >= selectedMax)
{
// Append a new line because we reached the maximum limit
selectedMax = maxChars;
processed = 0;
photoBlock.Append("\n ");
}
}
masterContactBuilder.AppendLine($"{_photoSpecifierWithType}ENCODING=BLOB;TYPE=JPEG:{photoBlock}");
d15 = d15.StartsWith("X") ? d15.Substring(1) : d15;
d15 = VcardCommonTools.MakeStringBlock(d15.ReleaseDoubleQuotes(), maxChars - _photoSpecifierWithType.Length);
masterContactBuilder.AppendLine($"{_photoSpecifierWithType}{d15}");
break;
}

Expand Down

0 comments on commit 3475617

Please sign in to comment.