diff --git a/app/build.gradle b/app/build.gradle index b4229cd3..53214c08 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -1,7 +1,7 @@ // Manifest version information! def versionMajor = 1 def versionMinor = 1 -def versionPatch = 2 +def versionPatch = 3 def versionBuild = 0 // bump for dogfood builds, public betas, etc. apply plugin: 'com.android.application' diff --git a/app/src/main/java/com/rockthevote/grommet/data/api/model/ApiContactMethod.java b/app/src/main/java/com/rockthevote/grommet/data/api/model/ApiContactMethod.java index a0adf587..7699780f 100644 --- a/app/src/main/java/com/rockthevote/grommet/data/api/model/ApiContactMethod.java +++ b/app/src/main/java/com/rockthevote/grommet/data/api/model/ApiContactMethod.java @@ -11,6 +11,7 @@ import java.util.ArrayList; import java.util.List; +import static com.rockthevote.grommet.data.db.model.ContactMethod.Type.PHONE; import static com.rockthevote.grommet.data.db.model.RockyRequest.PhoneType; @AutoValue @@ -44,7 +45,7 @@ public static ApiContactMethod fromContactMethod(ContactMethod contactMethod, Ph List capabilities = new ArrayList<>(); // right now we only support phone (no fax) - if (contactMethod.type() == ContactMethod.Type.PHONE || + if (contactMethod.type() == PHONE || contactMethod.type() == ContactMethod.Type.ASSISTANT_PHONE) { capabilities.add(ContactMethod.Capability.VOICE.toString()); if(phoneType == PhoneType.MOBILE){ @@ -52,8 +53,25 @@ public static ApiContactMethod fromContactMethod(ContactMethod contactMethod, Ph } } + /* + special replacement for assistant_phone. We need to just use "phone" as the string value + for this enum but we cannot change the enum since both voter and helper phone numbers + are stored in the same table, hence we need different types to differentiate. + */ + + String type; + switch (contactMethod.type()) { + case ASSISTANT_PHONE: + case PHONE: + type = PHONE.toString(); + break; + default: + type = contactMethod.type().toString(); + break; + } + return builder() - .type(contactMethod.type().toString()) + .type(type) .value(contactMethod.value()) .capabilities(capabilities) .build(); diff --git a/app/src/main/java/com/rockthevote/grommet/ui/registration/AdditionalInfoFragment.java b/app/src/main/java/com/rockthevote/grommet/ui/registration/AdditionalInfoFragment.java index f130de7f..dc89c760 100644 --- a/app/src/main/java/com/rockthevote/grommet/ui/registration/AdditionalInfoFragment.java +++ b/app/src/main/java/com/rockthevote/grommet/ui/registration/AdditionalInfoFragment.java @@ -11,7 +11,6 @@ import android.widget.EditText; import com.f2prateek.rx.preferences.Preference; -import com.google.i18n.phonenumbers.PhoneNumberUtil; import com.jakewharton.rxbinding.widget.RxCompoundButton; import com.jakewharton.rxbinding.widget.RxTextView; import com.mobsandgeeks.saripaar.Validator; @@ -28,7 +27,7 @@ import com.rockthevote.grommet.ui.misc.EnumAdapter; import com.rockthevote.grommet.ui.misc.ObservableValidator; import com.rockthevote.grommet.util.EmailOrEmpty; -import com.rockthevote.grommet.util.PhoneOrEmpty; +import com.rockthevote.grommet.util.Phone; import com.squareup.sqlbrite.BriteDatabase; import java.util.concurrent.TimeUnit; @@ -88,7 +87,7 @@ public class AdditionalInfoFragment extends BaseRegistrationFragment { @BindView(R.id.email_opt_in) CheckBox emailOptIn; - @PhoneOrEmpty(messageResId = R.string.phone_format_error) + @Phone(messageResId = R.string.phone_format_error, allowEmpty = true) @BindView(R.id.til_phone_number) TextInputLayout phoneNumber; @BindView(R.id.phone) EditText phone; @@ -127,7 +126,7 @@ public void onViewCreated(View view, Bundle savedInstanceState) { super.onViewCreated(view, savedInstanceState); ButterKnife.bind(this, view); - Validator.registerAnnotation(PhoneOrEmpty.class); + Validator.registerAnnotation(Phone.class); Validator.registerAnnotation(EmailOrEmpty.class); Validator.registerAnnotation(NotEmpty.class); @@ -195,7 +194,7 @@ public void onResume() { super.onResume(); subscriptions = new CompositeSubscription(); - phoneFormatter = new PhoneNumberFormattingTextWatcher("en"); + phoneFormatter = new PhoneNumberFormattingTextWatcher("US"); phone.addTextChangedListener(phoneFormatter); subscriptions.add(RxTextView.afterTextChangeEvents(raceSpinner.getEditText()) diff --git a/app/src/main/java/com/rockthevote/grommet/ui/registration/AssistantInfoFragment.java b/app/src/main/java/com/rockthevote/grommet/ui/registration/AssistantInfoFragment.java index 8ad111e0..6db20c78 100644 --- a/app/src/main/java/com/rockthevote/grommet/ui/registration/AssistantInfoFragment.java +++ b/app/src/main/java/com/rockthevote/grommet/ui/registration/AssistantInfoFragment.java @@ -11,17 +11,19 @@ import android.widget.EditText; import com.f2prateek.rx.preferences.Preference; +import com.jakewharton.rxbinding.widget.RxCompoundButton; import com.jakewharton.rxbinding.widget.RxTextView; import com.mobsandgeeks.saripaar.Validator; import com.mobsandgeeks.saripaar.annotation.Checked; import com.rockthevote.grommet.R; +import com.rockthevote.grommet.data.db.model.AdditionalInfo; import com.rockthevote.grommet.data.db.model.ContactMethod; import com.rockthevote.grommet.data.db.model.RockyRequest; import com.rockthevote.grommet.data.prefs.CurrentRockyRequestId; import com.rockthevote.grommet.ui.misc.ObservableValidator; import com.rockthevote.grommet.ui.views.AddressView; import com.rockthevote.grommet.ui.views.NameView; -import com.rockthevote.grommet.util.PhoneOrEmpty; +import com.rockthevote.grommet.util.Phone; import com.squareup.sqlbrite.BriteDatabase; import java.util.concurrent.TimeUnit; @@ -36,6 +38,7 @@ import rx.subscriptions.CompositeSubscription; import static com.rockthevote.grommet.data.db.Db.DEBOUNCE; +import static com.rockthevote.grommet.data.db.model.AdditionalInfo.Type.ASSISTANT_DECLARATION; import static com.rockthevote.grommet.data.db.model.ContactMethod.Type.ASSISTANT_PHONE; public class AssistantInfoFragment extends BaseRegistrationFragment { @@ -46,7 +49,7 @@ public class AssistantInfoFragment extends BaseRegistrationFragment { @BindView(R.id.assistant_address) AddressView addressView; - @PhoneOrEmpty(messageResId = R.string.phone_format_error) + @Phone(messageResId = R.string.phone_format_error) @BindView(R.id.til_assistant_phone) TextInputLayout phoneTIL; @BindView(R.id.assistant_phone) EditText phoneEditText; @@ -78,7 +81,7 @@ public void onViewCreated(View view, Bundle savedInstanceState) { super.onViewCreated(view, savedInstanceState); ButterKnife.bind(this, view); - Validator.registerAnnotation(PhoneOrEmpty.class); + Validator.registerAnnotation(Phone.class); validator = new ObservableValidator(this, getActivity()); } @@ -88,7 +91,7 @@ public void onResume() { super.onResume(); subscriptions = new CompositeSubscription(); - phoneFormatter = new PhoneNumberFormattingTextWatcher("en"); + phoneFormatter = new PhoneNumberFormattingTextWatcher("US"); phoneEditText.addTextChangedListener(phoneFormatter); subscriptions.add(RxTextView.afterTextChangeEvents(phoneEditText) @@ -103,6 +106,18 @@ public void onResume() { ); })); + subscriptions.add(RxCompoundButton.checkedChanges(assistantAffirmation) + .observeOn(Schedulers.io()) + .debounce(DEBOUNCE, TimeUnit.MILLISECONDS) + .skip(1) + .subscribe(checked -> { + AdditionalInfo.insertOrUpdate(db, rockyRequestRowId.get(), + ASSISTANT_DECLARATION, new AdditionalInfo.Builder() + .type(ASSISTANT_DECLARATION) + .stringValue(String.valueOf(checked)) + .build()); + })); + } @Override diff --git a/app/src/main/java/com/rockthevote/grommet/util/Phone.java b/app/src/main/java/com/rockthevote/grommet/util/Phone.java new file mode 100644 index 00000000..1b3a7fc5 --- /dev/null +++ b/app/src/main/java/com/rockthevote/grommet/util/Phone.java @@ -0,0 +1,23 @@ +package com.rockthevote.grommet.util; + + +import com.mobsandgeeks.saripaar.annotation.ValidateUsing; + +import java.lang.annotation.ElementType; +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; +import java.lang.annotation.Target; + +@ValidateUsing(PhoneRule.class) +@Retention(RetentionPolicy.RUNTIME) +@Target(ElementType.FIELD) + +public @interface Phone { + int messageResId() default -1; // Mandatory attribute + + String message() default "Oops... too pricey"; // Mandatory attribute + + int sequence() default -1; // Mandatory attribute + + boolean allowEmpty() default false; +} diff --git a/app/src/main/java/com/rockthevote/grommet/util/PhoneOrEmpty.java b/app/src/main/java/com/rockthevote/grommet/util/PhoneOrEmpty.java deleted file mode 100644 index edb8a296..00000000 --- a/app/src/main/java/com/rockthevote/grommet/util/PhoneOrEmpty.java +++ /dev/null @@ -1,19 +0,0 @@ -package com.rockthevote.grommet.util; - - -import com.mobsandgeeks.saripaar.annotation.ValidateUsing; - -import java.lang.annotation.ElementType; -import java.lang.annotation.Retention; -import java.lang.annotation.RetentionPolicy; -import java.lang.annotation.Target; - -@ValidateUsing(PhoneOrEmptyRule.class) -@Retention(RetentionPolicy.RUNTIME) -@Target(ElementType.FIELD) - -public @interface PhoneOrEmpty { - public int messageResId() default -1; // Mandatory attribute - public String message() default "Oops... too pricey"; // Mandatory attribute - public int sequence() default -1; // Mandatory attribute -} diff --git a/app/src/main/java/com/rockthevote/grommet/util/PhoneOrEmptyRule.java b/app/src/main/java/com/rockthevote/grommet/util/PhoneRule.java similarity index 77% rename from app/src/main/java/com/rockthevote/grommet/util/PhoneOrEmptyRule.java rename to app/src/main/java/com/rockthevote/grommet/util/PhoneRule.java index 7c5ba9e1..92b5f16c 100644 --- a/app/src/main/java/com/rockthevote/grommet/util/PhoneOrEmptyRule.java +++ b/app/src/main/java/com/rockthevote/grommet/util/PhoneRule.java @@ -5,17 +5,18 @@ import com.google.i18n.phonenumbers.Phonenumber; import com.mobsandgeeks.saripaar.AnnotationRule; -public class PhoneOrEmptyRule extends AnnotationRule { +public class PhoneRule extends AnnotationRule { - protected PhoneOrEmptyRule(final PhoneOrEmpty email) { - super(email); + protected PhoneRule(final Phone phone) { + super(phone); } @Override public boolean isValid(final String phone) { - if (Strings.isBlank(phone)) { + if (mRuleAnnotation.allowEmpty() && Strings.isBlank(phone)) { return true; } + PhoneNumberUtil phoneUtil = PhoneNumberUtil.getInstance(); Phonenumber.PhoneNumber number; try { diff --git a/build.gradle b/build.gradle index 253ef5fa..abb5b5d9 100644 --- a/build.gradle +++ b/build.gradle @@ -6,7 +6,7 @@ buildscript { jcenter() } dependencies { - classpath 'com.android.tools.build:gradle:2.2.0-beta2' + classpath 'com.android.tools.build:gradle:2.2.0-beta3' classpath 'com.neenbedankt.gradle.plugins:android-apt:1.8' classpath('com.stanfy.spoon:spoon-gradle-plugin:1.0.3') { // Workaround for https://github.com/stanfy/spoon-gradle-plugin/issues/33