Skip to content

Commit

Permalink
start to add assistant fields
Browse files Browse the repository at this point in the history
minor json/logic adjustments
  • Loading branch information
Aaron Huttner authored and Aaron Huttner committed Aug 22, 2016
1 parent 5dfbb20 commit ac48029
Show file tree
Hide file tree
Showing 18 changed files with 186 additions and 35 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -49,9 +49,9 @@
import rx.schedulers.Schedulers;
import timber.log.Timber;

import static com.rockthevote.grommet.data.db.model.Address.Type.MAILING;
import static com.rockthevote.grommet.data.db.model.Address.Type.PREVIOUS;
import static com.rockthevote.grommet.data.db.model.Address.Type.REGISTRATION;
import static com.rockthevote.grommet.data.db.model.Address.Type.MAILING_ADDRESS;
import static com.rockthevote.grommet.data.db.model.Address.Type.PREVIOUS_ADDRESS;
import static com.rockthevote.grommet.data.db.model.Address.Type.REGISTRATION_ADDRESS;
import static com.rockthevote.grommet.data.db.model.RockyRequest.GENERATED_DATE;
import static com.rockthevote.grommet.data.db.model.RockyRequest.STATUS;
import static com.rockthevote.grommet.data.db.model.RockyRequest.Status.ABANDONED;
Expand Down Expand Up @@ -265,11 +265,11 @@ private ApiRockyRequestWrapper zipRockyRequest(RockyRequest rockyRequest,
EnumMap<AdditionalInfo.Type, AdditionalInfo> additionalInfo) {


ApiAddress apiRegAddress = ApiAddress.fromDb(addresses.get(REGISTRATION));
ApiAddress apiRegAddress = ApiAddress.fromDb(addresses.get(REGISTRATION_ADDRESS));
ApiAddress apiMailAddress = rockyRequest.hasMailingAddress() ?
ApiAddress.fromDb(addresses.get(MAILING)) : null;
ApiAddress.fromDb(addresses.get(MAILING_ADDRESS)) : null;
ApiAddress apiPrevAddress = rockyRequest.hasPreviousAddress() ?
ApiAddress.fromDb(addresses.get(PREVIOUS)) : null;
ApiAddress.fromDb(addresses.get(PREVIOUS_ADDRESS)) : null;

ApiName apiName = ApiName.fromDb(names.get(Name.Type.CURRENT_NAME));
ApiName apiPrevName = rockyRequest.hasPreviousName() ?
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ public class DbOpenHelper extends SQLiteOpenHelper {
+ RockyRequest.OPEN_TRACKING_ID + " TEXT,"
+ RockyRequest.GENERATED_DATE + " TEXT NOT NULL,"
+ RockyRequest.DATE_OF_BIRTH + " TEXT,"
+ RockyRequest.HAS_MAILING_ADDRESS + " INTEGER DEFAULT " + Db.BOOLEAN_TRUE + ","
+ RockyRequest.HAS_MAILING_ADDRESS + " INTEGER DEFAULT " + Db.BOOLEAN_FALSE + ","
+ RockyRequest.RACE + " TEXT,"
+ RockyRequest.PARTY + " TEXT,"
+ RockyRequest.SIGNATURE + " BLOB,"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -159,9 +159,10 @@ public ContentValues build() {
}

public enum Type {
MAILING("mailing_address"),
PREVIOUS("previous_address"),
REGISTRATION("registration_address");
MAILING_ADDRESS("mailing_address"),
PREVIOUS_ADDRESS("previous_address"),
REGISTRATION_ADDRESS("registration_address"),
ASSISTANT_ADDRESS("assistant_address");

private final String type;

Expand All @@ -180,7 +181,7 @@ public static Type fromString(String type) {
return val;
}
}
return MAILING;
return MAILING_ADDRESS;
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,9 @@ public static void insertOrUpdate(BriteDatabase db, long rockyRequestId,
}

public enum Type {
PHONE("phone"), EMAIL("email");
PHONE("phone"),
ASSISTANT_PHONE("assistant_phone"),
EMAIL("email");

private final String type;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,8 @@ public ContentValues build() {

public enum Type {
CURRENT_NAME("current_name"),
PREVIOUS_NAME("previous_name");
PREVIOUS_NAME("previous_name"),
ASSISTANT_NAME("assistant_name");

private final String type;

Expand Down
2 changes: 2 additions & 0 deletions app/src/main/java/com/rockthevote/grommet/ui/UiModule.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@


import com.rockthevote.grommet.ui.registration.AdditionalInfoFragment;
import com.rockthevote.grommet.ui.registration.AssistantInfoFragment;
import com.rockthevote.grommet.ui.registration.NewRegistrantFragment;
import com.rockthevote.grommet.ui.registration.PersonalInfoFragment;
import com.rockthevote.grommet.ui.registration.RegistrationActivity;
Expand All @@ -26,6 +27,7 @@
NewRegistrantFragment.class,
PersonalInfoFragment.class,
AdditionalInfoFragment.class,
AssistantInfoFragment.class,
ReviewAndConfirmFragment.class,
AddressView.class,
NameView.class,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -102,8 +102,8 @@ public class AdditionalInfoFragment extends BaseRegistrationFragment {
private PhoneNumberFormattingTextWatcher phoneFormatter;

// must be initialized to true to trigger the observable default, unchecked, state (it's reversed)
private final BehaviorSubject<Boolean> doesNotHavePennDOT = BehaviorSubject.create(true);
private final BehaviorSubject<Boolean> doesNotHaveSSN = BehaviorSubject.create(true);
private final BehaviorSubject<Boolean> doesNotHavePennDOT = BehaviorSubject.create(false);
private final BehaviorSubject<Boolean> doesNotHaveSSN = BehaviorSubject.create(false);

@Nullable
@Override
Expand Down Expand Up @@ -298,7 +298,7 @@ public void onDriversLicenseChecked(boolean checked) {
// disabling it prevents Saripaar from trying to validate it
pennDOTTIL.setEnabled(!checked);
pennDOTTIL.setErrorEnabled(!checked);
doesNotHavePennDOT.onNext(!checked);
doesNotHavePennDOT.onNext(checked);
}

@OnCheckedChanged(R.id.ssn_last_four_checkbox)
Expand All @@ -308,7 +308,7 @@ public void onSSNChecked(boolean checked) {
// disabling it prevents Saripaar from trying to validate it
ssnTIL.setEnabled(!checked);
ssnTIL.setErrorEnabled(!checked);
doesNotHaveSSN.onNext(!checked);
doesNotHaveSSN.onNext(checked);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
package com.rockthevote.grommet.ui.registration;

import android.os.Bundle;
import android.support.annotation.Nullable;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import com.f2prateek.rx.preferences.Preference;
import com.rockthevote.grommet.R;
import com.rockthevote.grommet.data.prefs.CurrentRockyRequestId;
import com.squareup.sqlbrite.BriteDatabase;

import javax.inject.Inject;

import butterknife.ButterKnife;

public class AssistantInfoFragment extends BaseRegistrationFragment {

@Inject @CurrentRockyRequestId Preference<Long> rockyRequestRowId;

@Inject BriteDatabase db;

@Nullable
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
setContentView(R.layout.fragment_assistant_info);
return super.onCreateView(inflater, container, savedInstanceState);
}

@Override
public void onViewCreated(View view, Bundle savedInstanceState) {
super.onViewCreated(view, savedInstanceState);
ButterKnife.bind(this, view);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ public RegistrationPagerAdapter(FragmentManager fm, Context context) {
titles.put(0, context.getString(R.string.fragment_title_new_registrant));
titles.put(1, context.getString(R.string.fragment_title_personal_info));
titles.put(2, context.getString(R.string.fragment_title_additional_info));
// titles.put(3, context.getString(R.string.fragment_title_assistant_info));
titles.put(3, context.getString(R.string.fragment_title_review));
}

Expand All @@ -36,6 +37,8 @@ private Fragment getNewFragment(int position) {
return new PersonalInfoFragment();
case 2:
return new AdditionalInfoFragment();
// case 3:
// return new AssistantInfoFragment();
case 3:
return new ReviewAndConfirmFragment();
default:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,8 @@
import rx.android.schedulers.AndroidSchedulers;
import rx.subscriptions.CompositeSubscription;

import static com.rockthevote.grommet.data.db.model.Address.Type.MAILING;
import static com.rockthevote.grommet.data.db.model.Address.Type.REGISTRATION;
import static com.rockthevote.grommet.data.db.model.Address.Type.MAILING_ADDRESS;
import static com.rockthevote.grommet.data.db.model.Address.Type.REGISTRATION_ADDRESS;
import static com.rockthevote.grommet.data.db.model.ContactMethod.Type.EMAIL;
import static com.rockthevote.grommet.data.db.model.ContactMethod.Type.PHONE;
import static com.rockthevote.grommet.data.db.model.Name.Type.CURRENT_NAME;
Expand Down Expand Up @@ -103,7 +103,7 @@ public void onResume() {
}));

subscriptions.add(db.createQuery(Address.TABLE, Address.SELECT_BY_TYPE,
new String[]{String.valueOf(rockyRequestRowId.get()), REGISTRATION.toString()})
new String[]{String.valueOf(rockyRequestRowId.get()), REGISTRATION_ADDRESS.toString()})
.mapToOne(Address.MAPPER)
.observeOn(AndroidSchedulers.mainThread())
.subscribe(address -> {
Expand All @@ -126,7 +126,7 @@ public void onResume() {
}));

subscriptions.add(db.createQuery(Address.TABLE, Address.SELECT_BY_TYPE,
new String[]{String.valueOf(rockyRequestRowId.get()), MAILING.toString()})
new String[]{String.valueOf(rockyRequestRowId.get()), MAILING_ADDRESS.toString()})
.mapToOne(Address.MAPPER)
.observeOn(AndroidSchedulers.mainThread())
.subscribe(address -> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -102,14 +102,16 @@ public AddressView(Context context, AttributeSet attrs, int defStyleAttr) {
int val = typedArray.getInt(R.styleable.AddressView_address_type, 0);
switch (val) {
case 1:
type = Address.Type.MAILING;
type = Address.Type.MAILING_ADDRESS;
break;
case 2:
type = Address.Type.PREVIOUS;
type = Address.Type.PREVIOUS_ADDRESS;
break;
case 3:
type = Address.Type.REGISTRATION;
type = Address.Type.REGISTRATION_ADDRESS;
break;
case 4:
type = Address.Type.ASSISTANT_ADDRESS;
}
} finally {
typedArray.recycle();
Expand All @@ -124,15 +126,17 @@ protected void onFinishInflate() {
validator = new ObservableValidator(this, getContext());

switch (type) {
case REGISTRATION:
case REGISTRATION_ADDRESS:
sectionTitle.setText(R.string.section_label_registration_address);
break;
case MAILING:
case MAILING_ADDRESS:
sectionTitle.setText(R.string.section_label_mailing_address);
break;
case PREVIOUS:
case PREVIOUS_ADDRESS:
sectionTitle.setText(R.string.section_label_previous_address);
break;
case ASSISTANT_ADDRESS:
sectionTitle.setText(R.string.section_label_registration_address);
}

countyAdapter = ArrayAdapter.createFromResource(getContext(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,9 @@ public NameView(Context context, AttributeSet attrs, int defStyleAttr) {
case 2:
type = Name.Type.PREVIOUS_NAME;
break;
case 3:
type = Name.Type.ASSISTANT_NAME;
break;
}
} finally {
typedArray.recycle();
Expand All @@ -123,6 +126,9 @@ protected void onFinishInflate() {
case PREVIOUS_NAME:
sectionTitle.setText(R.string.section_label_previous_name);
break;
case ASSISTANT_NAME:
sectionTitle.setText(R.string.section_label_name);
break;
}

titleEnumAdapter = new EnumAdapter<>(getContext(), Name.Prefix.class);
Expand Down
2 changes: 2 additions & 0 deletions app/src/main/res/layout/activity_registration.xml
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@
android:layout_height="@dimen/increment"
android:background="@android:color/transparent"
android:elevation="4dp"
app:tabMode="fixed"
app:tabGravity="fill"
tools:background="@color/colorSecondaryText"
/>

Expand Down
1 change: 1 addition & 0 deletions app/src/main/res/layout/fragment_additional_info.xml
Original file line number Diff line number Diff line change
Expand Up @@ -209,4 +209,5 @@
android:paddingBottom="@dimen/content_area_padding"
android:paddingTop="@dimen/content_area_padding"
android:text="@string/label_receive_text"/>

</GridLayout>
89 changes: 89 additions & 0 deletions app/src/main/res/layout/fragment_assistant_info.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
<?xml version="1.0" encoding="utf-8"?>
<GridLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:animateLayoutChanges="true"
android:columnCount="2"
android:useDefaultMargins="true"
>

<CheckBox
android:id="@+id/checkbox_has_assistant"
style="@style/GrommetContentArea"
android:layout_width="wrap_content"
android:layout_columnSpan="2"
android:paddingBottom="@dimen/content_area_padding"
android:paddingTop="@dimen/content_area_padding"
android:text="@string/label_has_assistant"/>

<View
style="@style/GrommetDivider"
android:layout_width="0dp"
android:layout_columnSpan="2"
android:layout_gravity="fill_horizontal"
android:layout_marginStart="@dimen/content_margin"
android:paddingBottom="@dimen/content_area_padding"
android:paddingTop="@dimen/content_area_padding"/>

<TextView
android:id="@+id/assistant_section_label"
android:layout_width="match_parent"
android:layout_columnSpan="2"
android:layout_marginEnd="@dimen/content_margin"
android:layout_marginStart="@dimen/content_margin"
android:paddingBottom="@dimen/content_area_padding"
android:paddingTop="@dimen/content_area_padding"
android:text="@string/section_label_assistant"
android:textAppearance="@android:style/TextAppearance.Material.Subhead"/>

<com.rockthevote.grommet.ui.views.NameView
android:id="@+id/name"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_columnSpan="2"
android:layout_gravity="start|bottom"
app:name_type="ASSISTANT"/>

<com.rockthevote.grommet.ui.views.AddressView
android:id="@+id/assistant_address"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_columnSpan="2"
android:layout_gravity="start|bottom"
android:visibility="gone"
app:address_type="ASSISTANT"
tools:visibility="visible"
/>

<android.support.design.widget.TextInputLayout
android:id="@+id/til_assistant_phone_number"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_columnWeight=".7"
android:layout_gravity="fill_horizontal"
android:layout_marginStart="@dimen/content_margin"
app:errorEnabled="true">

<android.support.design.widget.TextInputEditText
android:id="@+id/assistant_phone"
android:layout_width="match_parent"
android:layout_height="@dimen/list_item_height"
android:hint="@string/label_phone"
android:inputType="phone"
android:maxLines="1"/>

</android.support.design.widget.TextInputLayout>

<CheckBox
android:id="@+id/checkbox_assistant_affirmation"
style="@style/GrommetContentArea"
android:layout_width="wrap_content"
android:layout_columnSpan="2"
android:paddingBottom="@dimen/content_area_padding"
android:paddingTop="@dimen/content_area_padding"
tools:text="a agree to stuff and things"/>

</GridLayout>
7 changes: 3 additions & 4 deletions app/src/main/res/layout/tab_stepper.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
android:layout_height="wrap_content"
android:background="@android:color/transparent"
android:gravity="center"
android:orientation="horizontal">
android:orientation="vertical">

<TextView
android:id="@+id/step_number"
Expand All @@ -24,9 +24,8 @@
android:id="@+id/step_name"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:gravity="center_vertical"
android:paddingStart="@dimen/content_area_padding"
android:layout_gravity="center"
android:gravity="center"
android:textAllCaps="false"
android:textAppearance="@android:style/TextAppearance.Material.Widget.TabWidget"
android:textColor="@color/selector_enabled_text_color"
Expand Down
Loading

0 comments on commit ac48029

Please sign in to comment.