diff options
author | Marcus Hagerott <mhagerott@google.com> | 2016-12-15 09:30:17 -0800 |
---|---|---|
committer | Marcus Hagerott <mhagerott@google.com> | 2016-12-16 16:43:07 -0800 |
commit | 9a679e742e9e738d659f6f8a566c1db7a252f77f (patch) | |
tree | 2f1ab14e65635fd41d7b2a2357210420941ef495 /src/com/android/contacts/model | |
parent | 75895e73379aa26a3d4135c772af4ecb8a79b4c9 (diff) | |
download | Contacts-9a679e742e9e738d659f6f8a566c1db7a252f77f.tar.gz |
Use loader for accounts in editor account chooser
The list of accounts on the dialog now updates when they are added or
removed.
Test: manually verify that list of accounts updates when adding or
removing accounts
Bug 33627801
Change-Id: I3c92c80f0a93a865050b115b5b3d931eea80b2af
Diffstat (limited to 'src/com/android/contacts/model')
-rw-r--r-- | src/com/android/contacts/model/AccountTypeManager.java | 2 | ||||
-rw-r--r-- | src/com/android/contacts/model/account/AccountsLoader.java | 58 |
2 files changed, 59 insertions, 1 deletions
diff --git a/src/com/android/contacts/model/AccountTypeManager.java b/src/com/android/contacts/model/AccountTypeManager.java index 93ddd04ac..961fa6377 100644 --- a/src/com/android/contacts/model/AccountTypeManager.java +++ b/src/com/android/contacts/model/AccountTypeManager.java @@ -429,7 +429,7 @@ class AccountTypeManagerImpl extends AccountTypeManager reloadAccountTypes(); } - /* This notification will arrive on the background thread */ + /* This notification will arrive on the UI thread */ public void onAccountsUpdated(Account[] accounts) { onAccountsUpdatedInternal(); } diff --git a/src/com/android/contacts/model/account/AccountsLoader.java b/src/com/android/contacts/model/account/AccountsLoader.java new file mode 100644 index 000000000..78f309b12 --- /dev/null +++ b/src/com/android/contacts/model/account/AccountsLoader.java @@ -0,0 +1,58 @@ +/* + * Copyright (C) 2016 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package com.android.contacts.model.account; + +import android.content.Context; +import android.content.IntentFilter; + +import com.android.contacts.model.AccountTypeManager; +import com.android.contacts.util.concurrent.ListenableFutureLoader; +import com.google.common.base.Objects; +import com.google.common.base.Predicate; +import com.google.common.base.Predicates; +import com.google.common.util.concurrent.ListenableFuture; + +import java.util.List; + +/** + * Loads the accounts from AccountTypeManager + */ +public class AccountsLoader extends ListenableFutureLoader<List<AccountInfo>> { + private final AccountTypeManager mAccountTypeManager; + private final Predicate<AccountInfo> mFilter; + + public AccountsLoader(Context context) { + this(context, Predicates.<AccountInfo>alwaysTrue()); + } + + public AccountsLoader(Context context, Predicate<AccountInfo> filter) { + super(context, new IntentFilter(AccountTypeManager.BROADCAST_ACCOUNTS_CHANGED)); + mAccountTypeManager = AccountTypeManager.getInstance(context); + mFilter = filter; + } + + @Override + protected ListenableFuture<List<AccountInfo>> loadData() { + return mAccountTypeManager.filterAccountsAsync(mFilter); + } + + @Override + protected boolean isSameData(List<AccountInfo> previous, List<AccountInfo> next) { + return Objects.equal(AccountInfo.extractAccounts(previous), + AccountInfo.extractAccounts(next)); + } + +} |