Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
import java.util.HashSet;
import java.util.List;
import java.util.Set;
import java.util.TreeSet;
import java.util.regex.Pattern;

import androidx.annotation.NonNull;
Expand Down Expand Up @@ -425,22 +426,13 @@ public void onClick(View v) {
R.string.demo_previous_call_stats_one));
} else {
vh.numCalls.setText(mActivity.getResources().getString(
R.string.call_count_one));
R.string.call_count_today_one));
vh.previousCallStats.setVisibility(View.GONE);
}
return;
}

if (mAddressErrorType != NO_ERROR) {
// If there was an address error, clear the number of calls to make
vh.numCalls.setText("");
vh.numCalls.setVisibility(View.GONE);
vh.previousCallStats.setVisibility(View.GONE);
issue.contacts = null;
return;
}
vh.numCalls.setVisibility(View.VISIBLE);

// Sometimes an issue is shown with no contact areas in order to
// inform users that a major vote or change has happened.
if (issue.contactAreas.isEmpty()) {
Expand All @@ -450,6 +442,23 @@ public void onClick(View v) {
return;
}

if (mAddressErrorType != NO_ERROR) {
// If there was an address error, show generic info about the number
// of calls to make.
String contactAreaText = areasToCallsOverviewString(
mActivity.getApplicationContext(), issue.contactAreas);
if (TextUtils.isEmpty(contactAreaText)) {
vh.numCalls.setText("");
vh.numCalls.setVisibility(View.GONE);
} else {
vh.numCalls.setText(mActivity.getResources().getString(R.string.calls_to_make,
contactAreaText));
}
vh.previousCallStats.setVisibility(View.GONE);
issue.contacts = null;
return;
}

populateIssueContacts(issue);
displayPreviousCallStats(issue, vh);
} else if (type == VIEW_TYPE_EMPTY_REQUEST) {
Expand Down Expand Up @@ -525,49 +534,67 @@ private void displayPreviousCallStats(Issue issue, IssueViewHolder vh) {
.getDatabaseHelper();
// Calls ever made.
int totalUserCalls = dbHelper.getTotalCallsForIssueAndContacts(issue.id, issue.contacts);
// Calls per day.
int totalDayCalls = issue.contacts.size();

// Calls today only.
int callsLeft = issue.contacts.size();
for (Contact contact : issue.contacts) {
if(dbHelper.hasCalledToday(issue.id, contact.id)) {
callsLeft--;
}
}
if (totalUserCalls == 0) {
// If the user is somewhere like DC, which doesn't have all the contact areas,
// don't even tell them about those areas.
List<String> actualContactAreas = new ArrayList<>();
for (Contact contact : issue.contacts) {
actualContactAreas.add(contact.area);
}
String contactAreaText = areasToCallsOverviewString(mActivity.getApplicationContext(),
actualContactAreas);

// The user has never called on this issue before. Show a simple number of calls
// text, without the word "today".
vh.previousCallStats.setVisibility(View.GONE);
if (callsLeft == 1) {
vh.numCalls.setText(
mActivity.getResources().getString(R.string.call_count_one));
if (totalDayCalls == 0) {
vh.numCalls.setText(mActivity.getResources().getString(
R.string.call_count_zero));
} else if (totalDayCalls == 1) {
vh.numCalls.setText(mActivity.getResources().getString(
R.string.call_count_one, contactAreaText));
} else {
vh.numCalls.setText(String.format(
mActivity.getResources().getString(R.string.call_count), callsLeft));
vh.numCalls.setText(mActivity.getResources().getString(
R.string.call_count, totalDayCalls, contactAreaText));
}
} else {
vh.previousCallStats.setVisibility(View.VISIBLE);
return;
}

// Previous call stats
if (totalUserCalls == 1) {
vh.previousCallStats.setText(mActivity.getResources().getString(
R.string.previous_call_count_one));
} else {
vh.previousCallStats.setText(
mActivity.getResources().getString(
R.string.previous_call_count_many, totalUserCalls));
// Calls today only.
int callsLeft = totalDayCalls;
for (Contact contact : issue.contacts) {
if(dbHelper.hasCalledToday(issue.id, contact.id)) {
callsLeft--;
}
}

// Calls to make today.
if (callsLeft == 0) {
vh.numCalls.setText(
mActivity.getResources().getString(R.string.call_count_today_done));
} else if (callsLeft == 1) {
vh.numCalls.setText(
mActivity.getResources().getString(R.string.call_count_today_one));
} else {
vh.numCalls.setText(String.format(
mActivity.getResources().getString(R.string.call_count_today), callsLeft));
}
// Previous call stats
vh.previousCallStats.setVisibility(View.VISIBLE);
if (totalUserCalls == 1) {
vh.previousCallStats.setText(mActivity.getResources().getString(
R.string.previous_call_count_one));
} else {
vh.previousCallStats.setText(
mActivity.getResources().getString(
R.string.previous_call_count_many, totalUserCalls));
}

// Calls to make today.
if (callsLeft == 0) {
vh.numCalls.setText(
mActivity.getResources().getString(R.string.call_count_today_done));
return;
}

if (callsLeft == 1) {
vh.numCalls.setText(mActivity.getResources().getString(
R.string.call_count_today_one));
} else {
vh.numCalls.setText(mActivity.getResources().getString(
R.string.call_count_today, callsLeft));
}
}

Expand Down Expand Up @@ -669,4 +696,57 @@ ArrayList<Issue> sortIssuesWithMetaPriority(List<Issue> issues) {

return result;
}

public static String areasToCallsOverviewString(Context context, List<String> areas) {
if (areas == null || areas.isEmpty()) {
return "";
}

boolean hasStateUpper = areas.contains(Contact.AREA_STATE_UPPER);
boolean hasStateLower = areas.contains(Contact.AREA_STATE_LOWER);

Set<String> formattedLabels = new TreeSet<>();
for (String area : areas) {
boolean isStateArea = Contact.AREA_STATE_UPPER.equals(area) ||
Contact.AREA_STATE_LOWER.equals(area);
if (isStateArea && hasStateUpper && hasStateLower) {
formattedLabels.add(context.getString(R.string.state_reps));
} else if (isStateArea) {
formattedLabels.add(context.getString(R.string.state_rep));
} else {
formattedLabels.add(areaToNiceString(context, area));
}
}

StringBuilder resultBuilder = new StringBuilder();
boolean isFirst = true;
for (String label : formattedLabels) {
if (!isFirst) {
resultBuilder.append(", ");
}
resultBuilder.append(label);
isFirst = false;
}

return resultBuilder.toString();
}

/**
* Converts an area name to a generic office name that can be used in the interface.
*/
public static String areaToNiceString(Context context, String area) {
return switch (area) {
case Contact.AREA_HOUSE -> context.getString(R.string.house_rep);
case Contact.AREA_SENATE -> context.getString(R.string.senators);

// State legislatures call themselves different things by state,
// so let's use a generic term for all of them
case Contact.AREA_STATE_UPPER, Contact.AREA_STATE_LOWER -> context.getString(R.string.state_reps);
case Contact.AREA_GOVERNOR -> context.getString(R.string.governor);
case Contact.AREA_ATTORNEY_GENERAL -> context.getString(R.string.attorneys_general);
case Contact.AREA_SECRETARY_OF_STATE -> context.getString(R.string.secretary_of_state);
default -> area;
};
}
}

Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ public class Contact implements Parcelable {
public static final String AREA_STATE_LOWER = "StateLower";
public static final String AREA_STATE_UPPER = "StateUpper";
public static final String AREA_GOVERNOR = "Governor";
public static final String AREA_ATTORNEY_GENERAL = "AttorneyGeneral";
public static final String AREA_ATTORNEY_GENERAL = "AttorneysGeneral";
public static final String AREA_SECRETARY_OF_STATE = "SecretaryOfState";

// Used to show the placeholder contact for the demonstration issue.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ private static Pattern wholeRegex(Pattern introPattern) {
case Contact.AREA_SENATE, SENATE -> context.getString(R.string.title_us_senate);
case Contact.AREA_STATE_LOWER, Contact.AREA_STATE_UPPER -> context.getString(R.string.title_state_rep);
case Contact.AREA_GOVERNOR -> context.getString(R.string.title_governor);
case Contact.AREA_ATTORNEY_GENERAL -> context.getString(R.string.title_attorney_general);
case Contact.AREA_ATTORNEY_GENERAL -> context.getString(R.string.title_attorneys_general);
case Contact.AREA_SECRETARY_OF_STATE -> context.getString(R.string.title_secretary_of_state);
default -> null;
};
Expand Down
19 changes: 17 additions & 2 deletions 5calls/app/src/main/res/values-es/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,13 @@
<string name="json_error">Error: Datos inválidos o inexistentes para esta ubicación</string>

<!-- Message telling a user how many calls they still need to make on a particular issue [CHAR_LIMIT=30] -->
<string name="call_count"><xliff:g id="callCount">%1$d</xliff:g> llamadas por hacer</string>
<string name="call_count"><xliff:g id="callCount">%1$d</xliff:g> llamadas: <xliff:g id="area">%2$s</xliff:g></string>

<!-- Message telling a user they have no calls to make on a particular issue (because of their address) [CHAR_LIMIT=30] -->
<string name="call_count_zero">0 llamadas por hacer</string>

<!-- Message telling a user they sill have one call to make on a particular issue [CHAR_LIMIT=30] -->
<string name="call_count_one">1 llamada por hacer</string>
<string name="call_count_one">1 llamada: <xliff:g id="area">%1$s</xliff:g></string>

<!-- Message telling a user how many calls they still need to make on a particular issue today [CHAR_LIMIT=none] -->
<string name="call_count_today"><xliff:g id="callCount">%1$d</xliff:g> llamadas por hacer hoy</string>
Expand Down Expand Up @@ -527,6 +530,18 @@
<!-- Button linking to the privacy policy [CHAR_LIMIT=30] -->
<string name="privacy_btn">Política de privacidad</string>

<!-- Strings describing various contact roles. -->
<string name="house_rep">Representante</string>
<string name="senators">Senadores</string>
<string name="state_reps">Representantes Estatales</string>
<string name="state_rep">Representante Estatal</string>
<string name="governor">Gobernador</string>
<string name="attorneys_general">Fiscal General</string>
<string name="secretary_of_state">Secretario de Estado</string>

<!-- String describing which contact roles will need to be called. -->
<string name="calls_to_make">Llamar a <xliff:g id="contact_areas">%1$s</xliff:g></string>

<!-- Title of the section inviting users to sign up for the newsletter. -->
<string name="newsletter_signup_title">Obtenga actualizaciones sobre temas más recientes</string>

Expand Down
21 changes: 18 additions & 3 deletions 5calls/app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,13 @@
<string name="json_error">Error: Invalid or no data for this location. Try again later.</string>

<!-- Message telling a user how many calls they still need to make on a particular issue [CHAR_LIMIT=30] -->
<string name="call_count"><xliff:g id="callCount">%1$d</xliff:g> calls to make</string>
<string name="call_count"><xliff:g id="callCount">%1$d</xliff:g> calls: <xliff:g id="area">%2$s</xliff:g></string>

<!-- Message telling a user they have no calls to make on a particular issue (because of their address) [CHAR_LIMIT=30] -->
<string name="call_count_zero">0 calls to make</string>

<!-- Message telling a user they sill have one call to make on a particular issue [CHAR_LIMIT=30] -->
<string name="call_count_one">1 call to make</string>
<string name="call_count_one">1 call: <xliff:g id="area">%1$s</xliff:g></string>

<!-- Message telling a user how many calls they still need to make on a particular issue today [CHAR_LIMIT=none] -->
<string name="call_count_today"><xliff:g id="callCount">%1$d</xliff:g> calls to make today</string>
Expand Down Expand Up @@ -626,9 +629,21 @@
<string name="title_us_senate" translatable="false">Senator</string>
<string name="title_state_rep" translatable="false">Legislator</string>
<string name="title_governor" translatable="false">Governor</string>
<string name="title_attorney_general" translatable="false">Attorney General</string>
<string name="title_attorneys_general" translatable="false">Attorney General</string>
<string name="title_secretary_of_state" translatable="false">Secretary of State</string>

<!-- Strings describing various contact roles. -->
<string name="house_rep">House Rep</string>
<string name="senators">Senators</string>
<string name="state_reps">State Reps</string>
<string name="state_rep">State Rep</string>
<string name="governor">Governor</string>
<string name="attorneys_general">Attorney General</string>
<string name="secretary_of_state">Secretary of State</string>

<!-- String describing which contact roles will need to be called. -->
<string name="calls_to_make">Call <xliff:g id="contact_areas">%1$s</xliff:g></string>

<!-- Title of the section inviting users to sign up for the newsletter. -->
<string name="newsletter_signup_title">Get updates on the latest issues</string>

Expand Down
1 change: 1 addition & 0 deletions 5calls/app/src/main/res/values/styles.xml
Original file line number Diff line number Diff line change
Expand Up @@ -290,6 +290,7 @@
<style name="issueCallCountStyle" parent="Widget.FiveCalls.TextView.Paragraph.PrimaryDark">
<item name="android:paddingTop">4dp</item>
<item name="android:paddingBottom">4dp</item>
<item name="android:paddingEnd">48dp</item>
<item name="android:textStyle">bold</item>
</style>

Expand Down
Loading