Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(3093)

Unified Diff: chrome/android/java/src/org/chromium/chrome/browser/payments/ContactEditor.java

Issue 2529043003: [Payments] Show required information for contact details and set appropriate editor title (Closed)
Patch Set: correct indentation Created 4 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: chrome/android/java/src/org/chromium/chrome/browser/payments/ContactEditor.java
diff --git a/chrome/android/java/src/org/chromium/chrome/browser/payments/ContactEditor.java b/chrome/android/java/src/org/chromium/chrome/browser/payments/ContactEditor.java
index 7924e096ad4af89ae292d9c0900e486b3b074064..ad65b7985e7c77c04c1d801b8cb75363677ac671 100644
--- a/chrome/android/java/src/org/chromium/chrome/browser/payments/ContactEditor.java
+++ b/chrome/android/java/src/org/chromium/chrome/browser/payments/ContactEditor.java
@@ -4,6 +4,7 @@
package org.chromium.chrome.browser.payments;
+import android.support.annotation.IntDef;
import android.telephony.PhoneNumberUtils;
import android.text.TextUtils;
import android.util.Patterns;
@@ -16,6 +17,8 @@ import org.chromium.chrome.browser.payments.ui.EditorFieldModel;
import org.chromium.chrome.browser.payments.ui.EditorFieldModel.EditorFieldValidator;
import org.chromium.chrome.browser.payments.ui.EditorModel;
+import java.lang.annotation.Retention;
+import java.lang.annotation.RetentionPolicy;
import java.util.HashSet;
import java.util.Set;
@@ -25,6 +28,20 @@ import javax.annotation.Nullable;
* Contact information editor.
*/
public class ContactEditor extends EditorBase<AutofillContact> {
+ @IntDef({INVALID_NAME, INVALID_EMAIL, INVALID_PHONE_NUMBER, INVALID_MULTIPLE_FIELDS})
+ @Retention(RetentionPolicy.SOURCE)
+ public @interface CompletionStatus {}
+ /** Can be sent to the merchant as-is without editing first. */
+ public static final int COMPLETE = 0;
+ /** The contact name is missing. */
+ public static final int INVALID_NAME = 1;
+ /** The contact email is invalid or missing. */
+ public static final int INVALID_EMAIL = 2;
+ /** The contact phone number is invalid or missing. */
+ public static final int INVALID_PHONE_NUMBER = 3;
+ /** Multiple fields are invalid or missing. */
+ public static final int INVALID_MULTIPLE_FIELDS = 4;
+
private final boolean mRequestPayerName;
private final boolean mRequestPayerPhone;
private final boolean mRequestPayerEmail;
@@ -53,19 +70,39 @@ public class ContactEditor extends EditorBase<AutofillContact> {
}
/**
- * Returns whether the following contact information can be sent to the merchant as-is without
- * editing first.
+ * Returns the contact completion status with the given name, phone and email.
*
* @param name The payer name to check.
* @param phone The phone number to check.
* @param email The email address to check.
- * @return Whether the contact information is complete.
+ * @return The completion status.
*/
- public boolean isContactInformationComplete(
+ @CompletionStatus
+ public int checkContactCompletionStatus(
@Nullable String name, @Nullable String phone, @Nullable String email) {
- return (!mRequestPayerName || !TextUtils.isEmpty(name))
- && (!mRequestPayerPhone || getPhoneValidator().isValid(phone))
- && (!mRequestPayerEmail || getEmailValidator().isValid(email));
+ int invalidFieldCount = 0;
+ int completionStatus = COMPLETE;
+
+ if (mRequestPayerName && TextUtils.isEmpty(name)) {
+ invalidFieldCount++;
+ completionStatus = INVALID_NAME;
+ }
+
+ if (mRequestPayerPhone && !getPhoneValidator().isValid(phone)) {
+ invalidFieldCount++;
+ completionStatus = INVALID_PHONE_NUMBER;
+ }
+
+ if (mRequestPayerEmail && !getEmailValidator().isValid(email)) {
+ invalidFieldCount++;
+ completionStatus = INVALID_EMAIL;
+ }
+
+ if (invalidFieldCount > 1) {
+ completionStatus = INVALID_MULTIPLE_FIELDS;
+ }
+
+ return completionStatus;
}
/**
@@ -101,7 +138,9 @@ public class ContactEditor extends EditorBase<AutofillContact> {
super.edit(toEdit, callback);
final AutofillContact contact = toEdit == null
- ? new AutofillContact(new AutofillProfile(), null, null, null, false) : toEdit;
+ ? new AutofillContact(mContext, new AutofillProfile(), null, null, null,
+ INVALID_MULTIPLE_FIELDS)
+ : toEdit;
final EditorFieldModel nameField = mRequestPayerName
? EditorFieldModel.createTextInput(EditorFieldModel.INPUT_TYPE_HINT_PERSON_NAME,
@@ -129,9 +168,10 @@ public class ContactEditor extends EditorBase<AutofillContact> {
contact.getPayerEmail())
: null;
- EditorModel editor = new EditorModel(
- mContext.getString(toEdit == null ? R.string.payments_add_contact_details_label
- : R.string.payments_edit_contact_details_label));
+ EditorModel editor = new EditorModel(toEdit == null
+ ? mContext.getString(R.string.payments_add_contact_details_label)
+ : toEdit.getEditTitle());
+
if (nameField != null) editor.addField(nameField);
if (phoneField != null) editor.addField(phoneField);
if (emailField != null) editor.addField(emailField);

Powered by Google App Engine
This is Rietveld 408576698