summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJay Shrauner <shrauner@google.com>2015-01-09 11:41:14 -0800
committerJay Shrauner <shrauner@google.com>2015-01-09 13:38:17 -0800
commit67e83223e954ed54898daa5e32400dbff6d3831a (patch)
tree440f6f6c6cb09b9a18c509a8bf713572b24ec6a7
parent3a9e3b15ba184232412b2df6456589a42cab9745 (diff)
downloadpackages_apps_Contacts-67e83223e954ed54898daa5e32400dbff6d3831a.tar.gz
packages_apps_Contacts-67e83223e954ed54898daa5e32400dbff6d3831a.tar.bz2
packages_apps_Contacts-67e83223e954ed54898daa5e32400dbff6d3831a.zip
Local account handling cleanup
Clean up null account handling and update local account detection to allow for a non-null account to represent a local account. Bug: 18959158 Change-Id: I0d5f7acb7d9a8d1ba7b6d3a4e0b6584e3646934a
-rw-r--r--src/com/android/contacts/activities/AttachPhotoActivity.java6
-rw-r--r--src/com/android/contacts/editor/ContactEditorFragment.java22
-rw-r--r--src/com/android/contacts/editor/ContactEditorUtils.java7
3 files changed, 10 insertions, 25 deletions
diff --git a/src/com/android/contacts/activities/AttachPhotoActivity.java b/src/com/android/contacts/activities/AttachPhotoActivity.java
index 3196f875b..ad64d8d8e 100644
--- a/src/com/android/contacts/activities/AttachPhotoActivity.java
+++ b/src/com/android/contacts/activities/AttachPhotoActivity.java
@@ -321,11 +321,7 @@ public class AttachPhotoActivity extends ContactsActivity {
// Otherwise, there should be a default account. Then either create a local contact
// (if default account is null) or create a contact with the specified account.
AccountWithDataSet defaultAccount = editorUtils.getDefaultAccount();
- if (defaultAccount == null) {
- createNewRawContact(null);
- } else {
- createNewRawContact(defaultAccount);
- }
+ createNewRawContact(defaultAccount);
}
}
diff --git a/src/com/android/contacts/editor/ContactEditorFragment.java b/src/com/android/contacts/editor/ContactEditorFragment.java
index 664b8c715..e98ba7d58 100644
--- a/src/com/android/contacts/editor/ContactEditorFragment.java
+++ b/src/com/android/contacts/editor/ContactEditorFragment.java
@@ -682,11 +682,7 @@ public class ContactEditorFragment extends Fragment implements
// Otherwise, there should be a default account. Then either create a local contact
// (if default account is null) or create a contact with the specified account.
AccountWithDataSet defaultAccount = mEditorUtils.getDefaultAccount();
- if (defaultAccount == null) {
- createContact(null);
- } else {
- createContact(defaultAccount);
- }
+ createContact(defaultAccount);
}
}
@@ -715,9 +711,7 @@ public class ContactEditorFragment extends Fragment implements
*/
private void createContact(AccountWithDataSet account) {
final AccountTypeManager accountTypes = AccountTypeManager.getInstance(mContext);
- final AccountType accountType =
- accountTypes.getAccountType(account != null ? account.type : null,
- account != null ? account.dataSet : null);
+ final AccountType accountType = accountTypes.getAccountTypeForAccount(account);
if (accountType.getCreateContactActivityClassName() != null) {
if (mListener != null) {
@@ -740,10 +734,8 @@ public class ContactEditorFragment extends Fragment implements
RawContactDelta oldState, AccountWithDataSet oldAccount,
AccountWithDataSet newAccount) {
AccountTypeManager accountTypes = AccountTypeManager.getInstance(mContext);
- AccountType oldAccountType = accountTypes.getAccountType(
- oldAccount.type, oldAccount.dataSet);
- AccountType newAccountType = accountTypes.getAccountType(
- newAccount.type, newAccount.dataSet);
+ AccountType oldAccountType = accountTypes.getAccountTypeForAccount(oldAccount);
+ AccountType newAccountType = accountTypes.getAccountTypeForAccount(newAccount);
if (newAccountType.getCreateContactActivityClassName() != null) {
Log.w(TAG, "external activity called in rebind situation");
@@ -772,11 +764,7 @@ public class ContactEditorFragment extends Fragment implements
mStatus = Status.EDITING;
final RawContact rawContact = new RawContact();
- if (newAccount != null) {
- rawContact.setAccount(newAccount);
- } else {
- rawContact.setAccountToLocal();
- }
+ rawContact.setAccount(newAccount);
final ValuesDelta valuesDelta = ValuesDelta.fromAfter(rawContact.getValues());
final RawContactDelta insert = new RawContactDelta(valuesDelta);
diff --git a/src/com/android/contacts/editor/ContactEditorUtils.java b/src/com/android/contacts/editor/ContactEditorUtils.java
index b132217fb..105b88552 100644
--- a/src/com/android/contacts/editor/ContactEditorUtils.java
+++ b/src/com/android/contacts/editor/ContactEditorUtils.java
@@ -119,7 +119,7 @@ public class ContactEditorUtils {
final SharedPreferences.Editor editor = mPrefs.edit()
.putBoolean(KEY_ANYTHING_SAVED, true);
- if (defaultAccount == null) {
+ if (defaultAccount == null || defaultAccount.isLocalAccount()) {
// If the default is "local only", there should be no writable accounts.
// This should always be the case with our spec, but because we load the account list
// asynchronously using a worker thread, it is possible that there are accounts at this
@@ -165,7 +165,7 @@ public class ContactEditorUtils {
*/
@VisibleForTesting
boolean isValidAccount(AccountWithDataSet account) {
- if (account == null) {
+ if (account == null || account.isLocalAccount()) {
return true; // It's "local only" account, which is valid.
}
return getWritableAccounts().contains(account);
@@ -227,7 +227,8 @@ public class ContactEditorUtils {
// ("local" account) while there are multiple accounts, then show the notification dialog.
// This shouldn't ever happen, but this should allow the user can get back into a normal
// state after they respond to the notification.
- if (defaultAccount == null && currentWritableAccounts.size() > 0) {
+ if ((defaultAccount == null || defaultAccount.isLocalAccount())
+ && currentWritableAccounts.size() > 0) {
Log.e(TAG, "Preferences file in an inconsistent state, request that the default account"
+ " and current writable accounts be saved again");
return true;