Skip to content

Commit

Permalink
- don't call complete callback twice
Browse files Browse the repository at this point in the history
  • Loading branch information
dbachelder committed May 14, 2015
1 parent e1e1371 commit 73cdd7a
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 21 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import android.os.Parcelable;
import android.os.SystemClock;
import android.support.annotation.NonNull;
import android.text.Editable;
import android.text.InputType;
import android.text.TextWatcher;
import android.util.AttributeSet;
Expand All @@ -27,8 +28,9 @@ public abstract class CreditEntryFieldBase extends EditText implements

CreditCardFieldDelegate delegate;
final Context context;

private boolean valid = false;
String lastValue = null;

private boolean valid = false;

public CreditEntryFieldBase(Context context) {
super(context);
Expand Down Expand Up @@ -65,9 +67,17 @@ public void onTextChanged(CharSequence s, int start, int before, int end) {
if (delegate != null) {
delegate.focusOnPreviousField(this);
}
}
} else if(!String.valueOf(s).equals(String.valueOf(lastValue))) {
lastValue = String.valueOf(s);
textChanged(s, start, before, end);
}
}

@Override public void beforeTextChanged(CharSequence s, int start, int count, int after) {}
@Override public void afterTextChanged(Editable s) {}

public void textChanged(CharSequence s, int start, int before, int end) { }

@Override
public InputConnection onCreateInputConnection(@NonNull EditorInfo outAttrs) {
outAttrs.actionLabel = null;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,29 +36,26 @@ void init() {
}

/* TextWatcher Implementation Methods */
public void beforeTextChanged(CharSequence s, int start, int count,
int after) {
}

public void beforeTextChanged(CharSequence s, int start, int count, int after) {}
public void afterTextChanged(Editable s) {

if(type == null) {
this.removeTextChangedListener(this);
this.setText("");
this.addTextChangedListener(this);
}
}

public void textChanged(CharSequence s, int start, int before, int count) {
if (type != null) {
String number = s.toString();

if (number.length() == length) {
delegate.onSecurityCodeValid();
setValid(true);
}
else
{
} else {
setValid(false);
}
} else {
this.removeTextChangedListener(this);
this.setText("");
this.addTextChangedListener(this);
}

}

@SuppressWarnings("unused")
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package com.devmarvel.creditcardentry.fields;

import android.content.Context;
import android.text.Editable;
import android.text.InputFilter;
import android.util.AttributeSet;

Expand Down Expand Up @@ -35,10 +34,8 @@ public String helperText() {
return context.getString(R.string.ZipHelp);
}

/* TextWatcher Implementation Methods */
public void beforeTextChanged(CharSequence s, int start, int count, int after) { }

public void afterTextChanged(Editable s) {
@Override
public void textChanged(CharSequence s, int start, int before, int end) {
String zipCode = s.toString();
if (zipCode.length() == 5) {
delegate.onZipCodeValid();
Expand Down
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,9 @@ In code:

# Version History

###5/14/2015
- don't call complete callback twice

###5/13/2015
- add setters for other CC fields
- correctly manage state such that more than one form on a screen can handle state change
Expand Down

0 comments on commit 73cdd7a

Please sign in to comment.