Skip to content

Commit

Permalink
Update county names.
Browse files Browse the repository at this point in the history
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
  • Loading branch information
Aaron Huttner authored and Aaron Huttner committed Aug 25, 2016
1 parent bc42e85 commit 039818d
Show file tree
Hide file tree
Showing 18 changed files with 304 additions and 111 deletions.
4 changes: 0 additions & 4 deletions .idea/misc.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

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 = 0
def versionPatch = 6
def versionPatch = 7
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 @@ -2,6 +2,8 @@

import com.squareup.moshi.Moshi;

import java.util.concurrent.TimeUnit;

import javax.inject.Named;
import javax.inject.Singleton;

Expand Down Expand Up @@ -51,6 +53,7 @@ public final class ApiModule {

// add the O-Auth interceptor here
static OkHttpClient.Builder createApiClient(OkHttpClient client) {
return client.newBuilder();
return client.newBuilder()
.connectTimeout(10000, TimeUnit.MILLISECONDS);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -152,31 +152,45 @@ private void doWork(final RockyRequest rockyRequest) {
stopSelf();
}
})
.subscribe(regResponse -> {
RockyRequest.Status status =
!regResponse.isError() && regResponse.response().isSuccessful()
? REGISTER_SUCCESS : REGISTER_SERVER_FAILURE;


UploadNotification.notify(getApplicationContext(), status);

db.update(RockyRequest.TABLE,
new RockyRequest.Builder()
.status(status)
.build(),
RockyRequest._ID + " = ? ", String.valueOf(rockyRequest.id()));
.subscribe(regResponse ->
{
if (regResponse.isError()) {
// there was an error contacting the server, don't delete the row
UploadNotification.notify(getApplicationContext(), REGISTER_SERVER_FAILURE);
} else {

RockyRequest.Status status;

if (regResponse.response().isSuccessful()) {
status = REGISTER_SUCCESS;
} else {
int code = regResponse.response().code();
if (code < 500) {
status = REGISTER_CLIENT_FAILURE;
} else {
status = REGISTER_SERVER_FAILURE;
}
}
updateRegistrationStatus(status, rockyRequest.id());
}
},
throwable -> {
// mark the row for removal if the data is corrupt
db.update(RockyRequest.TABLE,
new RockyRequest.Builder()
.status(REGISTER_CLIENT_FAILURE)
.build(),
RockyRequest._ID + " = ? ", String.valueOf(rockyRequest.id()));
// this is a client error, meaning the network request was never made
updateRegistrationStatus(REGISTER_CLIENT_FAILURE, rockyRequest.id());
}
);
}

private void updateRegistrationStatus(RockyRequest.Status status, long rowId) {
UploadNotification.notify(getApplicationContext(), status);
db.update(RockyRequest.TABLE,
new RockyRequest.Builder()
.status(status)
.build(),
RockyRequest._ID + " = ? ", String.valueOf(rowId));
}

/**
* check for <p>
* {@link RockyRequest.Status#ABANDONED},<p>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,19 @@ public static ApiVoterRegistration fromDb(RockyRequest rockyRequest,
List<ApiAdditionalInfo> additionalInfo,
ApiRegistrationHelper registrationHelper) {

return builder()
String party;
switch (rockyRequest.party()) {
case OTHER_PARTY:
party = rockyRequest.otherParty();
break;
default:
party = rockyRequest.party().toString();
break;
}

Builder builder = builder();

builder
.dateOfBirth(Dates.formatAsISO8601_ShortDate(rockyRequest.dateOfBirth()))
.mailingAddress(mailingAddress)
.previousRegistrationAddress(previousRegistrationAddress)
Expand All @@ -133,14 +145,18 @@ public static ApiVoterRegistration fromDb(RockyRequest rockyRequest,
.name(name)
.previousName(previousName)
.gender(Gender.fromPrefix(Prefix.fromString(name.titlePrefix())).toString())
.race(rockyRequest.race().toString())
.party(rockyRequest.party().toString())
.party(party)
.voterClassifications(voterClassifications)
.signature(signature)
.voterIds(voterIds)
.contactMethods(contactMethods)
.additionalInfo(additionalInfo)
.registrationHelper(registrationHelper)
.build();
;

if (null != rockyRequest.race()) {
builder.race(rockyRequest.race().toString());
}
return builder.build();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,8 @@ public class DbOpenHelper extends SQLiteOpenHelper {
+ RockyRequest.LONGITUDE + " REAL,"
+ RockyRequest.HAS_PREVIOUS_NAME + " INTEGER DEFAULT " + Db.BOOLEAN_FALSE + ","
+ RockyRequest.HAS_PREVIOUS_ADDRESS + " INTEGER DEFAULT " + Db.BOOLEAN_FALSE + ","
+ RockyRequest.HAS_ASSISTANT + " INTEGER DEFAULT " + Db.BOOLEAN_FALSE
+ RockyRequest.HAS_ASSISTANT + " INTEGER DEFAULT " + Db.BOOLEAN_FALSE + ","
+ RockyRequest.OTHER_PARTY + " TEXT "
+ ")";

private static final String CREATE_ADDRESS = ""
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ public abstract class RockyRequest implements Parcelable, BaseColumns {
public static final String HAS_PREVIOUS_NAME = "has_previous_name";
public static final String HAS_PREVIOUS_ADDRESS = "has_previous_address";
public static final String HAS_ASSISTANT = "has_assistant";
public static final String OTHER_PARTY = "other_party";

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

public abstract boolean hasMailingAddress();

@Nullable
public abstract Race race();

@Nullable
public abstract Party party();

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

public abstract boolean hasAssistant();

@Nullable
public abstract String otherParty();

public static final Func1<Cursor, RockyRequest> MAPPER = cursor -> {
long id = Db.getLong(cursor, _ID);
Status status = Status.fromString(Db.getString(cursor, STATUS));
Expand All @@ -136,12 +138,13 @@ public abstract class RockyRequest implements Parcelable, BaseColumns {
boolean hasPreviousName = Db.getBoolean(cursor, HAS_PREVIOUS_NAME);
boolean hasPreviousAddress = Db.getBoolean(cursor, HAS_PREVIOUS_ADDRESS);
boolean hasAssistant = Db.getBoolean(cursor, HAS_ASSISTANT);
String otherParty = Db.getString(cursor, OTHER_PARTY);

return new AutoValue_RockyRequest(id, status, language, phoneType, partnerId, optInEmail, optInSMS,
optInVolunteer, partnerOptInSMS, partnerOptInEmail,
sourceTrackingId, partnerTrackingId, openTrackingId,
generatedDate, dateOfBirth, hasMailingAddress, race, party, signature,
latitude, longitude, hasPreviousName, hasPreviousAddress, hasAssistant);
latitude, longitude, hasPreviousName, hasPreviousAddress, hasAssistant, otherParty);
};

public static final class Builder {
Expand Down Expand Up @@ -272,6 +275,11 @@ public Builder hasAssistant(boolean hasAssistant) {
return this;
}

public Builder otherParty(String otherParty) {
values.put(OTHER_PARTY, otherParty);
return this;
}

public ContentValues build() {
return values;
}
Expand Down Expand Up @@ -311,7 +319,8 @@ public static Race fromString(String race) {
public enum Party {
DEMOCRATIC("Democratic"),
REPUBLICAN("Republican"),
OTHER("Other");
NO_PARTY("none"),
OTHER_PARTY("Other");

private final String party;

Expand All @@ -330,7 +339,7 @@ public static Party fromString(String party) {
return val;
}
}
return OTHER;
return OTHER_PARTY;
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ public static void notify(final Context context, RockyRequest.Status status) {
new Intent(context, MainActivity.class),
PendingIntent.FLAG_UPDATE_CURRENT))
.setContentTitle(context.getString(getNotifTitle(status)))
.setContentText(context.getString(getContentText(status)))
.setSmallIcon(R.drawable.ic_stat_upload)
.setAutoCancel(false);

Expand All @@ -71,12 +72,26 @@ int getNotifTitle(RockyRequest.Status status) {
switch (status) {
case REGISTER_SUCCESS:
return R.string.upload_notification_title_success;
default:
case REGISTER_SERVER_FAILURE:
default:
return R.string.upload_notification_title_failure;
}
}

private static
@StringRes
int getContentText(RockyRequest.Status status) {
switch (status) {
case REGISTER_SUCCESS:
return R.string.upload_notification_content_success;
case REGISTER_CLIENT_FAILURE:
return R.string.upload_notification_content_client_failure;
case REGISTER_SERVER_FAILURE:
default:
return R.string.upload_notification_content_connection_failure;
}
}

private static int getNotificationId(RockyRequest.Status status) {
switch (status) {
case REGISTER_SUCCESS:
Expand All @@ -98,8 +113,7 @@ private static String getNotificationTag(RockyRequest.Status status) {
}

/**
* Cancels any notifications of this type previously shown using
* {@link #notify(Context, boolean)}.
* Cancels any notifications of this type previously shown
*/
public static void cancelSuccess(final Context context) {
final NotificationManager nm = (NotificationManager) context
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@
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.RockyRequest.Party;
import static com.rockthevote.grommet.data.db.model.RockyRequest.Party.OTHER_PARTY;
import static com.rockthevote.grommet.data.db.model.RockyRequest.Race;
import static com.rockthevote.grommet.data.db.model.VoterId.Type.DRIVERS_LICENSE;
import static com.rockthevote.grommet.data.db.model.VoterId.Type.SSN_LAST_FOUR;
Expand All @@ -55,8 +56,13 @@ public class AdditionalInfoFragment extends BaseRegistrationFragment {

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

@NotEmpty
@BindView(R.id.spinner_party) BetterSpinner partySpinner;

@NotEmpty
@BindView(R.id.til_other_party) TextInputLayout otherPartyTIL;
@BindView(R.id.other_party_edit_text) EditText otherPartyEditText;

@BindView(R.id.preferred_language) EditText preferredLanguage;

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

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


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


// Setup Party Spinner
partyEnumAdapter = new EnumAdapter<>(getActivity(), Party.class);
partySpinner.setAdapter(partyEnumAdapter);
partySpinner.setOnItemClickListener((adapterView, view1, i, l) -> {
partySpinner.getEditText().setText(partyEnumAdapter.getItem(i).toString());
Party party = partyEnumAdapter.getItem(i);

partySpinner.getEditText().setText(party.toString());
partySpinner.dismiss();

otherPartyTIL.setEnabled(OTHER_PARTY == party);
otherPartyTIL.setVisibility(OTHER_PARTY == party ? View.VISIBLE : View.GONE);

// clear the error out for a new attempt
if (OTHER_PARTY == party) {
otherPartyTIL.setErrorEnabled(false);
}
});
partySpinner.getEditText().setText(Party.OTHER.toString());


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

subscriptions.add(RxTextView.afterTextChangeEvents(otherPartyEditText)
.observeOn(Schedulers.io())
.skip(1)
.debounce(DEBOUNCE, TimeUnit.MILLISECONDS)
.subscribe(otherParty -> {
db.update(RockyRequest.TABLE,
new RockyRequest.Builder()
.otherParty(otherParty.editable().toString())
.build(),
RockyRequest._ID + " = ? ", String.valueOf(rockyRequestRowId.get()));
}));

subscriptions.add(RxTextView.afterTextChangeEvents(partySpinner.getEditText())
.observeOn(Schedulers.io())
.skip(1)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ private void setupViewPager() {
adapter = new RegistrationPagerAdapter(getSupportFragmentManager(), this);

viewPager.setAdapter(adapter);
viewPager.setOffscreenPageLimit(3);
viewPager.setOffscreenPageLimit(4);

tabLayout.setupWithViewPager(viewPager);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
import com.rockthevote.grommet.data.prefs.CurrentRockyRequestId;
import com.rockthevote.grommet.data.prefs.EventRegTotal;
import com.rockthevote.grommet.util.Dates;
import com.rockthevote.grommet.util.Images;
import com.squareup.sqlbrite.BriteDatabase;

import java.io.ByteArrayOutputStream;
Expand Down Expand Up @@ -197,7 +198,9 @@ public void onStartSigning() {
@Override
public void onSigned() {
ByteArrayOutputStream baos = new ByteArrayOutputStream();
signaturePad.getSignatureBitmap().compress(Bitmap.CompressFormat.PNG, 100, baos);
Bitmap image = (Images.aspectSafeScale(Images.transformAspectRatio(signaturePad.getSignatureBitmap(), 3, 1), 180, 60));
image.compress(Bitmap.CompressFormat.PNG, 100, baos);

db.update(RockyRequest.TABLE,
new RockyRequest.Builder()
.signature(baos.toByteArray())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ public class AddressView extends FrameLayout {

@BindView(R.id.spinner_state) BetterSpinner stateSpinner;

@Length(min = 5)
@Length(min = 5, max = 10)
@BindView(R.id.til_zip_code) TextInputLayout zipTIL;
@BindView(R.id.zip) EditText zipEditText;

Expand Down
Loading

0 comments on commit 039818d

Please sign in to comment.