Handle reading loaded Contact data in the base edit fragment
This reduces the number of abstract methods sub classes
must implement and also keeps us from having to duplicate
the logic to set up the new/local/me/existing RawContactData
List (mState) in all sub edit fragments.
The crux of this CL is moving the "bindEditor" methods
into the base fragment.
Also renamed the various bindEditors methods which are
mostly reading fields the loaded Contact and settting up
mState to be "setState" since we it seemed more appropriate
to reserve the name bindEditors for setting up the actual
Views.
Bug 19124091
Change-Id: Ieb4a906ac372faa20694e546caa3bcba8c6b53b4
diff --git a/src/com/android/contacts/editor/CompactContactEditorFragment.java b/src/com/android/contacts/editor/CompactContactEditorFragment.java
index aee1f73..98339a6 100644
--- a/src/com/android/contacts/editor/CompactContactEditorFragment.java
+++ b/src/com/android/contacts/editor/CompactContactEditorFragment.java
@@ -16,13 +16,8 @@
package com.android.contacts.editor;
-import com.google.common.collect.ImmutableList;
-
import com.android.contacts.R;
import com.android.contacts.activities.ContactEditorBaseActivity.ContactEditor;
-import com.android.contacts.common.model.RawContact;
-import com.android.contacts.common.model.account.AccountType;
-import com.android.contacts.common.model.account.AccountWithDataSet;
import android.content.Intent;
import android.net.Uri;
@@ -61,21 +56,11 @@
//
@Override
- protected void bindEditorsForExistingContact(String displayName, boolean isUserProfile,
- ImmutableList<RawContact> rawContacts) {
- }
-
- @Override
- protected void bindEditorsForNewContact(AccountWithDataSet account,
- AccountType accountType) {
- }
-
- @Override
protected void bindEditors() {
}
@Override
- protected void bindGroupMetaData() {
+ protected void setEnabled(boolean enabled) {
}
//
@@ -87,7 +72,7 @@
}
@Override
- public boolean save(int saveMode) {
+ protected boolean doSaveAction(int saveMode) {
onSaveCompleted(/* hadChanges =*/ false, saveMode,
/* saveSucceeded =*/ mLookupUri != null, mLookupUri);
return true;
diff --git a/src/com/android/contacts/editor/ContactEditorBaseFragment.java b/src/com/android/contacts/editor/ContactEditorBaseFragment.java
index 4b7af5b..fcfb86d 100644
--- a/src/com/android/contacts/editor/ContactEditorBaseFragment.java
+++ b/src/com/android/contacts/editor/ContactEditorBaseFragment.java
@@ -29,8 +29,10 @@
import com.android.contacts.common.model.Contact;
import com.android.contacts.common.model.ContactLoader;
import com.android.contacts.common.model.RawContact;
+import com.android.contacts.common.model.RawContactDelta;
import com.android.contacts.common.model.RawContactDeltaList;
import com.android.contacts.common.model.RawContactModifier;
+import com.android.contacts.common.model.ValuesDelta;
import com.android.contacts.common.model.account.AccountType;
import com.android.contacts.common.model.account.AccountWithDataSet;
import com.android.contacts.quickcontact.QuickContactActivity;
@@ -49,12 +51,16 @@
import android.content.Intent;
import android.content.Loader;
import android.database.Cursor;
-import android.graphics.Rect;
import android.media.RingtoneManager;
import android.net.Uri;
import android.os.Bundle;
import android.os.SystemClock;
import android.provider.ContactsContract;
+import android.provider.ContactsContract.CommonDataKinds.Email;
+import android.provider.ContactsContract.CommonDataKinds.Event;
+import android.provider.ContactsContract.CommonDataKinds.Organization;
+import android.provider.ContactsContract.CommonDataKinds.Phone;
+import android.provider.ContactsContract.CommonDataKinds.StructuredPostal;
import android.provider.ContactsContract.Contacts;
import android.provider.ContactsContract.Intents;
import android.provider.ContactsContract.QuickContact;
@@ -185,6 +191,9 @@
protected Context mContext;
protected Listener mListener;
+ //
+ // Views
+ //
protected LinearLayout mContent;
//
@@ -207,12 +216,13 @@
//
// Loaded data
//
- // Used to temporarily store existing contact data during a rebind call (i.e. account switch)
+ // Used to store existing contact data so it can be re-applied during a rebind call,
+ // i.e. account switch. Only used in {@link ContactEditorFragment}.
protected ImmutableList<RawContact> mRawContacts;
protected Cursor mGroupMetaData;
//
- // Contact editor state
+ // Editor state
//
protected RawContactDeltaList mState;
protected int mStatus;
@@ -225,15 +235,27 @@
protected boolean mIsEdit;
protected boolean mExistingContactDataReady;
- // Phone specific option menus
+ // Whether we are editing the "me" profile
+ protected boolean mIsUserProfile;
+
+ // Phone specific option menu items
private boolean mSendToVoicemailState;
private boolean mArePhoneOptionsChangable;
private String mCustomRingtone;
- protected boolean mIsUserProfile;
+ // Whether editor views and options menu items should be enabled
+ private boolean mEnabled = true;
- // Whether editors and options menu items are enabled
- protected boolean mEnabled = true;
+ //
+ // Editor state for {@link ContactEditorView}.
+ // (Not saved/restored on rotates)
+ //
+
+ // Used to pre-populate the editor with a display name when a user edits a read-only contact.
+ protected String mDefaultDisplayName;
+
+ // Whether the name editor should receive focus after being bound
+ protected boolean mRequestFocus;
/**
* The contact data loader listener.
@@ -250,10 +272,10 @@
}
@Override
- public void onLoadFinished(Loader<Contact> loader, Contact data) {
+ public void onLoadFinished(Loader<Contact> loader, Contact contact) {
final long loaderCurrentTime = SystemClock.elapsedRealtime();
Log.v(TAG, "Time needed for loading: " + (loaderCurrentTime-mLoaderStartTime));
- if (!data.isLoaded()) {
+ if (!contact.isLoaded()) {
// Item has been deleted. Close activity without saving again.
Log.i(TAG, "No contact found. Closing activity");
mStatus = Status.CLOSING;
@@ -262,9 +284,10 @@
}
mStatus = Status.EDITING;
- mLookupUri = data.getLookupUri();
+ mLookupUri = contact.getLookupUri();
final long setDataStartTime = SystemClock.elapsedRealtime();
- setData(data);
+ setState(contact);
+ setStateForPhoneMenuItems(contact);
final long setDataEndTime = SystemClock.elapsedRealtime();
Log.v(TAG, "Time needed for setting UI: " + (setDataEndTime - setDataStartTime));
@@ -289,7 +312,7 @@
@Override
public void onLoadFinished(Loader<Cursor> loader, Cursor data) {
mGroupMetaData = data;
- bindGroupMetaData();
+ setGroupMetaData();
}
@Override
@@ -339,13 +362,13 @@
mIsEdit = savedState.getBoolean(KEY_IS_EDIT);
mExistingContactDataReady = savedState.getBoolean(KEY_EXISTING_CONTACT_READY);
+ mIsUserProfile = savedState.getBoolean(KEY_IS_USER_PROFILE);
+
// Phone specific options menus
mSendToVoicemailState = savedState.getBoolean(KEY_SEND_TO_VOICE_MAIL_STATE);
mArePhoneOptionsChangable = savedState.getBoolean(KEY_ARE_PHONE_OPTIONS_CHANGEABLE);
mCustomRingtone = savedState.getString(KEY_CUSTOM_RINGTONE);
- mIsUserProfile = savedState.getBoolean(KEY_IS_USER_PROFILE);
-
mEnabled = savedState.getBoolean(KEY_ENABLED);
}
@@ -447,18 +470,18 @@
outState.putBoolean(KEY_IS_EDIT, mIsEdit);
outState.putBoolean(KEY_EXISTING_CONTACT_READY, mExistingContactDataReady);
+ outState.putBoolean(KEY_IS_USER_PROFILE, mIsUserProfile);
+
// Phone specific options
outState.putBoolean(KEY_SEND_TO_VOICE_MAIL_STATE, mSendToVoicemailState);
outState.putBoolean(KEY_ARE_PHONE_OPTIONS_CHANGEABLE, mArePhoneOptionsChangable);
outState.putString(KEY_CUSTOM_RINGTONE, mCustomRingtone);
- outState.putBoolean(KEY_IS_USER_PROFILE, mIsUserProfile);
outState.putBoolean(KEY_ENABLED, mEnabled);
super.onSaveInstanceState(outState);
}
-
@Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
switch (requestCode) {
@@ -487,14 +510,14 @@
if (data != null) {
final Uri pickedUri = data.getParcelableExtra(
RingtoneManager.EXTRA_RINGTONE_PICKED_URI);
- handleRingtonePicked(pickedUri);
+ onRingtonePicked(pickedUri);
}
break;
}
}
}
- private void handleRingtonePicked(Uri pickedUri) {
+ private void onRingtonePicked(Uri pickedUri) {
if (pickedUri == null || RingtoneManager.isDefault(pickedUri)) {
mCustomRingtone = null;
} else {
@@ -505,6 +528,19 @@
mContext.startService(intent);
}
+ //
+ // Options menu
+ //
+
+ private void setStateForPhoneMenuItems(Contact contact) {
+ if (contact != null) {
+ mSendToVoicemailState = contact.isSendToVoicemail();
+ mCustomRingtone = contact.getCustomRingtone();
+ mArePhoneOptionsChangable = !contact.isDirectoryEntry()
+ && PhoneCapabilityTester.isPhone(mContext);
+ }
+ }
+
@Override
public void onCreateOptionsMenu(Menu menu, final MenuInflater inflater) {
inflater.inflate(R.menu.edit_contact, menu);
@@ -661,6 +697,44 @@
}
}
+ @Override
+ public boolean save(int saveMode) {
+ if (!hasValidState() || mStatus != Status.EDITING) {
+ return false;
+ }
+
+ // If we are about to close the editor - there is no need to refresh the data
+ if (saveMode == SaveMode.CLOSE || saveMode == SaveMode.SPLIT) {
+ getLoaderManager().destroyLoader(LOADER_DATA);
+ }
+
+ mStatus = Status.SAVING;
+
+ if (!hasPendingChanges()) {
+ if (mLookupUri == null && saveMode == SaveMode.RELOAD) {
+ // We don't have anything to save and there isn't even an existing contact yet.
+ // Nothing to do, simply go back to editing mode
+ mStatus = Status.EDITING;
+ return true;
+ }
+ onSaveCompleted(false, saveMode, /* saveSucceeded =*/ mLookupUri != null, mLookupUri);
+ return true;
+ }
+
+ maybeSetEnabled(false);
+
+ return doSaveAction(saveMode);
+ }
+
+ /**
+ * Persist the accumulated editor deltas.
+ */
+ abstract protected boolean doSaveAction(int saveMode);
+
+ //
+ // State accessor methods
+ //
+
/**
* Check if our internal {@link #mState} is valid, usually checked before
* performing user actions.
@@ -682,6 +756,13 @@
return RawContactModifier.hasChanges(mState, accountTypes);
}
+ /**
+ * Whether editor inputs and the options menu should be enabled.
+ */
+ protected boolean isEnabled() {
+ return mEnabled;
+ }
+
//
// Account creation
//
@@ -740,7 +821,7 @@
mListener.onCustomCreateContactActivityRequested(account, mIntentExtras);
}
} else {
- bindEditorsForNewContact(account, accountType);
+ setStateForNewContact(account, accountType);
}
}
@@ -748,8 +829,7 @@
// Data binding
//
- private void setData(Contact contact) {
-
+ private void setState(Contact contact) {
// If we have already loaded data, we do not want to change it here to not confuse the user
if (!mState.isEmpty()) {
Log.v(TAG, "Ignoring background change. This will have to be rebased later");
@@ -790,28 +870,101 @@
// This also adds deltas to list
// If displayName is null at this point it is simply ignored later on by the editor.
- bindEditorsForExistingContact(displayName, contact.isUserProfile(),
- mRawContacts);
-
- bindMenuItemsForPhone(contact);
+ setStateForExistingContact(displayName, contact.isUserProfile(), mRawContacts);
}
- private void bindMenuItemsForPhone(Contact contact) {
- if (contact != null) {
- mSendToVoicemailState = contact.isSendToVoicemail();
- mCustomRingtone = contact.getCustomRingtone();
- mArePhoneOptionsChangable = !contact.isDirectoryEntry()
- && PhoneCapabilityTester.isPhone(mContext);
+ /**
+ * Prepare {@link #mState} for a newly created phone-local contact.
+ */
+ private void setStateForNewContact(AccountWithDataSet account, AccountType accountType) {
+ setStateForNewContact(account, accountType,
+ /* oldState =*/ null, /* oldAccountType =*/ null);
+ }
+
+ /**
+ * Prepare {@link #mState} for a newly created phone-local contact, migrating the state
+ * specified by oldState and oldAccountType.
+ */
+ protected void setStateForNewContact(AccountWithDataSet account, AccountType accountType,
+ RawContactDelta oldState, AccountType oldAccountType) {
+ mStatus = Status.EDITING;
+ mState.add(createNewRawContactDelta(mContext, mIntentExtras, account, accountType,
+ mIsUserProfile, oldState, oldAccountType));
+ mRequestFocus = true;
+ mNewContactDataReady = true;
+ bindEditors();
+ }
+
+ /**
+ * Prepare {@link #mState} for an existing contact.
+ */
+ protected void setStateForExistingContact(String displayName, boolean isUserProfile,
+ ImmutableList<RawContact> rawContacts) {
+ maybeSetEnabled(true);
+ mDefaultDisplayName = displayName;
+
+ mState.addAll(rawContacts.iterator());
+ setIntentExtras(mIntentExtras);
+ mIntentExtras = null;
+
+ // For user profile, change the contacts query URI
+ mIsUserProfile = isUserProfile;
+ boolean localProfileExists = false;
+
+ if (mIsUserProfile) {
+ for (RawContactDelta rawContactDelta : mState) {
+ // For profile contacts, we need a different query URI
+ rawContactDelta.setProfileQueryUri();
+ // Try to find a local profile contact
+ if (rawContactDelta.getValues().getAsString(RawContacts.ACCOUNT_TYPE) == null) {
+ localProfileExists = true;
+ }
+ }
+ // Editor should always present a local profile for editing
+ if (!localProfileExists) {
+ mState.add(createLocalRawContactDelta());
+ }
+ }
+ mRequestFocus = true;
+ mExistingContactDataReady = true;
+ bindEditors();
+ }
+
+ /**
+ * Sets group metadata on all bound editors.
+ */
+ // TODO: can this be private? Does it really need to be called from
+ // {@link ContactEditFragment#bindEdtiors}? If not we can remove mGroupMetaData too.
+ protected void setGroupMetaData() {
+ if (mGroupMetaData == null) {
+ return;
+ }
+ int editorCount = mContent.getChildCount();
+ for (int i = 0; i < editorCount; i++) {
+ BaseRawContactEditorView editor = (BaseRawContactEditorView) mContent.getChildAt(i);
+ editor.setGroupMetaData(mGroupMetaData);
}
}
- // TODO: add javadocs after these are finalized
- abstract protected void bindEditorsForExistingContact(String displayName, boolean isUserProfile,
- ImmutableList<RawContact> rawContacts);
- abstract protected void bindEditorsForNewContact(AccountWithDataSet account,
- final AccountType accountType);
- abstract protected void bindEditors();
- abstract protected void bindGroupMetaData();
+ /**
+ * Bind editors using {@link #mState} and other members intialized from the loaded (or new)
+ * Contact.
+ */
+ abstract void bindEditors();
+
+ /**
+ * Set the enabled state of editors.
+ */
+ // TODO: The implementation in ContactEditorFragment can be moved to this class when
+ // the aggregation Views are moved to the base and we can get rid of maybeSetEnabled
+ abstract void setEnabled(boolean enabled);
+
+ private void maybeSetEnabled(boolean enabled) {
+ if (mEnabled != enabled) {
+ mEnabled = enabled;
+ setEnabled(mEnabled);
+ }
+ }
//
// ContactEditor
@@ -838,6 +991,10 @@
}
}
+ //
+ // Utility methods
+ //
+
/**
* Returns a legacy version of the given contactLookupUri if a legacy Uri was originally
* passed to the contact editor.
@@ -874,4 +1031,59 @@
intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
return intent;
}
+
+ /**
+ * Returns a {@link RawContactDelta} for a new contact suitable for addition into
+ * {@link #mState}.
+ *
+ * If oldState and oldAccountType are specified, the state specified by those parameters
+ * is migrated to the result {@link RawContactDelta}.
+ */
+ private static RawContactDelta createNewRawContactDelta(Context context, Bundle intentExtras,
+ AccountWithDataSet account, AccountType accountType, boolean isNewLocalProfile,
+ RawContactDelta oldState, AccountType oldAccountType) {
+ final RawContact rawContact = new RawContact();
+ rawContact.setAccount(account);
+
+ final RawContactDelta result = new RawContactDelta(
+ ValuesDelta.fromAfter(rawContact.getValues()));
+ if (oldState == null) {
+ // Parse any values from incoming intent
+ RawContactModifier.parseExtras(context, accountType, result, intentExtras);
+ } else {
+ RawContactModifier.migrateStateForNewContact(
+ context, oldState, result, oldAccountType, accountType);
+ }
+
+ // Ensure we have some default fields (if the account type does not support a field,
+ // ensureKind will not add it, so it is safe to add e.g. Event)
+ RawContactModifier.ensureKindExists(result, accountType, Phone.CONTENT_ITEM_TYPE);
+ RawContactModifier.ensureKindExists(result, accountType, Email.CONTENT_ITEM_TYPE);
+ RawContactModifier.ensureKindExists(result, accountType, Organization.CONTENT_ITEM_TYPE);
+ RawContactModifier.ensureKindExists(result, accountType, Event.CONTENT_ITEM_TYPE);
+ RawContactModifier.ensureKindExists(result, accountType,
+ StructuredPostal.CONTENT_ITEM_TYPE);
+
+ // Set the correct URI for saving the contact as a profile
+ if (isNewLocalProfile) {
+ result.setProfileQueryUri();
+ }
+
+ return result;
+ }
+
+ /**
+ * Returns a {@link RawContactDelta} for a local contact suitable for addition into
+ * {@link #mState}.
+ */
+ private static RawContactDelta createLocalRawContactDelta() {
+ final RawContact rawContact = new RawContact();
+ rawContact.setAccountToLocal();
+
+ final RawContactDelta result = new RawContactDelta(
+ ValuesDelta.fromAfter(rawContact.getValues()));
+ result.setProfileQueryUri();
+
+ return result;
+ }
}
diff --git a/src/com/android/contacts/editor/ContactEditorFragment.java b/src/com/android/contacts/editor/ContactEditorFragment.java
index 7fb4378..d78d171 100644
--- a/src/com/android/contacts/editor/ContactEditorFragment.java
+++ b/src/com/android/contacts/editor/ContactEditorFragment.java
@@ -25,16 +25,9 @@
import android.content.DialogInterface;
import android.content.Intent;
import android.graphics.Bitmap;
-import android.media.RingtoneManager;
import android.net.Uri;
import android.os.Bundle;
-import android.provider.ContactsContract.CommonDataKinds.Email;
-import android.provider.ContactsContract.CommonDataKinds.Event;
-import android.provider.ContactsContract.CommonDataKinds.Organization;
-import android.provider.ContactsContract.CommonDataKinds.Phone;
import android.provider.ContactsContract.CommonDataKinds.Photo;
-import android.provider.ContactsContract.CommonDataKinds.StructuredPostal;
-import android.provider.ContactsContract.Intents;
import android.provider.ContactsContract.RawContacts;
import android.text.TextUtils;
import android.util.Log;
@@ -53,7 +46,6 @@
import com.android.contacts.activities.ContactEditorActivity;
import com.android.contacts.activities.ContactEditorBaseActivity.ContactEditor;
import com.android.contacts.common.model.AccountTypeManager;
-import com.android.contacts.common.model.RawContact;
import com.android.contacts.common.model.RawContactDelta;
import com.android.contacts.common.model.RawContactDeltaList;
import com.android.contacts.common.model.RawContactModifier;
@@ -117,13 +109,6 @@
// Used to store which raw contact editors have been expanded. Keyed on raw contact ids.
private HashMap<Long, Boolean> mExpandedEditors = new HashMap<Long, Boolean>();
- // Whether the name editor should receive focus after being bound
- private boolean mRequestFocus;
-
- // This is used to pre-populate the editor with a display name when a user edits a read-only
- // contact.
- private String mDefaultDisplayName;
-
// Photos
/**
* The raw contact for which we started "take photo" or "choose photo from gallery" most
@@ -205,19 +190,18 @@
public ContactEditorFragment() {
}
- public void setEnabled(boolean enabled) {
- if (mEnabled != enabled) {
- mEnabled = enabled;
- if (mContent != null) {
- int count = mContent.getChildCount();
- for (int i = 0; i < count; i++) {
- mContent.getChildAt(i).setEnabled(enabled);
- }
+
+ @Override
+ protected void setEnabled(boolean enabled) {
+ if (mContent != null) {
+ int count = mContent.getChildCount();
+ for (int i = 0; i < count; i++) {
+ mContent.getChildAt(i).setEnabled(enabled);
}
- setAggregationSuggestionViewEnabled(enabled);
- final Activity activity = getActivity();
- if (activity != null) activity.invalidateOptionsMenu();
}
+ setAggregationSuggestionViewEnabled(enabled);
+ final Activity activity = getActivity();
+ if (activity != null) activity.invalidateOptionsMenu();
}
@Override
@@ -269,8 +253,6 @@
mExpandedEditors = (HashMap<Long, Boolean>)
savedState.getSerializable(KEY_EXPANDED_EDITORS);
- // NOTE: mRequestFocus and mDefaultDisplayName are not saved/restored
-
// Photos
mRawContactIdRequestingPhoto = savedState.getLong(
KEY_RAW_CONTACT_ID_REQUESTING_PHOTO);
@@ -294,45 +276,6 @@
}
@Override
- protected void bindEditorsForExistingContact(String displayName, boolean isUserProfile,
- ImmutableList<RawContact> rawContacts) {
- setEnabled(true);
- mDefaultDisplayName = displayName;
-
- mState.addAll(rawContacts.iterator());
- setIntentExtras(mIntentExtras);
- mIntentExtras = null;
-
- // For user profile, change the contacts query URI
- mIsUserProfile = isUserProfile;
- boolean localProfileExists = false;
-
- if (mIsUserProfile) {
- for (RawContactDelta state : mState) {
- // For profile contacts, we need a different query URI
- state.setProfileQueryUri();
- // Try to find a local profile contact
- if (state.getValues().getAsString(RawContacts.ACCOUNT_TYPE) == null) {
- localProfileExists = true;
- }
- }
- // Editor should always present a local profile for editing
- if (!localProfileExists) {
- final RawContact rawContact = new RawContact();
- rawContact.setAccountToLocal();
-
- RawContactDelta insert = new RawContactDelta(ValuesDelta.fromAfter(
- rawContact.getValues()));
- insert.setProfileQueryUri();
- mState.add(insert);
- }
- }
- mRequestFocus = true;
- mExistingContactDataReady = true;
- bindEditors();
- }
-
- @Override
public void setIntentExtras(Bundle extras) {
if (extras == null || extras.size() == 0) {
return;
@@ -373,60 +316,14 @@
mExistingContactDataReady = false;
mNewContactDataReady = false;
mState = new RawContactDeltaList();
- bindEditorsForNewContact(newAccount, newAccountType, oldState, oldAccountType);
+ setStateForNewContact(newAccount, newAccountType, oldState, oldAccountType);
if (mIsEdit) {
- bindEditorsForExistingContact(mDefaultDisplayName, mIsUserProfile, mRawContacts);
+ setStateForExistingContact(mDefaultDisplayName, mIsUserProfile, mRawContacts);
}
}
}
@Override
- protected void bindEditorsForNewContact(AccountWithDataSet account,
- final AccountType accountType) {
- bindEditorsForNewContact(account, accountType, null, null);
- }
-
- private void bindEditorsForNewContact(AccountWithDataSet newAccount,
- final AccountType newAccountType, RawContactDelta oldState,
- AccountType oldAccountType) {
- mStatus = Status.EDITING;
-
- final RawContact rawContact = new RawContact();
- rawContact.setAccount(newAccount);
-
- final ValuesDelta valuesDelta = ValuesDelta.fromAfter(rawContact.getValues());
- final RawContactDelta insert = new RawContactDelta(valuesDelta);
- if (oldState == null) {
- // Parse any values from incoming intent
- RawContactModifier.parseExtras(mContext, newAccountType, insert, mIntentExtras);
- } else {
- RawContactModifier.migrateStateForNewContact(mContext, oldState, insert,
- oldAccountType, newAccountType);
- }
-
- // Ensure we have some default fields (if the account type does not support a field,
- // ensureKind will not add it, so it is safe to add e.g. Event)
- RawContactModifier.ensureKindExists(insert, newAccountType, Phone.CONTENT_ITEM_TYPE);
- RawContactModifier.ensureKindExists(insert, newAccountType, Email.CONTENT_ITEM_TYPE);
- RawContactModifier.ensureKindExists(insert, newAccountType, Organization.CONTENT_ITEM_TYPE);
- RawContactModifier.ensureKindExists(insert, newAccountType, Event.CONTENT_ITEM_TYPE);
- RawContactModifier.ensureKindExists(insert, newAccountType,
- StructuredPostal.CONTENT_ITEM_TYPE);
-
- // Set the correct URI for saving the contact as a profile
- if (mNewLocalProfile) {
- insert.setProfileQueryUri();
- }
-
- mState.add(insert);
-
- mRequestFocus = true;
-
- mNewContactDataReady = true;
- bindEditors();
- }
-
- @Override
protected void bindEditors() {
// bindEditors() can only bind views if there is data in mState, so immediately return
// if mState is null
@@ -475,7 +372,7 @@
addAccountSwitcher(mState.get(0), editor);
}
- editor.setEnabled(mEnabled);
+ editor.setEnabled(isEnabled());
if (mExpandedEditors.containsKey(rawContactId)) {
editor.setCollapsed(mExpandedEditors.get(rawContactId));
@@ -548,7 +445,7 @@
mRequestFocus = false;
- bindGroupMetaData();
+ setGroupMetaData();
// Show editor now that we've loaded state
mContent.setVisibility(View.VISIBLE);
@@ -633,19 +530,6 @@
}
}
- @Override
- protected void bindGroupMetaData() {
- if (mGroupMetaData == null) {
- return;
- }
-
- int editorCount = mContent.getChildCount();
- for (int i = 0; i < editorCount; i++) {
- BaseRawContactEditorView editor = (BaseRawContactEditorView) mContent.getChildAt(i);
- editor.setGroupMetaData(mGroupMetaData);
- }
- }
-
private void saveDefaultAccountIfNecessary() {
// Verify that this is a newly created contact, that the contact is composed of only
// 1 raw contact, and that the contact is not a user profile.
@@ -708,31 +592,7 @@
}
@Override
- public boolean save(int saveMode) {
- if (!hasValidState() || mStatus != Status.EDITING) {
- return false;
- }
-
- // If we are about to close the editor - there is no need to refresh the data
- if (saveMode == SaveMode.CLOSE || saveMode == SaveMode.SPLIT) {
- getLoaderManager().destroyLoader(LOADER_DATA);
- }
-
- mStatus = Status.SAVING;
-
- if (!hasPendingChanges()) {
- if (mLookupUri == null && saveMode == SaveMode.RELOAD) {
- // We don't have anything to save and there isn't even an existing contact yet.
- // Nothing to do, simply go back to editing mode
- mStatus = Status.EDITING;
- return true;
- }
- onSaveCompleted(false, saveMode, mLookupUri != null, mLookupUri);
- return true;
- }
-
- setEnabled(false);
-
+ protected boolean doSaveAction(int saveMode) {
// Store account as default account, only if this is a new contact
saveDefaultAccountIfNecessary();