Wire up saving edits using the compact contact editor
Also fix refreshing the edit activity data after joining
Bug 19124091
Change-Id: I161e38d9eaea89e3d090986d2b52cb6f8ee85422
diff --git a/src/com/android/contacts/editor/CompactContactEditorFragment.java b/src/com/android/contacts/editor/CompactContactEditorFragment.java
index f1df4f8..89c7521 100644
--- a/src/com/android/contacts/editor/CompactContactEditorFragment.java
+++ b/src/com/android/contacts/editor/CompactContactEditorFragment.java
@@ -16,9 +16,11 @@
package com.android.contacts.editor;
+import com.android.contacts.ContactSaveService;
import com.android.contacts.R;
-import com.android.contacts.activities.ContactEditorBaseActivity.ContactEditor;
+import com.android.contacts.activities.CompactContactEditorActivity;
+import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.util.Log;
@@ -30,8 +32,7 @@
/**
* Contact editor with only the most important fields displayed initially.
*/
-public class CompactContactEditorFragment extends ContactEditorBaseFragment
- implements ContactEditor {
+public class CompactContactEditorFragment extends ContactEditorBaseFragment {
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedState) {
@@ -89,10 +90,31 @@
@Override
protected void setGroupMetaData() {
+ // The compact editor does not support groups.
}
@Override
protected boolean doSaveAction(int saveMode) {
- return false;
+ // Store account as default account, only if this is a new contact
+ saveDefaultAccountIfNecessary();
+
+ // Save contact
+ final Intent intent = ContactSaveService.createSaveContactIntent(mContext, mState,
+ SAVE_MODE_EXTRA_KEY, saveMode, isEditingUserProfile(),
+ ((Activity) mContext).getClass(),
+ CompactContactEditorActivity.ACTION_SAVE_COMPLETED,
+ /* updatedPhotos =*/ new Bundle());
+ mContext.startService(intent);
+
+ return true;
+ }
+
+ @Override
+ protected void joinAggregate(final long contactId) {
+ final Intent intent = ContactSaveService.createJoinContactsIntent(
+ mContext, mContactIdForJoin, contactId, mContactWritableForJoin,
+ CompactContactEditorActivity.class,
+ CompactContactEditorActivity.ACTION_JOIN_COMPLETED);
+ mContext.startService(intent);
}
}
diff --git a/src/com/android/contacts/editor/ContactEditorBaseFragment.java b/src/com/android/contacts/editor/ContactEditorBaseFragment.java
index ce0e5cd..6961c4c 100644
--- a/src/com/android/contacts/editor/ContactEditorBaseFragment.java
+++ b/src/com/android/contacts/editor/ContactEditorBaseFragment.java
@@ -324,8 +324,8 @@
private long mAggregationSuggestionsRawContactId;
// Join Activity
- private long mContactIdForJoin;
- private boolean mContactWritableForJoin;
+ protected long mContactIdForJoin;
+ protected boolean mContactWritableForJoin;
//
// Editor state for {@link ContactEditorView}.
@@ -978,6 +978,30 @@
}
}
+ /**
+ * Saves all writable accounts and the default account, but only for new contacts.
+ */
+ protected 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.
+ if (!Intent.ACTION_INSERT.equals(mAction) && mState.size() == 1 &&
+ !isEditingUserProfile()) {
+ return;
+ }
+
+ // 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
//
@@ -1422,12 +1446,7 @@
/**
* Performs aggregation with the contact selected by the user from suggestions or A-Z list.
*/
- private void joinAggregate(final long contactId) {
- Intent intent = ContactSaveService.createJoinContactsIntent(mContext, mContactIdForJoin,
- contactId, mContactWritableForJoin,
- ContactEditorActivity.class, ContactEditorActivity.ACTION_JOIN_COMPLETED);
- mContext.startService(intent);
- }
+ abstract protected void joinAggregate(long contactId);
//
// Utility methods
diff --git a/src/com/android/contacts/editor/ContactEditorFragment.java b/src/com/android/contacts/editor/ContactEditorFragment.java
index f30360c..236c977 100644
--- a/src/com/android/contacts/editor/ContactEditorFragment.java
+++ b/src/com/android/contacts/editor/ContactEditorFragment.java
@@ -35,11 +35,9 @@
import com.android.contacts.ContactSaveService;
import com.android.contacts.R;
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.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;
@@ -62,7 +60,6 @@
* Contact editor with all fields displayed.
*/
public class ContactEditorFragment extends ContactEditorBaseFragment implements
- ContactEditor, SplitContactConfirmationDialogFragment.Listener,
RawContactReadOnlyEditorView.Listener {
private static final String KEY_EXPANDED_EDITORS = "expandedEditors";
@@ -379,27 +376,6 @@
}
}
- 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.
- if (!Intent.ACTION_INSERT.equals(mAction) && mState.size() == 1 &&
- !isEditingUserProfile()) {
- return;
- }
-
- // 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);
- }
-
private void addAccountSwitcher(
final RawContactDelta currentState, BaseRawContactEditorView editor) {
final AccountWithDataSet currentAccount = new AccountWithDataSet(
@@ -482,6 +458,14 @@
super.onActivityResult(requestCode, resultCode, data);
}
+ @Override
+ protected void joinAggregate(final long contactId) {
+ final Intent intent = ContactSaveService.createJoinContactsIntent(
+ mContext, mContactIdForJoin, contactId, mContactWritableForJoin,
+ ContactEditorActivity.class, ContactEditorActivity.ACTION_JOIN_COMPLETED);
+ mContext.startService(intent);
+ }
+
/**
* Sets the photo stored in mPhoto and writes it to the RawContact with the given id
*/