Don't change the default account when saving contacts (E2)
Also address some comments on ag/766424 that were given
after that CL was submitted.
Bug 23667287
Bug 23589603
Change-Id: If2a5aee5c17358278fd3b59ed56b4c5344e5ecf6
diff --git a/src/com/android/contacts/editor/CompactRawContactsEditorView.java b/src/com/android/contacts/editor/CompactRawContactsEditorView.java
index c38fa3e..693b8fd 100644
--- a/src/com/android/contacts/editor/CompactRawContactsEditorView.java
+++ b/src/com/android/contacts/editor/CompactRawContactsEditorView.java
@@ -364,12 +364,12 @@
private void parseRawContactDeltas(RawContactDeltaList rawContactDeltas) {
// Get the raw contact delta for the primary account (the one displayed at the top)
- if (mPrimaryAccount == null || mPrimaryAccount.name == null
- || mReadOnlyDisplayName != null) {
- // Use the first writable contact if this is 1) a phone local contact or 2) an insert,
- // for a read-only contact. For the last case, we can assume the first writable
- // raw contact is the newly created one because inserts have a raw contact delta list
- // of size 1 and read-only contacts have a list of size 2
+ if (mPrimaryAccount == null || TextUtils.isEmpty(mPrimaryAccount.name)
+ || !TextUtils.isEmpty(mReadOnlyDisplayName)) {
+ // Use the first writable contact if this is an insert for a read-only contact.
+ // In this case we can assume the first writable raw contact is the newly created one
+ // because inserts have a raw contact delta list of size 1 and read-only contacts have
+ // a list of size 2.
for (RawContactDelta rawContactDelta : rawContactDeltas) {
if (!rawContactDelta.isVisible()) continue;
final AccountType accountType = rawContactDelta.getAccountType(mAccountTypeManager);
@@ -564,7 +564,7 @@
}
private void addAccountHeader(Pair<String,String> accountInfo) {
- if (accountInfo.first == null) {
+ if (TextUtils.isEmpty(accountInfo.first)) {
// Hide this view so the other text view will be centered vertically
mAccountHeaderName.setVisibility(View.GONE);
} else {
@@ -581,7 +581,7 @@
private void addAccountSelector(Pair<String,String> accountInfo) {
mAccountSelectorContainer.setVisibility(View.VISIBLE);
- if (accountInfo.first == null) {
+ if (TextUtils.isEmpty(accountInfo.first)) {
// Hide this view so the other text view will be centered vertically
mAccountSelectorName.setVisibility(View.GONE);
} else {
diff --git a/src/com/android/contacts/editor/ContactEditorBaseFragment.java b/src/com/android/contacts/editor/ContactEditorBaseFragment.java
index 828754d..4e5fff4 100644
--- a/src/com/android/contacts/editor/ContactEditorBaseFragment.java
+++ b/src/com/android/contacts/editor/ContactEditorBaseFragment.java
@@ -972,9 +972,6 @@
setEnabled(false);
- // Store account as default account, only if this is a new contact
- saveDefaultAccountIfNecessary();
-
if (isInsert(getActivity().getIntent()) && saveMode == SaveMode.COMPACT
&& mListener != null && backPressed) {
// If we're coming back from the fully expanded editor and this is an insert, just
@@ -1137,27 +1134,6 @@
}
}
- /**
- * Saves all writable accounts and the default account, but only for new contacts.
- */
- protected void saveDefaultAccountIfNecessary() {
- // Verify that this is a newly created contact composed of only 1 raw contact
- // and not a user profile
- if (isInsert(mAction) && mState.size() == 1 && !isEditingUserProfile()) {
- // Find the associated account for this contact (retrieve it here because there are
- // multiple paths to creating a contact and this ensures we always have the correct
- // account).
- final RawContactDelta rawContactDelta = mState.get(0);
- String name = rawContactDelta.getAccountName();
- String type = rawContactDelta.getAccountType();
- String dataSet = rawContactDelta.getDataSet();
-
- AccountWithDataSet account = (name == null || type == null) ? null :
- new AccountWithDataSet(name, type, dataSet);
- mEditorUtils.saveDefaultAndAllAccounts(account);
- }
- }
-
//
// Data binding
//