Skip to content

Commit

Permalink
fix assistant info bugs
Browse files Browse the repository at this point in the history
  • Loading branch information
Aaron Huttner authored and Aaron Huttner committed Sep 1, 2016
1 parent 81a2e2e commit f6dcec0
Show file tree
Hide file tree
Showing 8 changed files with 73 additions and 36 deletions.
2 changes: 1 addition & 1 deletion app/build.gradle
Original file line number Diff line number Diff line change
@@ -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'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -44,16 +45,33 @@ public static ApiContactMethod fromContactMethod(ContactMethod contactMethod, Ph

List<String> 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){
capabilities.add(ContactMethod.Capability.SMS.toString());
}
}

/*
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();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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);

Expand Down Expand Up @@ -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())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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 {
Expand All @@ -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;
Expand Down Expand Up @@ -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());

}
Expand All @@ -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)
Expand All @@ -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
Expand Down
23 changes: 23 additions & 0 deletions app/src/main/java/com/rockthevote/grommet/util/Phone.java
Original file line number Diff line number Diff line change
@@ -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;
}
19 changes: 0 additions & 19 deletions app/src/main/java/com/rockthevote/grommet/util/PhoneOrEmpty.java

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -5,17 +5,18 @@
import com.google.i18n.phonenumbers.Phonenumber;
import com.mobsandgeeks.saripaar.AnnotationRule;

public class PhoneOrEmptyRule extends AnnotationRule<PhoneOrEmpty, String> {
public class PhoneRule extends AnnotationRule<Phone, String> {

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 {
Expand Down
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit f6dcec0

Please sign in to comment.