Skip to content

Commit

Permalink
Merge pull request #602 from opensrp/spinner-fix
Browse files Browse the repository at this point in the history
added spinner inflation fix in android 5.0
  • Loading branch information
ndegwamartin authored Sep 21, 2021
2 parents 7cc5855 + 0040683 commit 64081d2
Show file tree
Hide file tree
Showing 5 changed files with 55 additions and 18 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -219,17 +219,27 @@ public void fetchFields(List<View> viewsFromJson, String stepName, JsonFormFragm
}
}

private void fetchViews(List<View> viewsFromJson, String stepName, JsonFormFragment formFragment,
String type, JSONObject jsonObject, CommonListener listener, Boolean popup) {
private void fetchViews(final List<View> viewsFromJson, final String stepName, final JsonFormFragment formFragment,
final String type, final JSONObject jsonObject, final CommonListener listener, final Boolean popup) {
try {
FormWidgetFactory formWidgetFactory = map.get(type);
if (formWidgetFactory != null) {
List<View> views = formWidgetFactory
.getViewsFromJson(stepName, formFragment.getActivity(), formFragment, jsonObject, listener, popup);
if (views.size() > 0) {
viewsFromJson.addAll(views);
formFragment.getJsonApi().getAppExecutors().mainThread().execute(new Runnable() {
@Override
public void run() {
FormWidgetFactory formWidgetFactory = map.get(type);
if (formWidgetFactory != null) {
List<View> views = null;
try {
views = formWidgetFactory.getViewsFromJson(stepName, formFragment.getActivity(), formFragment, jsonObject, listener, popup);
} catch (Exception e) {
e.printStackTrace();
}
if (views.size() > 0) {
viewsFromJson.addAll(views);
}
}
}
}
});

} catch (RuntimeException e) {
closeActivityAfterRuntimeException(formFragment, e);
} catch (Exception e) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
/**
* Created by Vincent Karuri on 09/12/2020
*/
@LooperMode(PAUSED)

public class JsonFormInteractorTest extends BaseTest {

private JsonFormInteractor jsonFormInteractor;
Expand All @@ -59,7 +59,7 @@ public void testFetchViewsShouldSetCorrectResultForRTE() throws Exception {
JsonFormFragment jsonFormFragment = Mockito.mock(JsonFormFragment.class);
Mockito.doReturn(activity).when(jsonFormFragment).getActivity();
Mockito.doReturn(activity).when(jsonFormFragment).getJsonApi();

shadowOf(getMainLooper()).idle();
Whitebox.invokeMethod(jsonFormInteractor, "fetchViews", new ArrayList<View>(), "",
jsonFormFragment, "", null, Mockito.mock(CommonListener.class), false);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -321,13 +321,13 @@ public void testOnNextClickReturnsFalseIfFormIsInvalid() {
@Test
public void testValidateAndWriteValuesWithInvalidFields() throws InterruptedException {
initWithActualForm();
presenter.validateAndWriteValues();
shadowOf(getMainLooper()).idle();
presenter.validateAndWriteValues();
assertEquals(2, presenter.getInvalidFields().size());
assertEquals("Please enter the last name", presenter.getInvalidFields().get("step1#Basic Form One:user_last_name").getErrorMessage());
assertEquals("Please enter the sex", presenter.getInvalidFields().get("step1#Basic Form One:user_spinner").getErrorMessage());
shadowOf(getMainLooper()).idle();
verify(formFragment, times(1)).writeValue(anyString(), anyString(), anyString(), anyString(), anyString(),
verify(formFragment, times(2)).writeValue(anyString(), anyString(), anyString(), anyString(), anyString(),
anyString(), anyBoolean());
verify(onFieldsInvalid, times(1)).passInvalidFields(presenter.getInvalidFields());
}
Expand All @@ -347,7 +347,7 @@ public void testValidateAndWriteValues() throws InterruptedException {
presenter.validateAndWriteValues();
shadowOf(getMainLooper()).idle();
assertEquals(0, presenter.getInvalidFields().size());
verify(formFragment, times(3)).writeValue(anyString(), anyString(), anyString(), anyString(), anyString(),
verify(formFragment, times(4)).writeValue(anyString(), anyString(), anyString(), anyString(), anyString(),
anyString(), anyBoolean());
verify(onFieldsInvalid, times(2)).passInvalidFields(presenter.getInvalidFields());
}
Expand All @@ -370,7 +370,7 @@ public void testOnSaveClickDisplaysErrorFragmentAndDisplaysToast() throws Interr
assertEquals(2, presenter.getInvalidFields().size());
assertEquals("Please enter the last name", presenter.getInvalidFields().get("step1#Basic Form One:user_last_name").getErrorMessage());
assertEquals("Please enter the sex", presenter.getInvalidFields().get("step1#Basic Form One:user_spinner").getErrorMessage());
verify(formFragment, times(1)).writeValue(anyString(), anyString(), anyString(), anyString(), anyString(),
verify(formFragment, times(2)).writeValue(anyString(), anyString(), anyString(), anyString(), anyString(),
anyString(), anyBoolean());
assertTrue(presenter.getErrorFragment().isVisible());
Toast toast = ShadowToast.getLatestToast();
Expand All @@ -390,7 +390,7 @@ public void testOnSaveClickFinishesForm() throws JSONException, InterruptedExcep
presenter.onSaveClick(formFragment.getMainView());
shadowOf(getMainLooper()).idle();
assertEquals(0, presenter.getInvalidFields().size());
verify(formFragment, times(1)).writeValue(anyString(), anyString(), anyString(), anyString(), anyString(),
verify(formFragment, times(2)).writeValue(anyString(), anyString(), anyString(), anyString(), anyString(),
anyString(), anyBoolean());
assertNull(presenter.getErrorFragment());
assertNull(ShadowToast.getLatestToast());
Expand Down Expand Up @@ -418,7 +418,7 @@ public void testOnSaveClickErrorFragmentDisabledAndDisplaysSnackbar() throws JSO
assertEquals(2, presenter.getInvalidFields().size());
assertEquals("Please enter the last name", presenter.getInvalidFields().get("step1#Basic Form One:user_last_name").getErrorMessage());
assertEquals("Please enter the sex", presenter.getInvalidFields().get("step1#Basic Form One:user_spinner").getErrorMessage());
verify(formFragment, times(1)).writeValue(anyString(), anyString(), anyString(), anyString(), anyString(),
verify(formFragment, times(2)).writeValue(anyString(), anyString(), anyString(), anyString(), anyString(),
anyString(), anyBoolean());
assertNull(presenter.getErrorFragment());
assertNull(ShadowToast.getLatestToast());
Expand Down
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
VERSION_NAME=2.1.8-SNAPSHOT
VERSION_NAME=2.1.9-SNAPSHOT
VERSION_CODE=1
GROUP=org.smartregister
POM_SETTING_DESCRIPTION=OpenSRP Client Native Form Json Wizard
Expand Down
27 changes: 27 additions & 0 deletions sample/src/main/assets/json.form/basic_form.json
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,33 @@
"uploadButtonText": "Verify finger print",
"image_file": ""
},

{
"key": "Sex",
"openmrs_entity_parent": "",
"openmrs_entity": "",
"openmrs_entity_id": "",
"type": "spinner",
"hint": "hint",
"options": [
{
"key": "male",
"text": "male",
"openmrs_entity": "",
"openmrs_entity_id": ""
},
{
"key": "female",
"text": "female",
"openmrs_entity": "",
"openmrs_entity_id": ""
}
],
"v_required": {
"value": "true",
"err": "please select the gender"
}
},
{
"key": "user_first_name",
"openmrs_entity_parent": "",
Expand Down

0 comments on commit 64081d2

Please sign in to comment.