Skip to content
This repository has been archived by the owner on Jun 9, 2022. It is now read-only.

Commit

Permalink
Merge pull request #192 from andreweskeclarke/master
Browse files Browse the repository at this point in the history
Use title fields to display children and enquiries
  • Loading branch information
andreweskeclarke committed Oct 22, 2014
2 parents bb15955 + f2aa29c commit 63446e5
Show file tree
Hide file tree
Showing 7 changed files with 52 additions and 7 deletions.
1 change: 1 addition & 0 deletions RapidFTR-Android/res/values/styles.xml
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,7 @@
<item name="android:paddingTop">2dp</item>
<item name="android:paddingRight">5dp</item>
<item name="android:paddingBottom">3dp</item>
<item name="android:textStyle">bold</item>
</style>

<style name="childname">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,13 +26,15 @@ public class HighlightedFieldsViewAdapter<T extends BaseModel> extends BaseModel
protected Map<Integer, FormField> highlightedFields;
private FormService formService;
private Class<CollectionActivity> activityToLaunch;
private final List<FormField> titleFields;

public HighlightedFieldsViewAdapter(Context context, List<T> baseModels, String formName, Class<CollectionActivity> activityToLaunch) {
super(context, R.layout.row_highlighted_fields, baseModels);

formService = RapidFtrApplication.getApplicationInstance().getBean(FormService.class);

List<FormField> fields = formService.getHighlightedFields(formName);
titleFields = formService.getTitleFields(formName);

highlightedFields = new TreeMap<Integer, FormField>();
this.activityToLaunch = activityToLaunch;
Expand Down Expand Up @@ -61,7 +63,7 @@ public View getView(int position, View convertView, ViewGroup viewGroup){

ImageView imageView = (ImageView) view.findViewById(R.id.thumbnail);
try {
setFields(String.valueOf(baseModel.getShortId()), uniqueIdView);
setFields(String.valueOf(buildTitle(baseModel)), uniqueIdView);
assignThumbnail(baseModel, imageView);

view.setOnClickListener(createClickListener(baseModel, activityToLaunch));
Expand All @@ -71,4 +73,19 @@ public View getView(int position, View convertView, ViewGroup viewGroup){
}
return view;
}

private String buildTitle(T baseModel) throws JSONException {
if(titleFields.size() == 0) {
return baseModel.getShortId();
}
StringBuilder titleBuilder = new StringBuilder();
for (int i = 0; i < titleFields.size(); i++) {
FormField titleField = titleFields.get(i);
titleBuilder.append(baseModel.optString(titleField.getId()));
if((i + 1) < titleFields.size()) {
titleBuilder.append(" ");
}
}
return String.format("%s (%s)", titleBuilder.toString(), baseModel.getShortId());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,9 @@ public class FormField {
@JsonProperty("highlight_information")
private HighlightInfo highlightInfo;

@JsonProperty("title_field")
private boolean titleField;

private boolean editable;

private String type;
Expand Down
12 changes: 12 additions & 0 deletions RapidFTR-Android/src/main/java/com/rapidftr/forms/FormSection.java
Original file line number Diff line number Diff line change
Expand Up @@ -64,4 +64,16 @@ public List<FormField> getOrderedHighLightedFields() {

return Arrays.asList(sortedFormFields.values().toArray(new FormField[]{}));
}

public List<FormField> getOrderedTitleFields() {
SortedMap<Integer, FormField> sortedFormFields = new TreeMap<Integer, FormField>();
for (FormField formField : fields) {
if (formField.isTitleField() && formField.getHighlightInfo() != null && formField.getHighlightInfo().getHighlighted()) {
Integer order = Integer.parseInt(formField.getHighlightInfo().getOrder());
sortedFormFields.put(order, formField);
}
}

return Arrays.asList(sortedFormFields.values().toArray(new FormField[]{}));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import com.google.common.collect.Lists;
import com.rapidftr.RapidFtrApplication;
import com.rapidftr.database.Database;
import com.rapidftr.forms.Form;
import com.rapidftr.repository.ChildRepository;
import com.rapidftr.repository.EnquiryRepository;
import com.rapidftr.repository.PotentialMatchRepository;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -109,4 +109,15 @@ public List<FormField> getHighlightedFields(String formName) {
return formFields;
}

public List<FormField> getTitleFields(String formName) {
List<FormField> formFields = new ArrayList<FormField>();

List<FormSection> formSections = getFormSections(formName);
for (FormSection formSection : formSections) {
formFields.addAll(formSection.getOrderedTitleFields());
}

return formFields;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -27,14 +27,14 @@ public class CustomTestRunner extends RobolectricTestRunner {

public static List<FormSection> formSectionSeed = Arrays.asList(
new FormSection(new HashMap<String, String>(){{put("en", "Section 1");}}, 1, true, new HashMap<String, String>(){{put("en", "Section Help 1");}}, Arrays.asList(
new FormField("f1", null, true, "text_field", new HashMap<String, String>(){{put("en", "Field 1");}}, new HashMap<String, String>(){{put("en", "Help 1");}}, null, null),
new FormField("f2", null, true, "textarea", new HashMap<String, String>(){{put("en", "Field 2");}}, new HashMap<String, String>(){{put("en", "Help 2");}}, null, null),
new FormField("f3", null, true, "numeric_field", new HashMap<String, String>(){{put("en", "Field 3");}}, new HashMap<String, String>(){{put("en", "Help 3");}}, null, null)
new FormField("f1", null, false, true, "text_field", new HashMap<String, String>(){{put("en", "Field 1");}}, new HashMap<String, String>(){{put("en", "Help 1");}}, null, null),
new FormField("f2", null, false, true, "textarea", new HashMap<String, String>(){{put("en", "Field 2");}}, new HashMap<String, String>(){{put("en", "Help 2");}}, null, null),
new FormField("f3", null, false, true, "numeric_field", new HashMap<String, String>(){{put("en", "Field 3");}}, new HashMap<String, String>(){{put("en", "Help 3");}}, null, null)
)),
new FormSection(new HashMap<String, String>(){{put("en", "Section 2");}}, 1, true, new HashMap<String, String>(){{put("en", "Section Help 2");}}, Arrays.asList(
new FormField("f4", null, true, "radio_button", new HashMap<String, String>(){{put("en", "Field 4");}}, new HashMap<String, String>(){{put("en", "Help 4");}}, new HashMap<String, List<String>>(){{put("en", Arrays.asList("radio1", "radio2", "radio3"));}}, null),
new FormField("f5", null, true, "check_boxes", new HashMap<String, String>(){{put("en", "Field 5");}}, new HashMap<String, String>(){{put("en", "Help 5");}}, new HashMap<String, List<String>>(){{put("en", Arrays.asList("check1", "check2", "check3"));}}, null),
new FormField("f6", null, true, "date_field", new HashMap<String, String>(){{put("en", "Field 6");}}, new HashMap<String, String>(){{put("en", "Help 6");}}, null, null)
new FormField("f4", null, false, true, "radio_button", new HashMap<String, String>(){{put("en", "Field 4");}}, new HashMap<String, String>(){{put("en", "Help 4");}}, new HashMap<String, List<String>>(){{put("en", Arrays.asList("radio1", "radio2", "radio3"));}}, null),
new FormField("f5", null, false, true, "check_boxes", new HashMap<String, String>(){{put("en", "Field 5");}}, new HashMap<String, String>(){{put("en", "Help 5");}}, new HashMap<String, List<String>>(){{put("en", Arrays.asList("check1", "check2", "check3"));}}, null),
new FormField("f6", null, false, true, "date_field", new HashMap<String, String>(){{put("en", "Field 6");}}, new HashMap<String, String>(){{put("en", "Help 6");}}, null, null)
))
);

Expand Down

0 comments on commit 63446e5

Please sign in to comment.