Merge "Don't show Note and Nickname if they are empty database rows; some clean up"
diff --git a/src/com/android/contacts/model/EntityDelta.java b/src/com/android/contacts/model/EntityDelta.java
index cdf2e41..f88e27b 100644
--- a/src/com/android/contacts/model/EntityDelta.java
+++ b/src/com/android/contacts/model/EntityDelta.java
@@ -612,33 +612,45 @@
return (mBefore != null && mBefore.containsKey(mIdColumn));
}
+ /**
+ * When "after" is present, then visible
+ */
public boolean isVisible() {
- // When "after" is present, then visible
return (mAfter != null);
}
+ /**
+ * When "after" is wiped, action is "delete"
+ */
public boolean isDelete() {
- // When "after" is wiped, action is "delete"
return beforeExists() && (mAfter == null);
}
+ /**
+ * When no "before" or "after", is transient
+ */
public boolean isTransient() {
- // When no "before" or "after", is transient
return (mBefore == null) && (mAfter == null);
}
+ /**
+ * When "after" has some changes, action is "update"
+ */
public boolean isUpdate() {
- // When "after" has some changes, action is "update"
return beforeExists() && (mAfter != null && mAfter.size() > 0);
}
+ /**
+ * When "after" has no changes, action is no-op
+ */
public boolean isNoop() {
- // When "after" has no changes, action is no-op
return beforeExists() && (mAfter != null && mAfter.size() == 0);
}
+ /**
+ * When no "before" id, and has "after", action is "insert"
+ */
public boolean isInsert() {
- // When no "before" id, and has "after", action is "insert"
return !beforeExists() && (mAfter != null);
}
diff --git a/src/com/android/contacts/ui/widget/ContactEditorView.java b/src/com/android/contacts/ui/widget/ContactEditorView.java
index 4cae9a6..9df9705 100644
--- a/src/com/android/contacts/ui/widget/ContactEditorView.java
+++ b/src/com/android/contacts/ui/widget/ContactEditorView.java
@@ -48,7 +48,6 @@
import android.widget.Button;
import android.widget.ImageView;
import android.widget.TextView;
-import android.widget.Toast;
import java.util.ArrayList;
diff --git a/src/com/android/contacts/ui/widget/GenericEditorView.java b/src/com/android/contacts/ui/widget/GenericEditorView.java
index 6068660..d313b48 100644
--- a/src/com/android/contacts/ui/widget/GenericEditorView.java
+++ b/src/com/android/contacts/ui/widget/GenericEditorView.java
@@ -41,7 +41,6 @@
import android.telephony.PhoneNumberFormattingTextWatcher;
import android.text.Editable;
import android.text.InputType;
-import android.text.TextUtils;
import android.text.TextWatcher;
import android.util.AttributeSet;
import android.view.ContextThemeWrapper;
@@ -346,18 +345,6 @@
}
}
- public boolean isAnyFieldFilledOut() {
- if (mFieldEditTexts != null) {
- for (int index = 0; index < mFieldEditTexts.length; index++) {
- final EditText editText = mFieldEditTexts[index];
- if (!TextUtils.isEmpty(editText.getText())) {
- return true;
- }
- }
- }
- return false;
- }
-
private void rebuildValues() {
setValues(mKind, mEntry, mState, mReadOnly, mViewIdGenerator);
}
diff --git a/src/com/android/contacts/ui/widget/KindSectionView.java b/src/com/android/contacts/ui/widget/KindSectionView.java
index 6f876cd..371966f 100644
--- a/src/com/android/contacts/ui/widget/KindSectionView.java
+++ b/src/com/android/contacts/ui/widget/KindSectionView.java
@@ -27,11 +27,12 @@
import com.android.contacts.util.ViewGroupAnimator;
import android.content.Context;
+import android.opengl.Texture;
import android.provider.ContactsContract.Data;
+import android.text.TextUtils;
import android.util.AttributeSet;
import android.util.DisplayMetrics;
import android.util.TypedValue;
-import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.view.WindowManager;
@@ -90,7 +91,6 @@
/** {@inheritDoc} */
public void onDeleted(Editor editor) {
updateAddEnabled();
- updateEditorsVisible();
updateVisible();
}
@@ -115,7 +115,6 @@
rebuildFromState();
updateAddEnabled();
- updateEditorsVisible();
updateVisible();
}
@@ -123,26 +122,6 @@
return mTitle.getText();
}
- public boolean getFieldCount() {
- if (mState == null) {
- return false;
- }
-
- if (!mState.hasMimeEntries(mKind.mimeType)) {
- return false;
- }
-
- int editorCount = getEditorCount();
- for (int i = 0; i < editorCount; i++) {
- GenericEditorView editorView = (GenericEditorView) mEditors.getChildAt(i);
- if (editorView.isAnyFieldFilledOut()) {
- return true;
- }
- }
-
- return false;
- }
-
/**
* Build editors for all current {@link #mState} rows.
*/
@@ -158,6 +137,7 @@
for (ValuesDelta entry : mState.getMimeEntries(mKind.mimeType)) {
// Skip entries that aren't visible
if (!entry.isVisible()) continue;
+ if (isEmptyNoop(entry)) continue;
final GenericEditorView editor = new GenericEditorView(mContext);
@@ -172,6 +152,20 @@
}
/**
+ * Tests whether the given item has no changes (so it exists in the database) but is empty
+ */
+ private boolean isEmptyNoop(ValuesDelta item) {
+ if (!item.isNoop()) return false;
+ final int fieldCount = mKind.fieldList.size();
+ for (int i = 0; i < fieldCount; i++) {
+ final String column = mKind.fieldList.get(i).column;
+ final String value = item.getAsString(column);
+ if (!TextUtils.isEmpty(value)) return false;
+ }
+ return true;
+ }
+
+ /**
* Reads the scrollbarSize of the current theme
*/
private static int getThemeScrollbarSize(Context context) {
@@ -188,11 +182,6 @@
return sCachedThemePaddingRight;
}
- protected void updateEditorsVisible() {
- final boolean hasChildren = getEditorCount() > 0;
- mEditors.setVisibility(hasChildren ? View.VISIBLE : View.GONE);
- }
-
private void updateVisible() {
setVisibility(getEditorCount() != 0 ? VISIBLE : GONE);
}
@@ -216,7 +205,6 @@
final ValuesDelta newValues = EntityModifier.insertChild(mState, mKind);
rebuildFromState();
updateAddEnabled();
- updateEditorsVisible();
// Find the newly added EditView and set focus.
final int newFieldId = mViewIdGenerator.getId(mState, mKind, newValues, 0);