use of org.kde.kdeconnect.Helpers.ContactsHelper.VCardBuilder in project kdeconnect-android by KDE.
the class ContactsPlugin method handleRequestVCardsByUIDs.
private boolean handleRequestVCardsByUIDs(NetworkPacket np) {
if (!np.has("uids")) {
Log.e("ContactsPlugin", "handleRequestNamesByUIDs received a malformed packet with no uids key");
return false;
}
List<String> uIDsAsStrings = np.getStringList("uids");
// Convert to Collection<uIDs> to call getVCardsForContactIDs
Set<uID> uIDs = new HashSet<>(uIDsAsStrings.size());
for (String uID : uIDsAsStrings) {
uIDs.add(new uID(uID));
}
Map<uID, VCardBuilder> uIDsToVCards = ContactsHelper.getVCardsForContactIDs(context, uIDs);
// ContactsHelper.getVCardsForContactIDs(..) is allowed to reply without
// some of the requested uIDs if they were not in the database, so update our list
uIDsAsStrings = new ArrayList<>(uIDsToVCards.size());
NetworkPacket reply = new NetworkPacket(PACKET_TYPE_CONTACTS_RESPONSE_VCARDS);
// Add the vcards to the packet
for (uID uID : uIDsToVCards.keySet()) {
VCardBuilder vcard = uIDsToVCards.get(uID);
try {
vcard = this.addVCardMetadata(vcard, uID);
// Store this as a valid uID
uIDsAsStrings.add(uID.toString());
// Add the uid -> vcard pairing to the packet
reply.set(uID.toString(), vcard.toString());
} catch (ContactsHelper.ContactNotFoundException e) {
e.printStackTrace();
}
}
// Add the valid uIDs to the packet
reply.set("uids", uIDsAsStrings);
device.sendPacket(reply);
return true;
}
Aggregations