From 51aecba9a00cf8b518ffec98b076c93e986a5e41 Mon Sep 17 00:00:00 2001 From: Tom Hacohen Date: Tue, 25 Apr 2017 17:20:34 +0100 Subject: [PATCH] LocalAddressBook: Add a way to get address book by UID. --- .../syncadapter/resource/LocalAddressBook.java | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/app/src/main/java/com/etesync/syncadapter/resource/LocalAddressBook.java b/app/src/main/java/com/etesync/syncadapter/resource/LocalAddressBook.java index 60adac5a..fd3498b8 100644 --- a/app/src/main/java/com/etesync/syncadapter/resource/LocalAddressBook.java +++ b/app/src/main/java/com/etesync/syncadapter/resource/LocalAddressBook.java @@ -84,6 +84,18 @@ public class LocalAddressBook extends AndroidAddressBook implements LocalCollect return result.toArray(new LocalAddressBook[result.size()]); } + public static LocalAddressBook findByUid(@NonNull Context context, @NonNull ContentProviderClient provider, @Nullable Account mainAccount, String uid) throws ContactsStorageException { + AccountManager accountManager = AccountManager.get(context); + + for (Account account : accountManager.getAccountsByType(App.getAddressBookAccountType())) { + LocalAddressBook addressBook = new LocalAddressBook(context, account, provider); + if (addressBook.getURL().equals(uid) && (mainAccount == null || addressBook.getMainAccount().equals(mainAccount))) + return addressBook; + } + + return null; + } + public static LocalAddressBook create(@NonNull Context context, @NonNull ContentProviderClient provider, @NonNull Account mainAccount, @NonNull JournalEntity journalEntity) throws ContactsStorageException { CollectionInfo info = journalEntity.getInfo(); AccountManager accountManager = AccountManager.get(context);