Commit c178d837 authored by Marcin Wiacek's avatar Marcin Wiacek Committed by Commit Bot

Improve readability by moving const inside @IntDef ErrorType

Change-Id: I522d8ef23a39e78c687dfcff6f8e69dd1c5cf662
Reviewed-on: https://chromium-review.googlesource.com/1125067Reviewed-by: default avatarYaron Friedman <yfriedman@chromium.org>
Commit-Queue: Marcin Wiącek <marcin@mwiacek.com>
Cr-Commit-Position: refs/heads/master@{#572587}
parent 8700bb99
...@@ -92,19 +92,18 @@ public class CardUnmaskPrompt implements TextWatcher, OnClickListener, ModalDial ...@@ -92,19 +92,18 @@ public class CardUnmaskPrompt implements TextWatcher, OnClickListener, ModalDial
private static final int EXPIRATION_FIELDS_LENGTH = 2; private static final int EXPIRATION_FIELDS_LENGTH = 2;
public static final int ERROR_TYPE_EXPIRATION_MONTH = 1; @IntDef({ErrorType.EXPIRATION_MONTH, ErrorType.EXPIRATION_YEAR, ErrorType.EXPIRATION_DATE,
public static final int ERROR_TYPE_EXPIRATION_YEAR = 2; ErrorType.CVC, ErrorType.CVC_AND_EXPIRATION, ErrorType.NOT_ENOUGH_INFO, ErrorType.NONE})
public static final int ERROR_TYPE_EXPIRATION_DATE = 3;
public static final int ERROR_TYPE_CVC = 4;
public static final int ERROR_TYPE_CVC_AND_EXPIRATION = 5;
public static final int ERROR_TYPE_NOT_ENOUGH_INFO = 6;
public static final int ERROR_TYPE_NONE = 7;
@Retention(RetentionPolicy.SOURCE) @Retention(RetentionPolicy.SOURCE)
@IntDef({ERROR_TYPE_EXPIRATION_MONTH, ERROR_TYPE_EXPIRATION_YEAR, ERROR_TYPE_EXPIRATION_DATE, public @interface ErrorType {
ERROR_TYPE_CVC, ERROR_TYPE_CVC_AND_EXPIRATION, ERROR_TYPE_NOT_ENOUGH_INFO, int EXPIRATION_MONTH = 1;
ERROR_TYPE_NONE}) int EXPIRATION_YEAR = 2;
public @interface ErrorType {} int EXPIRATION_DATE = 3;
int CVC = 4;
int CVC_AND_EXPIRATION = 5;
int NOT_ENOUGH_INFO = 6;
int NONE = 7;
}
/** /**
* An interface to handle the interaction with an CardUnmaskPrompt object. * An interface to handle the interaction with an CardUnmaskPrompt object.
...@@ -350,7 +349,7 @@ public class CardUnmaskPrompt implements TextWatcher, OnClickListener, ModalDial ...@@ -350,7 +349,7 @@ public class CardUnmaskPrompt implements TextWatcher, OnClickListener, ModalDial
Button positiveButton = mDialog.getButton(ModalDialogView.BUTTON_POSITIVE); Button positiveButton = mDialog.getButton(ModalDialogView.BUTTON_POSITIVE);
@ErrorType int errorType = getExpirationAndCvcErrorType(); @ErrorType int errorType = getExpirationAndCvcErrorType();
positiveButton.setEnabled(errorType == ERROR_TYPE_NONE); positiveButton.setEnabled(errorType == ErrorType.NONE);
showDetailedErrorMessage(errorType); showDetailedErrorMessage(errorType);
moveFocus(errorType); moveFocus(errorType);
...@@ -457,7 +456,7 @@ public class CardUnmaskPrompt implements TextWatcher, OnClickListener, ModalDial ...@@ -457,7 +456,7 @@ public class CardUnmaskPrompt implements TextWatcher, OnClickListener, ModalDial
* @param errorType The type of error detected. * @param errorType The type of error detected.
*/ */
private void moveFocus(@ErrorType int errorType) { private void moveFocus(@ErrorType int errorType) {
if (errorType == ERROR_TYPE_NOT_ENOUGH_INFO) { if (errorType == ErrorType.NOT_ENOUGH_INFO) {
if (mMonthInput.isFocused() if (mMonthInput.isFocused()
&& mMonthInput.getText().length() == EXPIRATION_FIELDS_LENGTH) { && mMonthInput.getText().length() == EXPIRATION_FIELDS_LENGTH) {
// The user just finished typing in the month field and there are no validation // The user just finished typing in the month field and there are no validation
...@@ -489,28 +488,23 @@ public class CardUnmaskPrompt implements TextWatcher, OnClickListener, ModalDial ...@@ -489,28 +488,23 @@ public class CardUnmaskPrompt implements TextWatcher, OnClickListener, ModalDial
*/ */
private void showDetailedErrorMessage(@ErrorType int errorType) { private void showDetailedErrorMessage(@ErrorType int errorType) {
switch (errorType) { switch (errorType) {
case ERROR_TYPE_EXPIRATION_MONTH: case ErrorType.EXPIRATION_MONTH:
showErrorMessage(mExpirationMonthErrorMessage); showErrorMessage(mExpirationMonthErrorMessage);
break; break;
case ErrorType.EXPIRATION_YEAR:
case ERROR_TYPE_EXPIRATION_YEAR:
showErrorMessage(mExpirationYearErrorMessage); showErrorMessage(mExpirationYearErrorMessage);
break; break;
case ErrorType.EXPIRATION_DATE:
case ERROR_TYPE_EXPIRATION_DATE:
showErrorMessage(mExpirationDateErrorMessage); showErrorMessage(mExpirationDateErrorMessage);
break; break;
case ErrorType.CVC:
case ERROR_TYPE_CVC:
showErrorMessage(mCvcErrorMessage); showErrorMessage(mCvcErrorMessage);
break; break;
case ErrorType.CVC_AND_EXPIRATION:
case ERROR_TYPE_CVC_AND_EXPIRATION:
showErrorMessage(mCvcAndExpirationErrorMessage); showErrorMessage(mCvcAndExpirationErrorMessage);
break; break;
case ErrorType.NONE:
case ERROR_TYPE_NONE: case ErrorType.NOT_ENOUGH_INFO:
case ERROR_TYPE_NOT_ENOUGH_INFO:
default: default:
clearInputError(); clearInputError();
return; return;
...@@ -536,14 +530,13 @@ public class CardUnmaskPrompt implements TextWatcher, OnClickListener, ModalDial ...@@ -536,14 +530,13 @@ public class CardUnmaskPrompt implements TextWatcher, OnClickListener, ModalDial
PorterDuff.Mode.SRC_IN); PorterDuff.Mode.SRC_IN);
// Decide on what field(s) to apply the filter. // Decide on what field(s) to apply the filter.
boolean filterMonth = errorType == ERROR_TYPE_EXPIRATION_MONTH boolean filterMonth = errorType == ErrorType.EXPIRATION_MONTH
|| errorType == ERROR_TYPE_EXPIRATION_DATE || errorType == ErrorType.EXPIRATION_DATE
|| errorType == ERROR_TYPE_CVC_AND_EXPIRATION; || errorType == ErrorType.CVC_AND_EXPIRATION;
boolean filterYear = errorType == ERROR_TYPE_EXPIRATION_YEAR boolean filterYear = errorType == ErrorType.EXPIRATION_YEAR
|| errorType == ERROR_TYPE_EXPIRATION_DATE || errorType == ErrorType.EXPIRATION_DATE
|| errorType == ERROR_TYPE_CVC_AND_EXPIRATION; || errorType == ErrorType.CVC_AND_EXPIRATION;
boolean filterCvc = boolean filterCvc = errorType == ErrorType.CVC || errorType == ErrorType.CVC_AND_EXPIRATION;
errorType == ERROR_TYPE_CVC || errorType == ERROR_TYPE_CVC_AND_EXPIRATION;
updateColorForInput(mMonthInput, filterMonth ? filter : null); updateColorForInput(mMonthInput, filterMonth ? filter : null);
updateColorForInput(mYearInput, filterYear ? filter : null); updateColorForInput(mYearInput, filterYear ? filter : null);
...@@ -557,7 +550,8 @@ public class CardUnmaskPrompt implements TextWatcher, OnClickListener, ModalDial ...@@ -557,7 +550,8 @@ public class CardUnmaskPrompt implements TextWatcher, OnClickListener, ModalDial
* @return The ErrorType value representing the type of error found for the unmask fields. * @return The ErrorType value representing the type of error found for the unmask fields.
*/ */
@ErrorType private int getExpirationAndCvcErrorType() { @ErrorType private int getExpirationAndCvcErrorType() {
@ErrorType int errorType = ERROR_TYPE_NONE; @ErrorType
int errorType = ErrorType.NONE;
if (mShouldRequestExpirationDate) errorType = getExpirationDateErrorType(); if (mShouldRequestExpirationDate) errorType = getExpirationDateErrorType();
...@@ -567,15 +561,15 @@ public class CardUnmaskPrompt implements TextWatcher, OnClickListener, ModalDial ...@@ -567,15 +561,15 @@ public class CardUnmaskPrompt implements TextWatcher, OnClickListener, ModalDial
if (mDidFocusOnCvc && !mCardUnmaskInput.isFocused()) { if (mDidFocusOnCvc && !mCardUnmaskInput.isFocused()) {
// The CVC is invalid and the user has typed in the CVC field, but is not focused on it // The CVC is invalid and the user has typed in the CVC field, but is not focused on it
// now. Add the CVC error to the current error. // now. Add the CVC error to the current error.
if (errorType == ERROR_TYPE_NONE || errorType == ERROR_TYPE_NOT_ENOUGH_INFO) { if (errorType == ErrorType.NONE || errorType == ErrorType.NOT_ENOUGH_INFO) {
errorType = ERROR_TYPE_CVC; errorType = ErrorType.CVC;
} else { } else {
errorType = ERROR_TYPE_CVC_AND_EXPIRATION; errorType = ErrorType.CVC_AND_EXPIRATION;
} }
} else { } else {
// The CVC is invalid but the user is not done with the field. // The CVC is invalid but the user is not done with the field.
// If no other errors were detected, set that there is not enough information. // If no other errors were detected, set that there is not enough information.
if (errorType == ERROR_TYPE_NONE) errorType = ERROR_TYPE_NOT_ENOUGH_INFO; if (errorType == ErrorType.NONE) errorType = ErrorType.NOT_ENOUGH_INFO;
} }
return errorType; return errorType;
...@@ -591,7 +585,7 @@ public class CardUnmaskPrompt implements TextWatcher, OnClickListener, ModalDial ...@@ -591,7 +585,7 @@ public class CardUnmaskPrompt implements TextWatcher, OnClickListener, ModalDial
@ErrorType private int getExpirationDateErrorType() { @ErrorType private int getExpirationDateErrorType() {
if (mThisYear == -1 || mThisMonth == -1) { if (mThisYear == -1 || mThisMonth == -1) {
mValidationWaitsForCalendarTask = true; mValidationWaitsForCalendarTask = true;
return ERROR_TYPE_NOT_ENOUGH_INFO; return ErrorType.NOT_ENOUGH_INFO;
} }
int month = getMonth(); int month = getMonth();
...@@ -599,9 +593,9 @@ public class CardUnmaskPrompt implements TextWatcher, OnClickListener, ModalDial ...@@ -599,9 +593,9 @@ public class CardUnmaskPrompt implements TextWatcher, OnClickListener, ModalDial
if (mMonthInput.getText().length() == EXPIRATION_FIELDS_LENGTH if (mMonthInput.getText().length() == EXPIRATION_FIELDS_LENGTH
|| (!mMonthInput.isFocused() && mDidFocusOnMonth)) { || (!mMonthInput.isFocused() && mDidFocusOnMonth)) {
// mFinishedTypingMonth = true; // mFinishedTypingMonth = true;
return ERROR_TYPE_EXPIRATION_MONTH; return ErrorType.EXPIRATION_MONTH;
} }
return ERROR_TYPE_NOT_ENOUGH_INFO; return ErrorType.NOT_ENOUGH_INFO;
} }
int year = getFourDigitYear(); int year = getFourDigitYear();
...@@ -609,16 +603,16 @@ public class CardUnmaskPrompt implements TextWatcher, OnClickListener, ModalDial ...@@ -609,16 +603,16 @@ public class CardUnmaskPrompt implements TextWatcher, OnClickListener, ModalDial
if (mYearInput.getText().length() == EXPIRATION_FIELDS_LENGTH if (mYearInput.getText().length() == EXPIRATION_FIELDS_LENGTH
|| (!mYearInput.isFocused() && mDidFocusOnYear)) { || (!mYearInput.isFocused() && mDidFocusOnYear)) {
// mFinishedTypingYear = true; // mFinishedTypingYear = true;
return ERROR_TYPE_EXPIRATION_YEAR; return ErrorType.EXPIRATION_YEAR;
} }
return ERROR_TYPE_NOT_ENOUGH_INFO; return ErrorType.NOT_ENOUGH_INFO;
} }
if (year == mThisYear && month < mThisMonth) { if (year == mThisYear && month < mThisMonth) {
return ERROR_TYPE_EXPIRATION_DATE; return ErrorType.EXPIRATION_DATE;
} }
return ERROR_TYPE_NONE; return ErrorType.NONE;
} }
/** /**
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment