Skip to content

Commit 039818d

Browse files
Aaron HuttnerAaron Huttner
authored andcommitted
Update county names.
Add image helper methods to change the aspect ratio of the signature and shrink the file size Add other party field. Change registration address --> residential address version bump
1 parent bc42e85 commit 039818d

18 files changed

Lines changed: 304 additions & 111 deletions

.idea/misc.xml

Lines changed: 0 additions & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

app/build.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
// Manifest version information!
22
def versionMajor = 1
33
def versionMinor = 0
4-
def versionPatch = 6
4+
def versionPatch = 7
55
def versionBuild = 0 // bump for dogfood builds, public betas, etc.
66

77
apply plugin: 'com.android.application'

app/src/main/java/com/rockthevote/grommet/data/api/ApiModule.java

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22

33
import com.squareup.moshi.Moshi;
44

5+
import java.util.concurrent.TimeUnit;
6+
57
import javax.inject.Named;
68
import javax.inject.Singleton;
79

@@ -51,6 +53,7 @@ public final class ApiModule {
5153

5254
// add the O-Auth interceptor here
5355
static OkHttpClient.Builder createApiClient(OkHttpClient client) {
54-
return client.newBuilder();
56+
return client.newBuilder()
57+
.connectTimeout(10000, TimeUnit.MILLISECONDS);
5558
}
5659
}

app/src/main/java/com/rockthevote/grommet/data/api/RegistrationService.java

Lines changed: 32 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -152,31 +152,45 @@ private void doWork(final RockyRequest rockyRequest) {
152152
stopSelf();
153153
}
154154
})
155-
.subscribe(regResponse -> {
156-
RockyRequest.Status status =
157-
!regResponse.isError() && regResponse.response().isSuccessful()
158-
? REGISTER_SUCCESS : REGISTER_SERVER_FAILURE;
159-
160-
161-
UploadNotification.notify(getApplicationContext(), status);
162-
163-
db.update(RockyRequest.TABLE,
164-
new RockyRequest.Builder()
165-
.status(status)
166-
.build(),
167-
RockyRequest._ID + " = ? ", String.valueOf(rockyRequest.id()));
155+
.subscribe(regResponse ->
156+
{
157+
if (regResponse.isError()) {
158+
// there was an error contacting the server, don't delete the row
159+
UploadNotification.notify(getApplicationContext(), REGISTER_SERVER_FAILURE);
160+
} else {
161+
162+
RockyRequest.Status status;
163+
164+
if (regResponse.response().isSuccessful()) {
165+
status = REGISTER_SUCCESS;
166+
} else {
167+
int code = regResponse.response().code();
168+
if (code < 500) {
169+
status = REGISTER_CLIENT_FAILURE;
170+
} else {
171+
status = REGISTER_SERVER_FAILURE;
172+
}
173+
}
174+
updateRegistrationStatus(status, rockyRequest.id());
175+
}
168176
},
169177
throwable -> {
170178
// mark the row for removal if the data is corrupt
171-
db.update(RockyRequest.TABLE,
172-
new RockyRequest.Builder()
173-
.status(REGISTER_CLIENT_FAILURE)
174-
.build(),
175-
RockyRequest._ID + " = ? ", String.valueOf(rockyRequest.id()));
179+
// this is a client error, meaning the network request was never made
180+
updateRegistrationStatus(REGISTER_CLIENT_FAILURE, rockyRequest.id());
176181
}
177182
);
178183
}
179184

185+
private void updateRegistrationStatus(RockyRequest.Status status, long rowId) {
186+
UploadNotification.notify(getApplicationContext(), status);
187+
db.update(RockyRequest.TABLE,
188+
new RockyRequest.Builder()
189+
.status(status)
190+
.build(),
191+
RockyRequest._ID + " = ? ", String.valueOf(rowId));
192+
}
193+
180194
/**
181195
* check for <p>
182196
* {@link RockyRequest.Status#ABANDONED},<p>

app/src/main/java/com/rockthevote/grommet/data/api/model/ApiVoterRegistration.java

Lines changed: 20 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,19 @@ public static ApiVoterRegistration fromDb(RockyRequest rockyRequest,
124124
List<ApiAdditionalInfo> additionalInfo,
125125
ApiRegistrationHelper registrationHelper) {
126126

127-
return builder()
127+
String party;
128+
switch (rockyRequest.party()) {
129+
case OTHER_PARTY:
130+
party = rockyRequest.otherParty();
131+
break;
132+
default:
133+
party = rockyRequest.party().toString();
134+
break;
135+
}
136+
137+
Builder builder = builder();
138+
139+
builder
128140
.dateOfBirth(Dates.formatAsISO8601_ShortDate(rockyRequest.dateOfBirth()))
129141
.mailingAddress(mailingAddress)
130142
.previousRegistrationAddress(previousRegistrationAddress)
@@ -133,14 +145,18 @@ public static ApiVoterRegistration fromDb(RockyRequest rockyRequest,
133145
.name(name)
134146
.previousName(previousName)
135147
.gender(Gender.fromPrefix(Prefix.fromString(name.titlePrefix())).toString())
136-
.race(rockyRequest.race().toString())
137-
.party(rockyRequest.party().toString())
148+
.party(party)
138149
.voterClassifications(voterClassifications)
139150
.signature(signature)
140151
.voterIds(voterIds)
141152
.contactMethods(contactMethods)
142153
.additionalInfo(additionalInfo)
143154
.registrationHelper(registrationHelper)
144-
.build();
155+
;
156+
157+
if (null != rockyRequest.race()) {
158+
builder.race(rockyRequest.race().toString());
159+
}
160+
return builder.build();
145161
}
146162
}

app/src/main/java/com/rockthevote/grommet/data/db/DbOpenHelper.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,8 @@ public class DbOpenHelper extends SQLiteOpenHelper {
4545
+ RockyRequest.LONGITUDE + " REAL,"
4646
+ RockyRequest.HAS_PREVIOUS_NAME + " INTEGER DEFAULT " + Db.BOOLEAN_FALSE + ","
4747
+ RockyRequest.HAS_PREVIOUS_ADDRESS + " INTEGER DEFAULT " + Db.BOOLEAN_FALSE + ","
48-
+ RockyRequest.HAS_ASSISTANT + " INTEGER DEFAULT " + Db.BOOLEAN_FALSE
48+
+ RockyRequest.HAS_ASSISTANT + " INTEGER DEFAULT " + Db.BOOLEAN_FALSE + ","
49+
+ RockyRequest.OTHER_PARTY + " TEXT "
4950
+ ")";
5051

5152
private static final String CREATE_ADDRESS = ""

app/src/main/java/com/rockthevote/grommet/data/db/model/RockyRequest.java

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ public abstract class RockyRequest implements Parcelable, BaseColumns {
4343
public static final String HAS_PREVIOUS_NAME = "has_previous_name";
4444
public static final String HAS_PREVIOUS_ADDRESS = "has_previous_address";
4545
public static final String HAS_ASSISTANT = "has_assistant";
46+
public static final String OTHER_PARTY = "other_party";
4647

4748
public static final String SELECT_BY_ID = ""
4849
+ "SELECT * FROM "
@@ -92,10 +93,8 @@ public abstract class RockyRequest implements Parcelable, BaseColumns {
9293

9394
public abstract boolean hasMailingAddress();
9495

95-
@Nullable
9696
public abstract Race race();
9797

98-
@Nullable
9998
public abstract Party party();
10099

101100
@Nullable
@@ -111,6 +110,9 @@ public abstract class RockyRequest implements Parcelable, BaseColumns {
111110

112111
public abstract boolean hasAssistant();
113112

113+
@Nullable
114+
public abstract String otherParty();
115+
114116
public static final Func1<Cursor, RockyRequest> MAPPER = cursor -> {
115117
long id = Db.getLong(cursor, _ID);
116118
Status status = Status.fromString(Db.getString(cursor, STATUS));
@@ -136,12 +138,13 @@ public abstract class RockyRequest implements Parcelable, BaseColumns {
136138
boolean hasPreviousName = Db.getBoolean(cursor, HAS_PREVIOUS_NAME);
137139
boolean hasPreviousAddress = Db.getBoolean(cursor, HAS_PREVIOUS_ADDRESS);
138140
boolean hasAssistant = Db.getBoolean(cursor, HAS_ASSISTANT);
141+
String otherParty = Db.getString(cursor, OTHER_PARTY);
139142

140143
return new AutoValue_RockyRequest(id, status, language, phoneType, partnerId, optInEmail, optInSMS,
141144
optInVolunteer, partnerOptInSMS, partnerOptInEmail,
142145
sourceTrackingId, partnerTrackingId, openTrackingId,
143146
generatedDate, dateOfBirth, hasMailingAddress, race, party, signature,
144-
latitude, longitude, hasPreviousName, hasPreviousAddress, hasAssistant);
147+
latitude, longitude, hasPreviousName, hasPreviousAddress, hasAssistant, otherParty);
145148
};
146149

147150
public static final class Builder {
@@ -272,6 +275,11 @@ public Builder hasAssistant(boolean hasAssistant) {
272275
return this;
273276
}
274277

278+
public Builder otherParty(String otherParty) {
279+
values.put(OTHER_PARTY, otherParty);
280+
return this;
281+
}
282+
275283
public ContentValues build() {
276284
return values;
277285
}
@@ -311,7 +319,8 @@ public static Race fromString(String race) {
311319
public enum Party {
312320
DEMOCRATIC("Democratic"),
313321
REPUBLICAN("Republican"),
314-
OTHER("Other");
322+
NO_PARTY("none"),
323+
OTHER_PARTY("Other");
315324

316325
private final String party;
317326

@@ -330,7 +339,7 @@ public static Party fromString(String party) {
330339
return val;
331340
}
332341
}
333-
return OTHER;
342+
return OTHER_PARTY;
334343
}
335344
}
336345

app/src/main/java/com/rockthevote/grommet/ui/UploadNotification.java

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@ public static void notify(final Context context, RockyRequest.Status status) {
5555
new Intent(context, MainActivity.class),
5656
PendingIntent.FLAG_UPDATE_CURRENT))
5757
.setContentTitle(context.getString(getNotifTitle(status)))
58+
.setContentText(context.getString(getContentText(status)))
5859
.setSmallIcon(R.drawable.ic_stat_upload)
5960
.setAutoCancel(false);
6061

@@ -71,12 +72,26 @@ int getNotifTitle(RockyRequest.Status status) {
7172
switch (status) {
7273
case REGISTER_SUCCESS:
7374
return R.string.upload_notification_title_success;
74-
default:
7575
case REGISTER_SERVER_FAILURE:
76+
default:
7677
return R.string.upload_notification_title_failure;
7778
}
7879
}
7980

81+
private static
82+
@StringRes
83+
int getContentText(RockyRequest.Status status) {
84+
switch (status) {
85+
case REGISTER_SUCCESS:
86+
return R.string.upload_notification_content_success;
87+
case REGISTER_CLIENT_FAILURE:
88+
return R.string.upload_notification_content_client_failure;
89+
case REGISTER_SERVER_FAILURE:
90+
default:
91+
return R.string.upload_notification_content_connection_failure;
92+
}
93+
}
94+
8095
private static int getNotificationId(RockyRequest.Status status) {
8196
switch (status) {
8297
case REGISTER_SUCCESS:
@@ -98,8 +113,7 @@ private static String getNotificationTag(RockyRequest.Status status) {
98113
}
99114

100115
/**
101-
* Cancels any notifications of this type previously shown using
102-
* {@link #notify(Context, boolean)}.
116+
* Cancels any notifications of this type previously shown
103117
*/
104118
public static void cancelSuccess(final Context context) {
105119
final NotificationManager nm = (NotificationManager) context

app/src/main/java/com/rockthevote/grommet/ui/registration/AdditionalInfoFragment.java

Lines changed: 35 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@
4747
import static com.rockthevote.grommet.data.db.model.ContactMethod.Type.EMAIL;
4848
import static com.rockthevote.grommet.data.db.model.ContactMethod.Type.PHONE;
4949
import static com.rockthevote.grommet.data.db.model.RockyRequest.Party;
50+
import static com.rockthevote.grommet.data.db.model.RockyRequest.Party.OTHER_PARTY;
5051
import static com.rockthevote.grommet.data.db.model.RockyRequest.Race;
5152
import static com.rockthevote.grommet.data.db.model.VoterId.Type.DRIVERS_LICENSE;
5253
import static com.rockthevote.grommet.data.db.model.VoterId.Type.SSN_LAST_FOUR;
@@ -55,8 +56,13 @@ public class AdditionalInfoFragment extends BaseRegistrationFragment {
5556

5657
@BindView(R.id.spinner_race) BetterSpinner raceSpinner;
5758

59+
@NotEmpty
5860
@BindView(R.id.spinner_party) BetterSpinner partySpinner;
5961

62+
@NotEmpty
63+
@BindView(R.id.til_other_party) TextInputLayout otherPartyTIL;
64+
@BindView(R.id.other_party_edit_text) EditText otherPartyEditText;
65+
6066
@BindView(R.id.preferred_language) EditText preferredLanguage;
6167

6268
@BindView(R.id.does_not_have_penn_dot_checkbox) CheckBox noPennDOTCheckbox;
@@ -125,6 +131,8 @@ public void onViewCreated(View view, Bundle savedInstanceState) {
125131

126132
validator = new ObservableValidator(this, getActivity());
127133

134+
135+
// Setup Race Spinner
128136
raceEnumAdapter = new EnumAdapter<>(getActivity(), Race.class);
129137
raceSpinner.setAdapter(raceEnumAdapter);
130138
raceSpinner.setOnItemClickListener((adapterView, view1, i, l) -> {
@@ -133,14 +141,27 @@ public void onViewCreated(View view, Bundle savedInstanceState) {
133141
});
134142
raceSpinner.getEditText().setText(Race.OTHER.toString());
135143

144+
145+
// Setup Party Spinner
136146
partyEnumAdapter = new EnumAdapter<>(getActivity(), Party.class);
137147
partySpinner.setAdapter(partyEnumAdapter);
138148
partySpinner.setOnItemClickListener((adapterView, view1, i, l) -> {
139-
partySpinner.getEditText().setText(partyEnumAdapter.getItem(i).toString());
149+
Party party = partyEnumAdapter.getItem(i);
150+
151+
partySpinner.getEditText().setText(party.toString());
140152
partySpinner.dismiss();
153+
154+
otherPartyTIL.setEnabled(OTHER_PARTY == party);
155+
otherPartyTIL.setVisibility(OTHER_PARTY == party ? View.VISIBLE : View.GONE);
156+
157+
// clear the error out for a new attempt
158+
if (OTHER_PARTY == party) {
159+
otherPartyTIL.setErrorEnabled(false);
160+
}
141161
});
142-
partySpinner.getEditText().setText(Party.OTHER.toString());
143162

163+
164+
// Setup Phone Type Spinner
144165
phoneTypeEnumAdapter = new EnumAdapter<>(getActivity(), RockyRequest.PhoneType.class);
145166
phoneTypeSpinner.setAdapter(phoneTypeEnumAdapter);
146167
phoneTypeSpinner.setOnItemClickListener((adapterView, view1, i, l) -> {
@@ -175,6 +196,18 @@ public void onResume() {
175196
RockyRequest._ID + " = ? ", String.valueOf(rockyRequestRowId.get()));
176197
}));
177198

199+
subscriptions.add(RxTextView.afterTextChangeEvents(otherPartyEditText)
200+
.observeOn(Schedulers.io())
201+
.skip(1)
202+
.debounce(DEBOUNCE, TimeUnit.MILLISECONDS)
203+
.subscribe(otherParty -> {
204+
db.update(RockyRequest.TABLE,
205+
new RockyRequest.Builder()
206+
.otherParty(otherParty.editable().toString())
207+
.build(),
208+
RockyRequest._ID + " = ? ", String.valueOf(rockyRequestRowId.get()));
209+
}));
210+
178211
subscriptions.add(RxTextView.afterTextChangeEvents(partySpinner.getEditText())
179212
.observeOn(Schedulers.io())
180213
.skip(1)

app/src/main/java/com/rockthevote/grommet/ui/registration/RegistrationActivity.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ private void setupViewPager() {
7070
adapter = new RegistrationPagerAdapter(getSupportFragmentManager(), this);
7171

7272
viewPager.setAdapter(adapter);
73-
viewPager.setOffscreenPageLimit(3);
73+
viewPager.setOffscreenPageLimit(4);
7474

7575
tabLayout.setupWithViewPager(viewPager);
7676

0 commit comments

Comments
 (0)